summaryrefslogtreecommitdiff
path: root/includes/Handle.h
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-11-25 00:05:48 -0800
committerPixel <pixel@nobis-crew.org>2011-11-25 00:05:48 -0800
commit5db0c9feb06217d2d343d75cdc6e2b3a5fec7343 (patch)
tree73da318b65da4ad4c351ced09df793f50d51f437 /includes/Handle.h
parentef6356cf6453f8bf624369942ed57769f80c087a (diff)
Adding a 'HandlePrinter' Handle type, to easily print out the results of a handle, and some small helpers; more helpers to come.
Diffstat (limited to 'includes/Handle.h')
-rw-r--r--includes/Handle.h16
1 files changed, 16 insertions, 0 deletions
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 <Exceptions.h>
#include <Printer.h>
+#include <BString.h>
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) { }