From 5db0c9feb06217d2d343d75cdc6e2b3a5fec7343 Mon Sep 17 00:00:00 2001 From: Pixel Date: Fri, 25 Nov 2011 00:05:48 -0800 Subject: Adding a 'HandlePrinter' Handle type, to easily print out the results of a handle, and some small helpers; more helpers to come. --- includes/Handle.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'includes/Handle.h') diff --git a/includes/Handle.h b/includes/Handle.h index f304086..d205925 100644 --- a/includes/Handle.h +++ b/includes/Handle.h @@ -2,6 +2,7 @@ #include #include +#include namespace Balau { @@ -50,6 +51,8 @@ class Handle { virtual time_t getMTime(); ssize_t forceRead(void * buf, size_t count, Events::BaseEvent * evt = NULL) throw (GeneralException); ssize_t forceWrite(const void * buf, size_t count, Events::BaseEvent * evt = NULL) throw (GeneralException); + ssize_t write(const String & str) { return write(str.to_charp(), str.strlen()); } + uint8_t readU8() { uint8_t r; read(&r, 1); return r; } protected: Handle() : m_refCount(0) { } private: @@ -68,6 +71,19 @@ class Handle { int m_refCount; }; +class HPrinter : public Handle { + public: + virtual void close() throw (GeneralException) { } + virtual bool isClosed() { return false; } + virtual bool isEOF() { return false; } + virtual bool canWrite() { return true; } + virtual const char * getName() { return "HPrinter"; } + virtual ssize_t write(const void * buf, size_t count) throw (GeneralException) { + Printer::print("%s", (const char *) buf); + return count; + } +}; + class IOBase { public: IOBase() : m_h(NULL) { } -- cgit v1.2.3