/* * 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" #include "IOS.h" class CcuString; 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, public UchIOS { 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 Clear (); void NeedSize (int n); void Grow () { NeedSize (GrowSize); } void Flush (int n = -1); void Flush (byte*); void SetSizes (int, int, int); void WriteBuf (const byte*, int); void WriteByte (byte); void WriteChar (char); void WriteShort (sword); void WriteLong (lword); void WriteString (const char*); void ReadBuf (byte*, int); void ReadByte (byte&); void ReadChar (char&); void ReadShort (sword&); void ReadLong (lword&); void ReadString (char*); void ReadString (CcuString&); void Append (const char*, bool = true); void WriteMsg (UchMessage&); bool Get (byte*, int, bool = false); bool Get (byte& b, bool peek = false) { return Get (&b, 1, peek); } bool Get (char& c, bool peek = false) { return Get ((byte*) &c, 1, 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 = -1, const char* = 0, bool = false); int Get (CcuString&, bool = false); bool ReadMsg (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; } #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_ */