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  {
97  };
98 
99  virtual ~OutputTextStream() {}
100 
102  OutputTextStream<Device>& operator << ( const char *s ) ecl_assert_throw_decl(ecl::StandardException);
103  OutputTextStream<Device>& operator << ( const std::string &s ) ecl_assert_throw_decl(ecl::StandardException);
104  OutputTextStream<Device>& operator << ( const short &i ) ecl_assert_throw_decl(ecl::StandardException);
105  OutputTextStream<Device>& operator << ( const int &i ) ecl_assert_throw_decl(ecl::StandardException);
106  OutputTextStream<Device>& operator << ( const long &i ) ecl_assert_throw_decl(ecl::StandardException);
107  OutputTextStream<Device>& operator << ( const long long &i ) ecl_assert_throw_decl(ecl::StandardException);
108  OutputTextStream<Device>& operator << ( const unsigned short &i ) ecl_assert_throw_decl(ecl::StandardException);
109  OutputTextStream<Device>& operator << ( const unsigned int &i ) ecl_assert_throw_decl(ecl::StandardException);
110  OutputTextStream<Device>& operator << ( const unsigned long &i ) ecl_assert_throw_decl(ecl::StandardException);
111  OutputTextStream<Device>& operator << ( const unsigned long long &i ) ecl_assert_throw_decl(ecl::StandardException);
112  OutputTextStream<Device>& operator << ( const bool b ) ecl_assert_throw_decl(ecl::StandardException);
113  OutputTextStream<Device>& operator << ( const float &f ) ecl_assert_throw_decl(ecl::StandardException);
114  OutputTextStream<Device>& operator << ( const double &d ) ecl_assert_throw_decl(ecl::StandardException);
115 
116  /*********************
117  * Friend Manipulators
118  *********************/
119  template <typename Action>
120  OutputTextStream<Device>& operator << ( ecl::Manipulator<Action> &manipulator ) ecl_assert_throw_decl(ecl::StandardException)
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() ecl_assert_throw_decl(ecl::StandardException);
142 
143  private:
144  ecl::Converter<char*> toCharString;
145 };
146 
147 /*****************************************************************************
148 ** Implementation [OutputTextStream]
149 *****************************************************************************/
150 
158 template <typename Device>
159 OutputTextStream<Device>& OutputTextStream<Device,true>::operator<< ( const char& c ) ecl_assert_throw_decl(ecl::StandardException) {
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
361 void OutputTextStream<Device,true>::flush() ecl_assert_throw_decl(ecl::StandardException) {
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_ */
Parent class for text stream functionality.
OutputTextStream()
Connects the stream to an output device.
#define LOC
#define ecl_assert_throw(expression, exception)
Parent template for output text streams.
OutputStream & operator<<(OutputStream &ostream, FormatNumber< N > &formatter) ecl_assert_throw_decl(StandardException)
void d()
#define ecl_assert_throw_decl(exception)
#define ecl_compile_time_concept_check(Model)
#define ECL_PUBLIC


ecl_streams
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:50