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>
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);
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)
158 {
159  ecl_assert_throw(formatter.ready_to_format, StandardException(LOC,UsageError,"The formatter cannot print any data - "
160  "either there is no data available, or you have tried to use the "
161  "formatter more than once in a single streaming operation. "
162  "C++ produces unspecified results when functors are used multiply "
163  "in the same stream sequence, so this is not permitted here.") );
164 
166  ostream << "[ ";
167  for ( unsigned int i = 0; i < formatter.push_and_pop_container->size(); ++i ) {
168  ostream << format((*(formatter.push_and_pop_container))[i]) << " ";
169  }
170  ostream << "]";
171  ostream.flush();
172  return ostream;
173 }
174 
175 /*****************************************************************************
176  ** Specialisations [PushAndPopFormatter][Char Types]
177  *****************************************************************************/
178 
189 template<size_t N>
190 class ECL_PUBLIC PushAndPopFormatter< unsigned char,N >
191 {
192 public:
194  return formatter(container);
195  }
196 
197 private:
199 };
200 
201 
202 /*****************************************************************************
203 ** Not Yet Implemented - formatters for signed, char types
204 *****************************************************************************/
205 
206 } // namespace formatters
207 } // namespace ecl
208 
209 
210 #endif /* ECL_CONTAINERS_PUSH_AND_POP_FORMATTERS_HPP_ */
ecl::formatters::operator<<
OutputStream & operator<<(OutputStream &ostream, const ByteArrayFormatter< CharType, M > &formatter)
Definition: array/formatters.hpp:207
ecl::Hex
Hex
ecl::NoAlign
NoAlign
ecl::UsageError
UsageError
floats.hpp
common.hpp
LOC
#define LOC
number.hpp
ecl::StandardException
ecl::formatters::BytePushAndPopFormatter
Parent template for the byte push and pop formatters.
Definition: push_and_pop/formatters.hpp:118
ecl::Format
ecl_assert_throw
#define ecl_assert_throw(expression, exception)
ecl::PushAndPop
Surpport push and pack operation.
Definition: push_and_pop_fixed.hpp:82
macros.hpp
ecl::formatters::BytePushAndPopFormatter::ready_to_format
bool ready_to_format
Definition: push_and_pop/formatters.hpp:163
ecl
Embedded control libraries.
ECL_PUBLIC
#define ECL_PUBLIC


ecl_containers
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:34