# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

NLNET::CMessage Class Reference

Message memory stream for network. More...

#include <message.h>

Inheritance diagram for NLNET::CMessage:

NLMISC::CMemStream NLMISC::IStream List of all members.

Public Types

enum  TStreamFormat { UseDefault, Binary, String }

Public Methods

 CMessage (NLMISC::CStringIdArray &sida, const std::string &name="", bool inputStream=false, TStreamFormat streamformat=UseDefault, uint32 defaultCapacity=1000)
 CMessage (const std::string &name="", bool inputStream=false, TStreamFormat streamformat=UseDefault, uint32 defaultCapacity=1000)
 CMessage (NLMISC::CMemStream &memstr)
 CMessage (const CMessage &other)
 Copy constructor. More...

CMessage & operator= (const CMessage &other)
 Assignment operator. More...

void setType (NLMISC::CStringIdArray::TStringId id)
 Sets the message type as a number (in range 0..32767) and put it in the buffer if we are in writing mode. More...

void setType (const std::string &name)
 Sets the message type as a string and put it in the buffer if we are in writing mode. More...

uint32 getHeaderSize ()
 Returns the size, in byte of the header that contains the type name of the message or the type number. More...

void readType ()
bool typeIsSet () const
void invert ()
 Transforms the message from input to output or from output to input. More...

void clear ()
 Clears the message. More...

std::string getName () const
 Returns the type name in string if available. Be sure that the message have the name of the message type. More...

NLMISC::CStringIdArray::TStringId getId () const
 Returns the type id of this message is available. More...

std::string toString () const
 Returns a readable string to display it to the screen. More...


Static Public Methods

void setDefaultStringMode (bool stringmode)
 Set default stream mode. More...


Public Attributes

bool TypeHasAnId
bool TypeHasAName

Protected Methods

void init (const std::string &name, TStreamFormat streamformat)
 Utility method. More...


Private Attributes

bool _TypeSet
NLMISC::CStringIdArray_SIDA
std::string _Name
NLMISC::CStringIdArray::TStringId _Id
uint32 _HeaderSize

Static Private Attributes

bool _DefaultStringMode = false

Detailed Description

Message memory stream for network.

Can be serialized to/from (see SerialBuffer()). Can be sent or received over a network, using the NeL network engine. If MESSAGES_PLAIN_TEXT is defined, the messages will be serialized to/from plain text (human-readable), instead of binary. Warning: if you don't give a "sida", the message type will not be associated with id so, it'll not be optimized Warning: THE ASSOCIATION Id<->String SYSTEM FOR THE MESSAGE TYPE IS DISABLED BECAUSE 2 DIFFERENT CLIENTS COULD HAVE SAME STRING ASSOC AND DIFFERENT ID SO WE HAVE TO PUT ONE SIDA TABLE PER CONNECTION AND NOT PER NET_BASE

Author:
Vianney Lecroart , Nevrax France
Date:
2001

Definition at line 56 of file message.h.


Member Enumeration Documentation

enum NLNET::CMessage::TStreamFormat
 

Enumeration values:
UseDefault 
Binary 
String 

Definition at line 60 of file message.h.


Constructor & Destructor Documentation

NLNET::CMessage::CMessage NLMISC::CStringIdArray   sida,
const std::string &    name = "",
bool    inputStream = false,
TStreamFormat    streamformat = UseDefault,
uint32    defaultCapacity = 1000
 

Definition at line 46 of file message.cpp.

References init.

NLNET::CMessage::CMessage const std::string &    name = "",
bool    inputStream = false,
TStreamFormat    streamformat = UseDefault,
uint32    defaultCapacity = 1000
 

Definition at line 53 of file message.cpp.

References init.

NLNET::CMessage::CMessage NLMISC::CMemStream   memstr
 

Definition at line 80 of file message.cpp.

References NLMISC::CMemStream::fill, id, NLMISC::CMemStream::serial, setType, and NLMISC::CStringIdArray::TStringId.

NLNET::CMessage::CMessage const CMessage &    other
 

Copy constructor.

Definition at line 103 of file message.cpp.

References operator=.


Member Function Documentation

void NLNET::CMessage::clear   [virtual]
 

Clears the message.

Reimplemented from NLMISC::CMemStream.

Definition at line 294 of file message.cpp.

References _TypeSet.

uint32 NLNET::CMessage::getHeaderSize  
 

Returns the size, in byte of the header that contains the type name of the message or the type number.

Definition at line 242 of file message.cpp.

References _HeaderSize, NLMISC::IStream::isReading, and nlassert.

NLMISC::CStringIdArray::TStringId NLNET::CMessage::getId   const
 

Returns the type id of this message is available.

Definition at line 308 of file message.cpp.

References _Id, _TypeSet, nlassert, NLMISC::CStringIdArray::TStringId, and TypeHasAnId.

std::string NLNET::CMessage::getName   const
 

Returns the type name in string if available. Be sure that the message have the name of the message type.

Definition at line 301 of file message.cpp.

References _Name, _TypeSet, nlassert, and TypeHasAName.

void NLNET::CMessage::init const std::string &    name,
TStreamFormat    streamformat
[protected]
 

Utility method.

Definition at line 64 of file message.cpp.

References _DefaultStringMode, NLMISC::CMemStream::setStringMode, setType, String, and UseDefault.

Referenced by CMessage.

void NLNET::CMessage::invert   [inline, virtual]
 

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

Reimplemented from NLMISC::CMemStream.

Definition at line 90 of file message.h.

References _TypeSet, NLMISC::IStream::isReading, and readType.

CMessage & NLNET::CMessage::operator= const CMessage &    other
 

Assignment operator.

Definition at line 109 of file message.cpp.

References _HeaderSize, _Id, _Name, _SIDA, _TypeSet, TypeHasAName, and TypeHasAnId.

Referenced by CMessage.

void NLNET::CMessage::readType  
 

Definition at line 250 of file message.cpp.

References NLMISC::CMemStream::_StringMode, NLMISC::IStream::begin, format, id, NLMISC::IStream::isReading, nlassert, NLMISC::CMemStream::seek, NLMISC::CMemStream::serial, setType, and NLMISC::CStringIdArray::TStringId.

Referenced by invert.

void NLNET::CMessage::setDefaultStringMode bool    stringmode [inline, static]
 

Set default stream mode.

Definition at line 118 of file message.h.

References _DefaultStringMode.

void NLNET::CMessage::setType const std::string &    name
 

Sets the message type as a string and put it in the buffer if we are in writing mode.

Definition at line 178 of file message.cpp.

References _HeaderSize, _Id, _Name, NLMISC::CMemStream::_StringMode, _TypeSet, format, FormatLong, FormatShort, NLMISC::CMemStream::getPos, id, NLMISC::IStream::isReading, NLMISC::CMemStream::length, nlassert, NLMISC::CMemStream::serial, NLMISC::CStringIdArray::TStringId, TypeHasAName, and TypeHasAnId.

void NLNET::CMessage::setType NLMISC::CStringIdArray::TStringId    id
 

Sets the message type as a number (in range 0..32767) and put it in the buffer if we are in writing mode.

Definition at line 124 of file message.cpp.

References _HeaderSize, _Id, _Name, _SIDA, NLMISC::CMemStream::_StringMode, _TypeSet, format, FormatLong, NLMISC::CMemStream::getPos, NLMISC::CStringIdArray::getString, id, NLMISC::IStream::isReading, NLMISC::CMemStream::length, nlassert, nlinfo, nlstop, NLMISC::CMemStream::serial, NLMISC::CStringIdArray::TStringId, TypeHasAName, and TypeHasAnId.

Referenced by CMessage, init, and readType.

std::string NLNET::CMessage::toString   const
 

Returns a readable string to display it to the screen.

It's only for debugging purpose! Don't use it for anything else than to debugging, the string format could change in the futur

Definition at line 317 of file message.cpp.

References _Id, _Name, _SIDA, _TypeSet, NLMISC::CStringIdArray::getId, NLMISC::CStringIdArray::getString, nlassert, s, TypeHasAName, and TypeHasAnId.

bool NLNET::CMessage::typeIsSet   const
 

Definition at line 288 of file message.cpp.

References _TypeSet.


Member Data Documentation

bool NLNET::CMessage::_DefaultStringMode = false [static, private]
 

Definition at line 39 of file message.cpp.

Referenced by init, and setDefaultStringMode.

uint32 NLNET::CMessage::_HeaderSize [private]
 

Definition at line 136 of file message.h.

Referenced by getHeaderSize, operator=, and setType.

NLMISC::CStringIdArray::TStringId NLNET::CMessage::_Id [private]
 

Definition at line 133 of file message.h.

Referenced by getId, operator=, setType, and toString.

std::string NLNET::CMessage::_Name [private]
 

Definition at line 132 of file message.h.

Referenced by getName, operator=, setType, and toString.

NLMISC::CStringIdArray* NLNET::CMessage::_SIDA [private]
 

Definition at line 130 of file message.h.

Referenced by operator=, setType, and toString.

bool NLNET::CMessage::_TypeSet [private]
 

Definition at line 129 of file message.h.

Referenced by clear, getId, getName, invert, operator=, setType, toString, and typeIsSet.

bool NLNET::CMessage::TypeHasAName
 

Definition at line 121 of file message.h.

Referenced by getName, operator=, setType, and toString.

bool NLNET::CMessage::TypeHasAnId
 

Definition at line 120 of file message.h.

Referenced by getId, operator=, setType, and toString.


The documentation for this class was generated from the following files: