Yagl::Message Class Reference

#include <message.h>

List of all members.

Public Member Functions

 Message ()
 Constructor.
 Message (const Message &message)
 copy constructor
virtual ~Message ()
 Destructor.
Messageoperator= (const Message &message)
 overloaded assignment
void enlargeBuffer (unsigned int additional_bytes)
 enlarges a buffer
void setBufferSize (unsigned int size)
 sets the buffer size
void setMessageSize (unsigned int size)
 set the message size
void setSenderAddress (std::string address)
 sets the message's sender address
void setSenderPort (unsigned short port)
 sets the message's sender port
char * getBufferPointer ()
 returns a pointer to the internal buffer
unsigned int getBufferSize ()
unsigned int getMessageSize ()
std::string & getSenderAddress ()
unsigned short getSenderPort ()
void insert (const void *data, unsigned int data_size)
 inserts the given data of the given length
void append (const void *data, unsigned int data_size)
 appends the given data

Protected Attributes

char * buffer_
 buffer for holding the message
unsigned int buffer_size_
 holds the buffers size
unsigned int message_size_
 holds the messages size. can be <= buffer_size
std::string sender_address_
 holds the adress of the sender if this is a received message
unsigned short sender_port_
 holds the port of the sender if this is a received message


Detailed Description

This Class is used to store Message for processing and sending. Note that this class is not threadsafe


Constructor & Destructor Documentation

Yagl::Message::Message  ) 
 

Constructor.

initializes members

Yagl::Message::Message const Message message  ) 
 

copy constructor

copies a message to another. if the buffer of the destination message is allocated it will get destroyed

virtual Yagl::Message::~Message  )  [virtual]
 

Destructor.

destroys the buffer of the message if allocated ( buffer_size > 0 )


Member Function Documentation

void Yagl::Message::append const void *  data,
unsigned int  data_size
 

appends the given data

this method will resize the buffer so it can exactly fit the old message plus the new data and then appends the new data. the message size is set to old_message_size + data_size.

Parameters:
data a pointer to the data to be appended
data_size the size of the data in bytes

void Yagl::Message::enlargeBuffer unsigned int  additional_bytes  ) 
 

enlarges a buffer

this will add additional_bytes to the buffer size and resize the buffer the content is preserved

Parameters:
additional_bytes number of bytes to enlarge the buffer with

char* Yagl::Message::getBufferPointer  ) 
 

returns a pointer to the internal buffer

this method will return a pointer to the internal buffer, use this with care and only if you know what you do. use insert and append instead.

unsigned int Yagl::Message::getBufferSize  ) 
 

returns the internal buffers size

unsigned int Yagl::Message::getMessageSize  ) 
 

returns the messages size

std::string& Yagl::Message::getSenderAddress  ) 
 

returns the senders ip adress if this is a received message

unsigned short Yagl::Message::getSenderPort  ) 
 

returns the senders port adress if this is a received message

void Yagl::Message::insert const void *  data,
unsigned int  data_size
 

inserts the given data of the given length

this method will clear the internal buffer, allocate data_size bytes and insert data_size bytes from the given data into the buffer. the message size is set to data_size

Parameters:
data a pointer to the data to be inserted
data_size the size of the data in bytes

Message& Yagl::Message::operator= const Message message  )  [inline]
 

overloaded assignment

copies the assigned message to the assignments l-value messge if the buffer of the l-value message is already allocated it gets destroyed

void Yagl::Message::setBufferSize unsigned int  size  ) 
 

sets the buffer size

this will destroy an already existant buffer size, reset the message_size to 0 and allocate a new buffer with the given size

Parameters:
size number of bytes to set the buffer size to

void Yagl::Message::setMessageSize unsigned int  size  ) 
 

set the message size

this will set the message size. if the size is bigger than the buffer_size it is clamped to the buffer_size. use this if you don't append or insert your data but are manipulating the buffer directly via the getBufferPointer method

Parameters:
size size of the message in bytes
See also:
getBufferPointer( )

void Yagl::Message::setSenderAddress std::string  address  ) 
 

sets the message's sender address

used internally in BiDirectionalConnection::receive

void Yagl::Message::setSenderPort unsigned short  port  ) 
 

sets the message's sender port

used internally in BiDirectionalConnection::receive


The documentation for this class was generated from the following file:
Generated on Tue Jan 10 15:42:38 2006 for YAGL - yet another gameprogramming library by  doxygen 1.4.5