/* * The Unix Channel * * by Michel Beaudouin-Lafon * * Copyright 1990-1997 * Laboratoire de Recherche en Informatique (LRI) * * Buffers for messages * * $Id$ * $CurLog$ * Removed smart pointers * Removed global.h */ #ifndef Buffer_H_ #define Buffer_H_ #include "cplus_bugs.h" #include "ivl/bool.h" #include "ivl/word.h" #include "IOS.h" class IvlString; class IvlMessage; // Buffer is the buffer itself, End points after its last byte // Start and Stop limit its content // a buffer grows and shrinks automatically // class IvlMsgBuffer : public IvlIOS { protected: byte* Begin; byte* Start; byte* Stop; byte* End; bool GetErr; int GrowSize, MaxSize, MinSize; bool GetBuf (byte*, int, bool, int = 0); int GetString (char*, int, const char*, bool, int = 0); public: IvlMsgBuffer (); IvlMsgBuffer (int); IvlMsgBuffer (int, int, int); IvlMsgBuffer (const IvlMsgBuffer&, int = 0); // construct a fake buffer ~IvlMsgBuffer (); 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*); bool ReadByte (byte&); bool ReadChar (char&); bool ReadShort (sword&); bool ReadLong (lword&); bool ReadBuf (byte*, int); int ReadString (char*, const char*, int = -1); int ReadString (char*, char, int = -1); int ReadString (char*, int = -1); int ReadString (IvlString&); bool ReadMsg (IvlMessage&); void Append (const char*, bool = true); void WriteMsg (IvlMessage&); bool PeekByte (byte&, int = 0); bool PeekShort (sword&, int = 0); bool PeekLong (lword&, int = 0); bool PeekBuf (byte*, int, int = 0); int PeekString (char*, int=-1, const char* = 0, int = 0); int PeekString (char*, int, char, int = 0); int PeekString (IvlString&, int = 0); 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 IvlMsgBuffer& operator << (type data); IvlMsgBuffer& operator >> (type& data); IvlMsgBuffer& operator >> (type* data); #endif friend IvlMsgBuffer& DbgPrint (IvlMsgBuffer&, int); }; #endif /* Buffer_H_ */