containers/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>
21 #include <ecl/formatters/common.hpp>
22 #include <ecl/formatters/number.hpp>
23 #include <ecl/formatters/floats.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  {}
75  ecl::Array<Type,N>& operator()(ecl::Array<Type,N> &array) {
76  return array;
77  }
78 };
79 
80 /*****************************************************************************
81  ** Interface [ByteArrayFormatter]
82  *****************************************************************************/
83 
106 template<typename Byte, size_t N>
107 class ECL_PUBLIC ByteArrayFormatter
108 {
109 public:
117  ByteArrayFormatter() : ready_to_format(false)
118  {};
126  ByteArrayFormatter<Byte,N>& operator()(const Array<Byte,N> &array)
127  {
128  begin_iterator = array.begin();
129  end_iterator = array.end();
130  ready_to_format = true;
131  return *this;
132  }
140  ByteArrayFormatter<Byte,N>& operator()(const Stencil< Array<Byte,N> > &stencil)
141  {
142  begin_iterator = stencil.begin();
143  end_iterator = stencil.end();
144  ready_to_format = true;
145  return *this;
146  }
158  ByteArrayFormatter<Byte,N>& operator()(typename Array<Byte,N>::const_iterator begin_iter,
159  typename Array<Byte,N>::const_iterator end_iter
160  ) ecl_assert_throw_decl(StandardException)
161  {
162 
163  begin_iterator = begin_iter;
164  end_iterator = end_iter;
165  ready_to_format = true;
166  return *this;
167  }
168 
169  virtual ~ByteArrayFormatter()
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:
185  typename Array<Byte,N>::const_iterator begin_iterator;
186  typename Array<Byte,N>::const_iterator end_iterator;
187  bool ready_to_format;
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
#define LOC
Stringify the line of code you are at.
Primary template for all formatter classes.
Definition: common.hpp:99
#define ecl_assert_throw(expression, exception)
Debug mode throw with a logical condition check.
Standard exception type, provides code location and error string.
iterator end()
UsageError
#define ECL_PUBLIC
TFSIMD_FORCE_INLINE const tfScalar & w() const
#define ecl_assert_throw_decl(exception)
Assure throw exception declaration.
Parent template for the byte array formatters.
Parent interface for formatters of fixed size float/double containers.
iterator begin()


xbot_node
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:28:13