console.hpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Ifdefs
10 *****************************************************************************/
11 
12 #ifndef ECL_DEVICES_CONSOLE_HPP_
13 #define ECL_DEVICES_CONSOLE_HPP_
14 
15 /*****************************************************************************
16 ** Includes
17 *****************************************************************************/
18 
20 #include "traits.hpp"
21 #include <ecl/errors/handlers.hpp>
23 #include "macros.hpp"
24 
25 /*****************************************************************************
26 ** Namespaces
27 *****************************************************************************/
28 
29 namespace ecl {
30 
31 /*****************************************************************************
32 ** Interface [OConsole]
33 *****************************************************************************/
34 
43 class ecl_devices_PUBLIC OConsole {
44 public:
48  OConsole() : error_handler(NoError) {}
49  virtual ~OConsole() {}
50 
51  /*********************
52  ** Output Device API
53  **********************/
62  bool open() { return true; }
63 
74  long write(const char &c);
86  long write(const char* s, unsigned long n);
93  void flush();
94 
103  const Error& error() const { return error_handler; }
104 private:
106  Error error_handler;
107 };
108 
109 /*****************************************************************************
110 ** Interface [EConsole]
111 *****************************************************************************/
112 
121 public:
125  EConsole() : error_handler(NoError) {}
126  virtual ~EConsole() {}
127 
128  /*********************
129  ** Output Device API
130  **********************/
139  bool open() { return true; }
140 
151  long write(const char &c);
163  long write(const char* s, unsigned long n);
170  void flush();
171 
180  const Error& error() const { return error_handler; }
181 
182 private:
183  devices::CharStringBuffer buffer;
184  Error error_handler;
185 };
186 
187 /*****************************************************************************
188 ** Interface [IConsole]
189 *****************************************************************************/
190 
204 public:
208  IConsole() : error_handler(NoError) {}
209  virtual ~IConsole() {}
210  /*********************
211  ** Input Device API
212  **********************/
221  bool open() { return true; }
230  long read(char &c);
240  long read(char *s, const unsigned long &n);
241 
242 // long remaining() {
243 // long pos = ftell(stdin); // get current position marker.
244 // fseek(stdin,0,SEEK_END); // move pointer to the end of the file.
245 // long size = ftell(stdin);
246 // fseek(stdin,pos,SEEK_SET);
247 //
248 // return size;
249 // }
258  const Error& error() const { return error_handler; }
259 private:
260  Error error_handler;
261 };
262 
263 
264 /*****************************************************************************
265 ** Traits [Console]
266 *****************************************************************************/
273 template <>
274 class is_source<IConsole> : public True {
275 
276 };
277 
283 template <>
284 class is_sink<OConsole> : public True {};
285 
291 template <>
292 class is_sink<EConsole> : public True {};
293 
294 } // namespace ecl
295 
296 #endif /* ECL_DEVICES_CONSOLE_HPP_ */
ecl::is_sink
Default action for detection of sink devices (output) (false).
Definition: traits.hpp:56
ecl::devices::CharStringBuffer
Simple char string buffer class for use internally by the devices.
Definition: character_buffer.hpp:91
ecl::Bool
ecl::Error
ecl::OConsole
Device for writing to standard output.
Definition: console.hpp:49
macros.hpp
Macros for ecl devices.
character_buffer.hpp
A generic buffer for devices.
ecl_devices_PUBLIC
#define ecl_devices_PUBLIC
Definition: macros.hpp:37
ecl::NoError
NoError
True
Bool< true > True
handlers.hpp
standard_exception.hpp
ecl::IConsole
Device for reading from standard output.
Definition: console.hpp:209
traits.hpp
Traits for devices.
ecl
Embedded control libraries.
ecl::EConsole
Device for writing o standard error.
Definition: console.hpp:126
ecl::is_source
Default action for detection of source devices (input) (false).
Definition: traits.hpp:45


ecl_devices
Author(s): Daniel Stonier
autogenerated on Sun Aug 2 2020 03:12:18