console.hpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Ifdefs
00010 *****************************************************************************/
00011 
00012 #ifndef ECL_DEVICES_CONSOLE_HPP_
00013 #define ECL_DEVICES_CONSOLE_HPP_
00014 
00015 /*****************************************************************************
00016 ** Includes
00017 *****************************************************************************/
00018 
00019 #include "detail/character_buffer.hpp"
00020 #include "traits.hpp"
00021 #include <ecl/errors/handlers.hpp>
00022 #include <ecl/exceptions/standard_exception.hpp>
00023 
00024 /*****************************************************************************
00025 ** Namespaces
00026 *****************************************************************************/
00027 
00028 namespace ecl {
00029 
00030 /*****************************************************************************
00031 ** Interface [OConsole]
00032 *****************************************************************************/
00033 
00042 class OConsole {
00043 public:
00047         OConsole() : error_handler(NoError) {}
00048         virtual ~OConsole() {}
00049 
00050         /*********************
00051         ** Output Device API
00052         **********************/
00061         bool open() { return true; }
00062 
00073         long write(const char &c) ecl_assert_throw_decl(StandardException);
00085         long write(const char* s, unsigned long n) ecl_assert_throw_decl(StandardException);
00092         void flush() ecl_assert_throw_decl(StandardException);
00093 
00102         const Error& error() const { return error_handler; }
00103 private:
00104         devices::CharStringBuffer buffer;
00105         Error error_handler;
00106 };
00107 
00108 /*****************************************************************************
00109 ** Interface [EConsole]
00110 *****************************************************************************/
00111 
00119 class EConsole {
00120 public:
00124         EConsole() : error_handler(NoError) {}
00125         virtual ~EConsole() {}
00126 
00127         /*********************
00128         ** Output Device API
00129         **********************/
00138         bool open() { return true; }
00139 
00150         long write(const char &c) ecl_assert_throw_decl(StandardException);
00162         long write(const char* s, unsigned long n) ecl_assert_throw_decl(StandardException);
00169         void flush() ecl_assert_throw_decl(StandardException);
00170 
00179         const Error& error() const { return error_handler; }
00180 
00181 private:
00182         devices::CharStringBuffer buffer;
00183         Error error_handler;
00184 };
00185 
00186 /*****************************************************************************
00187 ** Interface [IConsole]
00188 *****************************************************************************/
00189 
00202 class IConsole {
00203 public:
00207         IConsole() : error_handler(NoError) {}
00208         virtual ~IConsole() {}
00209         /*********************
00210         ** Input Device API
00211         **********************/
00220         bool open() { return true; }
00229     long read(char &c) ecl_assert_throw_decl(StandardException);
00239     long read(char *s, const unsigned long &n) ecl_assert_throw_decl(StandardException);
00240 
00241 //    long remaining() {
00242 //        long pos = ftell(stdin); // get current position marker.
00243 //        fseek(stdin,0,SEEK_END); // move pointer to the end of the file.
00244 //        long size = ftell(stdin);
00245 //        fseek(stdin,pos,SEEK_SET);
00246 //
00247 //        return size;
00248 //    }
00257         const Error& error() const { return error_handler; }
00258 private:
00259         Error error_handler;
00260 };
00261 
00262 
00263 /*****************************************************************************
00264 ** Traits [Console]
00265 *****************************************************************************/
00272 template <>
00273 class is_source<IConsole> : public True {
00274 
00275 };
00276 
00282 template <>
00283 class is_sink<OConsole> : public True {};
00284 
00290 template <>
00291 class is_sink<EConsole> : public True {};
00292 
00293 } // namespace ecl
00294 
00295 #endif /* ECL_DEVICES_CONSOLE_HPP_ */


ecl_devices
Author(s): Daniel Stonier (d.stonier@gmail.com)
autogenerated on Thu Jan 2 2014 11:12:50