formatters.hpp
Go to the documentation of this file.
00001 
00010 /*****************************************************************************
00011 ** Ifdefs
00012 *****************************************************************************/
00013 
00014 #ifndef ECL_CONTAINERS_PUSH_AND_POP_FORMATTERS_HPP_
00015 #define ECL_CONTAINERS_PUSH_AND_POP_FORMATTERS_HPP_
00016 
00017 /*****************************************************************************
00018  ** Includes
00019  *****************************************************************************/
00020 
00021 #include <cmath>
00022 #include <ecl/config/macros.hpp>
00023 #include <ecl/formatters/common.hpp>
00024 #include <ecl/formatters/number.hpp>
00025 #include <ecl/formatters/floats.hpp>
00026 #include "../common/formatters.hpp"
00027 #include "../push_and_pop.hpp"
00028 
00029 /*****************************************************************************
00030  ** Namespaces
00031  *****************************************************************************/
00032 
00033 namespace ecl
00034 {
00035 namespace formatters
00036 {
00037 
00038 /*****************************************************************************
00039  ** Using
00040  *****************************************************************************/
00041 
00065 template<typename Type, size_t N>
00066 class ECL_PUBLIC PushAndPopFormatter
00067 {
00068 public:
00069   virtual ~PushAndPopFormatter()
00070   {}
00077   ecl::PushAndPop<Type,N>& operator()(const ecl::PushAndPop<Type,N> &container) {
00078     return container;
00079   }
00080 };
00081 
00082 /*****************************************************************************
00083  ** Interface [ByteArrayFormatter]
00084  *****************************************************************************/
00085 
00105 template<typename Byte, size_t N>
00106 class ECL_PUBLIC BytePushAndPopFormatter
00107 {
00108 public:
00116   BytePushAndPopFormatter() : ready_to_format(false)
00117   {};
00125   BytePushAndPopFormatter<Byte,N>& operator()(const ecl::PushAndPop<Byte,N> &push_and_pop)
00126   {
00127     push_and_pop_container = &push_and_pop;
00128     ready_to_format = true;
00129     return *this;
00130   }
00131 
00132   virtual ~BytePushAndPopFormatter()
00133   {}
00144   template <typename OutputStream, typename CharType, size_t M>
00145   friend OutputStream& operator << (OutputStream& ostream, const BytePushAndPopFormatter<CharType,M> &formatter) ecl_assert_throw_decl(StandardException);
00146 
00147 private:
00148   const typename ecl::PushAndPop<Byte,N> *push_and_pop_container;
00149   bool ready_to_format;
00150 };
00151 
00152 /*****************************************************************************
00153  ** Implementation [ByteArrayFormatter]
00154  *****************************************************************************/
00155 
00156 template <typename OutputStream, typename CharType, size_t M>
00157 OutputStream& operator <<(OutputStream& ostream, const BytePushAndPopFormatter<CharType, M> &formatter)
00158 ecl_assert_throw_decl(StandardException)
00159 {
00160   ecl_assert_throw(formatter.ready_to_format, StandardException(LOC,UsageError,"The formatter cannot print any data - "
00161           "either there is no data available, or you have tried to use the "
00162           "formatter more than once in a single streaming operation. "
00163           "C++ produces unspecified results when functors are used multiply "
00164           "in the same stream sequence, so this is not permitted here.") );
00165 
00166   ecl::Format<CharType> format(-1, ecl::NoAlign, ecl::Hex);
00167   ostream  << "[ ";
00168   for ( unsigned int i = 0; i < formatter.push_and_pop_container->size(); ++i ) {
00169     ostream << format((*(formatter.push_and_pop_container))[i]) << " ";
00170   }
00171   ostream << "]";
00172   ostream.flush();
00173   return ostream;
00174 }
00175 
00176 /*****************************************************************************
00177  ** Specialisations [PushAndPopFormatter][Char Types]
00178  *****************************************************************************/
00179 
00190 template<size_t N>
00191 class ECL_PUBLIC PushAndPopFormatter< unsigned char,N >
00192 {
00193 public:
00194   typename ecl::formatters::BytePushAndPopFormatter<unsigned char, N>& operator()(const ecl::PushAndPop<unsigned char, N> &container) {
00195     return formatter(container);
00196   }
00197 
00198 private:
00199   typename ecl::formatters::BytePushAndPopFormatter<unsigned char, N> formatter;
00200 };
00201 
00202 
00203 /*****************************************************************************
00204 ** Not Yet Implemented - formatters for signed, char types
00205 *****************************************************************************/
00206 
00207 } // namespace formatters
00208 } // namespace ecl
00209 
00210 
00211 #endif /* ECL_CONTAINERS_PUSH_AND_POP_FORMATTERS_HPP_ */


ecl_containers
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 21:17:43