array/formatters.hpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9  ** Ifdefs
10  *****************************************************************************/
11 
12 #ifndef ECL_CONTAINERS_ARRAY_FORMATTERS_HPP_
13 #define ECL_CONTAINERS_ARRAY_FORMATTERS_HPP_
14 
15 /*****************************************************************************
16  ** Includes
17  *****************************************************************************/
18 
19 #include <cmath>
20 #include <ecl/config/macros.hpp>
24 #include "../common/formatters.hpp"
25 #include "../array.hpp"
26 
27 /*****************************************************************************
28  ** Namespaces
29  *****************************************************************************/
30 
31 namespace ecl
32 {
33 namespace formatters
34 {
35 
36 /*****************************************************************************
37  ** Using
38  *****************************************************************************/
39 
63 template<typename Type, size_t N>
64 class ECL_PUBLIC ArrayFormatter
65 {
66 public:
67  virtual ~ArrayFormatter()
68  {}
76  return array;
77  }
78 };
79 
80 /*****************************************************************************
81  ** Interface [ByteArrayFormatter]
82  *****************************************************************************/
83 
106 template<typename Byte, size_t N>
108 {
109 public:
117  ByteArrayFormatter() : ready_to_format(false)
118  {};
127  {
128  begin_iterator = array.begin();
129  end_iterator = array.end();
130  ready_to_format = true;
131  return *this;
132  }
141  {
142  begin_iterator = stencil.begin();
143  end_iterator = stencil.end();
144  ready_to_format = true;
145  return *this;
146  }
159  typename Array<Byte,N>::const_iterator end_iter
160  )
161  {
162 
163  begin_iterator = begin_iter;
164  end_iterator = end_iter;
165  ready_to_format = true;
166  return *this;
167  }
168 
170  {}
181  template <typename OutputStream, typename CharType, size_t M>
182  friend OutputStream& operator << (OutputStream& ostream, const ByteArrayFormatter<CharType,M> &formatter);
183 
184 private:
188 };
189 
190 /*****************************************************************************
191  ** Implementation [ByteArrayFormatter]
192  *****************************************************************************/
193 
194 template <typename OutputStream, typename CharType, size_t M>
195 OutputStream& operator <<(OutputStream& ostream, const ByteArrayFormatter<CharType, M> &formatter)
196 {
197  ecl_assert_throw(formatter.ready_to_format, StandardException(LOC,UsageError,"The formatter cannot print any data - "
198  "either there is no data available, or you have tried to use the "
199  "formatter more than once in a single streaming operation. "
200  "C++ produces unspecified results when functors are used multiply "
201  "in the same stream sequence, so this is not permitted here.") );
202 
205 ostream << "[ ";
206  for ( iter = formatter.begin_iterator; iter != formatter.end_iterator; ++iter )
207  {
208  ostream << format(*iter) << " ";
209  }
210  ostream << "]";
211  ostream.flush();
212  return ostream;
213 }
214 
215 /*****************************************************************************
216  ** Specialisations [ArrayFormatter][Char Types]
217  *****************************************************************************/
231 template<size_t N>
232 class ECL_PUBLIC ArrayFormatter< signed char,N > : public ByteArrayFormatter<signed char, N>
233 {};
234 
248 template<size_t N>
249 class ECL_PUBLIC ArrayFormatter< char,N > : public ByteArrayFormatter<char, N>
250 {};
251 
265 template<size_t N>
266 class ECL_PUBLIC ArrayFormatter< unsigned char,N > : public ByteArrayFormatter<unsigned char, N>
267 {
268 };
269 
279 template<size_t N>
280 class ECL_PUBLIC ArrayFormatter< float,N > : public FloatContainerFormatter< Array<float,N> >
281 {
282 public:
291  ArrayFormatter(const int p=2, const int w=-1) : FloatContainerFormatter< Array<float,N> >(p,w)
292  {};
293  virtual ~ArrayFormatter()
294  {}
295 };
296 
306 template<size_t N>
307 class ECL_PUBLIC ArrayFormatter< double,N > : public FloatContainerFormatter< Array<double,N> >
308 {
309 public:
318  ArrayFormatter(const int p=2, const int w=-1) : FloatContainerFormatter< Array<double,N> >(p,w)
319  {};
320  virtual ~ArrayFormatter()
321  {}
322 };
323 
324 } // namespace formatters
325 } // namespace ecl
326 
327 #endif /* ECL_CONTAINERS_ARRAY_FORMATTERS_HPP_ */
Fixed size container with a few bells and whistles.
const Type * const_iterator
Embedded control libraries.
Array< Byte, N >::const_iterator end_iterator
Array< Byte, N >::const_iterator begin_iterator
#define LOC
ArrayFormatter(const int p=2, const int w=-1)
Default constructor.
#define ecl_assert_throw(expression, exception)
ArrayFormatter(const int p=2, const int w=-1)
Default constructor.
ByteArrayFormatter< Byte, N > & operator()(const Stencil< Array< Byte, N > > &stencil)
Pseudo formatter for integral type arrays.
UsageError
ByteArrayFormatter< Byte, N > & operator()(const Array< Byte, N > &array)
A safe windowing class that opens onto array-like containers.
Parent template for the byte array formatters.
Parent interface for formatters of fixed size float/double containers.
ecl::Array< Type, N > & operator()(ecl::Array< Type, N > &array)
#define ECL_PUBLIC
ByteArrayFormatter< Byte, N > & operator()(typename Array< Byte, N >::const_iterator begin_iter, typename Array< Byte, N >::const_iterator end_iter)
Formats on a window of the array.


ecl_containers
Author(s): Daniel Stonier
autogenerated on Mon Feb 28 2022 22:18:43