summaryrefslogtreecommitdiff
path: root/common/streambuf.h
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-07 08:20:09 +0200
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-07 08:20:09 +0200
commitbfab72e50fe8b94bd3a7dbcf63114002008575ea (patch)
treec3bcb603a500f4f42e694514f7fba86570024390 /common/streambuf.h
parent6d05c17a8d00075f1578094163237c43128e1df9 (diff)
very simple non-working implementation of streambufs for hhvm
Diffstat (limited to 'common/streambuf.h')
-rw-r--r--common/streambuf.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/common/streambuf.h b/common/streambuf.h
new file mode 100644
index 0000000..ed1506a
--- /dev/null
+++ b/common/streambuf.h
@@ -0,0 +1,80 @@
+/**
+ * StreamBuf.h
+ *
+ * PHP output stream buffer which is used by the Php::out object to
+ * have an output stream just like the regular std::ostream buffers,
+ * but that sends all output to PHP output
+ *
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * @copyright 2014 Copernica BV
+ */
+
+/**
+ * Set up namespace
+ */
+namespace Php {
+
+/**
+ * Class definition
+ */
+class StreamBuf : public std::streambuf
+{
+public:
+ /**
+ * Constructor
+ * @param error the error type, or 0 for regular output
+ */
+ StreamBuf(int error);
+
+ /**
+ * No copying or moving
+ * @param that
+ */
+ StreamBuf(const StreamBuf &that) = delete;
+ StreamBuf(StreamBuf &&that) = delete;
+
+ /**
+ * Destructor
+ */
+ virtual ~StreamBuf() {}
+
+ /**
+ * No copying or moving
+ * @param that
+ */
+ StreamBuf &operator=(const StreamBuf &that) = delete;
+ StreamBuf &operator=(StreamBuf &&that) = delete;
+
+protected:
+ /**
+ * Method that is called when the internal buffer overflows
+ * @param c
+ * @return int
+ */
+ virtual int overflow(int c = EOF) override;
+
+ /**
+ * Called when the internal buffer should be synchronized
+ * @return int
+ */
+ virtual int sync() override;
+
+private:
+ /**
+ * The error type, or 0 for regular output
+ * @var int
+ */
+ int _error;
+
+ /**
+ * The internal buffer
+ * @var char[]
+ */
+ char _buffer[1024];
+};
+
+/**
+ * End namespace
+ */
+}
+