1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "nel/misc/class_registry.h"
20 #include "nel/misc/debug.h"
32 // ======================================================================================================
33 CClassRegistry::TClassMap
*CClassRegistry::RegistredClasses
= NULL
;
36 // ======================================================================================================
37 void CClassRegistry::init()
39 if (RegistredClasses
== NULL
)
40 RegistredClasses
= new TClassMap
;
43 // ======================================================================================================
44 void CClassRegistry::release()
46 if( RegistredClasses
)
47 delete RegistredClasses
;
48 RegistredClasses
= NULL
;
51 // ======================================================================================================
52 IClassable
*CClassRegistry::create(const string
&className
)
56 TClassMap::iterator it
;
58 it
=RegistredClasses
->find(className
);
60 if(it
==RegistredClasses
->end())
65 ptr
=it
->second
.Creator();
67 nlassert(CClassRegistry::checkObject(ptr
));
74 // ======================================================================================================
75 void CClassRegistry::registerClass(const string
&className
, IClassable
* (*creator
)(), const string
&typeidCheck
)
81 node
.TypeIdCheck
= typeidCheck
;
82 std::pair
<TClassMap::iterator
, bool> result
;
83 result
= RegistredClasses
->insert(TClassMap::value_type(className
, node
));
87 throw ERegisteredClass();
91 // ======================================================================================================
92 bool CClassRegistry::checkObject(IClassable
* obj
)
96 TClassMap::iterator it
;
97 it
=RegistredClasses
->find(obj
->getClassName());
98 if(it
==RegistredClasses
->end())
101 if( it
->second
.TypeIdCheck
!= string(typeid(*obj
).name()) )