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>
25 #include <ecl/exceptions/standard_exception.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 
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>
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.
Validates functionality for the output char device concept.
OutputTextStream()
Connects the stream to an output device.
#define LOC
Stringify the line of code you are at.
#define ecl_assert_throw(expression, exception)
Debug mode throw with a logical condition check.
Parent template for output text streams.
OutputStream & operator<<(OutputStream &ostream, FormatNumber< N > &formatter) ecl_assert_throw_decl(StandardException)
Definition: number.hpp:361
#define ECL_PUBLIC
Standard exception type, provides code location and error string.
Primary template and general fallback for converter classes.
Definition: converter.hpp:56
void d()
#define ecl_assert_throw_decl(exception)
Assure throw exception declaration.
#define ecl_compile_time_concept_check(Model)
Compile time concept checking assertion.
OutputStream & operator<<(OutputStream &ostream, const Pose2D< Float_, Storage_ > &pose)
Insertion operator for output streams.
Definition: pose2d.hpp:456
void f(int i) ecl_debug_throw_decl(StandardException)


xbot_driver
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:27:37