/* * 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_ */