Program Listing for File console.hpp
↰ Return to documentation for file (include/ecl/devices/console.hpp
)
/*****************************************************************************
** Ifdefs
*****************************************************************************/
#ifndef ECL_DEVICES_CONSOLE_HPP_
#define ECL_DEVICES_CONSOLE_HPP_
/*****************************************************************************
** Includes
*****************************************************************************/
#include "detail/character_buffer.hpp"
#include "traits.hpp"
#include <ecl/errors/handlers.hpp>
#include <ecl/exceptions/standard_exception.hpp>
#include "macros.hpp"
/*****************************************************************************
** Namespaces
*****************************************************************************/
namespace ecl {
/*****************************************************************************
** Interface [OConsole]
*****************************************************************************/
class ecl_devices_PUBLIC OConsole {
public:
OConsole() : error_handler(NoError) {}
virtual ~OConsole() {}
/*********************
** Output Device API
**********************/
bool open() { return true; }
long write(const char &c);
long write(const char* s, unsigned long n);
void flush();
const Error& error() const { return error_handler; }
private:
devices::CharStringBuffer buffer;
Error error_handler;
};
/*****************************************************************************
** Interface [EConsole]
*****************************************************************************/
class ecl_devices_PUBLIC EConsole {
public:
EConsole() : error_handler(NoError) {}
virtual ~EConsole() {}
/*********************
** Output Device API
**********************/
bool open() { return true; }
long write(const char &c);
long write(const char* s, unsigned long n);
void flush();
const Error& error() const { return error_handler; }
private:
devices::CharStringBuffer buffer;
Error error_handler;
};
/*****************************************************************************
** Interface [IConsole]
*****************************************************************************/
class ecl_devices_PUBLIC IConsole {
public:
IConsole() : error_handler(NoError) {}
virtual ~IConsole() {}
/*********************
** Input Device API
**********************/
bool open() { return true; }
long read(char &c);
long read(char *s, const unsigned long &n);
// long remaining() {
// long pos = ftell(stdin); // get current position marker.
// fseek(stdin,0,SEEK_END); // move pointer to the end of the file.
// long size = ftell(stdin);
// fseek(stdin,pos,SEEK_SET);
//
// return size;
// }
const Error& error() const { return error_handler; }
private:
Error error_handler;
};
/*****************************************************************************
** Traits [Console]
*****************************************************************************/
template <>
class is_source<IConsole> : public True {
};
template <>
class is_sink<OConsole> : public True {};
template <>
class is_sink<EConsole> : public True {};
} // namespace ecl
#endif /* ECL_DEVICES_CONSOLE_HPP_ */