# 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  

interpret_object.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/script/interpret_object.h"
00025 
00026 
00027 namespace NLAISCRIPT
00028 {
00029 
00030         void CComponent::save(NLMISC::IStream &os)
00031         {
00032                 os.serial( (NLAIC::CIdentType &) RegisterName->getType() );
00033                 RegisterName->save( os );
00034                 os.serial( (NLAIC::CIdentType &) ObjectName->getType() );
00035                 ObjectName->save( os );
00036         }
00037 
00038         void CComponent::load(NLMISC::IStream &is)
00039         {
00040                 NLAIC::CIdentTypeAlloc id;
00041                 is.serial( id );
00042                 RegisterName = (NLAIAGENT::IVarName *) id.allocClass();
00043                 RegisterName->load( is );
00044                 RegisterName->incRef();
00045 
00046                 is.serial( id );
00047                 ObjectName = (NLAIAGENT::IVarName *) id.allocClass();
00048                 ObjectName->load( is );
00049                 ObjectName->incRef();
00050         }
00051 
00052 
00055 
00056         IClassInterpret::IClassInterpret(const NLAIAGENT::IVarName &name, const IClassInterpret &a): IObjectIA(a), _Name( (NLAIAGENT::IVarName *) name.clone() )
00057         {                               
00058                 _IdType = new NLAIC::CIdentType( name.getString(), CClassInterpretFactory( this ) , NLAIC::CTypeOfObject::tAgent, 0);
00059         }
00060 
00061         IClassInterpret::IClassInterpret(NLAIC::CIdentType *idType):_Name(NULL),_IdType(idType)
00062         {
00063         }
00064 
00065         IClassInterpret::~IClassInterpret()
00066         {
00067                 if (_Name)
00068                         _Name->release();
00069 
00070                 if(_IdType) 
00071                         _IdType->release();
00072         }
00073 
00074         IClassInterpret::IClassInterpret():_Name(NULL),_IdType(NULL)
00075         {
00076         }
00077 
00078         const NLAIC::CIdentType &IClassInterpret::getType() const
00079         {
00080                 return *_IdType;
00081         }               
00082 
00083         void IClassInterpret::setType(NLAIC::CIdentType *idType)
00084         {
00085                 if(_IdType != NULL) _IdType->release();
00086                 _IdType = idType;
00087                 //_IdType->incRef();
00088         }
00089 
00090         void IClassInterpret::setType(const NLAIAGENT::IVarName &name, const IClassInterpret &a)
00091         {
00092                 if(_IdType != NULL) _IdType->release();
00093                 _IdType = new NLAIC::CIdentType( name.getString(), CClassInterpretFactory( this ), NLAIC::CTypeOfObject::tAgent, 0);
00094         }
00095 
00096         void IClassInterpret::setClassName(const NLAIAGENT::IVarName &name)
00097         {
00098                 if(_Name != NULL)
00099                 {
00100                         _Name->release();                               
00101                 }
00102                 _Name = (NLAIAGENT::IVarName *)name.clone();
00103 
00104         }
00105 
00106         const NLAIAGENT::IVarName *IClassInterpret::getClassName() const
00107         {
00108                 return _Name;
00109         }
00110 
00113 
00114         CClassInterpretFactory::CClassInterpretFactory(IClassInterpret *a) : _Inst(a)
00115         {                       
00116 
00117 /*#ifdef NL_DEBUG
00118                 static sint turc = 0;
00119                 nlinfo("%d CClassInterpretFactory(%0x)",turc++, _Inst);
00120 #endif*/
00121                 _Inst->incRef();
00122         }
00123 
00124         CClassInterpretFactory::CClassInterpretFactory(const IClassInterpret &a) : _Inst((IClassInterpret *)a.clone())
00125         {
00126         }
00127 
00128         CClassInterpretFactory::~CClassInterpretFactory()
00129         {
00130                 _Inst->release();
00131         }       
00132 
00133         void CClassInterpretFactory::setClass(const NLAIC::IBasicInterface &c)
00134         {
00135                 _Inst->release();
00136                 _Inst = (IClassInterpret *)c.clone();
00137         }
00138 
00139         void CClassInterpretFactory::getDebugString(std::string &text) const
00140         {
00141                 text += NLAIC::stringGetBuild("class factory: CClassInterpretFactory fabrique des instances pour l'interface %s",(const char *)_Inst->getType());
00142         }
00143 
00144         const NLAIC::IBasicType *CClassInterpretFactory::clone() const
00145         {
00146                  NLAIC::IBasicType *x = new CClassInterpretFactory(_Inst);
00147                  return x;
00148         }
00149 
00150         const NLAIC::IBasicType *CClassInterpretFactory::newInstance() const
00151         {
00152                 return clone();
00153         }
00154 
00155         const NLAIC::CIdentType &CClassInterpretFactory::getType() const
00156         {
00157                 return _Inst->getType();
00158         }
00159 
00160         const NLAIC::IBasicInterface *CClassInterpretFactory::createInstance() const 
00161         {
00162                 return (const NLAIC::IBasicInterface *)_Inst->buildNewInstance();
00163         }
00164 
00165         const NLAIC::IBasicInterface *CClassInterpretFactory::getClass() const 
00166         {
00167                 return _Inst;
00168         }
00169 }