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
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) ecl_assert_throw_decl(StandardException);
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)
197 {
198  ecl_assert_throw(formatter.ready_to_format, StandardException(LOC,UsageError,"The formatter cannot print any data - "
199  "either there is no data available, or you have tried to use the "
200  "formatter more than once in a single streaming operation. "
201  "C++ produces unspecified results when functors are used multiply "
202  "in the same stream sequence, so this is not permitted here.") );
203 
206 ostream << "[ ";
207  for ( iter = formatter.begin_iterator; iter != formatter.end_iterator; ++iter )
208  {
209  ostream << format(*iter) << " ";
210  }
211  ostream << "]";
212  ostream.flush();
213  return ostream;
214 }
215 
216 /*****************************************************************************
217  ** Specialisations [ArrayFormatter][Char Types]
218  *****************************************************************************/
232 template<size_t N>
233 class ECL_PUBLIC ArrayFormatter< signed char,N > : public ByteArrayFormatter<signed char, N>
234 {};
235 
249 template<size_t N>
250 class ECL_PUBLIC ArrayFormatter< char,N > : public ByteArrayFormatter<char, N>
251 {};
252 
266 template<size_t N>
267 class ECL_PUBLIC ArrayFormatter< unsigned char,N > : public ByteArrayFormatter<unsigned char, N>
268 {
269 };
270 
280 template<size_t N>
281 class ECL_PUBLIC ArrayFormatter< float,N > : public FloatContainerFormatter< Array<float,N> >
282 {
283 public:
292  ArrayFormatter(const int p=2, const int w=-1) : FloatContainerFormatter< Array<float,N> >(p,w)
293  {};
294  virtual ~ArrayFormatter()
295  {}
296 };
297 
307 template<size_t N>
308 class ECL_PUBLIC ArrayFormatter< double,N > : public FloatContainerFormatter< Array<double,N> >
309 {
310 public:
319  ArrayFormatter(const int p=2, const int w=-1) : FloatContainerFormatter< Array<double,N> >(p,w)
320  {};
321  virtual ~ArrayFormatter()
322  {}
323 };
324 
325 } // namespace formatters
326 } // namespace ecl
327 
328 #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)
ByteArrayFormatter< Byte, N > & operator()(typename Array< Byte, N >::const_iterator begin_iter, typename Array< Byte, N >::const_iterator end_iter) ecl_assert_throw_decl(StandardException)
Formats on a window of the array.
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)
#define ecl_assert_throw_decl(exception)
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


ecl_containers
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:30