output_text_stream.hpp
Go to the documentation of this file.
1 
11 /*****************************************************************************
12 ** Ifdefs
13 *****************************************************************************/
14 
15 #ifndef ECL_STREAMS_OUTPUT_TEXT_STREAM_HPP_
16 #define ECL_STREAMS_OUTPUT_TEXT_STREAM_HPP_
17 
18 /*****************************************************************************
19 ** Includes
20 *****************************************************************************/
21 
22 #include <cstring>
23 #include <string>
24 #include <ecl/config/macros.hpp>
26 #include <ecl/converters.hpp>
27 #include <ecl/concepts/devices.hpp>
28 #include "../manipulators/manipulator.hpp"
29 #include "../macros.hpp"
30 
31 /*****************************************************************************
32 ** Namespaces
33 *****************************************************************************/
34 
35 namespace ecl {
36 namespace interfaces {
37 
38 /*****************************************************************************
39 ** Interface [OutputTextStream]
40 *****************************************************************************/
41 
54 template <typename Device, bool OutputDevice = true >
56 
79 template <typename Device>
80 class ECL_PUBLIC OutputTextStream<Device,true> : public virtual BaseTextStream<Device> {
81  public:
94  toCharString(30) // character buffer size
95  {
96  ecl_compile_time_concept_check(OutputCharDeviceConcept<Device>);
97  };
98 
99  virtual ~OutputTextStream() {}
100 
101  OutputTextStream<Device>& operator << ( const char &c );
102  OutputTextStream<Device>& operator << ( const char *s );
103  OutputTextStream<Device>& operator << ( const std::string &s );
104  OutputTextStream<Device>& operator << ( const short &i );
106  OutputTextStream<Device>& operator << ( const long &i );
107  OutputTextStream<Device>& operator << ( const long long &i );
108  OutputTextStream<Device>& operator << ( const unsigned short &i );
109  OutputTextStream<Device>& operator << ( const unsigned int &i );
110  OutputTextStream<Device>& operator << ( const unsigned long &i );
111  OutputTextStream<Device>& operator << ( const unsigned long long &i );
112  OutputTextStream<Device>& operator << ( const bool b );
113  OutputTextStream<Device>& operator << ( const float &f );
114  OutputTextStream<Device>& operator << ( const double &d );
115 
116  /*********************
117  * Friend Manipulators
118  *********************/
119  template <typename Action>
121  {
122  manipulator.insert(*this);
123  return *this;
124  }
125 
132 // friend interfaces::OutputTextStream& operator << (interfaces::OutputTextStream& ostream, void (*manipulator)(interfaces::OutputTextStream&) )
133 // {
134 // (*manipulator)(ostream);
135 // return ostream;
136 // }
137 
138  /*********************
139  ** Buffer functionality
140  **********************/
141  void flush();
142 
143  private:
144  ecl::Converter<char*> toCharString;
145 };
146 
147 /*****************************************************************************
148 ** Implementation [OutputTextStream]
149 *****************************************************************************/
150 
158 template <typename Device>
160  ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
161  this->io_device.write(c);
162  return *this;
163 }
172 template <typename Device>
173 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const char *s ) {
174  ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
175  this->io_device.write(s,strlen(s));
176  return *this;
177 }
178 
187 template <typename Device>
188 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const std::string &s ) {
189  ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
190  this->io_device.write(&s[0],s.size());
191  return *this;
192 }
200 template <typename Device>
202 {
203  ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
204  *this << toCharString(i);
205  return *this;
206 }
214 template <typename Device>
216 {
217  ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
218  *this << toCharString(i);
219  return *this;
220 }
221 
229 template <typename Device>
230 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const long &i )
231 {
232  ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
233  *this << toCharString(i);
234  return *this;
235 }
236 
244 template <typename Device>
245 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const long long &i )
246 {
247  ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
248  *this << toCharString(i);
249  return *this;
250 }
251 
259 template <typename Device>
260 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const unsigned short &i )
261 {
262  ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
263  *this << toCharString(i);
264  return *this;
265 }
266 
274 template <typename Device>
275 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const unsigned int &i )
276 {
277  ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
278  *this << toCharString(i);
279  return *this;
280 }
281 
289 template <typename Device>
290 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const unsigned long &i )
291 {
292  ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
293  *this << toCharString(i);
294  return *this;
295 }
303 template <typename Device>
304 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const unsigned long long &i )
305 {
306  ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
307  *this << toCharString(i);
308  return *this;
309 }
317 template <typename Device>
318 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const bool b )
319 {
320  ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
321  if ( b ) { *this << "true"; } else { *this << "false"; };
322  return *this;
323 }
324 
331 template <typename Device>
332 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const float &f )
333 {
334  ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
335  *this << toCharString(f);
336  return *this;
337 }
338 
345 template <typename Device>
346 OutputTextStream<Device>& OutputTextStream<Device,true>::operator << ( const double &d )
347 {
348  ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
349  *this << toCharString(d);
350  return *this;
351 }
352 
360 template <typename Device>
362  ecl_assert_throw(this->io_device.open(),ecl::StandardException(LOC,OpenError,"The underlying stream device is not open."));
363  this->io_device.flush();
364 }
365 
366 } // namespace interfaces
367 } // namespace ecl
368 
369 #endif /* ECL_STREAMS_OUTPUT_TEXT_STREAM_HPP_ */
ecl::OpenError
OpenError
ecl_compile_time_concept_check
#define ecl_compile_time_concept_check(Model)
ecl::Manipulator
Parent template for c++ style stream manipulators.
Definition: manipulator.hpp:98
ecl::demos::f
void f()
Definition: log_streams.cpp:55
ecl::Manipulator::insert
void insert(interfaces::OutputTextStream< ODevice, true > &ostream)
The static crtp virtual parent call.
Definition: manipulator.hpp:117
ecl::interfaces::OutputTextStream< Device, true >::flush
void flush()
Flushes the underlying device's buffer.
Definition: output_text_stream.hpp:373
ecl::interfaces::OutputTextStream
Parent template for output text streams.
Definition: output_text_stream.hpp:67
LOC
#define LOC
ecl::StandardException
ecl_assert_throw
#define ecl_assert_throw(expression, exception)
ecl::interfaces::OutputTextStream< Device, true >::operator<<
OutputTextStream< Device > & operator<<(const char &c)
Sends an unformatted char to the stream. Sends an unformatted char to the stream.
Definition: output_text_stream.hpp:171
standard_exception.hpp
devices.hpp
macros.hpp
converters.hpp
ecl::interfaces::operator<<
OutputStream & operator<<(OutputStream &ostream, FormatFloat< N > &formatter)
ecl::interfaces::OutputTextStream
class ECL_PUBLIC OutputTextStream
Definition: manipulator.hpp:48
ecl
ecl::Converter< char * >
ECL_PUBLIC
#define ECL_PUBLIC


ecl_streams
Author(s): Daniel Stonier
autogenerated on Sun Aug 2 2020 03:12:20