NLMISC::CBitMemStream Class Reference

#include <bit_mem_stream.h>

Inheritance diagram for NLMISC::CBitMemStream:

NLMISC::CMemStream NLMISC::IStream

Detailed Description

Bit-oriented memory stream

How output mode works: In CMemStream, _BufPos points to the end of the stream, where to write new data. In CBitMemStream, _BufPos points to the last byte of the stream, where to write new data. Then _FreeBits tells the number of bits not used in this byte (i.e. (8-_FreeBits) is the number of bits already filled inside this byte). The minimum buffer size is 1: when nothing has been written yet, the position is at beginning and _FreeBits is 8.

How input mode works: Same as in CMemStream, but some bits may be free in the last byte (the information about how many is not stored in the CBitMemStream object, the reader needs to know the format of the data it reads).

Author:
Olivier Cado

Nevrax France

Date:
2001, 2003

Definition at line 356 of file bit_mem_stream.h.

Seek fonctionnality

enum  TSeekOrigin { begin, current, end }
virtual std::string getStreamName () const

Public Types


Public Member Functions

const uint8buffer () const
uint8bufferToFill (uint32 msgsize)
 See doc in CMemStream::bufferToFill().

 CBitMemStream (const CBitMemStream &other)
 Copy constructor.

 CBitMemStream (bool inputStream=false, uint32 defaultcapacity=32)
 Constructor.

virtual void clear ()
 Clears the message.

void displayLastBits (sint nbits, sint bitpos=-1, NLMISC::CLog *log=NLMISC::DebugLog)
 Display the bits of the stream just before the specified bitpos (or current pos if -1).

void displayStream (const char *title="", CLog *log=NLMISC::DebugLog)
 Returns the stream as a string with 0 and 1.

template<class T> void fastRead (T &value)
template<class T> void fastSerial (T &val)
template<class T> void fastWrite (const T &value)
void fill (const uint8 *srcbuf, uint32 len)
 See doc in CMemStream::fill().

sint32 getPos () const
 Const and not-virtual getPos(), for direct use. Caution: should not be overloaded in a child class.

virtual sint32 getPos () throw (EStream)
sint32 getPosInBit () const
 Returns the number of bit from the beginning of the buffer (in bit).

std::string getSerialItem (const TBMSSerialInfo &serialItem)
 Return a string showing the serial item.

void increaseBufferIfNecessary (uint32 len)
 Increase the buffer size if 'len' can't enter, otherwise, do nothing.

virtual void invert ()
 Transforms the message from input to output or from output to input.

bool isReading () const
 Is this stream a Read/Input stream?

bool isXML () const
virtual uint32 length () const
CBitMemStreamoperator= (const CBitMemStream &other)
 Assignment operator.

template<class T> void poke (T value, sint32 pos)
void poke (uint32 value, uint bitpos, uint nbits)
void pokeBits (const NLMISC::CBitSet &bitfield, uint bitpos)
void readBits (NLMISC::CBitSet &bitfield)
sint32 reserve (uint len)
void reserveBits (uint nbits)
void resetBufPos ()
void resetPtrTable ()
 Force to reset the ptr table.

void resize (uint32 size)
 Resize the buffer.

virtual bool seek (sint32 offset, TSeekOrigin origin) throw (EStream)
template<class T0, class T1, class T2, class T3, class T4, class T5> void serial (T0 &a, T1 &b, T2 &c, T3 &d, T4 &e, T5 &f)
template<class T0, class T1, class T2, class T3, class T4> void serial (T0 &a, T1 &b, T2 &c, T3 &d, T4 &e)
template<class T0, class T1, class T2, class T3> void serial (T0 &a, T1 &b, T2 &c, T3 &d)
template<class T0, class T1, class T2> void serial (T0 &a, T1 &b, T2 &c)
template<class T0, class T1> void serial (T0 &a, T1 &b)
template<class T> void serial (T &obj)
 Template serialisation (should take the one from IStream).

void serial (uint64 &value, uint nbits)
void serial (uint32 &value, uint nbits, bool resetvalue=true)
virtual void serialBit (bool &bit)
 Serialize one bit.

virtual void serialBuffer (uint8 *buf, uint len)
 Serialize a buffer.

virtual void serialBufferWithSize (uint8 *buf, uint32 len)
virtual void serialCont (std::vector< bool > &cont)
 Specialisation of serialCont() for vector<bool>.

virtual void serialCont (std::vector< sint8 > &cont)
 Specialisation of serialCont() for vector<sint8>.

virtual void serialCont (std::vector< uint8 > &cont)
 Specialisation of serialCont() for vector<uint8>.

template<class K, class T> void serialCont (std::multimap< K, T > &cont)
 Specialisation of serialCont() for vector<bool>.

template<class K, class T> void serialCont (std::map< K, T > &cont)
 Specialisation of serialCont() for vector<bool>.

template<class T> void serialCont (std::multiset< T > &cont)
 Specialisation of serialCont() for vector<bool>.

template<class T> void serialCont (std::set< T > &cont)
 Specialisation of serialCont() for vector<bool>.

template<class T> void serialCont (std::deque< T > &cont)
 Specialisation of serialCont() for vector<bool>.

template<class T> void serialCont (std::list< T > &cont)
 Specialisation of serialCont() for vector<bool>.

template<class T> void serialCont (std::vector< T > &cont)
template<class T> void serialEnum (T &em)
 Template enum serialisation. Serialized as a sint32.

virtual void serialMemStream (CMemStream &b)
 Serial memstream, bitmemstream...

void setStringMode (bool stringmode)
 Set string mode.

uint32 size () const
 Returns the size of the buffer (can be greater than the length, especially in output mode).

bool stringMode () const
 Return string mode.

Base type serialisation.
Those method are a specialisation of template method "void serial(T&)".

virtual void serial (CBitMemStream &b)
virtual void serial (ucstring &b)
virtual void serial (std::string &b)
virtual void serial (char &b)
virtual void serial (bool &b)
virtual void serial (double &b)
virtual void serial (float &b)
virtual void serial (sint64 &b)
virtual void serial (uint64 &b)
virtual void serial (sint32 &b)
virtual void serial (uint32 &b)
virtual void serial (sint16 &b)
virtual void serial (uint16 &b)
virtual void serial (sint8 &b)
virtual void serial (uint8 &b)
virtual void serialMemStream (CBitMemStream &b)

Static Public Member Functions

void getVersionException (bool &throwOnOlder, bool &throwOnNewer)
void setVersionException (bool throwOnOlder, bool throwOnNewer)

Protected Member Functions

void increaseBufferIfNecessary ()
void internalSerial (uint64 &value, uint nbits)
void internalSerial (uint32 &value, uint nbits, bool resetvalue=true)
uint32 lengthR () const
uint32 lengthS () const
 Returns the serialized length (number of bytes written or read).

void pointNextByte ()
void prepareNextByte ()
void serialPoke (uint32 value, uint nbits)
template<class T> void serialVector (T &cont)

Protected Attributes

CObjectVector< uint8, false > _Buffer
uint8_BufPos
CBMSDbgInfo _DbgInfo
 Debug details about what was serialised.

uint32 _DefaultCapacity
uint _FreeBits
 Number of bits unused at the current pos. If 8, means the current pos if full and we need to increment the pos!

bool _StringMode


Member Enumeration Documentation

enum NLMISC::IStream::TSeekOrigin [inherited]
 

Parameters for seek(). begin seek from the begining of the stream. current seek from the current location of the stream pointer. end seek from the end of the stream.

Enumeration values:
begin 
current 
end 

Definition at line 549 of file stream.h.

00549 { begin, current, end };


Constructor & Destructor Documentation

NLMISC::CBitMemStream::CBitMemStream bool  inputStream = false,
uint32  defaultcapacity = 32
 

Constructor.

Definition at line 51 of file bit_mem_stream.cpp.

References resetBufPos(), and uint32.

00051                                                                        :
00052         CMemStream( inputStream, false, defaultcapacity ),
00053         _FreeBits( 0 )
00054 {
00055         resetBufPos();
00056 }

NLMISC::CBitMemStream::CBitMemStream const CBitMemStream other  ) 
 

Copy constructor.

Definition at line 62 of file bit_mem_stream.cpp.

00062                                                          :
00063         CMemStream( other ),
00064         _FreeBits( other._FreeBits ),
00065         _DbgInfo( other._DbgInfo )
00066 {
00067 }


Member Function Documentation

const uint8* NLMISC::CMemStream::buffer  )  const [inline, inherited]
 

Returns a pointer to the message buffer (read only) Returns NULL if the buffer is empty

Definition at line 238 of file mem_stream.h.

References NLMISC::CObjectVector< uint8, false >::getPtr(), and uint8.

Referenced by NLNET::CMessage::assignFromSubMessage(), NLMISC::displayBitStream(), NLNET::CMessage::extractStreamFromPos(), NLNET::TMessageRecord::serial(), NLMISC::IStream::serialMemStream(), serialMemStream(), and NLNET::CMessage::serialMessage().

00239         {
00240                 return _Buffer.getPtr();
00241 /*              if ( _Buffer.empty() )
00242                 {
00243                         return NULL;
00244                 }
00245                 else
00246                 {
00247                         return &(*_Buffer.begin());
00248                 }*/
00249         }

uint8* NLMISC::CBitMemStream::bufferToFill uint32  msgsize  )  [inline]
 

See doc in CMemStream::bufferToFill().

Reimplemented from NLMISC::CMemStream.

Definition at line 460 of file bit_mem_stream.h.

References _DbgInfo, _FreeBits, NLMISC::CBMSDbgInfo::clear(), uint32, and uint8.

Referenced by serialMemStream().

00461         {
00462                 _FreeBits = 8;
00463                 _DbgInfo.clear();
00464                 return CMemStream::bufferToFill( msgsize );
00465         }

virtual void NLMISC::CBitMemStream::clear void   )  [inline, virtual]
 

Clears the message.

Reimplemented from NLMISC::CMemStream.

Definition at line 436 of file bit_mem_stream.h.

References resetBufPos().

00437         {
00438                 CMemStream::clear();
00439                 resetBufPos();
00440         }

void NLMISC::CBitMemStream::displayLastBits sint  nbits,
sint  bitpos = -1,
NLMISC::CLog log = NLMISC::DebugLog
 

Display the bits of the stream just before the specified bitpos (or current pos if -1).

Definition at line 641 of file bit_mem_stream.cpp.

References NLMISC::displayBitStream(), getPosInBit(), and sint.

00642 {
00643         if ( bitpos == -1 )
00644                 bitpos = getPosInBit(); 
00645         displayBitStream( *this, max(bitpos-nbits, 0), bitpos-1, log );
00646 }

void NLMISC::CBitMemStream::displayStream const char *  title = "",
CLog log = NLMISC::DebugLog
 

Returns the stream as a string with 0 and 1.

Definition at line 673 of file bit_mem_stream.cpp.

References _DbgInfo, _FreeBits, NLMISC::CBMSDbgInfo::beginEventBrowsing(), NLMISC::CLog::displayNL(), NLMISC::CLog::displayRawNL(), NLMISC::CBMSDbgInfo::endEventBrowsing(), NLMISC::CBMSDbgInfo::getEventIdAtBitPos(), NLMISC::CBMSDbgInfo::getEventLegendAtBitPos(), getPosInBit(), NLMISC::CObjectVector< uint8, false >::getPtr(), NLMISC::IStream::isReading(), nlassert, s, sint, sint32, NLMISC::CObjectVector< uint8, false >::size(), NLMISC::toString(), uint32, and uint8.

00674 {
00675         nlassert( (_BufPos >= _Buffer.getPtr()) && (_BufPos <= _Buffer.getPtr() + _Buffer.size()) );
00676 
00677         // Display title and information
00678         string s = (isReading()?string("I"):string("O")) + string("BMS ") + string(title) + ": ";
00679         string sLegend;
00680         if ( _BufPos == _Buffer.getPtr() )
00681         {
00682                 log->displayNL( (s + "Empty").c_str() );
00683                 return;
00684         }
00685 
00686         s += NLMISC::toString( "BitPos=%d Pos=%u FreeBits=%u Size=%u ", getPosInBit(), (uint32)(_BufPos-_Buffer.getPtr()), _FreeBits, _Buffer.size() );
00687         log->displayNL( s.c_str() );
00688         s.clear();
00689 
00690         // Display bitstream (output: until _BufPos/_FreeBits; input: whole buffer)
00691         _DbgInfo.beginEventBrowsing();
00692         sint32 eventId;
00693         uint32 bitpos = 0;
00694         uint8 *p;
00695         uint8 *endPos = isReading() ? (_Buffer.getPtr() + _Buffer.size()) : (_BufPos+1);
00696         for ( p=_Buffer.getPtr(); p!=endPos; ++p )
00697         {
00698                 sint i;
00699                 for ( i=7; i!=-1; --i )
00700                 {
00701                         //bitpos = (p-_Buffer.getPtr())*8 + (7-i);
00702                         if ( bitpos == (uint32)getPosInBit() )
00703                                 s += "<P>"; // display the current position
00704                         s += _DbgInfo.getEventIdAtBitPos( bitpos, &eventId );
00705                         s += ( ((*p) >> i) & 1 ) ? '1' : '0';
00706                         sLegend += _DbgInfo.getEventLegendAtBitPos( *this, eventId );
00707                         ++bitpos; 
00708                 }
00709 
00710                 s += ' '; // a blank char between each byte
00711                 if ( bitpos % 64 == 0 ) // limit to 8 bytes per line
00712                 {
00713                         log->displayRawNL( s.c_str() );
00714                         s.clear();
00715                 }
00716         }
00717         if ( bitpos % 64 != 0 )
00718                 log->displayRawNL( s.c_str() );
00719         _DbgInfo.endEventBrowsing();
00720         
00721         // Display legend
00722         string::size_type lineStart = 0;
00723         string::size_type crp = sLegend.find( '\n', lineStart );
00724         while ( crp != string::npos )
00725         {
00726                 log->displayRawNL( sLegend.substr( lineStart, crp-lineStart ).c_str() );
00727                 lineStart = crp + 1;
00728                 crp = sLegend.find( '\n', lineStart );
00729         }
00730         // sLegend ends with a '\n'
00731 }

template<class T>
void NLMISC::CMemStream::fastRead T &  value  )  [inline, inherited]
 

Definition at line 404 of file mem_stream.h.

References NLMISC::CMemStream::_BufPos, NLMISC::CMemStream::length(), NLMISC::CMemStream::lengthS(), and value.

00405         {
00406                 //nldebug( "MEMSTREAM: Reading %u-byte value in %p at pos %u", sizeof(value), this, _BufPos - _Buffer.getPtr() );
00407                 // Check that we don't read more than there is to read
00408                 if ( lengthS()+sizeof(value) > length() ) // calls virtual length (cf. sub messages)
00409                 {
00410                         throw EStreamOverflow();
00411                 }
00412                 // Serialize in
00413                 value = *(T*)_BufPos;
00414                 _BufPos += sizeof(value);
00415         }

template<class T>
void NLMISC::CMemStream::fastSerial T &  val  )  [inline, inherited]
 

Definition at line 371 of file mem_stream.h.

References NLMISC::CMemStream::_BufPos, NLMISC::CMemStream::increaseBufferIfNecessary(), NLMISC::IStream::isReading(), NLMISC::CMemStream::length(), and NLMISC::CMemStream::lengthS().

Referenced by NLMISC::CMemStream::serial().

00372         {
00373 #ifdef NL_LITTLE_ENDIAN
00374                 if(isReading())
00375                 {
00376                         // Check that we don't read more than there is to read
00377                         // TODO OPTIM we can remove the check if we want to be faster (50ms->43ms for 1 million serial)
00378                         if ( lengthS()+sizeof(T) > length() ) // calls virtual length (cf. sub messages)
00379                                 throw EStreamOverflow();
00380                         // Serialize in
00381                         val = *(T*)_BufPos;
00382                 }
00383                 else
00384                 {
00385                         increaseBufferIfNecessary (sizeof(T));
00386                         *(T*)_BufPos = val;
00387                 }
00388                 _BufPos += sizeof (T);
00389 #else // NL_LITTLE_ENDIAN
00390                 IStream::serial( val );
00391 #endif // NL_LITTLE_ENDIAN
00392         }

template<class T>
void NLMISC::CMemStream::fastWrite const T &  value  )  [inline, inherited]
 

Definition at line 395 of file mem_stream.h.

References NLMISC::CMemStream::_BufPos, NLMISC::CMemStream::increaseBufferIfNecessary(), and value.

00396         {
00397                 //nldebug( "MEMSTREAM: Writing %u-byte value in %p at pos %u", sizeof(value), this, _BufPos - _Buffer.getPtr() );
00398                 increaseBufferIfNecessary (sizeof(T));
00399                 *(T*)_BufPos = value;
00400                 _BufPos += sizeof (T);
00401         }

void NLMISC::CBitMemStream::fill const uint8 srcbuf,
uint32  len
[inline]
 

See doc in CMemStream::fill().

Reimplemented from NLMISC::CMemStream.

Definition at line 452 of file bit_mem_stream.h.

References _DbgInfo, _FreeBits, NLMISC::CBMSDbgInfo::clear(), len, uint32, and uint8.

00453         {
00454                 _FreeBits = 8;
00455                 _DbgInfo.clear();
00456                 CMemStream::fill( srcbuf, len );
00457         }

sint32 NLMISC::CMemStream::getPos void   )  const [inline, inherited]
 

Const and not-virtual getPos(), for direct use. Caution: should not be overloaded in a child class.

Definition at line 159 of file mem_stream.h.

References NLMISC::CMemStream::_BufPos, NLMISC::CObjectVector< uint8, false >::getPtr(), and sint32.

00160         {
00161                 return _BufPos - _Buffer.getPtr();
00162         }

virtual sint32 NLMISC::CMemStream::getPos void   )  throw (EStream) [inline, virtual, inherited]
 

Get the location of the stream pointer.

NB: If the stream doesn't support the seek fonctionnality, it throws ESeekNotSupported. Default implementation: { throw ESeekNotSupported; }

Parameters:
offset is the wanted offset from the origin.
origin is the origin of the seek
Returns:
the new offset regarding from the origin.
See also:
ESeekNotSupported SeekOrigin seek

Reimplemented from NLMISC::IStream.

Definition at line 153 of file mem_stream.h.

References NLMISC::CMemStream::_BufPos, NLMISC::CObjectVector< uint8, false >::getPtr(), and sint32.

Referenced by NLNET::CMessage::changeType(), NLNET::CMessage::CMessage(), NLNET::CMessage::getName(), NLNET::CMessage::lockSubMessage(), NLNET::CMessage::readType(), NLNET::CMessage::readTypeAtCurrentPos(), serial(), serialCont(), serialMemStream(), NLNET::CMessage::setType(), and NLNET::CMessage::unlockSubMessage().

00154         {
00155                 return _BufPos - _Buffer.getPtr();
00156         }

sint32 NLMISC::CBitMemStream::getPosInBit  )  const [inline]
 

Returns the number of bit from the beginning of the buffer (in bit).

Definition at line 443 of file bit_mem_stream.h.

References _FreeBits, NLMISC::CObjectVector< uint8, false >::getPtr(), and sint32.

Referenced by displayLastBits(), displayStream(), getSerialItem(), internalSerial(), poke(), pokeBits(), readBits(), reserveBits(), serial(), serialBit(), serialBuffer(), serialCont(), and serialMemStream().

00444         {
00445                 return (_BufPos - _Buffer.getPtr() + 1)*8 - _FreeBits;
00446         }

std::string NLMISC::CBitMemStream::getSerialItem const TBMSSerialInfo serialItem  ) 
 

Return a string showing the serial item.

Definition at line 737 of file bit_mem_stream.cpp.

References _FreeBits, NLMISC::TBMSSerialInfo::BitPos, NLMISC::TBMSSerialInfo::BitSize, getPosInBit(), NLMISC::CObjectVector< uint8, false >::getPtr(), NLMISC::IStream::isReading(), len, NLMISC::CMemStream::lengthR(), NL_I64, readBits(), NLMISC::CBitSet::resize(), s, serial(), serialBit(), serialBuffer(), NLMISC::IStream::setInOut(), NLMISC::CBitSet::toString(), NLMISC::toString(), NLMISC::TBMSSerialInfo::Type, uint, uint32, uint64, and uint8.

Referenced by NLMISC::CBMSDbgInfo::getEventLegendAtBitPos().

00738 {
00739         // Save the current pointers of the stream, and make them point to the required position
00740         uint savedFreeBits = _FreeBits;
00741         uint bytepos = serialItem.BitPos >> 3;
00742         _FreeBits = 8 - (serialItem.BitPos - (bytepos << 3));
00743         uint8 *savedBufPos = _BufPos;
00744         _BufPos = _Buffer.getPtr() + bytepos;
00745 
00746         bool wasOutput = false;;
00747         if ( ! isReading() )
00748         {
00749                 setInOut( true ); // lighter than invert()
00750                 wasOutput = true;
00751         }
00752 
00753         // Read and format string
00754         string s;
00755         if ( getPosInBit() + serialItem.BitSize > lengthR() * 8 )
00756         {
00757                 s = "<Stream Overflow>";
00758         }
00759         else
00760         {
00761                 switch ( serialItem.Type )
00762                 {
00763                 case TBMSSerialInfo::B:
00764                         {
00765                                 bool b;
00766                                 serialBit( b );
00767                                 s = NLMISC::toString( "%s", b?"TRUE":"FALSE" );
00768                                 break;
00769                         }
00770                 case TBMSSerialInfo::U: // no distinction with signed int!
00771                         {
00772                                 uint32 u;
00773                                 serial( u, serialItem.BitSize );
00774                                 s = NLMISC::toString( "%u", u );
00775                                 break;
00776                         }
00777                 case TBMSSerialInfo::U64: // no distinction with signed int64!
00778                         {
00779                                 uint64 u;
00780                                 serial( u, serialItem.BitSize );
00781                                 s = NLMISC::toString( "%"NL_I64"u", u );
00782                                 break;
00783                         }
00784                 case TBMSSerialInfo::F: // what about double?
00785                         {
00786                                 float f;
00787                                 serial( f );
00788                                 s = NLMISC::toString( "%g", f );
00789                                 break;
00790                         }
00791                 case TBMSSerialInfo::BF:
00792                         {
00793                                 CBitSet bs;
00794                                 bs.resize( serialItem.BitSize );
00795                                 readBits( bs );
00796                                 s = bs.toString();
00797                                 break;
00798                         }
00799                 case TBMSSerialInfo::Buffer:
00800                         {
00801                                 uint32 len = serialItem.BitSize / 8;
00802                                 s.resize( len + 2 );
00803                                 if ( len != 0 )
00804                                 {
00805                                         serialBuffer( &((uint8&)(s[1])), len );
00806                                         string::size_type p;
00807                                         for ( p=1; p!=len+1; ++p )
00808                                         {
00809                                                 if ( ! isalnum(s[p]) )
00810                                                         s[p] = '?'; // remove end-of-c_string
00811                                         }
00812                                 }
00813                                 s[0] = '[';
00814                                 s[len+1] = ']';
00815                                 break;
00816                         }
00817                 default:
00818                   break;
00819                 }
00820         }
00821 
00822         // Restore the current pointers
00823         if ( wasOutput )
00824         {
00825                 setInOut( false );
00826         }
00827 
00828         _FreeBits = savedFreeBits;
00829         _BufPos = savedBufPos;
00830 
00831         return s;
00832 }

string NLMISC::IStream::getStreamName  )  const [virtual, inherited]
 

Get a name for this stream. maybe a fileName if FileStream. Default is to return "".

Reimplemented in NLMISC::CIFile, and NLMISC::COFile.

Definition at line 420 of file stream.cpp.

Referenced by NLMISC::EStream::EStream().

00421 {
00422         return "";
00423 }

void NLMISC::IStream::getVersionException bool &  throwOnOlder,
bool &  throwOnNewer
[static, inherited]
 

Get the behavior of IStream regarding input stream that are older/newer than the class.

See also:
serialVersion() setVersionException()

Definition at line 78 of file stream.cpp.

References NLMISC::IStream::_ThrowOnNewer, and NLMISC::IStream::_ThrowOnOlder.

00079 {
00080         throwOnOlder=_ThrowOnOlder;
00081         throwOnNewer=_ThrowOnNewer;
00082 }

void NLMISC::CMemStream::increaseBufferIfNecessary uint32  len  )  [inline, inherited]
 

Increase the buffer size if 'len' can't enter, otherwise, do nothing.

Definition at line 358 of file mem_stream.h.

References NLMISC::CMemStream::_BufPos, NLMISC::CObjectVector< uint8, false >::getPtr(), len, NLMISC::CObjectVector< uint8, false >::resize(), NLMISC::CObjectVector< uint8, false >::size(), and uint32.

Referenced by NLMISC::CMemStream::fastSerial(), NLMISC::CMemStream::fastWrite(), NLMISC::CMemStream::reserve(), and NLMISC::CMemStream::serialBuffer().

00359         {
00360                 uint32 oldBufferSize = _Buffer.size();
00361                 if (_BufPos - _Buffer.getPtr() + len > oldBufferSize)
00362                 {
00363                         // need to increase the buffer size
00364                         uint32 pos = _BufPos - _Buffer.getPtr();
00365                         _Buffer.resize(oldBufferSize*2 + len);
00366                         _BufPos = _Buffer.getPtr() + pos;
00367                 }
00368         }

void NLMISC::CBitMemStream::increaseBufferIfNecessary  )  [inline, protected]
 

Increase the size of the buffer if necessary (outpout bit stream)

Preconditions:

Postconditions:

Definition at line 730 of file bit_mem_stream.h.

References NLMISC::CObjectVector< uint8, false >::empty(), NLMISC::CObjectVector< uint8, false >::getPtr(), NLMISC::IStream::isReading(), nlassert, NLMISC::CObjectVector< uint8, false >::resize(), NLMISC::CObjectVector< uint8, false >::size(), and uint32.

Referenced by prepareNextByte().

00731         {
00732 #ifdef NL_DEBUG
00733                 nlassert( (!isReading()) && (!_Buffer.empty()) );
00734                 nlassert( _BufPos <= _Buffer.getPtr() + _Buffer.size() );
00735 #endif
00736                 uint32 bytepos = _BufPos - _Buffer.getPtr();
00737                 if ( bytepos == _Buffer.size() )
00738                 {
00739                         _Buffer.resize( bytepos * 2 );
00740                         _BufPos = _Buffer.getPtr() + bytepos; // don't change the pos but update pointer (needed because the buffer may have moved when reallocating)
00741                 }
00742         }

void NLMISC::CBitMemStream::internalSerial uint64 value,
uint  nbits
[inline, protected]
 

Helper for serial(uint64,uint)

Definition at line 650 of file bit_mem_stream.h.

References internalSerial(), NLMISC::IStream::isReading(), uint, uint32, uint64, and value.

00651         {
00652                 if ( nbits > 32 )
00653                 {
00654                         if ( isReading() )
00655                         {
00656                                 // Reset and read MSD
00657                                 uint32 msd = 0;
00658                                 internalSerial( msd, nbits-32 );
00659                                 value = (uint64)msd << 32;
00660                                 // Reset and read LSD
00661                                 internalSerial( (uint32&)value, 32 );
00662                         }
00663                         else
00664                         {
00665                                 // Write MSD
00666                                 uint32 msd = (uint32)(value >> 32);
00667                                 internalSerial( msd, nbits-32 );
00668                                 // Write LSD
00669                                 internalSerial( (uint32&)value, 32 );
00670                         }
00671                 }
00672                 else
00673                 {
00674                         if ( isReading() )
00675                         {
00676                                 // Reset MSB (=0 is faster than value&=0xFFFFFFFF)
00677                                 value = 0;
00678                         }
00679                         // Read or write LSB
00680                         internalSerial( (uint32&)value, nbits );
00681                 }
00682         }

void NLMISC::CBitMemStream::internalSerial uint32 value,
uint  nbits,
bool  resetvalue = true
[protected]
 

Helper for serial(uint32,uint)

Definition at line 172 of file bit_mem_stream.cpp.

References _FreeBits, getPosInBit(), NLMISC::IStream::isReading(), NLMISC::CMemStream::lengthR(), nlassert, prepareNextByte(), uint, uint32, uint8, v, and value.

Referenced by internalSerial(), serial(), serialBit(), and serialBuffer().

00173 {
00174         if ( nbits == 0 )
00175                 return;
00176         if ( nbits > 32 )
00177                 throw EMemStream (string("trying to serial ")+NLMISC::toString(nbits)+string(" bits"));
00178 
00179         if ( isReading() )
00180         {
00181                 // Check that we don't read more than there is to read
00182                 if ( getPosInBit() + nbits > lengthR() * 8 )
00183                 {
00184                         //displayStream( "Stream Overflow" );
00185                         throw EStreamOverflow();
00186                 }
00187 
00188                 if ( resetvalue )
00189                 {
00190                         value = 0;
00191                 }
00192 
00193                 // Clear high-order bits after _FreeBits
00194                 uint8 v = *_BufPos & ((1 << _FreeBits) - 1);
00195 
00196                 if ( nbits > _FreeBits )
00197                 {
00198                         //nldebug( "Reading byte %u from %u free bits (%u remaining bits)", lengthS(), _FreeBits, nbits );
00199                         value |= (v << (nbits-_FreeBits));
00200                         ++_BufPos;
00201                         uint readbits = _FreeBits;
00202                         //displayByteBits( *_BufPos, 8, readbits-1, false );
00203                         _FreeBits = 8;
00204                         internalSerial( value, nbits - readbits, false ); // read without resetting value
00205                 }
00206                 else
00207                 {
00208                         //nlinfo( "Reading last byte %u from %u free bits (%u remaining bits)", lengthS(), _FreeBits, nbits );
00209                         //displayByteBits( *_BufPos, 8, _FreeBits-1, false );
00210                         value |= (v >> (_FreeBits-nbits));
00211                         //displayByteBits( *_BufPos, 8, _FreeBits-1, false );
00212                         _FreeBits -= nbits;
00213                         if ( _FreeBits == 0 )
00214                         {
00215                                 _FreeBits = 8;
00216                                 ++_BufPos;
00217                         }
00218                 }
00219         }
00220         else
00221         {
00222                 // Clear high-order bits after nbits
00223                 //displayDwordBits( value, 32, nbits-1, false );
00224 
00225                 //uint32 mask = (-1 >> (32-nbits)); // does not work
00226                 uint32 v;
00227                 if ( nbits != 32 ) // arg of shl/sal/shr/sal ranges from 0 to 31
00228                 {
00229                         uint32 mask = (1 << nbits) - 1;
00230                         v = value & mask;
00231                 }
00232                 else
00233                 {
00234                         v = value;
00235                 }
00236 
00237 #ifdef NL_DEBUG
00238                 // Check that the current byte is prepared
00239                 nlassert( ! ((_FreeBits == 8) && (*_BufPos != 0)) );
00240 #endif
00241 
00242                 // Set
00243                 if ( nbits > _FreeBits )
00244                 {
00245                         // Longer than the room in the current byte
00246                         //nldebug( "Writing byte %u into %u free bits (%u remaining bits)", lengthS(), _FreeBits, nbits );
00247                         //displayDwordBits( value, 32, nbits-1, false );
00248                         *_BufPos |= (v >> (nbits - _FreeBits));
00249                         uint filledbits = _FreeBits;
00250                         //displayByteBits( *_BufPos, 8, filledbits-1, false );
00251                         prepareNextByte();
00252                         internalSerial( v, nbits - filledbits );
00253                 }
00254                 else
00255                 {
00256                         // Shorter or equal
00257                         //nldebug( "Writing last byte %u into %u free bits (%u remaining bits)", lengthS(), _FreeBits, nbits );
00258                         //displayByteBits( *_BufPos, 8, 7, false );
00259                         *_BufPos |= (v << (_FreeBits-nbits));
00260                         //displayByteBits( *_BufPos, 8, _FreeBits-1, false );
00261                         _FreeBits -= nbits;
00262                         if ( _FreeBits == 0 )
00263                         {
00264                                 prepareNextByte();
00265                         }
00266                 }
00267         }
00268 }

virtual void NLMISC::CBitMemStream::invert  )  [inline, virtual]
 

Transforms the message from input to output or from output to input.

Reimplemented from NLMISC::CMemStream.

Definition at line 418 of file bit_mem_stream.h.

References NLMISC::CObjectVector< uint8, false >::getPtr(), NLMISC::IStream::isReading(), nlassert, and NLMISC::CObjectVector< uint8, false >::size().

00419         {
00420                 if ( ! isReading() )
00421                 {
00422                         ++_BufPos; // write->read: extend to keep the last byte inside the payload
00423                 }
00424                 CMemStream::invert();
00425                 if ( ! isReading() )
00426                 {
00427 #ifdef NL_DEBUG
00428                         nlassert( _BufPos == _Buffer.getPtr()+_Buffer.size() );
00429 #endif
00430                         --_BufPos; // read->write: set the position on the last byte, not at the end as in CMemStream::invert()
00431                 }
00432                 // Keep the same _FreeBits
00433         }

bool NLMISC::IStream::isReading  )  const [inline, inherited]
 

Is this stream a Read/Input stream?

Definition at line 64 of file stream_inline.h.

References NLMISC::IStream::_InputStream.

Referenced by NLNET::CMessage::assignFromSubMessage(), NLMISC::CMemStream::bufferToFill(), NL3D::CParticleSystemShape::buildFromPS(), NLNET::CMessage::clear(), NLMISC::CMemStream::clear(), NLNET::CMessage::CMessage(), displayStream(), NLMISC::CMemStream::fastSerial(), NLMISC::CMemStream::fill(), NL3D::CParticleSystemShape::flushTextures(), getSerialItem(), increaseBufferIfNecessary(), NLMISC::COXml::init(), NL3D::CParticleSystemShape::instanciatePS(), internalSerial(), NLNET::CMessage::invert(), NLMISC::CMemStream::invert(), invert(), NLNET::CMessage::length(), NLMISC::CMemStream::length(), length(), NLMISC::CBitmap::load(), NLMISC::CBitmap::loadSize(), NLNET::CMessage::lockSubMessage(), NLNET::CMessage::operator=(), pointNextByte(), NLMISC::CMemStream::poke(), poke(), pokeBits(), readBits(), NLMISC::CBitmap::readTGA(), NLNET::CMessage::readTypeAtCurrentPos(), NLMISC::CMemStream::reserve(), reserveBits(), resetBufPos(), NLPACS::CGlobalRetriever::CLrLoader::run(), NL3D::CZone::serial(), NL3D::CVegetableShape::serial(), NLPACS::CSurfaceQuadTree::serial(), NLPACS::CQuadBranch::serial(), NL3D::CSurfaceLightGrid::CCellCorner::serial(), NLMISC::CStringStream::serial(), NLMISC::IStream::serial(), NL3D::CInstanceGroup::serial(), NL3D::CInstanceGroup::CInstance::serial(), NLPACS::CRetrieverInstance::serial(), NLPACS::CRetrieverBank::serial(), NL3D::CPSAttrib< T >::serial(), NL3D::CPortal::serial(), NL3D::CPointLightNamed::serial(), NL3D::CPointLight::serial(), NL3D::CPatch::serial(), NLMISC::CObjectVector< sint8, false >::serial(), NLMISC::COXml::serial(), NLNET::TMessageRecord::serial(), NL3D::CMeshMRMSkinnedGeom::serial(), NLMISC::CMemStream::serial(), NLMISC::CMatrix::serial(), NL3D::CMaterial::CLightMap::serial(), NL3D::CMaterial::serial(), NLNET::CInetAddress::serial(), NL3D::CHLSTextureBank::serial(), NLPACS::CGlobalRetriever::serial(), NLPACS::CEdgeQuad::serial(), NL3D::CCluster::serial(), NLPACS::CChainQuad::serial(), NLPACS::COrderedChain::serial(), NLMISC::CBitSet::serial(), serial(), NL3D::CMaterialBase::CAnimatedTexture::serial(), NLMISC::CAABBoxExt::serial(), NL3D::CMaterial::CLightMap::serial2(), NLMISC::CStringStream::serialBit(), NLMISC::CMemStream::serialBit(), serialBit(), NLMISC::CMemStream::serialBuffer(), serialBuffer(), NLMISC::IStream::serialCheck(), NLMISC::CStringStream::serialCont(), NLMISC::IStream::serialCont(), serialCont(), NLMISC::IStream::serialEnum(), NL3D::CVertexBuffer::serialHeader(), NLMISC::CStringStream::serialHex(), NLMISC::CMemStream::serialHex(), NLMISC::IStream::serialIStreamable(), NL3D::CMeshMRMGeom::serialLodVertexData(), NLMISC::IStream::serialMap(), NLMISC::IStream::serialMemStream(), serialMemStream(), NLNET::CMessage::serialMessage(), NLMISC::IStream::serialMultimap(), NL3D::CVertexBuffer::serialOldV1Minus(), NLMISC::IStream::serialPtr(), NLMISC::CStringStream::serialSeparatedBufferIn(), NLMISC::CMemStream::serialSeparatedBufferIn(), NLMISC::CStringStream::serialSeparatedBufferOut(), NLMISC::COXml::serialSeparatedBufferOut(), NLMISC::CMemStream::serialSeparatedBufferOut(), NLMISC::IStream::serialSTLCont(), NLMISC::IStream::serialSTLContLen(), NLMISC::IStream::serialSTLContLenPolyPtr(), NLMISC::IStream::serialSTLContLenPtr(), NLMISC::IStream::serialSTLContPolyPtr(), NLMISC::IStream::serialSTLContPtr(), NL3D::CVertexBuffer::serialSubset(), NLMISC::IStream::serialVector(), NLMISC::IStream::serialVectorPolyPtr(), NLMISC::IStream::serialVectorPtr(), NLMISC::IStream::serialVersion(), NLNET::CMessage::setType(), NLNET::CMessage::unlockSubMessage(), NLMISC::CBitmap::writeTGA(), NLMISC::COXml::xmlBreakLineInternal(), NLMISC::COXml::xmlCommentInternal(), NLMISC::COXml::xmlPopInternal(), NLMISC::COXml::xmlPushBeginInternal(), NLMISC::COXml::xmlPushEndInternal(), and NLMISC::COXml::xmlSetAttribInternal().

00065 {
00066         return _InputStream;
00067 }

bool NLMISC::IStream::isXML  )  const [inline, inherited]
 

Definition at line 221 of file stream.h.

References NLMISC::IStream::_XML.

Referenced by NLMISC::CMemStream::serial().

00221 { return _XML; }        

virtual uint32 NLMISC::CBitMemStream::length  )  const [inline, virtual]
 

Returns the length (size) of the message, in bytes. If isReading(), it is the number of bytes that can be read, otherwise it is the number of bytes that have been written (the last byte may not be full, it may have free bits, see also getPosInBit()).

Reimplemented from NLMISC::CMemStream.

Definition at line 402 of file bit_mem_stream.h.

References _FreeBits, NLMISC::IStream::isReading(), NLMISC::CMemStream::lengthR(), NLMISC::CMemStream::lengthS(), and uint32.

Referenced by serial(), serialCont(), and serialMemStream().

00403         {
00404                 if ( isReading() )
00405                 {
00406                         return lengthR();
00407                 }
00408                 else
00409                 {
00410                         if ( _FreeBits == 8 )
00411                                 return lengthS();
00412                         else
00413                                 return lengthS() + 1;
00414                 }
00415         }

uint32 NLMISC::CMemStream::lengthR  )  const [inline, protected, inherited]
 

Returns the "read" message size (number of bytes to read) Do not use directly, use length() instead in reading mode (which is virtual)

Reimplemented in NLNET::CMessage.

Definition at line 511 of file mem_stream.h.

References NLMISC::CMemStream::size(), and uint32.

Referenced by getSerialItem(), internalSerial(), NLMISC::CMemStream::invert(), NLMISC::CMemStream::length(), and length().

00512         {
00513                 return size();
00514         }

uint32 NLMISC::CMemStream::lengthS  )  const [inline, protected, inherited]
 

Returns the serialized length (number of bytes written or read).

Definition at line 502 of file mem_stream.h.

References NLMISC::CMemStream::_BufPos, NLMISC::CObjectVector< uint8, false >::getPtr(), and uint32.

Referenced by NLMISC::CMemStream::fastRead(), NLMISC::CMemStream::fastSerial(), NLNET::CMessage::length(), NLMISC::CMemStream::length(), length(), NLMISC::CMemStream::operator=(), NLMISC::CMemStream::serialBuffer(), NLMISC::CStringStream::serialSeparatedBufferIn(), and NLMISC::CMemStream::serialSeparatedBufferIn().

00503         {
00504                 return _BufPos - _Buffer.getPtr(); // not calling getPos() because virtual and not const!
00505         }

CBitMemStream& NLMISC::CBitMemStream::operator= const CBitMemStream other  )  [inline]
 

Assignment operator.

Definition at line 367 of file bit_mem_stream.h.

References _DbgInfo, and _FreeBits.

00368         {
00369                 CMemStream::operator=( other );
00370                 _FreeBits = other._FreeBits;
00371                 _DbgInfo = other._DbgInfo;
00372                 return *this;
00373         }

void NLMISC::CBitMemStream::pointNextByte  )  [inline, protected]
 

Point the beginning of the byte after _BufPos

Preconditions

  • The last written byte, at pos _BufPos, is fully written (but _FreeBits may not be updated yet)

Postconditions

  • The pos was incremented by 1, _FreeBits is 8

Definition at line 710 of file bit_mem_stream.h.

References _FreeBits, NLMISC::IStream::isReading(), and nlassert.

Referenced by prepareNextByte(), and serialPoke().

00711         {
00712 #ifdef NL_DEBUG
00713                 nlassert( !isReading() );
00714 #endif
00715                 _FreeBits = 8;
00716                 ++_BufPos;
00717         }

template<class T>
void NLMISC::CMemStream::poke value,
sint32  pos
[inline, inherited]
 

When writing, fill a value previously reserved by reserve() (warning: you MUST have called reserve() with sizeof(T) before poking). Usually it's an alternative to use serialCont with a vector. Example: uint8 counter=0; sint32 counterPos = msgout.reserve( sizeof(counter) ); counter = serialSelectedItems( msgout ); msgout.poke( counter, counterPos );

Definition at line 190 of file mem_stream.h.

References NLMISC::CMemStream::_BufPos, NLMISC::CObjectVector< uint8, false >::getPtr(), NLMISC::IStream::isReading(), nlassert, sint32, uint8, and value.

00191         {
00192                 if ( ! isReading() )
00193                 {
00194                         uint8 *pokeBufPos = _Buffer.getPtr() + pos;
00195                         nlassert( pokeBufPos + sizeof(T) <= _BufPos );
00196                         *(T*)pokeBufPos = value;
00197                 }
00198         }

void NLMISC::CBitMemStream::poke uint32  value,
uint  bitpos,
uint  nbits
 

Definition at line 346 of file bit_mem_stream.cpp.

References _DbgInfo, _FreeBits, NLMISC::CBMSDbgInfo::addPoke(), getPosInBit(), NLMISC::CObjectVector< uint8, false >::getPtr(), NLMISC::IStream::isReading(), nlassert, serialPoke(), uint, uint32, uint8, and value.

00347 {
00348 #ifdef NL_DEBUG
00349         nlassert( (nbits <= 32) && (nbits != 0) );
00350         nlassert( ! isReading() );
00351         nlassert( bitpos+nbits <= (uint)getPosInBit() );
00352 #endif
00353 
00354         // Save the current pointers of the stream, and make them point to the required position
00355         uint savedFreeBits = _FreeBits;
00356         uint bytepos = bitpos >> 3;
00357         _FreeBits = 8 - (bitpos - (bytepos << 3));
00358         uint8 *savedBufPos = _BufPos;
00359         _BufPos = _Buffer.getPtr() + bytepos;
00360 
00361         // Serial
00362         _DbgInfo.addPoke( bitpos, nbits, TBMSSerialInfo::U );
00363         serialPoke( value, nbits );
00364 
00365         // Restore the current pointers
00366         _FreeBits = savedFreeBits;
00367         _BufPos = savedBufPos;
00368 }

void NLMISC::CBitMemStream::pokeBits const NLMISC::CBitSet bitfield,
uint  bitpos
 

Rewrite the bitfield at the specified position bitpos of the current output bit stream. The size of the bitfield is *not* written into the stream (unlike serialCont()). Precondition: bitpos+bitfield.size() <= the current length in bit of the stream. See also reserveBits().

Definition at line 375 of file bit_mem_stream.cpp.

References _DbgInfo, _FreeBits, NLMISC::CBMSDbgInfo::addPoke(), getPosInBit(), NLMISC::CObjectVector< uint8, false >::getPtr(), NLMISC::CBitSet::getVector(), NLMISC::IStream::isReading(), nlassert, serialPoke(), NLMISC::CBitSet::size(), uint, and uint8.

00376 {
00377 #ifdef NL_DEBUG
00378         nlassert( ! isReading() );
00379         nlassert( bitpos+bitfield.size() <= (uint)getPosInBit() );
00380 #endif
00381 
00382         // Save the current pointers of the stream, and make them point to the required position
00383         uint savedFreeBits = _FreeBits;
00384         uint bytepos = bitpos >> 3;
00385         _FreeBits = 8 - (bitpos - (bytepos << 3));
00386         uint8 *savedBufPos = _BufPos;
00387         _BufPos = _Buffer.getPtr() + bytepos;
00388 
00389         // Serial
00390         _DbgInfo.addPoke( bitpos, bitfield.size(), TBMSSerialInfo::BF );
00391         const vector<uint32>& uintVec = bitfield.getVector();
00392         if ( ! uintVec.empty() )
00393         {
00394                 for ( uint i=0; i<uintVec.size()-1; ++i )
00395                 {
00396                         //nldebug( "Bitfield: Poked %u at %d (bitpos %d)", uintVec[i], getPos(), getPosInBit() );
00397                         serialPoke( uintVec[i], 32 );
00398                 }
00399                 //nldebug( "Bitfield: Poked %u at %d (bitpos %d)", uintVec.back(), getPos(), getPosInBit() );
00400                 uint remainingBits = bitfield.size() % 32;
00401                 if ( remainingBits != 0 )
00402                         serialPoke( uintVec.back(), remainingBits );
00403         }
00404 
00405         // Restore the current pointers
00406         _FreeBits = savedFreeBits;
00407         _BufPos = savedBufPos;
00408 }

void NLMISC::CBitMemStream::prepareNextByte  )  [inline, protected]
 

Prepare next byte for writing.

Preconditions:

Postconditions:

Definition at line 694 of file bit_mem_stream.h.

References increaseBufferIfNecessary(), and pointNextByte().

Referenced by internalSerial().

00695         {
00696                 pointNextByte();
00697                 increaseBufferIfNecessary();
00698                 *_BufPos = 0;
00699         }

void NLMISC::CBitMemStream::readBits NLMISC::CBitSet bitfield  ) 
 

Read bitfield.size() bits from the input stream to fill the bitfield. It means you have to know the size and to resize the bitfield yourself.

Definition at line 415 of file bit_mem_stream.cpp.

References getPosInBit(), NLMISC::IStream::isReading(), len, nlassert, nldebug, serial(), NLMISC::CBitSet::setUint(), NLMISC::CBitSet::size(), uint, uint32, and v.

Referenced by getSerialItem().

00416 {
00417 #ifdef NL_DEBUG
00418         nlassert( isReading() );
00419 #endif
00420         uint len = bitfield.size();
00421         if ( len != 0 )
00422         {
00423 #ifdef LOG_ALL_TRAFFIC
00424                 if ( VerboseAllTraffic )
00425                         nldebug( "TRAFFIC/%p/%s: Reading %u bits bitfield at bitpos %d", this, isReading()?"I":"O", len, getPosInBit() );
00426 #endif
00427                 uint i = 0;
00428                 uint32 v;
00429                 while ( len > 32 )
00430                 {
00431                         serial( v, 32 );
00432                         //nldebug( "Bitfield: Read %u at %d", v, _BufPos-_Buffer.getPtr()-4 );
00433                         bitfield.setUint( v, i );
00434                         len -= 32;
00435                         ++i;
00436                 }
00437                 serial( v, len );
00438                 //nldebug( "Bitfield: Read %u at %d", v, _BufPos-_Buffer.getPtr()-4 );
00439                 bitfield.setUint( v, i );
00440         }
00441 }

sint32 NLMISC::CMemStream::reserve uint  len  )  [inline, inherited]
 

When writing, skip 'len' bytes and return the position of the blank space for a future poke(). Warning: this has nothing to do with the semantics of reserve() in std::vector!

Definition at line 168 of file mem_stream.h.

References NLMISC::CMemStream::_BufPos, NLMISC::CObjectVector< uint8, false >::getPtr(), NLMISC::CMemStream::increaseBufferIfNecessary(), NLMISC::IStream::isReading(), len, sint32, and uint.

00169         {
00170                 sint32 pos = _BufPos - _Buffer.getPtr();
00171                 if ( ! isReading() )
00172                 {
00173                         increaseBufferIfNecessary( len );
00174                         _BufPos += len;
00175                 }
00176                 return pos;
00177         }

void NLMISC::CBitMemStream::reserveBits uint  nbits  ) 
 

In a output bit stream, serialize nbits bits (no matter their value). Works even if the number of bits to add is larger than 64. See also poke() and pokeBits().

Definition at line 275 of file bit_mem_stream.cpp.

References getPosInBit(), NLMISC::IStream::isReading(), nldebug, serial(), uint, uint32, and v.

00276 {
00277 #ifdef LOG_ALL_TRAFFIC
00278         if ( VerboseAllTraffic )
00279                 nldebug( "TRAFFIC/%p/%s: Reserving %u bits at bitpos %d", this, isReading()?"I":"O", nbits, getPosInBit() );    
00280 #endif
00281 
00282         uint32 v = 0;
00283         while ( nbits > 32 )
00284         {
00285                 serial( v, 32 );
00286                 nbits -= 32;
00287         }
00288         if ( nbits != 0 )
00289                 serial( v, nbits );
00290 }

void NLMISC::CBitMemStream::resetBufPos  )  [inline]
 

Set the position at the beginning. In output mode, the method ensures the buffer contains at least one blank byte to write to.

If you are using the stream only in output mode, you can use this method as a faster version of clear() *if you don't serialize pointers*.

_Buffer.resize( 8 ); // at least 8 bytes

Reimplemented from NLMISC::CMemStream.

Definition at line 382 of file bit_mem_stream.h.

References _DbgInfo, _FreeBits, NLMISC::CBMSDbgInfo::clear(), NLMISC::CObjectVector< uint8, false >::empty(), NLMISC::IStream::isReading(), and nlassert.

Referenced by CBitMemStream(), clear(), and serialMemStream().

00383         {
00384                 // This is ensured in CMemStream::CMemStream() and CMemStream::clear()
00385                 //if ( (!isReading()) && _Buffer.empty() )
00387                 nlassert( ! ((!isReading()) && _Buffer.empty()) );
00388 
00389                 CMemStream::resetBufPos();
00390                 if ( !isReading() )
00391                         *_BufPos = 0; // partial prepareNextByte()
00392                 _FreeBits = 8;
00393                 _DbgInfo.clear();
00394         }

void NLMISC::CMemStream::resetPtrTable  )  [inline, inherited]
 

Force to reset the ptr table.

Reimplemented from NLMISC::IStream.

Definition at line 352 of file mem_stream.h.

Referenced by NLMISC::CMemStream::clear(), NL3D::CParticleSystemShape::flushTextures(), NL3D::CParticleSystemShape::instanciatePS(), and NLMISC::CMemStream::invert().

00352 { IStream::resetPtrTable() ; }

void NLMISC::CMemStream::resize uint32  size  )  [inherited]
 

Resize the buffer.

Definition at line 235 of file mem_stream.cpp.

References NLMISC::CMemStream::_BufPos, NLMISC::CObjectVector< uint8, false >::getPtr(), NLMISC::CMemStream::length(), NLMISC::CObjectVector< uint8, false >::resize(), size, and uint32.

00236 {
00237         if (size == length()) return;
00238         // need to increase the buffer size
00239         uint32 pos = _BufPos - _Buffer.getPtr();
00240         _Buffer.resize(size);
00241         _BufPos = _Buffer.getPtr() + pos;
00242 }

bool NLMISC::CMemStream::seek sint32  offset,
TSeekOrigin  origin
throw (EStream) [virtual, inherited]
 

Moves the stream pointer to a specified location.

Warning: in output mode, seek(end) does not point to the end of the serialized data, but on the end of the whole allocated buffer (see size()). If you seek back and want to return to the end of the serialized data, you have to store the position (a better way is to use reserve()/poke()).

NB: If the stream doesn't support the seek fonctionnality, it throws ESeekNotSupported. Default implementation: { throw ESeekNotSupported; }

Parameters:
offset is the wanted offset from the origin.
origin is the origin of the seek
Returns:
true if seek sucessfull.
See also:
ESeekNotSupported SeekOrigin getPos

Reimplemented from NLMISC::IStream.

Definition at line 177 of file mem_stream.cpp.

References offset, sint, and sint32.

Referenced by NLNET::CMessage::changeType(), NLNET::CMessage::CMessage(), NL3D::CParticleSystemShape::flushTextures(), NLNET::CMessage::getName(), NLNET::getNameOfMessageOrTransportClass(), NL3D::CParticleSystemShape::instanciatePS(), NLNET::CMessage::readType(), NLNET::CMessage::readTypeAtCurrentPos(), NLNET::CMessage::serialMessage(), and NLNET::CMessage::unlockSubMessage().

00178 {
00179         switch (origin)
00180         {
00181         case begin:
00182                 if (offset > (sint)length())
00183                         return false;
00184                 if (offset < 0)
00185                         return false;
00186                 _BufPos=_Buffer.getPtr()+offset;
00187                 break;
00188         case current:
00189                 if (getPos ()+offset > (sint)length())
00190                         return false;
00191                 if (getPos ()+offset < 0)
00192                         return false;
00193                 _BufPos+=offset;
00194                 break;
00195         case end:
00196                 if (offset < -(sint)length())
00197                         return false;
00198                 if (offset > 0)
00199                         return false;
00200                 _BufPos=_Buffer.getPtr()+_Buffer.size()+offset;
00201                 break;
00202         }
00203         return true;
00204 }

template<class T0, class T1, class T2, class T3, class T4, class T5>
void NLMISC::CMemStream::serial T0 &  a,
T1 &  b,
T2 &  c,
T3 &  d,
T4 &  e,
T5 &  f
[inline, inherited]
 

Reimplemented from NLMISC::IStream.

Reimplemented in NLMISC::CStringStream.

Definition at line 459 of file mem_stream.h.

References NLMISC::CMemStream::serial().

00460         { serial(a); serial(b); serial(c); serial(d); serial(e); serial(f);}

template<class T0, class T1, class T2, class T3, class T4>
void NLMISC::CMemStream::serial T0 &  a,
T1 &  b,
T2 &  c,
T3 &  d,
T4 &  e
[inline, inherited]
 

Reimplemented from NLMISC::IStream.

Reimplemented in NLMISC::CStringStream.

Definition at line 456 of file mem_stream.h.

References NLMISC::CMemStream::serial().

00457         { serial(a); serial(b); serial(c); serial(d); serial(e);}

template<class T0, class T1, class T2, class T3>
void NLMISC::CMemStream::serial T0 &  a,
T1 &  b,
T2 &  c,
T3 &  d
[inline, inherited]
 

Reimplemented from NLMISC::IStream.

Reimplemented in NLMISC::CStringStream.

Definition at line 453 of file mem_stream.h.

References NLMISC::CMemStream::serial().

00454         { serial(a); serial(b); serial(c); serial(d);}

template<class T0, class T1, class T2>
void NLMISC::CMemStream::serial T0 &  a,
T1 &  b,
T2 &  c
[inline, inherited]
 

Reimplemented from NLMISC::IStream.

Reimplemented in NLMISC::CStringStream.

Definition at line 450 of file mem_stream.h.

References NLMISC::CMemStream::serial().

00451         { serial(a); serial(b); serial(c);}

template<class T0, class T1>
void NLMISC::CMemStream::serial T0 &  a,
T1 &  b
[inline, inherited]
 

Reimplemented from NLMISC::IStream.

Reimplemented in NLMISC::CStringStream.

Definition at line 447 of file mem_stream.h.

References NLMISC::CMemStream::serial().

00448         { serial(a); serial(b);}

virtual void NLMISC::CBitMemStream::serial CBitMemStream b  )  [inline, virtual]
 

Definition at line 627 of file bit_mem_stream.h.

References serialMemStream().

00627 { serialMemStream(b); }

void NLMISC::CBitMemStream::serial ucstring b  )  [inline, virtual]
 

Reimplemented from NLMISC::CMemStream.

Definition at line 508 of file bit_mem_stream.cpp.

References getPosInBit(), NLMISC::IStream::isReading(), len, nldebug, NLMISC::SEPARATOR, serial(), serialBuffer(), sint, sint32, and uint8.

00509 {
00510 #ifdef LOG_ALL_TRAFFIC
00511         sint32 bitpos = getPosInBit();
00512 #endif
00513 
00514         if ( _StringMode )
00515         {
00516                 sint32  len=0;
00517                 // Read/Write the length.
00518                 if(isReading())
00519                 {
00520                         serial(len);
00521                         b.resize(len);
00522                 }
00523                 else
00524                 {
00525                         len= b.size();
00526                         serial(len);
00527                 }
00528                 // Read/Write the string.
00529                 for(sint i=0;i<len;i++)
00530                         serialBuffer( (uint8*)&b[i], sizeof( sizeof(b[i]) ) );
00531 
00532                 char sep = SEPARATOR;
00533                 serialBuffer( (uint8*)&sep, 1 );
00534         }
00535         else
00536         {
00537                 IStream::serial( b );
00538         }
00539 
00540 #ifdef LOG_ALL_TRAFFIC
00541         if ( VerboseAllTraffic )
00542                 nldebug( "TRAFFIC/%p/%s: Ucstring at bitpos %d", this, isReading()?"I":"O", bitpos );
00543 #endif
00544 
00545 }

void NLMISC::CBitMemStream::serial std::string &  b  )  [virtual]
 

Reimplemented from NLMISC::CMemStream.

Definition at line 467 of file bit_mem_stream.cpp.

References NLMISC::CMemStream::getPos(), getPosInBit(), NLMISC::IStream::isReading(), len, length(), nldebug, nlwarning, serial(), serialBuffer(), sint32, uint32, and uint8.

00468 {
00469 #ifdef LOG_ALL_TRAFFIC
00470         sint32 bitpos = getPosInBit();
00471 #endif
00472 
00473         uint32 len=0;
00474 
00475         // Serialize length
00476         if ( isReading() )
00477         {
00478                 serial( len );
00479                 if (len > length()-getPos())
00480                 {
00481                         nlwarning("BMS: string maximum length reached, perhaps invalid string size (%d)", len);
00482                         throw NLMISC::EInvalidDataStream();
00483                 }
00484                 b.resize( len );
00485         }
00486         else
00487         {
00488                 len = b.size();
00489                 serial( len );
00490         }
00491 
00492         // Serialize buffer
00493         if ( len != 0 )
00494         {
00495                 serialBuffer( (uint8*)(&*b.begin()), len );
00496         }
00497 
00498 #ifdef LOG_ALL_TRAFFIC
00499         if ( VerboseAllTraffic )
00500                 nldebug( "TRAFFIC/%p/%s: String (size 32+%u*8 bits) at bitpos %d", this, isReading()?"I":"O", len, bitpos );
00501 #endif
00502 }

virtual void NLMISC::CBitMemStream::serial char &  b  )  [inline, virtual]
 

Reimplemented from NLMISC::CMemStream.

Definition at line 621 of file bit_mem_stream.h.

References serialAdapt.

00621 { serialAdapt( b, char ); }

virtual void NLMISC::CBitMemStream::serial bool &  b  )  [inline, virtual]
 

Reimplemented from NLMISC::CMemStream.

Definition at line 619 of file bit_mem_stream.h.

References serialBit().

00619 { serialBit( b ); }

virtual void NLMISC::CBitMemStream::serial double &  b  )  [inline, virtual]
 

Reimplemented from NLMISC::CMemStream.

Definition at line 618 of file bit_mem_stream.h.

References serialAdapt64.

00618 { serialAdapt64( b ); }

void NLMISC::CBitMemStream::serial float &  b  )  [virtual]
 

Reimplemented from NLMISC::CMemStream.

Definition at line 447 of file bit_mem_stream.cpp.

References _DbgInfo, NLMISC::CBMSDbgInfo::addSerial(), getPosInBit(), internalSerial(), NLMISC::IStream::isReading(), and uint32.

00448 {
00449         _DbgInfo.addSerial( getPosInBit(), sizeof(b)*8, TBMSSerialInfo::F );
00450         uint32 uf=0;
00451         if ( isReading() )
00452         {
00453                 internalSerial( uf, sizeof(b)*8 );
00454                 b = *(float*)&uf;
00455         }
00456         else
00457         {
00458                 uf = *(uint32*)&b;
00459                 internalSerial( uf, sizeof(b)*8 );
00460         }
00461 }

virtual void NLMISC::CBitMemStream::serial sint64 b  )  [inline, virtual]
 

Reimplemented from NLMISC::CMemStream.

Definition at line 616 of file bit_mem_stream.h.

References serialAdapt64, and sint64.

00616 { serialAdapt64( b ); }

virtual void NLMISC::CBitMemStream::serial uint64 b  )  [inline, virtual]
 

Reimplemented from NLMISC::CMemStream.

Definition at line 615 of file bit_mem_stream.h.

References serialAdapt64, and uint64.

00615 { serialAdapt64( b ); }

virtual void NLMISC::CBitMemStream::serial sint32 b  )  [inline, virtual]
 

Reimplemented from NLMISC::CMemStream.

Definition at line 614 of file bit_mem_stream.h.

References serialAdapt, and sint32.

00614 { serialAdapt( b, sint32 ); }

virtual void NLMISC::CBitMemStream::serial uint32 b  )  [inline, virtual]
 

Reimplemented from NLMISC::CMemStream.

Definition at line 613 of file bit_mem_stream.h.

References serialAdapt, and uint32.

00613 { serialAdapt( b, uint32 ); }

virtual void NLMISC::CBitMemStream::serial sint16 b  )  [inline, virtual]
 

Reimplemented from NLMISC::CMemStream.

Definition at line 612 of file bit_mem_stream.h.

References serialAdapt, and sint16.

00612 { serialAdapt( b, sint16 ); }

virtual void NLMISC::CBitMemStream::serial uint16 b  )  [inline, virtual]
 

Reimplemented from NLMISC::CMemStream.

Definition at line 611 of file bit_mem_stream.h.

References serialAdapt, and uint16.

00611 { serialAdapt( b, uint16 ); }

virtual void NLMISC::CBitMemStream::serial sint8 b  )  [inline, virtual]
 

Reimplemented from NLMISC::CMemStream.

Definition at line 610 of file bit_mem_stream.h.

References serialAdapt, and sint8.

00610 { serialAdapt( b, sint8 ); }

virtual void NLMISC::CBitMemStream::serial uint8 b  )  [inline, virtual]
 

Reimplemented from NLMISC::CMemStream.

Definition at line 609 of file bit_mem_stream.h.

References serialAdapt, and uint8.

00609 { serialAdapt( b, uint8 ); }

template<class T>
void NLMISC::CBitMemStream::serial T &  obj  )  [inline]
 

Template serialisation (should take the one from IStream).

Reimplemented from NLMISC::CMemStream.

Definition at line 534 of file bit_mem_stream.h.

00534 { obj.serial(*this); }

void NLMISC::CBitMemStream::serial uint64 value,
uint  nbits
[inline]
 

Serialize only the nbits lower bits of 64-bit value (nbits range: [1..64])

Definition at line 492 of file bit_mem_stream.h.

References _DbgInfo, NLMISC::CBMSDbgInfo::addSerial(), getPosInBit(), internalSerial(), uint, uint64, and value.

00493         {
00494                 _DbgInfo.addSerial( getPosInBit(), nbits, TBMSSerialInfo::U64 );
00495                 internalSerial( value, nbits );
00496         }

void NLMISC::CBitMemStream::serial uint32 value,
uint  nbits,
bool  resetvalue = true
[inline]
 

Serialize only the nbits lower bits of value (nbits range: [1..32]) When using this method, always leave resetvalue to true.

Definition at line 483 of file bit_mem_stream.h.

References _DbgInfo, NLMISC::CBMSDbgInfo::addSerial(), getPosInBit(), internalSerial(), uint, uint32, and value.

Referenced by getSerialItem(), readBits(), reserveBits(), serial(), serialCont(), and serialMemStream().

00484         {
00485                 _DbgInfo.addSerial( getPosInBit(), nbits, TBMSSerialInfo::U );
00486                 internalSerial( value, nbits, resetvalue );
00487         }

void NLMISC::CBitMemStream::serialBit bool &  bit  )  [virtual]
 

Serialize one bit.

Reimplemented from NLMISC::CMemStream.

Definition at line 100 of file bit_mem_stream.cpp.

References _DbgInfo, NLMISC::CBMSDbgInfo::addSerial(), getPosInBit(), internalSerial(), NLMISC::IStream::isReading(), and uint32.

Referenced by getSerialItem(), serial(), and serialCont().

00101 {
00102         _DbgInfo.addSerial( getPosInBit(), 1, TBMSSerialInfo::B );
00103         uint32 ubit=0;
00104         if ( isReading() )
00105         {
00106                 internalSerial( ubit, 1 );
00107                 bit = ( ubit!=0 );
00108         }
00109         else
00110         {
00111                 ubit = bit;
00112                 internalSerial( ubit, 1 );
00113         }
00114 }

uint16 NLMISC::IStream::serialBitField16 uint16  bf  )  [inline, inherited]
 

Serialisation of bitfield <=16 bits.

Definition at line 332 of file stream_inline.h.

References NLMISC::IStream::serial(), and uint16.

00333 {
00334         serial(bf);
00335         return bf;
00336 }

uint32 NLMISC::IStream::serialBitField32 uint32  bf  )  [inline, inherited]
 

Serialisation of bitfield <=32 bits.

Definition at line 338 of file stream_inline.h.

References NLMISC::IStream::serial(), and uint32.

00339 {
00340         serial(bf);
00341         return bf;
00342 }

uint8 NLMISC::IStream::serialBitField8 uint8  bf  )  [inline, inherited]
 

Serialisation of bitfield <=8 bits.

Definition at line 326 of file stream_inline.h.

References NLMISC::IStream::serial(), and uint8.

Referenced by NL3D::CMaterial::CTexEnv::serial().

00327 {
00328         serial(bf);
00329         return bf;
00330 }

void NLMISC::CBitMemStream::serialBuffer uint8 buf,
uint  len
[virtual]
 

Serialize a buffer.

Reimplemented from NLMISC::CMemStream.

Definition at line 73 of file bit_mem_stream.cpp.

References _DbgInfo, NLMISC::CBMSDbgInfo::addSerial(), getPosInBit(), internalSerial(), NLMISC::IStream::isReading(), len, uint, uint32, uint8, and v.

Referenced by getSerialItem(), serial(), and serialMemStream().

00074 {
00075         _DbgInfo.addSerial( getPosInBit(), len*8, TBMSSerialInfo::Buffer );
00076         uint i;
00077         uint32 v;
00078         if ( isReading() )
00079         {
00080                 for ( i=0; i!=len; ++i )
00081                 {
00082                         internalSerial( v, 8 );
00083                         buf[i] = (uint8)v;
00084                 }
00085         }
00086         else
00087         {
00088                 for ( i=0; i!=len; ++i )
00089                 {
00090                         v = (uint32)buf[i];
00091                         internalSerial( v, 8 );
00092                 }
00093         }
00094 }

virtual void NLMISC::IStream::serialBufferWithSize uint8 buf,
uint32  len
[inline, virtual, inherited]
 

This method first serializes the size of the buffer and after the buffer itself, it enables the possibility to serial with a serialCont() on the other side.

Definition at line 877 of file stream.h.

References len, NLMISC::IStream::serial(), NLMISC::IStream::serialBuffer(), uint32, and uint8.

00878         {
00879                 serial (len);
00880                 serialBuffer (buf, len);
00881         }

template<class T>
void NLMISC::IStream::serialCheck const T &  value  )  [inline, inherited]
 

Serialize a check value. An object can stream a check value to check integrity or format of filed or streamed data. Just call serial check with a const value. Write will serial the value. Read will check the value is the same. If it is not, it will throw EInvalidDataStream exception.

NB: The type of the value must implement an operator == and must be serializable.

Parameters:
value the value used to the check.
See also:
EInvalidDataStream

Definition at line 520 of file stream.h.

References NLMISC::IStream::isReading(), NLMISC::IStream::serial(), value, NLMISC::IStream::xmlPop(), and NLMISC::IStream::xmlPush().

Referenced by NLNET::cbPacsAnswer(), NLNET::CPacsClient::initMessage(), loadForm(), NLLIGO::CZoneRegion::serial(), NLLIGO::CZoneBankElement::serial(), NL3D::CZone::serial(), NL3D::CVegetableShape::serial(), NL3D::CSkeletonWeight::serial(), NL3D::CInstanceGroup::serial(), NL3D::CLodCharacterShape::serial(), NL3D::CLodCharacterShapeBuild::serial(), NL3D::CAnimationSet::serial(), and NL3D::CAnimation::serial().

00521         {
00522                 // Open a node
00523                 xmlPush ("CHECK");
00524 
00525                 if (isReading()) 
00526                 { 
00527                         T read;
00528                         serial (read); 
00529                         if (read!=value) 
00530                                 throw EInvalidDataStream(*this); 
00531                 } 
00532                 else 
00533                 { 
00534                         serial (const_cast<T&>(value)); 
00535                 }
00536 
00537                 // Close the node 
00538                 xmlPop ();
00539         }

template<class T, class Allocator>
void NLMISC::IStream::serialCont std::vector< T, Allocator > &  cont  )  [inline, inherited]
 

Specialisation of serialCont() for vector<bool>.

Definition at line 324 of file stream.h.

References NLMISC::IStream::serialVector().

Referenced by NL3D::H_AUTO_DECL(), NLAISCRIPT::CLdbHeapMemberiOpCode::load(), NLAISCRIPT::CLdbStackMemberiOpCode::load(), NLAISCRIPT::CLdbMemberiOpCode::load(), NLAISCRIPT::CCallMethodi::load(), NLAISCRIPT::CCallStackMethodi::load(), NLAISCRIPT::CCallHeapMethodi::load(), NLAISCRIPT::CLibStackMemberMethod::load(), NLAISCRIPT::CLibCallMethodi::load(), NLAISCRIPT::CLibMemberMethodi::load(), NLAISCRIPT::CAffMemberiOpCode::load(), NLAISCRIPT::CAffHeapMemberiOpCode::load(), NLAISCRIPT::CLoadHeapObject::load(), NLAISCRIPT::CLoadStackObject::load(), NLAISCRIPT::CLoadSelfObject::load(), NLMISC::CEntityIdTranslator::load(), NLSOUND::CBackgroundSoundManager::load(), loadForm(), NLAISCRIPT::CLdbHeapMemberiOpCode::save(), NLAISCRIPT::CLdbStackMemberiOpCode::save(), NLAISCRIPT::CLdbMemberiOpCode::save(), NLAISCRIPT::CCallMethodi::save(), NLAISCRIPT::CCallStackMethodi::save(), NLAISCRIPT::CCallHeapMethodi::save(), NLAISCRIPT::CLibStackMemberMethod::save(), NLAISCRIPT::CLibCallMethodi::save(), NLAISCRIPT::CLibMemberMethodi::save(), NLAISCRIPT::CAffMemberiOpCode::save(), NLAISCRIPT::CAffHeapMemberiOpCode::save(), NLAISCRIPT::CLoadHeapObject::save(), NLAISCRIPT::CLoadStackObject::save(), NLAISCRIPT::CLoadSelfObject::save(), NLMISC::CEntityIdTranslator::save(), NLLIGO::CZoneRegion::serial(), NLLIGO::CZoneBankElement::serial(), NL3D::CZone::serial(), NL3D::CVegetableShape::serial(), NL3D::CTileVegetableDesc::serial(), NL3D::CSkeletonWeight::serial(), NL3D::CInstanceGroup::serial(), NL3D::CInstanceGroup::CInstance::serial(), NLPACS::CRetrieverInstance::serial(), NLPACS::CRetrieverBank::serial(), NLPACS::CRetrievableSurface::TLoop::serial(), NLPACS::CRetrievableSurface::serial(), NL3D::CPrimitiveBlock::serial(), NL3D::CPortal::serial(), NL3D::CPointLightNamedArray::serial(), NL3D::CPatch::serial(), NLMISC::CNoiseColorGradient::serial(), NL3D::CMeshMRMSkinnedGeom::CRdrPass::serial(), NL3D::CMeshMRMSkinnedGeom::CPackedVertexBuffer::serial(), NL3D::CMeshMRMSkinnedGeom::serial(), NL3D::CMeshBase::CLightMapInfoList::serial(), NL3D::CMeshBase::CLightInfoMapListV7::serial(), NL3D::CMeshGeom::CMatrixBlock::serial(), NL3D::CMaterial::serial(), NL3D::CLodCharacterTexture::serial(), NL3D::CLodCharacterShapeBank::serial(), NL3D::CLodCharacterShape::serial(), NL3D::CLodCharacterShape::CBoneInfluence::serial(), NL3D::CLodCharacterShape::CAnim::serial(), NL3D::CLodCharacterShapeBuild::serial(), NLPACS::CLocalRetriever::CTopology::serial(), NLPACS::CLocalRetriever::CTip::serial(), NLPACS::CLocalRetriever::serial(), NL3D::CIGSurfaceLight::serial(), NL3D::CHLSTextureBank::serial(), NL3D::CHLSColorTexture::serial(), NL3D::CHLSColorTexture::CMask::serial(), NLPACS::CGlobalRetriever::serial(), NLPACS::CFaceGrid::serial(), NLPACS::CExteriorMesh::serial(), NLPACS::CEdgeQuad::serial(), NLPACS::CCollisionMeshBuild::serial(), NL3D::CCluster::serial(), NLPACS::CChain::serial(), NLPACS::COrderedChain::serial(), NLPACS::COrderedChain3f::serial(), NLMISC::CBitSet::serial(), CAutomataDesc::CState::serial(), NL3D::CAnimationSet::serial(), NL3D::CAnimation::serial(), NL3D::CMaterialBase::serial(), and NLMISC::ICommand::serialCommands().

00324 {serialVector(cont);}

void NLMISC::CBitMemStream::serialCont std::vector< bool > &  cont  )  [virtual]
 

Specialisation of serialCont() for vector<bool>.

Reimplemented from NLMISC::CMemStream.

Definition at line 591 of file bit_mem_stream.cpp.

References NLMISC::contReset(), NLMISC::CMemStream::getPos(), getPosInBit(), NLMISC::IStream::isReading(), len, length(), nldebug, nlwarning, serial(), serialBit(), sint, sint32, and v.

00592 {
00593 #ifdef LOG_ALL_TRAFFIC
00594         sint32 bitpos = getPosInBit();
00595 #endif
00596 
00597         sint32  len=0;
00598         if(isReading())
00599         {
00600                 serial(len);
00601                 if (len/8 > (sint32)(length()-getPos()))
00602                 {
00603                         nlwarning("BMS: stl container maximum length reached, perhaps invalid container size (%d)", len);
00604                         throw NLMISC::EInvalidDataStream();
00605                 }
00606                 // special version for vector: adjut good size.
00607                 contReset(cont);
00608                 cont.reserve(len);
00609 
00610                 for(sint i=0;i<len;i++)
00611                 {
00612                         bool    v;
00613                         serialBit(v);
00614                         cont.insert(cont.end(), v);
00615                 }
00616         }
00617         else
00618         {
00619                 len= cont.size();
00620                 serial(len);
00621 
00622                 std::vector<bool>::iterator it= cont.begin();
00623                 for(sint i=0;i<len;i++, it++)
00624                 {
00625                         bool b = *it;
00626                         serialBit( b );
00627                 }
00628         }
00629 
00630 #ifdef LOG_ALL_TRAFFIC
00631         if ( VerboseAllTraffic )
00632                 nldebug( "TRAFFIC/%p/%s: Container (header: 32 bits) at bitpos %d", this, isReading()?"I":"O", bitpos );
00633 #endif
00634 
00635 }

virtual void NLMISC::CBitMemStream::serialCont std::vector< sint8 > &  cont  )  [inline, virtual]
 

Specialisation of serialCont() for vector<sint8>.

Reimplemented from NLMISC::CMemStream.

Definition at line 636 of file bit_mem_stream.h.

References NLMISC::IStream::serialVector().

00636 { serialVector(cont); }

virtual void NLMISC::CBitMemStream::serialCont std::vector< uint8 > &  cont  )  [inline, virtual]
 

Specialisation of serialCont() for vector<uint8>.

Reimplemented from NLMISC::CMemStream.

Definition at line 634 of file bit_mem_stream.h.

References NLMISC::IStream::serialVector().

00634 { serialVector(cont); }

template<class K, class T>
void NLMISC::CBitMemStream::serialCont std::multimap< K, T > &  cont  )  [inline]
 

Specialisation of serialCont() for vector<bool>.

Reimplemented from NLMISC::CMemStream.

Definition at line 550 of file bit_mem_stream.h.

00550 {CMemStream::serialCont(cont);}

template<class K, class T>
void NLMISC::CBitMemStream::serialCont std::map< K, T > &  cont  )  [inline]
 

Specialisation of serialCont() for vector<bool>.

Reimplemented from NLMISC::CMemStream.

Definition at line 548 of file bit_mem_stream.h.

00548 {CMemStream::serialCont(cont);}

template<class T>
void NLMISC::CBitMemStream::serialCont std::multiset< T > &  cont  )  [inline]
 

Specialisation of serialCont() for vector<bool>.

Reimplemented from NLMISC::CMemStream.

Definition at line 546 of file bit_mem_stream.h.

00546 {CMemStream::serialCont(cont);}

template<class T>
void NLMISC::CBitMemStream::serialCont std::set< T > &  cont  )  [inline]
 

Specialisation of serialCont() for vector<bool>.

Reimplemented from NLMISC::CMemStream.

Definition at line 544 of file bit_mem_stream.h.

00544 {CMemStream::serialCont(cont);}

template<class T>
void NLMISC::CBitMemStream::serialCont std::deque< T > &  cont  )  [inline]
 

Specialisation of serialCont() for vector<bool>.

Reimplemented from NLMISC::CMemStream.

Definition at line 542 of file bit_mem_stream.h.

00542 {CMemStream::serialCont(cont);}

template<class T>
void NLMISC::CBitMemStream::serialCont std::list< T > &  cont  )  [inline]
 

Specialisation of serialCont() for vector<bool>.

Reimplemented from NLMISC::CMemStream.

Definition at line 540 of file bit_mem_stream.h.

00540 {CMemStream::serialCont(cont);}

template<class T>
void NLMISC::CBitMemStream::serialCont std::vector< T > &  cont  )  [inline]
 

Reimplemented from NLMISC::CMemStream.

Definition at line 538 of file bit_mem_stream.h.

00538 {CMemStream::serialCont(cont);}

template<class T>
void NLMISC::IStream::serialContPolyPtr std::multiset< T > &  cont  )  [inline, inherited]
 

Serialize a check value. An object can stream a check value to check integrity or format of filed or streamed data. Just call serial check with a const value. Write will serial the value. Read will check the value is the same. If it is not, it will throw EInvalidDataStream exception.

NB: The type of the value must implement an operator == and must be serializable.

Parameters:
value the value used to the check.
See also:
EInvalidDataStream

Definition at line 379 of file stream.h.

References NLMISC::IStream::serialSTLContPolyPtr().

00379 {serialSTLContPolyPtr(cont);}

template<class T>
void NLMISC::IStream::serialContPolyPtr std::set< T > &  cont  )  [inline, inherited]
 

Serialize a check value. An object can stream a check value to check integrity or format of filed or streamed data. Just call serial check with a const value. Write will serial the value. Read will check the value is the same. If it is not, it will throw EInvalidDataStream exception.

NB: The type of the value must implement an operator == and must be serializable.

Parameters:
value the value used to the check.
See also:
EInvalidDataStream

Definition at line 377 of file stream.h.

References NLMISC::IStream::serialSTLContPolyPtr().

00377 {serialSTLContPolyPtr(cont);}

template<class T>
void NLMISC::IStream::serialContPolyPtr std::deque< T > &  cont  )  [inline, inherited]
 

Serialize a check value. An object can stream a check value to check integrity or format of filed or streamed data. Just call serial check with a const value. Write will serial the value. Read will check the value is the same. If it is not, it will throw EInvalidDataStream exception.

NB: The type of the value must implement an operator == and must be serializable.

Parameters:
value the value used to the check.
See also:
EInvalidDataStream

Definition at line 375 of file stream.h.

References NLMISC::IStream::serialSTLContPolyPtr().

00375 {serialSTLContPolyPtr(cont);}

template<class T>
void NLMISC::IStream::serialContPolyPtr std::list< T > &  cont  )  [inline, inherited]
 

Serialize a check value. An object can stream a check value to check integrity or format of filed or streamed data. Just call serial check with a const value. Write will serial the value. Read will check the value is the same. If it is not, it will throw EInvalidDataStream exception.

NB: The type of the value must implement an operator == and must be serializable.

Parameters:
value the value used to the check.
See also:
EInvalidDataStream

Definition at line 373 of file stream.h.

References NLMISC::IStream::serialSTLContPolyPtr().

00373 {serialSTLContPolyPtr(cont);}

template<class T, class Allocator>
void NLMISC::IStream::serialContPolyPtr std::vector< T, Allocator > &  cont  )  [inline, inherited]
 

Serialize a check value. An object can stream a check value to check integrity or format of filed or streamed data. Just call serial check with a const value. Write will serial the value. Read will check the value is the same. If it is not, it will throw EInvalidDataStream exception.

NB: The type of the value must implement an operator == and must be serializable.

Parameters:
value the value used to the check.
See also:
EInvalidDataStream

Definition at line 371 of file stream.h.

References NLMISC::IStream::serialVectorPolyPtr().

Referenced by NL3D::CAnimation::serial().

00371 {serialVectorPolyPtr(cont);}

template<class T>
void NLMISC::IStream::serialContPtr std::multiset< T > &  cont  )  [inline, inherited]
 

Definition at line 362 of file stream.h.

References NLMISC::IStream::serialSTLContPtr().

00362 {serialSTLContPtr(cont);}

template<class T>
void NLMISC::IStream::serialContPtr std::set< T > &  cont  )  [inline, inherited]
 

Definition at line 360 of file stream.h.

References NLMISC::IStream::serialSTLContPtr().

00360 {serialSTLContPtr(cont);}

template<class T>
void NLMISC::IStream::serialContPtr std::deque< T > &  cont  )  [inline, inherited]
 

Definition at line 358 of file stream.h.

References NLMISC::IStream::serialSTLContPtr().

00358 {serialSTLContPtr(cont);}

template<class T>
void NLMISC::IStream::serialContPtr std::list< T > &  cont  )  [inline, inherited]
 

Definition at line 356 of file stream.h.

References NLMISC::IStream::serialSTLContPtr().

00356 {serialSTLContPtr(cont);}

template<class T, class Allocator>
void NLMISC::IStream::serialContPtr std::vector< T, Allocator > &  cont  )  [inline, inherited]
 

Definition at line 354 of file stream.h.

References NLMISC::IStream::serialVectorPtr().

Referenced by NL3D::CAnimationSet::serial().

00354 {serialVectorPtr(cont);}

template<class T>
void NLMISC::IStream::serialEnum T &  em  )  [inline, inherited]
 

Template enum serialisation. Serialized as a sint32.

Definition at line 261 of file stream.h.

References NLMISC::IStream::isReading(), NLMISC::IStream::serial(), and sint32.

Referenced by NLNET::cbTCReceiveOtherSideClass(), NL3D::CVegetableShape::serial(), NL3D::CVegetable::serial(), NLPACS::CRetrieverInstance::serial(), NL3D::CPointLight::serial(), NL3D::CMaterial::serial(), NLPACS::CLocalRetriever::serial(), NLMISC::CSerialCommand::serial(), and NL3D::CAnimationPlaylist::serial().

00262         {
00263                 sint32  i;
00264                 if(isReading())
00265                 {
00266                         serial(i);
00267                         em = (T)i;
00268                 }
00269                 else
00270                 {
00271                         i = em;
00272                         serial(i);
00273                 }
00274         }

void NLMISC::CMemStream::serialHex uint32 b  )  [inline, virtual, inherited]
 

Serialisation in hexadecimal.

Reimplemented in NLMISC::CStringStream.

Definition at line 929 of file mem_stream.h.

References NLMISC::CMemStream::_StringMode, NLMISC::atoihex(), NLMISC::IStream::isReading(), readnumber, uint32, and writenumber.

Referenced by NLNET::TMessageRecord::serial().

00930 {
00931         if ( _StringMode )
00932         {
00933                 if ( isReading() )
00934                 {
00935                         readnumber( b, uint32, 10, atoihex ); // 4294967295
00936                 }
00937                 else
00938                 {
00939                         writenumber( b, "%x", 10 );
00940                 }
00941                 }
00942         else
00943         {
00944                 IStream::serial( b );
00945         }
00946 }

void NLMISC::IStream::serialMemStream CMemStream b  )  [virtual, inherited]
 

Serial memstream, bitmemstream...

Definition at line 436 of file stream.cpp.

References NLMISC::CMemStream::buffer(), NLMISC::CMemStream::bufferToFill(), NLMISC::IStream::isReading(), len, NLMISC::CMemStream::length(), NLMISC::CMemStream::resetBufPos(), NLMISC::IStream::serial(), NLMISC::IStream::serialBuffer(), uint32, and uint8.

00437 {
00438         uint32 len=0;
00439 
00440         // Serialize length
00441         if ( isReading() )
00442         {
00443                 // fill b with data from this
00444                 serial (len);
00445                 serialBuffer (b.bufferToFill (len), len);
00446                 b.resetBufPos ();
00447         }
00448         else
00449         {
00450                 // fill this with data from b
00451                 len = b.length();
00452 
00453                 serial( len );
00454                 serialBuffer( (uint8*) b.buffer (), len );
00455         }
00456 }

void NLMISC::CBitMemStream::serialMemStream CBitMemStream b  )  [virtual]
 

Definition at line 551 of file bit_mem_stream.cpp.

References NLMISC::CMemStream::buffer(), bufferToFill(), NLMISC::CMemStream::getPos(), getPosInBit(), NLMISC::IStream::isReading(), len, length(), nldebug, nlwarning, resetBufPos(), serial(), serialBuffer(), sint32, uint32, and uint8.

Referenced by serial().

00552 {
00553 #ifdef LOG_ALL_TRAFFIC
00554         sint32 bitpos = getPosInBit();
00555 #endif
00556 
00557         uint32 len=0;
00558 
00559         // Serialize length
00560         if ( isReading() )
00561         {
00562                 // fill b with data from this
00563                 serial (len);
00564                 if (len > length()-getPos())
00565                 {
00566                         nlwarning("BMS: bitmemstream maximum length reached, perhaps invalid bitmemstream size (%d)", len);
00567                         throw NLMISC::EInvalidDataStream();
00568                 }
00569 
00570                 serialBuffer (b.bufferToFill (len), len);
00571                 b.resetBufPos ();
00572         }
00573         else
00574         {
00575                 // fill this with data from b
00576                 len = b.length();
00577 
00578                 serial( len );
00579                 serialBuffer( (uint8*) b.buffer (), len );
00580         }
00581 
00582 #ifdef LOG_ALL_TRAFFIC
00583         if ( VerboseAllTraffic )
00584                 nldebug( "TRAFFIC/%p/%s: Sub-bitmemstream (size 32+%u*8 bits) at bitpos %d", this, isReading()?"I":"O", len, bitpos );
00585 #endif
00586 }

void NLMISC::CBitMemStream::serialPoke uint32  value,
uint  nbits
[protected]
 

Helper for poke(), to write a value inside an output stream (works because reserveBits sets to 0) Warning: if _FreeBits == 8, increments _BufPos.

Definition at line 296 of file bit_mem_stream.cpp.

References _FreeBits, NLMISC::CObjectVector< uint8, false >::getPtr(), nlassert, pointNextByte(), NLMISC::CObjectVector< uint8, false >::size(), uint, uint32, v, and value.

Referenced by poke(), and pokeBits().

00297 {
00298         uint32 v;
00299         if ( nbits != 32 ) // arg of shl/sal/shr/sal ranges from 0 to 31
00300         {
00301                 uint32 mask = (1 << nbits) - 1;
00302                 v = value & mask;
00303         }
00304         else
00305         {
00306                 v = value;
00307         }
00308 
00309         // Set
00310         if ( nbits > _FreeBits )
00311         {
00312                 // Longer than the room in the current byte
00313                 //nldebug( "Writing byte %u into %u free bits (%u remaining bits)", lengthS(), _FreeBits, nbits );
00314                 //displayDwordBits( value, 32, nbits-1, false );
00315                 *_BufPos |= (v >> (nbits - _FreeBits));
00316                 uint filledbits = _FreeBits;
00317                 //displayByteBits( *_BufPos, 8, filledbits-1, false );
00318                 pointNextByte(); // do not set next byte to 0!
00319                 nlassert( _BufPos < _Buffer.getPtr() + _Buffer.size() );
00320                 serialPoke( v, nbits - filledbits );
00321         }
00322         else
00323         {
00324                 // Shorter or equal
00325                 //nldebug( "Writing last byte %u into %u free bits (%u remaining bits)", lengthS(), _FreeBits, nbits );
00326                 //displayByteBits( *_BufPos, 8, 7, false );
00327                 *_BufPos |= (v << (_FreeBits-nbits));
00328                 //displayByteBits( *_BufPos, 8, _FreeBits-1, false );
00329                 _FreeBits -= nbits;
00330                 if ( _FreeBits == 0 )
00331                 {
00332                         pointNextByte(); // do not set next byte to 0!
00333                         nlassert( _BufPos < _Buffer.getPtr() + _Buffer.size() );
00334                 }
00335         }
00336 }

template<class T>
void NLMISC::IStream::serialPolyPtr T *&  ptr  )  [inline, inherited]
 

Serialize Polymorphic Objet Ptr. Works with NULL pointers. If the same object is found mutliple time in the stream, ONLY ONE instance is written! NB: The ptr is serialised as a uint64 (64 bit compliant).

Parameters:
ptr a pointer on a IStreamable object.
See also:
resetPtrTable()

Definition at line 492 of file stream.h.

References NLMISC::IStream::serialIStreamable().

Referenced by NL3D::CAnimationOptimizer::cloneTrack(), NL3D::CMaterial::CLightMap::serial(), NL3D::CMaterial::serial(), NL3D::CMaterialBase::CAnimatedTexture::serial(), NL3D::CMaterial::CLightMap::serial2(), and NLMISC::IStream::serialSTLContLenPolyPtr().

00493         { IStreamable *p=ptr; serialIStreamable(p); ptr= static_cast<T*>(p);}

template<class T>
void NLMISC::IStream::serialPtr T *&  ptr  )  [inline, inherited]
 

Serialize Non Polymorphic Objet Ptr. Works with NULL pointers. If the same object is found mutliple time in the stream, ONLY ONE instance is written! NB: The ptr is serialised as a uint64 (64 bit compliant).

Parameters:
ptr a pointer on a base type or an object.
See also:
resetPtrTable()

Definition at line 390 of file stream.h.

References NLMISC::IStream::_IdMap, NLMISC::IStream::_NextSerialPtrId, NLMISC::IStream::isReading(), NLMISC::IStream::ItIdMap, NLMISC::IStream::serial(), uint, uint64, NLMISC::IStream::ValueIdMap, NLMISC::IStream::xmlPop(), NLMISC::IStream::xmlPushBegin(), NLMISC::IStream::xmlPushEnd(), and NLMISC::IStream::xmlSetAttrib().

Referenced by NL3D::CParticleSystemShape::buildFromPS(), NL3D::CParticleSystemShape::flushTextures(), NL3D::CParticleSystemShape::instanciatePS(), and NLMISC::IStream::serialSTLContLenPtr().

00391         {
00392                 uint64  node;
00393 
00394                 // Open the node header
00395                 xmlPushBegin ("PTR");
00396 
00397                 xmlSetAttrib ("id");
00398 
00399                 if(isReading())
00400                 {
00401                         serial(node);
00402 
00403                         // Close the header
00404                         xmlPushEnd ();
00405 
00406                         if(node==0)
00407                                 ptr=NULL;
00408                         else
00409                         {
00410                                 ItIdMap it;
00411                                 it= _IdMap.find(node);
00412 
00413                                 // Test if object already created/read.
00414                                 if( it==_IdMap.end() )
00415                                 {
00416                                         // Construct object.                                    
00417                                         ptr= new T;
00418                                         if(ptr==NULL)
00419                                                 throw EStream();
00420 
00421                                         // Insert the node.
00422                                         _IdMap.insert( ValueIdMap(node, ptr) );
00423 
00424                                         // Read the object!
00425                                         serial(*ptr);
00426                                 }
00427                                 else
00428                                         ptr= static_cast<T*>(it->second);
00429                         }
00430                 }
00431                 else
00432                 {
00433                         if(ptr==NULL)
00434                         {
00435                                 node= 0;
00436                                 serial(node);
00437 
00438                                 // Close the header
00439                                 xmlPushEnd ();
00440                         }
00441                         else
00442                         {
00443                                 ItIdMap it;
00444                                 it = _IdMap.find((uint64)(uint)ptr);
00445 
00446                                 // Test if object has been already written
00447                                 if( it==_IdMap.end() )
00448                                 {
00449                                         // Not yet written
00450 
00451                                         // Get the next available ID
00452                                         node = _NextSerialPtrId++;
00453 
00454                                         // Serial the id
00455                                         serial(node);
00456 
00457                                         // Insert the pointer in the map with the id
00458                                         _IdMap.insert( ValueIdMap((uint64)(uint)ptr, (void*)(uint)node) );
00459 
00460                                         // Close the header
00461                                         xmlPushEnd ();
00462 
00463                                         // Write the object
00464                                         serial(*ptr);
00465                                 }
00466                                 else
00467                                 {
00468                                         // Write only the object id
00469                                         node = (uint64)(uint)(it->second);
00470 
00471                                         serial(node);
00472                 
00473                                         // Close the header
00474                                         xmlPushEnd ();
00475                                 }
00476                         }
00477                 }
00478 
00479                 // Close the node
00480                 xmlPop ();
00481         }

uint NLMISC::CMemStream::serialSeparatedBufferIn uint8 buf,
uint  len
[inherited]
 

Input: read len bytes at most from the stream until the next separator, and return the number of bytes read. The separator is then skipped.

Reimplemented in NLMISC::CStringStream.

Definition at line 307 of file mem_stream.cpp.

References NLMISC::CMemStream::_BufPos, NLMISC::CMemStream::_StringMode, NLMISC::CObjectVector< uint8, false >::getPtr(), NLMISC::IStream::isReading(), len, NLMISC::CMemStream::length(), NLMISC::CMemStream::lengthS(), nlassert, NLMISC::SEP_SIZE, NLMISC::SEPARATOR, NLMISC::CObjectVector< uint8, false >::size(), uint, uint32, and uint8.

00308 {
00309         nlassert( _StringMode && isReading() );
00310 
00311         // Check that we don't read more than there is to read
00312         if ( ( _BufPos == _Buffer.getPtr()+_Buffer.size() ) || // we are at the end
00313                  ( lengthS()+len+SEP_SIZE > length() ) && (_Buffer[_Buffer.size()-1] != SEPARATOR ) ) // we are before the end // calls virtual length (cf. sub messages)
00314         {
00315                 throw EStreamOverflow();
00316         }
00317         // Serialize in
00318         uint32 i = 0;
00319         while ( (i<len) && (*_BufPos) != SEPARATOR )
00320         {
00321                 *(buf+i) = *_BufPos;
00322                 i++;
00323                 _BufPos++;
00324         }
00325         // Exceeds len
00326         if ( (*_BufPos) != SEPARATOR )
00327         {
00328                 throw EStreamOverflow();
00329         }
00330         _BufPos += SEP_SIZE;
00331         return i;
00332 }

void NLMISC::CMemStream::serialSeparatedBufferOut uint8 buf,
uint  len
[inherited]
 

Output: writes len bytes from buf into the stream.

Reimplemented in NLMISC::CStringStream.

Definition at line 338 of file mem_stream.cpp.

References NLMISC::CMemStream::_BufPos, NLMISC::CMemStream::_StringMode, NLMISC::CObjectVector< uint8, false >::getPtr(), NLMISC::IStream::isReading(), len, nlassert, NLMISC::CObjectVector< uint8, false >::resize(), NLMISC::SEP_SIZE, NLMISC::SEPARATOR, NLMISC::CObjectVector< uint8, false >::size(), uint, uint32, and uint8.

00339 {
00340         nlassert( _StringMode && (!isReading()) );
00341         
00342         // Serialize out
00343         uint32 oldBufferSize = _Buffer.size();
00344         if (_BufPos - _Buffer.getPtr() + (len + SEP_SIZE) > oldBufferSize)
00345         {
00346                 // need to increase the buffer size
00347                 _Buffer.resize(oldBufferSize*2 + len + SEP_SIZE);
00348                 _BufPos = _Buffer.getPtr() + oldBufferSize;
00349         }
00350 
00351         CFastMem::memcpy( _BufPos, buf, len );
00352         _BufPos += len;
00353         *(_BufPos++) = SEPARATOR;
00354 
00355         // Serialize out
00356 /*      _Buffer.resize( _Buffer.size() + len + SEP_SIZE );
00357         _BufPos = _Buffer.end() - len - SEP_SIZE;
00358         CFastMem::memcpy( &(*_BufPos), buf, len );
00359         _Buffer[_Buffer.size()-1] = SEPARATOR;
00360         _BufPos = _Buffer.end();
00361 */}

template<class T>
void NLMISC::IStream::serialVector T &  cont  )  [inline, protected, inherited]
 

special version for serializing a vector. Support up to sint32 length containers.

Definition at line 992 of file stream.h.

References NLMISC::contReset(), NLMISC::IStream::isReading(), len, NLMISC::IStream::serial(), sint, sint32, NLMISC::IStream::xmlPop(), NLMISC::IStream::xmlPush(), NLMISC::IStream::xmlPushBegin(), NLMISC::IStream::xmlPushEnd(), and NLMISC::IStream::xmlSetAttrib().

Referenced by NLMISC::CStringStream::serialCont(), NLMISC::IStream::serialCont(), and serialCont().

00993         {
00994                 typedef typename T::value_type __value_type;
00995                 typedef typename T::iterator __iterator;
00996 
00997                 // Open a node header
00998                 xmlPushBegin ("VECTOR");
00999 
01000                 // Attrib size
01001                 xmlSetAttrib ("size");
01002 
01003                 sint32  len=0;
01004                 if(isReading())
01005                 {
01006                         serial(len);
01007 
01008                         // Open a node header
01009                         xmlPushEnd ();
01010 
01011                         // special version for vector: adjut good size.
01012                         contReset(cont);
01013                         cont.resize (len);
01014 
01015                         // Read the vector
01016                         for(sint i=0;i<len;i++)
01017                         {
01018                                 xmlPush ("ELM");
01019 
01020                                 serial(cont[i]);
01021 
01022                                 xmlPop ();
01023                         }
01024                 }
01025                 else
01026                 {
01027                         len= cont.size();
01028                         serial(len);
01029 
01030                         // Close the node header
01031                         xmlPushEnd ();
01032 
01033                         // Write the vector
01034                         __iterator              it= cont.begin();
01035                         for(sint i=0;i<len;i++, it++)
01036                         {
01037                                 xmlPush ("ELM");
01038 
01039                                 serial(const_cast<__value_type&>(*it));
01040 
01041                                 xmlPop ();
01042                         }
01043                 }
01044 
01045                 // Close the node
01046                 xmlPop ();
01047         }

uint NLMISC::IStream::serialVersion uint  currentVersion  )  [inherited]
 

Serialize a version number. Each object should store/read first a version number, using this method. Then he can use the streamVersion returned to see how he should serialise himself.

NB: Version Number is read/store as a uint8, or uint32 if too bigger..

Parameters:
currentVersion the current version of the class, provided by user.
Returns:
the version of the stream. If the stream is an Output stream, currentVersion is returned.
See also:
setVersionException() getVersionException()

Definition at line 266 of file stream.cpp.

References NLMISC::IStream::_ThrowOnNewer, NLMISC::IStream::_ThrowOnOlder, NLMISC::IStream::isReading(), NLMISC::IStream::serial(), uint, uint32, uint8, v, NLMISC::IStream::xmlPop(), and NLMISC::IStream::xmlPush().

Referenced by NL3D::H_AUTO_DECL(), NLMISC::CEntityIdTranslator::load(), loadForm(), NLMISC::CEntityIdTranslator::save(), NLLIGO::CZoneRegion::serial(), NLLIGO::CZoneRegion::SZoneUnit2::serial(), NLLIGO::CZoneBankElement::serial(), NL3D::CZone::serial(), NL3D::CPatchInfo::CBindInfo::serial(), NL3D::CZone::CPatchConnect::serial(), NL3D::CBorderVertex::serial(), NL3D::CVertexBuffer::serial(), NL3D::CVegetableShape::serial(), NL3D::CVegetable::serial(), NL3D::CTrackSampledVector::serial(), NL3D::CTrackSampledQuat::serial(), NL3D::CTrackSampledCommon::CTimeBlock::serial(), NL3D::CTileVegetableDesc::serial(), NL3D::CTileNoiseMap::serial(), NL3D::CTileNoise::serial(), NLPACS::CSurfaceQuadTree::serial(), NL3D::CSurfaceLightGrid::CCellCorner::serial(), NL3D::CSurfaceLightGrid::serial(), NL3D::CSkeletonWeight::CNode::serial(), NL3D::CSkeletonWeight::serial(), NL3D::CInstanceGroup::serial(), NL3D::CInstanceGroup::CInstance::serial(), NLPACS::CRetrieverInstance::serial(), NLPACS::CRetrieverBank::serial(), NLPACS::CRetrievableSurface::serial(), NL3D::CPSAttrib< T >::serial(), NL3D::CPrimitiveBlock::serial(), NL3D::CPortal::serial(), NL3D::CPointLightNamedArray::CPointLightGroup::serial(), NL3D::CPointLightNamedArray::serial(), NL3D::CPointLightNamed::serial(), NL3D::CPointLight::serial(), NL3D::CPatch::serial(), NLMISC::CNoiseColorGradient::serial(), NLMISC::CNoiseValue::serial(), NL3D::CMeshMRMSkinnedGeom::CRdrPass::serial(), NL3D::CMeshMRMSkinnedGeom::CShadowVertex::serial(), NL3D::CMeshMRMSkinnedGeom::CPackedVertexBuffer::CPackedVertex::serial(), NL3D::CMeshMRMSkinnedGeom::CPackedVertexBuffer::serial(), NL3D::CMeshMRMSkinned::serial(), NL3D::CMeshMRMSkinnedGeom::serial(), NL3D::CMeshMRMGeom::CLodInfo::serial(), NL3D::CMeshMRMGeom::CRdrPass::serial(), NL3D::CMeshMRMGeom::CShadowVertex::serial(), NL3D::CMeshBase::CLightMapInfoList::serial(), NL3D::CMeshBase::CLightMapInfoList::CMatStage::serial(), NL3D::CMeshGeom::CMatrixBlock::serial(), NL3D::CMeshGeom::CRdrPass::serial(), NLMISC::CMatrix::serial(), NL3D::CMaterial::serial(), NL3D::CLodCharacterTexture::serial(), NL3D::CLodCharacterShapeBank::serial(), NL3D::CLodCharacterShape::serial(), NL3D::CLodCharacterShape::CBoneInfluence::serial(), NL3D::CLodCharacterShape::CAnim::serial(), NL3D::CLodCharacterShapeBuild::serial(), NLPACS::CLocalRetriever::serial(), NL3D::CIGSurfaceLight::CRetrieverLightGrid::serial(), NL3D::CIGSurfaceLight::serial(), NL3D::CHLSTextureBank::CTextureInstance::serial(), NL3D::CHLSTextureBank::serial(), NL3D::CHLSColorTexture::serial(), NL3D::CHLSColorTexture::CMask::serial(), NL3D::CHLSColorDelta::serial(), NLPACS::CGlobalRetriever::serial(), NLPACS::CFaceGrid::serial(), NLPACS::CExteriorMesh::serial(), NLPACS::CEdgeQuad::serial(), NL3D::CCluster::serial(), NLPACS::CChainQuad::serial(), NLPACS::CChain::serial(), NLPACS::COrderedChain::serial(), NLPACS::COrderedChain3f::serial(), NL3D::CBoneBase::serial(), NLMISC::CBitSet::serial(), NL3D::CAnimationSet::serial(), NL3D::CAnimationPlaylist::serial(), NL3D::CAnimation::serial(), NL3D::CMaterialBase::CTexAnimTracks::serial(), NL3D::CMaterialBase::serial(), NLMISC::CAABBox::serial(), NL3D::CMaterial::CLightMap::serial2(), NL3D::CTrackSampledCommon::serialCommon(), NL3D::CVertexBuffer::serialHeader(), NL3D::CMeshMRMGeom::serialLodVertexData(), and NL3D::CVertexBuffer::serialSubset().

00267 {
00268         uint8   b=0;
00269         uint32  v=0;
00270         uint    streamVersion;
00271 
00272         // Open the node
00273         xmlPush ("VERSION");
00274 
00275         if(isReading())
00276         {
00277                 serial(b);
00278                 if(b==0xFF)
00279                         serial(v);
00280                 else
00281                         v=b;
00282                 streamVersion=v;
00283 
00284                 // Exception test.
00285                 if(_ThrowOnOlder && streamVersion < currentVersion)
00286                         throw EOlderStream(*this);
00287                 if(_ThrowOnNewer && streamVersion > currentVersion)
00288                         throw ENewerStream(*this);
00289         }
00290         else
00291         {
00292                 v= streamVersion=currentVersion;
00293                 if(v>=0xFF)
00294                 {
00295                         b=0xFF;
00296                         serial(b);
00297                         serial(v);
00298                 }
00299                 else
00300                 {
00301                         b= (uint8)v;
00302                         serial(b);
00303                 }
00304         }
00305 
00306         // Close the node
00307         xmlPop ();
00308 
00309         return streamVersion;
00310 }

void NLMISC::IStream::setInOut bool  inputStream  )  [protected, inherited]
 

Change, in live, the state of the inputStream. This could be usefull in certain case. The deriver which would want to do such a thing must call this method, and implement his own behavior. In certain case, it should call resetPtrTable() if he want to reset the stream ptr info (maybe always)...

Definition at line 413 of file stream.cpp.

References NLMISC::IStream::_InputStream.

Referenced by getSerialItem(), and NLMISC::CMemStream::invert().

00414 {
00415         _InputStream= inputStream;
00416 }

void NLMISC::CMemStream::setStringMode bool  stringmode  )  [inline, inherited]
 

Set string mode.

Definition at line 113 of file mem_stream.h.

References NLMISC::CMemStream::_StringMode.

Referenced by NLNET::CMessage::init().

00113 { _StringMode = stringmode; }

void NLMISC::IStream::setVersionException bool  throwOnOlder,
bool  throwOnNewer
[static, inherited]
 

Set the behavior of IStream regarding input stream that are older/newer than the class. If throwOnOlder==true, IStream throws a EOlderStream when needed. If throwOnNewer==true, IStream throws a ENewerStream when needed.

By default, the behavior is throwOnOlder=false, throwOnNewer=true.

See also:
serialVersion() getVersionException()

Definition at line 71 of file stream.cpp.

References NLMISC::IStream::_ThrowOnNewer, and NLMISC::IStream::_ThrowOnOlder.

00072 {
00073         _ThrowOnOlder=throwOnOlder;
00074         _ThrowOnNewer=throwOnNewer;
00075 }

void NLMISC::IStream::setXMLMode bool  on  )  [protected, inherited]
 

Set the XML mode is true to enable XML mode else false

Definition at line 427 of file stream.cpp.

References NLMISC::IStream::_XML.

Referenced by NLMISC::COXml::COXml(), and NLMISC::COXml::init().

00428 {
00429         _XML = on;
00430 }

uint32 NLMISC::CMemStream::size  )  const [inline, inherited]
 

Returns the size of the buffer (can be greater than the length, especially in output mode).

Definition at line 230 of file mem_stream.h.

References NLMISC::CObjectVector< uint8, false >::size(), and uint32.

Referenced by NLMISC::CMemStream::lengthR().

00231         {
00232                 return _Buffer.size();
00233         }

bool NLMISC::CMemStream::stringMode  )  const [inline, inherited]
 

Return string mode.

Definition at line 116 of file mem_stream.h.

References NLMISC::CMemStream::_StringMode.

Referenced by NLNET::TMessageRecord::serial(), and NLNET::CInetAddress::serial().

00116 { return _StringMode; }

bool NLMISC::IStream::xmlBreakLine  )  [inline, inherited]
 

xmlBreakLine() insert a break line in the XML stream.

Returns:
true if the break line is added, return false if no node is opened.

Definition at line 794 of file stream.h.

References NLMISC::IStream::_XML, and NLMISC::IStream::xmlBreakLineInternal().

00795         {
00796                 // XML Mode ?
00797                 if (_XML)
00798                 {
00799                         return xmlBreakLineInternal ();
00800                 }
00801 
00802                 // Return ok
00803                 return true;
00804         }

virtual bool NLMISC::IStream::xmlBreakLineInternal  )  [inline, protected, virtual, inherited]
 

xmlBreakLine implementation

Reimplemented in NLMISC::COXml.

Definition at line 845 of file stream.h.

Referenced by NLMISC::IStream::xmlBreakLine().

00845 { return true; };

bool NLMISC::IStream::xmlComment const char *  comment  )  [inline, inherited]
 

xmlComment() insert a comment line in the XML stream.

Returns:
true if the comment is added, return false if no node is opened.

Definition at line 811 of file stream.h.

References NLMISC::IStream::_XML, comment(), and NLMISC::IStream::xmlCommentInternal().

00812         {
00813                 // XML Mode ?
00814                 if (_XML)
00815                 {
00816                         return xmlCommentInternal (comment);
00817                 }
00818 
00819                 // Return ok
00820                 return true;
00821         }

virtual bool NLMISC::IStream::xmlCommentInternal const char *  comment  )  [inline, protected, virtual, inherited]
 

xmlComment implementation

Reimplemented in NLMISC::COXml.

Definition at line 848 of file stream.h.

Referenced by NLMISC::IStream::xmlComment().

00848 { return true; };

bool NLMISC::IStream::xmlPop  )  [inline, inherited]
 

xmlPop() close the node.

Returns:
true if you can close the node, false if the node can't be closed (its header is still opened) or if there is no node to close.

Definition at line 759 of file stream.h.

References NLMISC::IStream::_XML, and NLMISC::IStream::xmlPopInternal().

Referenced by NLLIGO::CZoneRegion::serial(), NLLIGO::CZoneBankElement::serial(), NL3D::CZone::serial(), NL3D::CPatch::serial(), NLMISC::CObjectVector< sint8, false >::serial(), NLMISC::COXml::serial(), NLMISC::COXml::serialBuffer(), NLMISC::IStream::serialCheck(), NLMISC::IStream::serialIStreamable(), NLMISC::IStream::serialMap(), NLMISC::IStream::serialMultimap(), NLMISC::IStream::serialPtr(), NLMISC::IStream::serialSTLCont(), NLMISC::IStream::serialSTLContLen(), NLMISC::IStream::serialSTLContPtr(), NLMISC::IStream::serialVector(), NLMISC::IStream::serialVectorPolyPtr(), NLMISC::IStream::serialVectorPtr(), NLMISC::IStream::serialVersion(), and NLMISC::IStream::xmlSerial().

00760         {
00761                 // XML Mode ?
00762                 if (_XML)
00763                 {
00764                         return xmlPopInternal ();
00765                 }
00766 
00767                 // Return ok
00768                 return true;
00769         }

virtual bool NLMISC::IStream::xmlPopInternal  )  [inline, protected, virtual, inherited]
 

xmlPop implementation

Reimplemented in NLMISC::COXml.

Definition at line 839 of file stream.h.

Referenced by NLMISC::IStream::xmlPop().

00839 { return true; };

bool NLMISC::IStream::xmlPush const char *  name  )  [inline, inherited]
 

Definition at line 701 of file stream.h.

References NLMISC::IStream::_XML, res, NLMISC::IStream::xmlPushBeginInternal(), and NLMISC::IStream::xmlPushEndInternal().

Referenced by NLLIGO::CZoneRegion::serial(), NLLIGO::CZoneBankElement::serial(), NL3D::CZone::serial(), NL3D::CPatch::serial(), NLMISC::CObjectVector< sint8, false >::serial(), NLMISC::COXml::serial(), NLMISC::COXml::serialBuffer(), NLMISC::IStream::serialCheck(), NLMISC::IStream::serialMap(), NLMISC::IStream::serialMultimap(), NLMISC::IStream::serialSTLContLen(), NLMISC::IStream::serialVector(), NLMISC::IStream::serialVersion(), and NLMISC::IStream::xmlSerial().

00702         {
00703                 // XML Mode ?
00704                 if (_XML)
00705                 {
00706                         // Open the header
00707                         bool res=xmlPushBeginInternal (name);
00708                         if (res)
00709                                 // close the header
00710                                 xmlPushEndInternal ();
00711                         // Return the result
00712                         return res;
00713                 }
00714 
00715                 // Return ok
00716                 return true;
00717         }

bool NLMISC::IStream::xmlPushBegin const char *  name  )  [inline, inherited]
 

xmlBreakLine() insert a break line in the XML stream.

Returns:
true if the break line is added, return false if no node is opened.

Definition at line 725 of file stream.h.

References NLMISC::IStream::_XML, and NLMISC::IStream::xmlPushBeginInternal().

Referenced by NLMISC::CObjectVector< sint8, false >::serial(), NLMISC::IStream::serialIStreamable(), NLMISC::IStream::serialMap(), NLMISC::IStream::serialMultimap(), NLMISC::IStream::serialPtr(), NLMISC::IStream::serialSTLCont(), NLMISC::IStream::serialSTLContPtr(), NLMISC::IStream::serialVector(), NLMISC::IStream::serialVectorPolyPtr(), and NLMISC::IStream::serialVectorPtr().

00726         {
00727                 // XML Mode ?
00728                 if (_XML)
00729                 {
00730                         return xmlPushBeginInternal (name);
00731                 }
00732 
00733                 // Return ok
00734                 return true;
00735         }

virtual bool NLMISC::IStream::xmlPushBeginInternal const char *  name  )  [inline, protected, virtual, inherited]
 

xmlPushBegin implementation

Reimplemented in NLMISC::COXml.

Definition at line 833 of file stream.h.

Referenced by NLMISC::IStream::xmlPush(), and NLMISC::IStream::xmlPushBegin().

00833 { return true; };

bool NLMISC::IStream::xmlPushEnd  )  [inline, inherited]
 

xmlPushEnd() close the node header.

Returns:
true if you can close the node header, false if no node header have been opened with xmlPushBegin().

Definition at line 742 of file stream.h.

References NLMISC::IStream::_XML, and NLMISC::IStream::xmlPushEndInternal().

Referenced by NLMISC::CObjectVector< sint8, false >::serial(), NLMISC::IStream::serialIStreamable(), NLMISC::IStream::serialMap(), NLMISC::IStream::serialMultimap(), NLMISC::IStream::serialPtr(), NLMISC::IStream::serialSTLCont(), NLMISC::IStream::serialSTLContPtr(), NLMISC::IStream::serialVector(), NLMISC::IStream::serialVectorPolyPtr(), and NLMISC::IStream::serialVectorPtr().

00743         {
00744                 // XML Mode ?
00745                 if (_XML)
00746                 {
00747                         return xmlPushEndInternal ();
00748                 }
00749 
00750                 // Return ok
00751                 return true;
00752         }

virtual bool NLMISC::IStream::xmlPushEndInternal  )  [inline, protected, virtual, inherited]
 

xmlPushEnd implementation

Reimplemented in NLMISC::COXml.

Definition at line 836 of file stream.h.

Referenced by NLMISC::IStream::xmlPush(), and NLMISC::IStream::xmlPushEnd().

00836 { return true; };

template<class T>
void NLMISC::IStream::xmlSerial T &  value0,
T &  value1,
T &  value2,
T &  value3,
const char *  nodeName
[inline, inherited]
 

Definition at line 683 of file stream.h.

References NLMISC::IStream::serial(), NLMISC::IStream::xmlPop(), and NLMISC::IStream::xmlPush().

00684         {
00685                 // Open the node
00686                 xmlPush (nodeName);
00687                 
00688                 // Serial the values
00689                 serial (value0, value1, value2, value3);
00690 
00691                 // Close the node
00692                 xmlPop ();
00693         }

template<class T>
void NLMISC::IStream::xmlSerial T &  value0,
T &  value1,
T &  value2,
const char *  nodeName
[inline, inherited]
 

Definition at line 671 of file stream.h.

References NLMISC::IStream::serial(), NLMISC::IStream::xmlPop(), and NLMISC::IStream::xmlPush().

00672         {
00673                 // Open the node
00674                 xmlPush (nodeName);
00675                 
00676                 // Serial the values
00677                 serial (value0, value1, value2);
00678 
00679                 // Close the node
00680                 xmlPop ();
00681         }

template<class T>
void NLMISC::IStream::xmlSerial T &  value0,
T &  value1,
const char *  nodeName
[inline, inherited]
 

Definition at line 659 of file stream.h.

References NLMISC::IStream::serial(), NLMISC::IStream::xmlPop(), and NLMISC::IStream::xmlPush().

00660         {
00661                 // Open the node
00662                 xmlPush (nodeName);
00663                 
00664                 // Serial the values
00665                 serial (value0, value1);
00666 
00667                 // Close the node
00668                 xmlPop ();
00669         }

template<class T>
void NLMISC::IStream::xmlSerial T &  value0,
const char *  nodeName
[inline, inherited]
 

xmlSerial() serial a values into a node.

Definition at line 647 of file stream.h.

References NLMISC::IStream::serial(), NLMISC::IStream::xmlPop(), and NLMISC::IStream::xmlPush().

Referenced by NLLIGO::CZoneRegion::serial(), NLLIGO::CZoneRegion::SZoneUnit2::serial(), NLLIGO::CZoneRegion::SZoneUnit::serial(), NL3D::CZone::serial(), NL3D::CPatchInfo::CBindInfo::serial(), NL3D::CZone::CPatchConnect::serial(), NL3D::CBorderVertex::serial(), NL3D::CTileElement::serial(), NL3D::CTileColorOldPatchVersion6::serial(), NL3D::CTileColor::serial(), and NL3D::CPatch::serial().

00648         {
00649                 // Open the node
00650                 xmlPush (nodeName);
00651                 
00652                 // Serial the value
00653                 serial (value0);
00654 
00655                 // Close the node
00656                 xmlPop ();
00657         }

bool NLMISC::IStream::xmlSetAttrib const char *  name  )  [inline, inherited]
 

xmlSetAttrib() set the name of the next node header attribute serialised.

is the name of the node header attribute serialised.

Returns:
true if the attribute name have been set, false if the node header is not open (the call is not between xmlPushBegin and xmlPushEnd)

Definition at line 777 of file stream.h.

References NLMISC::IStream::_XML, and NLMISC::IStream::xmlSetAttribInternal().

Referenced by NLMISC::CObjectVector< sint8, false >::serial(), NLMISC::IStream::serialIStreamable(), NLMISC::IStream::serialMap(), NLMISC::IStream::serialMultimap(), NLMISC::IStream::serialPtr(), NLMISC::IStream::serialSTLCont(), NLMISC::IStream::serialSTLContPtr(), NLMISC::IStream::serialVector(), NLMISC::IStream::serialVectorPolyPtr(), and NLMISC::IStream::serialVectorPtr().

00778         {
00779                 // XML Mode ?
00780                 if (_XML)
00781                 {
00782                         return xmlSetAttribInternal (name);
00783                 }
00784 
00785                 // Return ok
00786                 return true;
00787         }

virtual bool NLMISC::IStream::xmlSetAttribInternal const char *  name  )  [inline, protected, virtual, inherited]
 

xmlBreakLine implementation

Reimplemented in NLMISC::COXml.

Definition at line 842 of file stream.h.

Referenced by NLMISC::IStream::xmlSetAttrib().

00842 { return true; };


Field Documentation

CObjectVector<uint8, false> NLMISC::CMemStream::_Buffer [protected, inherited]
 

Definition at line 516 of file mem_stream.h.

Referenced by NLMISC::CMemStream::operator=().

uint8* NLMISC::CMemStream::_BufPos [protected, inherited]
 

Definition at line 517 of file mem_stream.h.

Referenced by NLMISC::CMemStream::bufferToFill(), NLMISC::CMemStream::clear(), NLMISC::CMemStream::CMemStream(), NLMISC::CMemStream::fastRead(), NLMISC::CMemStream::fastSerial(), NLMISC::CMemStream::fastWrite(), NLMISC::CMemStream::fill(), NLMISC::CMemStream::getPos(), NLMISC::CMemStream::increaseBufferIfNecessary(), NLMISC::CMemStream::invert(), NLMISC::CMemStream::lengthS(), NLMISC::CMemStream::operator=(), NLMISC::CMemStream::poke(), NLMISC::CMemStream::reserve(), NLMISC::CMemStream::resetBufPos(), NLMISC::CMemStream::resize(), NLMISC::CMemStream::serialBuffer(), NLMISC::CMemStream::serialSeparatedBufferIn(), and NLMISC::CMemStream::serialSeparatedBufferOut().

CBMSDbgInfo NLMISC::CBitMemStream::_DbgInfo [protected]
 

Debug details about what was serialised.

Definition at line 754 of file bit_mem_stream.h.

Referenced by bufferToFill(), displayStream(), fill(), operator=(), poke(), pokeBits(), resetBufPos(), serial(), serialBit(), and serialBuffer().

uint32 NLMISC::CMemStream::_DefaultCapacity [protected, inherited]
 

Definition at line 521 of file mem_stream.h.

Referenced by NLMISC::CMemStream::clear(), NLMISC::CMemStream::CMemStream(), and NLMISC::CMemStream::operator=().

uint NLMISC::CBitMemStream::_FreeBits [protected]
 

Number of bits unused at the current pos. If 8, means the current pos if full and we need to increment the pos!

Definition at line 751 of file bit_mem_stream.h.

Referenced by bufferToFill(), displayStream(), fill(), getPosInBit(), getSerialItem(), internalSerial(), length(), operator=(), pointNextByte(), poke(), pokeBits(), resetBufPos(), and serialPoke().

bool NLMISC::CMemStream::_StringMode [protected, inherited]
 

Definition at line 519 of file mem_stream.h.

Referenced by NLMISC::CMemStream::CMemStream(), NLMISC::CMemStream::operator=(), NLMISC::CMemStream::serial(), NLMISC::CMemStream::serialHex(), NLMISC::CMemStream::serialSeparatedBufferIn(), NLMISC::CMemStream::serialSeparatedBufferOut(), NLMISC::CMemStream::setStringMode(), and NLMISC::CMemStream::stringMode().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 13:04:34 2004 for NeL by doxygen 1.3.6