summaryrefslogtreecommitdiff
path: root/comm/MsgBuffer.h
diff options
context:
space:
mode:
authorchatty1993-04-07 11:50:31 +0000
committerchatty1993-04-07 11:50:31 +0000
commitba066c34dde204aa192d03a23a81356374d93731 (patch)
tree39391f6235d2cf8a59a0634ac5ea430cdd21f5d4 /comm/MsgBuffer.h
parent05ab076e1c2a9ca16472f9a6b47b8d22914b3783 (diff)
downloadivy-league-ba066c34dde204aa192d03a23a81356374d93731.zip
ivy-league-ba066c34dde204aa192d03a23a81356374d93731.tar.gz
ivy-league-ba066c34dde204aa192d03a23a81356374d93731.tar.bz2
ivy-league-ba066c34dde204aa192d03a23a81356374d93731.tar.xz
Initial revision
Diffstat (limited to 'comm/MsgBuffer.h')
-rw-r--r--comm/MsgBuffer.h112
1 files changed, 112 insertions, 0 deletions
diff --git a/comm/MsgBuffer.h b/comm/MsgBuffer.h
new file mode 100644
index 0000000..0f6a55c
--- /dev/null
+++ b/comm/MsgBuffer.h
@@ -0,0 +1,112 @@
+/*
+ * The Unix Channel
+ *
+ * by Michel Beaudouin-Lafon
+ *
+ * Copyright 1990-1993
+ * Laboratoire de Recherche en Informatique (LRI)
+ *
+ * Messages, buffers
+ *
+ * $Id$
+ * $CurLog$
+ */
+
+#ifndef Buffer_H_
+#define Buffer_H_
+
+#include "cplus_bugs.h"
+#include "global.h"
+#include "ccu/SmartPointer.h"
+
+class UchMessage;
+
+// Buffer is the buffer itself, End points after its last byte
+// Start and Stop limit its content
+// UchMsgBuffer derives from CcuSmartData to be able to have smart pointers (pUchMsgBuffer)
+// a buffer grows and shrinks automatically
+//
+class UchMsgBuffer : public CcuSmartData {
+protected:
+ byte* Begin;
+ byte* Start;
+ byte* Stop;
+ byte* End;
+ bool GetErr;
+ int GrowSize, MaxSize, MinSize;
+
+public:
+ UchMsgBuffer ();
+ UchMsgBuffer (int);
+ UchMsgBuffer (int, int, int);
+ UchMsgBuffer (const UchMsgBuffer&, int = 0); // construct a fake buffer
+ ~UchMsgBuffer ();
+
+ void Delete ();
+ void NeedSize (int n);
+ void Grow () { NeedSize (GrowSize); }
+ void Flush (int n = -1);
+ void Flush (byte*);
+ void SetSizes (int, int, int);
+
+ void Append (const byte*, int);
+ void Append (byte);
+ void Append (char c) { Append ((byte) c); }
+ void Append (sword s) { Append ((const byte*) &s, swsize); }
+ void Append (lword l) { Append ((const byte*) &l, lwsize); }
+ void Append (const char*, bool = TRUE);
+ void Append (UchMessage&);
+
+ bool Get (byte*, int, bool = FALSE);
+ bool Get (byte*, bool = FALSE);
+ bool Get (char* c, bool peek = FALSE) { return Get ((byte*) c, peek); }
+ bool Get (lword* l, bool peek = FALSE) { return Get ((byte*) l, lwsize, peek); }
+ bool Get (sword* s, bool peek = FALSE) { return Get ((byte*) s, swsize, peek); }
+ int Get (char*, int, char, bool = FALSE);
+ int Get (char*, int, const char* = 0, bool = FALSE);
+ bool Get (UchMessage*);
+
+ bool Peek (byte*, lword = 0);
+ bool Peek (sword*, lword = 0);
+ bool Peek (lword*, lword = 0);
+ bool Peek (int, byte*, lword = 0);
+ bool MsgPeek (byte* b, lword o = 0) { return Peek (b, o+lwsize); }
+ bool MsgPeek (sword* sw, lword o = 0) { return Peek (sw, o+lwsize); }
+ bool MsgPeek (lword* lw, lword o = 0) { return Peek (lw, o+lwsize); }
+ bool MsgPeek (int sz, byte* b, lword o = 0) { return Peek (sz, b, o+lwsize); }
+
+ byte* Buffer () { return Start; }
+ int BufLength () { return Stop - Start; }
+ byte* Free () { return Stop; }
+ int FreeLength () { return End - Stop; }
+ void More (int);
+ void Discard (int);
+
+ bool Error () { return GetErr; }
+ bool Ok () { return GetErr ? FALSE : TRUE; }
+ void ResetError () { GetErr = FALSE; }
+
+ UchMsgBuffer& operator << (lword l) { Append (l); return *this; }
+ UchMsgBuffer& operator << (sword s) { Append (s); return *this; }
+ UchMsgBuffer& operator << (byte b) { Append (b); return *this; }
+ UchMsgBuffer& operator << (char c) { Append (c); return *this; }
+ UchMsgBuffer& operator << (const char* s) { Append (s, TRUE); return *this; }
+
+ UchMsgBuffer& operator >> (lword& l) { Get (&l); return *this; }
+ UchMsgBuffer& operator >> (sword& s) { Get (&s); return *this; }
+ UchMsgBuffer& operator >> (byte& b) { Get ((byte*) &b, FALSE); return *this; }
+ UchMsgBuffer& operator >> (char& c) { Get ((byte*) &c, FALSE); return *this; }
+ UchMsgBuffer& operator >> (char* s) { Get (s, -1); return *this; }
+
+#ifdef DOC
+ UchMsgBuffer& operator << (type data);
+ UchMsgBuffer& operator >> (type& data);
+ UchMsgBuffer& operator >> (type* data);
+#endif
+
+friend UchMsgBuffer& DbgPrint (UchMsgBuffer&, int);
+};
+
+PointerClass (pUchMsgBuffer, UchMsgBuffer)
+
+#endif /* Buffer_H_ */