Home | nevrax.com |
|
comp_handle.hGo to the documentation of this file.00001 00008 /* Copyright, 2000 Nevrax Ltd. 00009 * 00010 * This file is part of NEVRAX NEL. 00011 * NEVRAX NEL is free software; you can redistribute it and/or modify 00012 * it under the terms of the GNU General Public License as published by 00013 * the Free Software Foundation; either version 2, or (at your option) 00014 * any later version. 00015 00016 * NEVRAX NEL is distributed in the hope that it will be useful, but 00017 * WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 * General Public License for more details. 00020 00021 * You should have received a copy of the GNU General Public License 00022 * along with NEVRAX NEL; see the file COPYING. If not, write to the 00023 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 00024 * MA 02111-1307, USA. 00025 */ 00026 00027 #ifndef NL_COMP_HANDLE_H_ 00028 #define NL_COMP_HANDLE_H_ 00029 00030 #include "nel/ai/agent/agent.h" 00031 //#include "nel/ai/agent/agent_script.h" 00032 //#include "nel/ai/agent/agent_manager.h" 00033 #include "nel/ai/logic/bool_cond.h" 00034 #include "nel/ai/script/type_def.h" 00035 //#include "nel/ai/script/interpret_actor.h" 00036 00037 namespace NLAIAGENT 00038 { 00039 class CComponentHandle/* : public IObjectIA */{ 00040 private: 00041 IVarName *_CompName; 00042 const IObjectIA *_Comp; 00043 IAgent *_CompFather; 00044 00045 public: 00046 CComponentHandle() 00047 { 00048 _Comp = NULL; 00049 _CompFather = NULL; 00050 } 00051 00052 ~CComponentHandle() 00053 { 00054 if(_CompName != NULL) _CompName->release(); 00055 // if ( _Comp ) 00056 // _Comp->release(); 00057 } 00058 00059 00060 CComponentHandle(const IVarName &comp_name, IAgent *comp_father , bool get = false) 00061 { 00062 _CompName = (IVarName *) comp_name.clone(); 00063 _CompFather = comp_father; 00064 if ( get ) 00065 getComponent(); 00066 else 00067 _Comp = NULL; 00068 } 00069 00070 void getComponent() 00071 { 00072 if ( _CompFather != NULL ) 00073 { 00074 00075 #ifdef _DEBUG 00076 const char *dbg_father_type = (const char *) _CompFather->getType(); 00077 const char *dbg_comp_name = (const char *) _CompName->getType(); 00078 std::string buffer; 00079 _CompName->getDebugString(buffer); 00080 #endif 00081 00082 // Looks in static components 00083 sint32 comp_id = _CompFather->getStaticMemberIndex( *_CompName ); 00084 if ( comp_id >= 0) 00085 _Comp = _CompFather->getStaticMember( comp_id ); 00086 else 00087 _Comp = NULL; 00088 00089 if ( _Comp == NULL ) 00090 { 00091 // Looks in dynamic component 00092 CGroupType *param = new CGroupType(); 00093 param->push( (IObjectIA *) new CStringType(*_CompName) ); 00094 IObjectIA::CProcessResult comp = ( (CAgentScript *) _CompFather)->getDynamicAgent(param); 00095 //param->pop(); 00096 delete param; 00097 NLAIAGENT::IBaseGroupType *result = (NLAIAGENT::IBaseGroupType *) comp.Result; 00098 if ( result->size() > 0 ) 00099 { 00100 _Comp = result->get(); 00101 ((IObjectIA *)_Comp)->incRef(); 00102 } 00103 else 00104 _Comp = NULL; 00105 00106 if(result != NULL) 00107 result->release(); 00108 } 00109 } 00110 } 00111 00112 const IObjectIA *getValue() 00113 { 00114 if ( _Comp ) 00115 return _Comp; 00116 00117 getComponent(); 00118 return _Comp; 00119 } 00120 00121 const IVarName *getCompName() 00122 { 00123 return _CompName; 00124 } 00125 }; 00126 } // NLAIAGENT 00127 00128 #endif // NL_COMP_HANDLE_H_ |