Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / alias_tree_owner.h
blob392a5333a3936f2f56c808dcd2639293c3e00721
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/>.
19 #ifndef _ALIAS_TREE_OWNER_
20 #define _ALIAS_TREE_OWNER_
22 #include "ai_share/ai_types.h"
23 #include "ai_share/ai_alias_description_node.h"
24 #include "nel/misc/smart_ptr.h"
26 extern NLLIGO::CLigoConfig LigoConfig;
27 class CAliasTreeOwner;
29 //////////////////////////////////////////////////////////////////////////////
30 // IAliasCont //
31 //////////////////////////////////////////////////////////////////////////////
33 class IAliasCont
35 public:
36 virtual uint32 size() const = 0;
37 virtual void removeChildByAlias (uint32 alias) = 0;
38 virtual void removeChildByIndex (uint32 index) = 0;
39 virtual CAliasTreeOwner* getAliasChildByAlias(uint32 alias) const = 0;
40 virtual CAliasTreeOwner* addAliasChild (CAliasTreeOwner* child) = 0;
41 virtual CAliasTreeOwner* addAliasChild (CAliasTreeOwner* child, uint32 index) = 0;
43 virtual ~IAliasCont() { }
46 //////////////////////////////////////////////////////////////////////////////
47 // CAliasTreeOwner //
48 //////////////////////////////////////////////////////////////////////////////
50 class CAliasTreeOwner;
52 class CAliasTreeOwnerLocator
54 public:
55 static CAliasTreeOwnerLocator* getInstance();
56 private:
57 CAliasTreeOwnerLocator() {}
58 static CAliasTreeOwnerLocator* _Instance;
60 public:
61 CAliasTreeOwner* getEntity(uint32 const alias) const;
62 CAliasTreeOwner* getEntity(std::string const& name) const;
63 void addEntity(uint32 const alias, std::string const& name, CAliasTreeOwner* entity);
64 void delEntity(uint32 const alias, std::string const& name, CAliasTreeOwner* entity);
65 private:
66 std::map<uint32, CAliasTreeOwner*> _EntitiesByAlias;
67 std::map<std::string, CAliasTreeOwner*> _EntitiesByName;
70 class CAliasTreeOwner
71 : public NLMISC::CDbgRefCount<CAliasTreeOwner>
73 public:
74 class CAliasDiff
76 public:
77 CAliasDiff(uint32 alias);
78 virtual ~CAliasDiff() { }
79 bool operator ()(CAliasTreeOwner const* other) const;
80 uint32 _Alias;
83 public:
84 explicit CAliasTreeOwner(CAIAliasDescriptionNode* aliasTree);
85 explicit CAliasTreeOwner(uint32 alias, std::string const& name);
86 virtual ~CAliasTreeOwner();
88 /// @name Virtual interface
89 //@{
90 // obtain the container associated with this type.
91 virtual IAliasCont* getAliasCont(AITYPES::TAIType type);
92 // create a child with the specified alias node.
93 virtual CAliasTreeOwner* createChild(IAliasCont* cont, CAIAliasDescriptionNode* aliasTree);
94 // done to allow postprocess dependencies updates.
95 virtual void updateDependencies(CAIAliasDescriptionNode const& aliasTree, CAliasTreeOwner* aliasTreeOwner);
96 //@}
98 CAIAliasDescriptionNode* getAliasNode() const;
100 uint32 getAlias() const;
101 std::string getAliasString() const;
103 std::string const& getName() const;
105 void setName(std::string const& name);
107 std::string getAliasFullName() const;
109 void updateAliasTree(CAIAliasDescriptionNode const& newTree);
110 bool getCont(CAliasTreeOwner*& childOwner, IAliasCont*& cont, AITYPES::TAIType _type);
112 void pushCurrentOwnerList() { _CurrentOwnerList.push_back(this); }
113 void popCurrentOwnerList() { _CurrentOwnerList.pop_back(); }
115 private:
116 uint32 _Alias;
117 std::string _Name;
119 NLMISC::CSmartPtr<CAIAliasDescriptionNode> _AliasTree;
121 static std::vector<NLMISC::CDbgPtr<CAliasTreeOwner> > _CurrentOwnerList;
124 /****************************************************************************/
125 /* Inlined methods */
126 /****************************************************************************/
128 //////////////////////////////////////////////////////////////////////////////
129 // CAliasTreeOwner //
130 //////////////////////////////////////////////////////////////////////////////
132 inline
133 CAliasTreeOwner::CAliasDiff::CAliasDiff(uint32 alias)
134 : _Alias(alias)
138 inline
139 bool CAliasTreeOwner::CAliasDiff::operator()(CAliasTreeOwner const* other) const
141 return other->getAlias()!=_Alias;
144 inline
145 CAliasTreeOwner::CAliasTreeOwner(CAIAliasDescriptionNode* aliasTree)
146 : _Alias(0)
147 , _Name(std::string())
148 , _AliasTree(aliasTree)
150 if (aliasTree)
152 CAliasTreeOwnerLocator::getInstance()->addEntity(aliasTree->getAlias(), aliasTree->getName(), this);
154 else
156 //DEBUG_STOP;
160 inline
161 CAliasTreeOwner::CAliasTreeOwner(uint32 alias, std::string const& name)
162 : _Alias(alias)
163 , _Name(name)
164 , _AliasTree(NULL)
166 CAliasTreeOwnerLocator::getInstance()->addEntity(_Alias, _Name, this);
169 inline
170 CAliasTreeOwner::~CAliasTreeOwner()
172 CAliasTreeOwnerLocator::getInstance()->delEntity(getAlias(), getName(), this);
175 inline
176 CAIAliasDescriptionNode* CAliasTreeOwner::getAliasNode() const
178 return _AliasTree;
181 inline
182 uint32 CAliasTreeOwner::getAlias() const
184 if (_AliasTree)
185 return _AliasTree->getAlias();
187 return _Alias;
190 inline
191 std::string CAliasTreeOwner::getAliasString() const
193 if (_AliasTree)
194 return LigoConfig.aliasToString(_AliasTree->getAlias());
196 return LigoConfig.aliasToString(_Alias);
199 inline
200 std::string const& CAliasTreeOwner::getName() const
202 if (_AliasTree)
203 return _AliasTree->getName();
205 return _Name;
208 inline
209 void CAliasTreeOwner::setName(std::string const& name)
211 // should be able to change the alias tree node name?
212 if (_AliasTree)
214 DEBUG_STOP;
215 return;
218 CAliasTreeOwnerLocator::getInstance()->delEntity(_Alias, _Name, this);
219 _Name = name;
220 CAliasTreeOwnerLocator::getInstance()->addEntity(_Alias, _Name, this);
223 inline
224 std::string CAliasTreeOwner::getAliasFullName() const
226 if (_AliasTree)
227 return _AliasTree->fullName();
229 return getName(); // to upgrade...
232 inline
233 IAliasCont* CAliasTreeOwner::getAliasCont(AITYPES::TAIType type)
235 return NULL;
238 inline
239 CAliasTreeOwner* CAliasTreeOwner::createChild(IAliasCont* cont, CAIAliasDescriptionNode* aliasTree)
241 return NULL;
244 inline
245 void CAliasTreeOwner::updateDependencies(CAIAliasDescriptionNode const& aliasTree, CAliasTreeOwner* aliasTreeOwner)
249 #endif