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 
19 #include "detail/character_buffer.hpp"
20 #include "traits.hpp"
21 #include <ecl/errors/handlers.hpp>
22 #include <ecl/exceptions/standard_exception.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) ecl_assert_throw_decl(StandardException);
86  long write(const char* s, unsigned long n) ecl_assert_throw_decl(StandardException);
93  void flush() ecl_assert_throw_decl(StandardException);
94 
103  const Error& error() const { return error_handler; }
104 private:
105  devices::CharStringBuffer buffer;
106  Error error_handler;
107 };
108 
109 /*****************************************************************************
110 ** Interface [EConsole]
111 *****************************************************************************/
112 
120 class ecl_devices_PUBLIC EConsole {
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) ecl_assert_throw_decl(StandardException);
163  long write(const char* s, unsigned long n) ecl_assert_throw_decl(StandardException);
170  void flush() ecl_assert_throw_decl(StandardException);
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 
203 class ecl_devices_PUBLIC IConsole {
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) ecl_assert_throw_decl(StandardException);
240  long read(char *s, const unsigned long &n) ecl_assert_throw_decl(StandardException);
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_ */
#define ecl_devices_PUBLIC
Error
Bool< true > True
#define ecl_assert_throw_decl(exception)
Assure throw exception declaration.


xbot_node
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:28:13