containers/push_and_pop/formatters.hpp
Go to the documentation of this file.
1 
10 /*****************************************************************************
11 ** Ifdefs
12 *****************************************************************************/
13 
14 #ifndef ECL_CONTAINERS_PUSH_AND_POP_FORMATTERS_HPP_
15 #define ECL_CONTAINERS_PUSH_AND_POP_FORMATTERS_HPP_
16 
17 /*****************************************************************************
18  ** Includes
19  *****************************************************************************/
20 
21 #include <cmath>
22 #include <ecl/config/macros.hpp>
23 #include <ecl/formatters/common.hpp>
24 #include <ecl/formatters/number.hpp>
25 #include <ecl/formatters/floats.hpp>
26 #include "../common/formatters.hpp"
27 #include "../push_and_pop.hpp"
28 
29 /*****************************************************************************
30  ** Namespaces
31  *****************************************************************************/
32 
33 namespace ecl
34 {
35 namespace formatters
36 {
37 
38 /*****************************************************************************
39  ** Using
40  *****************************************************************************/
41 
65 template<typename Type, size_t N>
66 class ECL_PUBLIC PushAndPopFormatter
67 {
68 public:
69  virtual ~PushAndPopFormatter()
70  {}
77  ecl::PushAndPop<Type,N>& operator()(const ecl::PushAndPop<Type,N> &container) {
78  return container;
79  }
80 };
81 
82 /*****************************************************************************
83  ** Interface [ByteArrayFormatter]
84  *****************************************************************************/
85 
105 template<typename Byte, size_t N>
106 class ECL_PUBLIC BytePushAndPopFormatter
107 {
108 public:
116  BytePushAndPopFormatter() : ready_to_format(false)
117  {};
125  BytePushAndPopFormatter<Byte,N>& operator()(const ecl::PushAndPop<Byte,N> &push_and_pop)
126  {
127  push_and_pop_container = &push_and_pop;
128  ready_to_format = true;
129  return *this;
130  }
131 
132  virtual ~BytePushAndPopFormatter()
133  {}
144  template <typename OutputStream, typename CharType, size_t M>
145  friend OutputStream& operator << (OutputStream& ostream, const BytePushAndPopFormatter<CharType,M> &formatter) ecl_assert_throw_decl(StandardException);
146 
147 private:
148  const typename ecl::PushAndPop<Byte,N> *push_and_pop_container;
149  bool ready_to_format;
150 };
151 
152 /*****************************************************************************
153  ** Implementation [ByteArrayFormatter]
154  *****************************************************************************/
155 
156 template <typename OutputStream, typename CharType, size_t M>
157 OutputStream& operator <<(OutputStream& ostream, const BytePushAndPopFormatter<CharType, M> &formatter)
159 {
160  ecl_assert_throw(formatter.ready_to_format, StandardException(LOC,UsageError,"The formatter cannot print any data - "
161  "either there is no data available, or you have tried to use the "
162  "formatter more than once in a single streaming operation. "
163  "C++ produces unspecified results when functors are used multiply "
164  "in the same stream sequence, so this is not permitted here.") );
165 
167  ostream << "[ ";
168  for ( unsigned int i = 0; i < formatter.push_and_pop_container->size(); ++i ) {
169  ostream << format((*(formatter.push_and_pop_container))[i]) << " ";
170  }
171  ostream << "]";
172  ostream.flush();
173  return ostream;
174 }
175 
176 /*****************************************************************************
177  ** Specialisations [PushAndPopFormatter][Char Types]
178  *****************************************************************************/
179 
190 template<size_t N>
191 class ECL_PUBLIC PushAndPopFormatter< unsigned char,N >
192 {
193 public:
195  return formatter(container);
196  }
197 
198 private:
200 };
201 
202 
203 /*****************************************************************************
204 ** Not Yet Implemented - formatters for signed, char types
205 *****************************************************************************/
206 
207 } // namespace formatters
208 } // namespace ecl
209 
210 
211 #endif /* ECL_CONTAINERS_PUSH_AND_POP_FORMATTERS_HPP_ */
Surpport push and pack operation.
#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.
UsageError
#define ECL_PUBLIC
#define ecl_assert_throw_decl(exception)
Assure throw exception declaration.


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