% Remember to use the lgrind style \File{buffer.h},{12:08},{Oct 24 1996} \L{\LB{\C{}\1\*}} \L{\LB{_\* Copyright (C) 1993}} \L{\LB{_\*}} \L{\LB{_\* Department of Computing Science,}} \L{\LB{_\* The University,}} \L{\LB{_\* Newcastle upon Tyne,}} \L{\LB{_\* UK.}} \L{\LB{_\*}} \L{\LB{_\* \$Id: Buffer.h,v 1.14 1995\103\107 14:59:20 ngdp Exp \$}} \L{\LB{_\*}} \L{\LB{_\* Permission granted to Dean Thompson to use this code for his honours}} \L{\LB{_\* thesis titled \"Object Request Broker Data Marshalling Performance\" by}} \L{\LB{_\* Professor Santosh Shrivastava on the 15 August 1996.}} \L{\LB{_\*\1\CE{}}} \L{\LB{}} \L{\LB{\K{\#ifndef}_\V{BUFFER\_H\_}}} \L{\LB{\K{\#define}_\V{BUFFER\_H\_}}} \L{\LB{}} \L{\LB{\K{\#ifndef}_\V{STUB}}} \L{\LB{\K{\#}__\K{include}_\<\V{Common}\1\V{Buffer\_stub}.\V{h}\>}} \L{\LB{\K{\#else}}} \L{\LB{}} \L{\LB{\C{}\1\*}} \L{\LB{_\*}} \L{\LB{_\* Class that implements the marshalling operations for the primitive C types}} \L{\LB{_\* supported by C++ (with certain obvious exceptions).}} \L{\LB{_\* The overloaded operations pack and unpack save\1restore the primitive}} \L{\LB{_\* C types to\1from memory which is allocated in chunks that default to the}} \L{\LB{_\* size defined below. This optimisation significantly improves the}} \L{\LB{_\* performance of this class.}} \L{\LB{_\* Buffers maintain an internal state variable that determines the}} \L{\LB{_\* state of the buffer. Only when the state is \'good()\' will pack\1unpack}} \L{\LB{_\* operations be performed.}} \L{\LB{_\*}} \L{\LB{_\* The member functions which are enclosed within this class are part of}} \L{\LB{_\* the Arjuna distribution unless otherwise stated}} \L{\LB{_\*\1\CE{}}} \L{\LB{}} \L{\LB{\K{\#ifndef}_\V{STDDEF\_H\_}}} \L{\LB{\K{\#}__\K{include}_\<\V{System}\1\V{stddef}.\V{h}\>}} \L{\LB{\K{\#endif}}} \L{\LB{}} \L{\LB{\K{\#ifndef}_\V{POINTERMAP\_H\_}}} \L{\LB{\K{\#}__\K{include}_\<\V{Common}\1\V{PointerMap}.\V{h}\>}} \L{\LB{\K{\#endif}}} \L{\LB{}} \L{\LB{\K{\#ifndef}_\V{COMMONT\_H\_}}} \L{\LB{\K{\#}__\K{include}_\<\V{Common}\1\V{CommonT}.\V{h}\>}} \L{\LB{\K{\#endif}}} \L{\LB{}} \L{\LB{\1\1_@\V{NoMarshall}}} \L{\LB{\K{enum}_\V{BufferState}_\{_\V{BUFFER\_GOOD},_\V{BUFFER\_BAD}_\};_____}} \L{\LB{}} \L{\LB{\C{}\1\* Avoid including iostream.h if at all possible \*\1\CE{}}} \L{\LB{}} \L{\LB{\1\1_@\V{NoRemote},_@\V{NoMarshall}}} \L{\LB{\V{class}_\V{ostream};}} \L{\LB{}} \L{\LB{\1\1_@\V{NoRemote},_@\V{NoMarshall}}} \L{\LB{\V{class}_\V{RpcBuffer};}} \L{\LB{}} \L{\LB{\K{static}_\V{const}_\V{size\_t}_\V{DEFAULT\_CHUNK\_SIZE}_=_512;}} \L{\LB{}} \L{\LB{\1\1_@\V{NoRemote},_@\V{UserMarshall}}} \L{\LB{\V{class}_\V{Buffer}}} \L{\LB{\{}} \L{\LB{\V{public}:}} \L{\LB{____\C{}\1\* Constructors \& destructor \*\1\CE{}}} \L{\LB{____}} \L{\LB{____\V{Buffer}_(\V{size\_t}_\V{buffSize}_=_\V{DEFAULT\_CHUNK\_SIZE});}} \L{\LB{____\V{Buffer}_(\V{size\_t}_\V{buffSize},_\K{char}_\*\V{buffer},_\V{Boolean}_\V{full}_=_\V{TRUE},}} \L{\LB{}\Tab{8}{____\V{Boolean}_\V{shouldDel}=_\V{TRUE});}} \L{\LB{____\V{Buffer}_(\V{const}_\V{Buffer}\&_\V{copyFrom});}} \L{\LB{____\V{virtual}_\~\V{Buffer}_();}} \L{\LB{}} \L{\LB{____\V{Boolean}_\V{sizeup}_(\V{size\_t});}} \L{\LB{____}} \L{\LB{____\C{}\1\* non-virtual member functions and operators \*\1\CE{}}} \L{\LB{____}} \L{\LB{____\V{const}_\K{char}_\*\V{buffer}_()_\V{const};}} \L{\LB{____\V{size\_t}_\V{length}_()_\V{const};}} \L{\LB{____\V{BufferState}_\V{readState}_()_\V{const};}} \L{\LB{____\K{void}_\V{reread}_();}} \L{\LB{____\K{void}_\V{rewrite}_();}} \L{\LB{}} \L{\LB{____\V{Boolean}_\V{setBuffer}_(\V{size\_t}_\V{buffSize},_\K{void}_\*\V{buffer},_\V{Boolean}_\V{full}_=_\V{TRUE},}} \L{\LB{}\Tab{16}{_______\V{Boolean}_\V{shouldDel}_=_\V{TRUE});}} \L{\LB{}} \L{\LB{____\K{void}_\V{setState}_(\V{BufferState});}} \L{\LB{____}} \L{\LB{____\C{}\1\* Pointer Manipulation handling \*\1\CE{}}} \L{\LB{____}} \L{\LB{____\V{Boolean}_\V{shouldPack}_(\V{const}_\K{void}_\*\V{ptr},_\V{Boolean}_=_\V{FALSE},_\V{Uint32}_=_0);}} \L{\LB{____\V{Boolean}_\V{saveUnpackedPtr}_(\V{const}_\K{void}_\*\V{ptr},_\V{Int32}\&_\V{ptrIndex});}} \L{\LB{____\V{Boolean}_\V{unpackPtr}_(\V{const}_\K{void}_\*\&_\V{ptr},_\V{Int32}\&_\V{ptrIndex});}} \L{\LB{}} \L{\LB{____\C{}\1\* pack operations for standard types \*\1\CE{}}} \L{\LB{}} \L{\LB{\K{\#ifdef}_\V{HAVE\_BOOLEAN\_TYPE}}} \L{\LB{____\V{Boolean}_\V{pack}_(\V{bool});}} \L{\LB{\K{\#endif}}} \L{\LB{____}} \L{\LB{____\V{Boolean}_\V{pack}_(\K{char});}} \L{\LB{____\V{Boolean}_\V{pack}_(\K{unsigned}_\K{char});}} \L{\LB{____\V{Boolean}_\V{pack}_(\K{short});}} \L{\LB{____\V{Boolean}_\V{pack}_(\K{unsigned}_\K{short});}} \L{\LB{____\V{Boolean}_\V{pack}_(\K{int});}} \L{\LB{____\V{Boolean}_\V{pack}_(\K{unsigned}_\K{int});}} \L{\LB{____\V{Boolean}_\V{pack}_(\K{long});}} \L{\LB{____\V{Boolean}_\V{pack}_(\K{unsigned}_\K{long});}} \L{\LB{\K{\#ifdef}_\V{HAVE\_LONG\_LONG}}} \L{\LB{____\V{Boolean}_\V{pack}_(\K{long}_\K{long});}} \L{\LB{____\V{Boolean}_\V{pack}_(\K{unsigned}_\K{long}_\K{long});}} \L{\LB{\K{\#endif}}} \L{\LB{____\V{Boolean}_\V{pack}_(\K{float});}} \L{\LB{____\V{Boolean}_\V{pack}_(\K{double});}} \L{\LB{____\V{Boolean}_\V{packMappedString}_(\V{const}_\K{char}_\*);}} \L{\LB{____\V{Boolean}_\V{packNonMappedString}_(\V{const}_\K{char}_\*);}} \L{\LB{____\V{Boolean}_\V{packMappedBlock}_(\V{const}_\K{void}_\*,_\V{const}_\V{size\_t});}} \L{\LB{____\V{Boolean}_\V{packNonMappedBlock}_(\V{const}_\K{void}_\*,_\V{const}_\V{size\_t});}} \L{\LB{}} \L{\LB{\K{\#ifdef}_\V{HAVE\_BOOLEAN\_TYPE}}} \L{\LB{____\V{Boolean}_\V{unpack}_(\V{bool}\&);}} \L{\LB{\K{\#endif}}} \L{\LB{____\V{Boolean}_\V{unpack}_(\K{char}\&);}} \L{\LB{____\V{Boolean}_\V{unpack}_(\K{unsigned}_\K{char}\&);}} \L{\LB{____\V{Boolean}_\V{unpack}_(\K{int}\&);}} \L{\LB{____\V{Boolean}_\V{unpack}_(\K{unsigned}_\K{int}\&);}} \L{\LB{____\V{Boolean}_\V{unpack}_(\K{long}\&);}} \L{\LB{____\V{Boolean}_\V{unpack}_(\K{unsigned}_\K{long}\&);}} \L{\LB{\K{\#ifdef}_\V{HAVE\_LONG\_LONG}}} \L{\LB{____\V{Boolean}_\V{unpack}_(\K{long}_\K{long}\&);}} \L{\LB{____\V{Boolean}_\V{unpack}_(\K{unsigned}_\K{long}_\K{long}\&);}} \L{\LB{\K{\#endif}_}} \L{\LB{____\V{Boolean}_\V{unpack}_(\K{short}\&);}} \L{\LB{____\V{Boolean}_\V{unpack}_(\K{unsigned}_\K{short}\&);}} \L{\LB{____\V{Boolean}_\V{unpack}_(\K{float}\&);}} \L{\LB{____\V{Boolean}_\V{unpack}_(\K{double}\&);}} \L{\LB{____\V{Boolean}_\V{unpack}_(\K{char}_\*\&);}} \L{\LB{____\V{Boolean}_\V{unpack}_(\K{void}_\*\&,_\V{size\_t}\&);}} \L{\LB{}} \L{\LB{____\C{}\1\* This converts the buffer into a number representation \*\1\CE{}}} \L{\LB{}} \L{\LB{____\K{int}_\V{constructBuffer}_(\K{char}_\*\V{passedInBuffer});__\1\1_\V{Added}_\V{by}_\V{Dean}_\V{Thompson}}} \L{\LB{_________________________________________________\1\1__\V{to}_\V{allow}_\V{a}_\V{class}_\V{to}_\V{be}}} \L{\LB{_________________________________________________\1\1__\V{represented}_\V{as}_\V{a}_}} \L{\LB{_________________________________________________\1\1__\V{character}_\V{array}}} \L{\LB{}} \L{\LB{____\V{Boolean}_\V{reconstructBuffer}_(\K{char}_\*\V{bufferInString});_\1\1_\V{Added}_\V{by}_\V{Dean}_\V{Thompson}}} \L{\LB{______________________________________________________\1\1__\V{to}_\V{allow}_\V{a}_\V{class}_\V{to}}} \L{\LB{______________________________________________________\1\1__\V{be}_\V{reconstructed}_}} \L{\LB{______________________________________________________\1\1__\V{from}_\V{a}_\V{character}}} \L{\LB{______________________________________________________\1\1__\V{array}.}} \L{\LB{}} \L{\LB{____\K{int}_\V{calculateSize}();__\1\1_\V{Added}_\V{by}_\V{Dean}_\V{Thompson}_\V{to}_\V{provide}_\V{support}_\K{for}}} \L{\LB{__________________________\1\1__\V{calculating}_\V{the}_\V{amount}_\V{of}_\V{space}_\V{required}_\V{to}_\V{store}}} \L{\LB{__________________________\1\1__\V{the}_\V{class}_\V{in}_\V{a}_\V{character}_\V{array}.}} \L{\LB{}} \L{\LB{____\C{}\1\* other operators \*\1\CE{}}} \L{\LB{____}} \L{\LB{____\V{Buffer}\&_\V{operator}=_(\V{const}_\V{Buffer}\&);}\Tab{40}{\C{}\1\* assignment that copies the buffer \*\1\CE{}}} \L{\LB{____\V{Buffer}\&_\V{operator}+=_(\V{const}_\V{Buffer}\&);}\Tab{40}{\C{}\1\* concatentation operator \*\1\CE{}}} \L{\LB{____\V{Boolean}_\V{operator}==_(\V{const}_\V{Buffer}\&)_\V{const};_\C{}\1\* equality operator \*\1\CE{}}} \L{\LB{____}} \L{\LB{____\C{}\1\* virtual member functions and operators \*\1\CE{}}} \L{\LB{_}} \L{\LB{____\C{}\1\* Allow Buffers to be packed into other Buffers \*\1\CE{}}} \L{\LB{}} \L{\LB{____\V{virtual}_\V{Boolean}_\V{packInto}_(\V{Buffer}\&)_\V{const};}} \L{\LB{____\V{virtual}_\V{Boolean}_\V{unpackFrom}_(\V{Buffer}\&);}} \L{\LB{____\V{virtual}_\V{Boolean}_\V{appendUnused}_(\V{const}_\V{Buffer}\&);}} \L{\LB{___}} \L{\LB{____\C{}\1\* Rpc marshalling \*\1\CE{}}} \L{\LB{}} \L{\LB{____\V{virtual}_\K{void}_\V{marshall}_(\V{RpcBuffer}\&)_\V{const};}} \L{\LB{____\V{virtual}_\K{void}_\V{unmarshall}_(\V{RpcBuffer}\&);}} \L{\LB{____}} \L{\LB{____\V{virtual}_\V{ostream}\&_\V{print}_(\V{ostream}\&)_\V{const};}} \L{\LB{}} \L{\LB{\V{private}:}} \L{\LB{____}} \L{\LB{____\C{}\1\* private member functions \*\1\CE{}}} \L{\LB{____}} \L{\LB{____\K{void}_\V{copybuff}_(\V{const}_\V{Buffer}\&);}} \L{\LB{____\V{Boolean}_\V{initBuffer}_();}} \L{\LB{____\V{Boolean}_\V{pack32bits}_(\V{Uint32});}} \L{\LB{____\V{Boolean}_\V{pack64bits}_(\V{Uint64});}} \L{\LB{____\V{Boolean}_\V{packBlock}_(\V{const}_\K{void}_\*,_\V{size\_t},_\V{Boolean});}} \L{\LB{____\V{Boolean}_\V{unpack32bits}_(\V{Uint32}\&);}} \L{\LB{____\V{Boolean}_\V{unpack64bits}_(\V{Uint64}\&);}} \L{\LB{____\V{Boolean}_\V{unpackBlock}_(\K{void}_\*\&,_\V{size\_t}\&);}} \L{\LB{____\V{Boolean}_\V{realign}_(\K{char}_\*\&);____}} \L{\LB{____\K{void}_\V{setLength}_(\V{size\_t});}} \L{\LB{____}} \L{\LB{____\C{}\1\* private state variables \*\1\CE{}}} \L{\LB{}} \L{\LB{____\K{char}_\V{shortSize};}\Tab{40}{\C{}\1\* bytes in a short \*\1\CE{}}} \L{\LB{____\K{char}_\V{intSize};}\Tab{40}{\C{}\1\* bytes in an int \*\1\CE{}}} \L{\LB{____\K{char}_\V{longSize};}\Tab{40}{\C{}\1\* bytes in a long \*\1\CE{}}} \L{\LB{____\K{char}_\V{longlongSize};}\Tab{40}{\C{}\1\* bytes in a long long \*\1\CE{}}} \L{\LB{____}} \L{\LB{____\V{BufferState}_\V{buffState};}} \L{\LB{____\K{char}_\*\V{bufferEnd};}} \L{\LB{____\K{char}_\*\V{bufferStart};}} \L{\LB{____\K{char}_\V{bufferContents}[\V{DEFAULT\_CHUNK\_SIZE}];}} \L{\LB{____\K{int}_\V{rereadOffset};}} \L{\LB{____}} \L{\LB{____\V{size\_t}_\V{chunkSize};}} \L{\LB{____\K{char}_\*\V{packPoint};}} \L{\LB{____\K{char}_\*\V{unpackPoint};}} \L{\LB{}} \L{\LB{____\V{Boolean}_\V{shouldDelete};}} \L{\LB{____\V{Boolean}_\V{readOnly};}} \L{\LB{____}} \L{\LB{____\V{PointerMap}_\V{packPointers};}} \L{\LB{____\V{PointerMap}_\V{unpackPointers};}} \L{\LB{\};}} \L{\LB{}} \L{\LB{\K{\#include}_\<\V{Common}\1\V{Buffer}.\V{n}\>}} \L{\LB{}} \L{\LB{\K{\#}__\K{endif}}} \L{\LB{\K{\#endif}}} \L{\LB{}}