Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / gameplay_module_lib / module_parent.h
blob33a88f66c27fdba4ee5443b622bdd7f7970fc32b
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
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.
8 //
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/>.
17 #ifndef RY_MODULE_PARENT_H
18 #define RY_MODULE_PARENT_H
20 #include "nel/misc/types_nl.h"
21 #include "nel/misc/smart_ptr.h"
23 #include "module_core.h"
24 #include "module_utils.h"
26 class IModuleCore;
27 class IModule;
29 /**
30 * A module parent is a class encapsulating the modules contained in a module core
31 * It mainly provides accessors to the modules
32 * \author Nicolas Brigand
33 * \author Nevrax France
34 * \date 2004
36 class CModuleParent : public NLMISC::CRefCount
38 public:
39 /// ctor : a valid module core must be passed
40 CModuleParent(::IModuleCore * owner)
41 :_Owner(owner)
43 MODULE_AST(owner);
45 /// dtor : inform the modules that they must delete themselves
46 ~CModuleParent();
48 /// returns the core owning of the modules
49 ::IModuleCore* getOwner()const{ return _Owner; }
51 /// get a module of the specified type WARNING : the module must be unique
52 template <class ModuleClass>
53 bool getModule( ModuleClass* & module )const
55 module = NULL;
56 const uint size = (uint)_Modules.size();
57 for (uint i = 0;i < size; i++ )
59 ModuleClass * moduleChecked = dynamic_cast<ModuleClass*>( (::IModule*)_Modules[i] );
60 if ( moduleChecked )
62 module = moduleChecked;
63 // additional checks to ensure module uniqueness
64 #ifdef RY_MODULE_DEBUG
65 for (uint j = i + 1; j < size; j++ )
67 ModuleClass * moduleTest = dynamic_cast<ModuleClass*>( (::IModule*)_Modules[j] );
68 if ( moduleTest )
69 nlerror("you required a unique module but there is more than 1!!!!");
71 #endif
72 return module != NULL ;
75 return false;
77 /// get all the module of the specified type
78 // I would have coded getModules( std::vector<ModuleClass> & modules ) but VC6 has an internal compiler error
79 template <class ModuleClassVector, class ModuleClass>
80 void getModules( ModuleClassVector & modules,ModuleClass * dummy )const
82 const uint size = _Modules.size();
83 for (uint i = 0;i < size; i++ )
85 ModuleClass * module = dynamic_cast<ModuleClass*>( (::IModule*)_Modules[i]);
86 if ( module )
87 modules.push_back(module);
91 /// remove a child module. Called by a module to remove itself from the parent
92 void removeChildModule(::IModule* module);
93 /// add a new module to this container. Called by a module to register itself in the parent
94 void addChildModule(::IModule* module);
95 private:
96 /// core owning this structure
97 NLMISC::CRefPtr< ::IModuleCore> _Owner;
98 /// children modules
99 std::vector< NLMISC::CRefPtr< ::IModule> > _Modules;
102 //#include "module.h"
103 //#include "module_utils.h"
104 //#include "module_parent_inline.h"
107 #endif // RY_MODULE_PARENT_H
109 /* End of module_parent.h */