# 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  

msg_stream.cpp

Go to the documentation of this file.
00001 
00006 /* Copyright, 2000 Nevrax Ltd.
00007  *
00008  * This file is part of NEVRAX NEL.
00009  * NEVRAX NEL is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2, or (at your option)
00012  * any later version.
00013 
00014  * NEVRAX NEL is distributed in the hope that it will be useful, but
00015  * WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017  * General Public License for more details.
00018 
00019  * You should have received a copy of the GNU General Public License
00020  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00021  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00022  * MA 02111-1307, USA.
00023  */
00024 #include "nel/ai/agent/msg_stream.h"
00025 #include "nel/ai/agent/agent_digital.h"
00026 
00027 namespace NLAIAGENT
00028 {
00029 
00030         template<class X, class Y>
00031         X getValue(const IObjectIA *o)
00032         {               
00033                 return (X)((const Y *)o)->getValue();
00034         }
00035 
00036         template<class X, class Y>
00037         Y *getValue(X v)
00038         {               
00039                 return new Y(v);
00040         }
00041 
00042 //####################
00043 //class CMsgIStream
00044 //####################
00045         void CMsgIStream::serial(uint8 &b) throw(NLMISC::EStream)
00046         {               
00047                 b = getValue<uint8, UInt8Type>(_It++);
00048                 _Pos ++;
00049         }
00050 
00051         void CMsgIStream::serial(sint8 &b) throw(NLMISC::EStream)
00052         {
00053                 b = getValue<sint8, CharType>(_It++);
00054                 _Pos ++;
00055         }
00056 
00057         void CMsgIStream::serial(uint16 &b) throw(NLMISC::EStream)
00058         {
00059                 b = getValue<uint16, UInt16Type>(_It++);
00060                 _Pos ++;
00061         }
00062 
00063         void CMsgIStream::serial(sint16 &b) throw(NLMISC::EStream)
00064         {
00065                 b = getValue<sint16, ShortIntegerType>(_It++);
00066                 _Pos ++;
00067         }
00068 
00069         void CMsgIStream::serial(uint32 &b) throw(NLMISC::EStream)
00070         {
00071                 b = getValue<uint32, UInt32Type>(_It++);
00072                 _Pos ++;
00073         }
00074 
00075         void CMsgIStream::serial(sint32 &b) throw(NLMISC::EStream)
00076         {
00077                 b = getValue<sint32, IntegerType>(_It++);
00078                 _Pos ++;
00079         }
00080 
00081         void CMsgIStream::serial(uint64 &b) throw(NLMISC::EStream)
00082         {
00083                 b = getValue<uint64, UInt64Type>(_It++);
00084                 _Pos ++;
00085         }
00086 
00087         void CMsgIStream::serial(sint64 &b) throw(NLMISC::EStream)
00088         {
00089                 b = getValue<sint64, UInt64Type>(_It++);
00090                 _Pos ++;
00091         }
00092 
00093         void CMsgIStream::serial(float &b) throw(NLMISC::EStream)
00094         {
00095                 b = getValue<float, DigitalType>(_It++);
00096                 _Pos ++;
00097         }
00098 
00099         void CMsgIStream::serial(double &b) throw(NLMISC::EStream)
00100         {
00101                 b = getValue<double, DDigitalType>(_It++);
00102                 _Pos ++;
00103         }
00104 
00105         void CMsgIStream::serial(bool &b) throw(NLMISC::EStream)
00106         {
00107                 b = getValue<uint8, UInt8Type>(_It++) ? true : false;
00108                 _Pos ++;
00109         }
00110 
00111 #ifndef NL_OS_CYGWIN
00112         void CMsgIStream::serial(char &b) throw(NLMISC::EStream)
00113         {
00114                 b = getValue<sint8, CharType>(_It++);
00115                 _Pos ++;
00116         }
00117 #endif
00118 
00119         void CMsgIStream::serial(std::string &b) throw(NLMISC::EStream)
00120         {
00121                 CStringType *s= (CStringType *)(_It++);
00122                 b = s->getStr().getString();
00123                 _Pos ++;
00124         }
00125 
00126         void CMsgIStream::serial(ucstring &b) throw(NLMISC::EStream)
00127         {
00128                 throw NLMISC::EReadError((const char *)_List.getType());
00129         }
00130 
00131         void CMsgIStream::serial(IObjectIA &b) throw(NLMISC::EStream)
00132         {               
00133                 const IObjectIA *o= (const IObjectIA *)(_It++);
00134                 b = *o;         
00135         }
00136 
00137         void CMsgIStream::serial(IObjectIA* &b) throw(NLMISC::EStream)
00138         {               
00139                 IObjectIA *o= (IObjectIA *)(_It++);
00140                 b = o;
00141         }
00142 
00143 //####################
00144 //class CMsgIStream
00145 //####################
00146 
00147         void CMsgOStream::serial(uint8 &b) throw(NLMISC::EStream)
00148         {
00149                 _List.push(getValue<uint8, UInt8Type>(b));
00150         }
00151 
00152         void CMsgOStream::serial(sint8 &b) throw(NLMISC::EStream)
00153         {
00154                 _List.push(getValue<sint8, CharType>(b));
00155         }
00156 
00157         void CMsgOStream::serial(uint16 &b) throw(NLMISC::EStream)
00158         {
00159                 _List.push(getValue<uint16, UInt16Type>(b));
00160         }
00161 
00162         void CMsgOStream::serial(sint16 &b) throw(NLMISC::EStream)
00163         {
00164                 _List.push(getValue<sint16, ShortIntegerType>(b));
00165         }
00166 
00167         void CMsgOStream::serial(uint32 &b) throw(NLMISC::EStream)
00168         {
00169                 _List.push(getValue<uint32, UInt32Type>(b));
00170         }
00171 
00172         void CMsgOStream::serial(sint32 &b) throw(NLMISC::EStream)
00173         {               
00174                 _List.push(getValue<sint32, IntegerType>(b));
00175         }
00176 
00177         void CMsgOStream::serial(uint64 &b) throw(NLMISC::EStream)
00178         {
00179                 _List.push(getValue<uint64, UInt64Type>(b));
00180         }
00181         void CMsgOStream::serial(sint64 &b) throw(NLMISC::EStream)
00182         {
00183                 _List.push(getValue<sint64, UInt64Type>(b));
00184         }
00185         void CMsgOStream::serial(float &b) throw(NLMISC::EStream)
00186         {
00187                 _List.push(getValue<float, DigitalType>(b));
00188         }
00189         void CMsgOStream::serial(double &b) throw(NLMISC::EStream)
00190         {
00191                 _List.push(getValue<double, DDigitalType>(b));
00192         }
00193 
00194         void CMsgOStream::serial(bool &b) throw(NLMISC::EStream)
00195         {
00196                 _List.push(getValue<uint8, UInt8Type>(b ? true : false));
00197         }
00198 
00199 #ifndef NL_OS_CYGWIN
00200         void CMsgOStream::serial(char &b) throw(NLMISC::EStream)
00201         {
00202                 _List.push(getValue<sint8, CharType>(b));
00203         }
00204 #endif
00205 
00206         void CMsgOStream::serial(std::string &b) throw(NLMISC::EStream)
00207         {
00208                 CStringType *s= new CStringType(CStringVarName(b.c_str()));
00209                 _List.push(s);
00210         }
00211 
00212         void CMsgOStream::serial(ucstring &b) throw(NLMISC::EStream)
00213         {
00214                 throw NLMISC::EReadError((const char *)_List.getType());
00215         }
00216 
00217         void CMsgOStream::serial(IObjectIA &b) throw(NLMISC::EStream)
00218         {
00219                 /*((NLAIC::CIdentType &)b.getType()).serial(*this);
00220                 b.serial(*this);*/
00221                 _List.push((IObjectIA*)b.clone());
00222         }
00223 
00224         void CMsgOStream::serial(IObjectIA* &b) throw(NLMISC::EStream)
00225         {
00226                 /*((NLAIC::CIdentType &)b->getType()).serial(*this);
00227                 b->serial(*this);*/
00228                 _List.push(b);
00229                 b->incRef();
00230         }
00231 }