# 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  

message.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef NL_MESSAGE_H
00027 #define NL_MESSAGE_H
00028 
00029 #include "nel/misc/types_nl.h"
00030 
00031 #include <sstream>
00032 
00033 #include "nel/misc/mem_stream.h"
00034 
00035 #include "nel/misc/string_id_array.h"
00036 
00037 #include <vector>
00038 
00039 namespace NLNET
00040 {
00041 
00042 
00056 class CMessage : public NLMISC::CMemStream
00057 {
00058 public:
00059 
00060         enum TStreamFormat { UseDefault, Binary, String };
00061 
00062         CMessage (NLMISC::CStringIdArray &sida, const std::string &name = "", bool inputStream = false, TStreamFormat streamformat = UseDefault, uint32 defaultCapacity = 1000);
00063 
00064         CMessage (const std::string &name = "", bool inputStream = false, TStreamFormat streamformat = UseDefault, uint32 defaultCapacity = 1000);
00065 
00066         CMessage (NLMISC::CMemStream &memstr);
00067 
00069         CMessage (const CMessage &other);
00070 
00072         CMessage &operator= (const CMessage &other);
00073         
00075         void setType (NLMISC::CStringIdArray::TStringId id);
00076 
00078         void setType (const std::string &name);
00079 
00081         uint32 getHeaderSize ();
00082         
00083         // The message was filled with an CMemStream, Now, we'll get the message type on this buffer
00084         void readType ();
00085 
00086         // Returns true if the message type was already set
00087         bool typeIsSet () const;
00088 
00089         // Transforms the message from input to output or from output to input
00090         void invert()
00091         {
00092                 CMemStream::invert();
00093 
00094                 if ( isReading() )
00095                 {
00096                         // Write -> Read: skip the header 
00097                         _TypeSet = false;
00098                         readType();
00099                 }
00100                 // For Read -> Write, please use clear()
00101         }
00102 
00103         // Clear the message. With this function, you can reuse a message to create another message
00104         void clear ();
00105 
00107         std::string getName () const;
00108         
00110         NLMISC::CStringIdArray::TStringId getId () const;
00111 
00115         std::string toString () const;
00116 
00118         static void     setDefaultStringMode( bool stringmode ) { _DefaultStringMode = stringmode; }
00119 
00120         bool TypeHasAnId;
00121         bool TypeHasAName;
00122 
00123 protected:
00124 
00126         void            init( const std::string &name, TStreamFormat streamformat );
00127 
00128 private:
00129         bool                                                            _TypeSet;
00130         NLMISC::CStringIdArray                          *_SIDA;
00131         
00132         std::string                                                     _Name;
00133         NLMISC::CStringIdArray::TStringId       _Id;
00134         
00135         // Size of the header (that contains the name type or number type)
00136         uint32                                                          _HeaderSize;
00137 
00138         // Default stream format
00139         static bool                                                     _DefaultStringMode;
00140 };
00141 
00142 }
00143 
00144 #endif // NL_MESSAGE_H
00145 
00146 /* End of message.h */