1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
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 #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 //////////////////////////////////////////////////////////////////////////////
31 //////////////////////////////////////////////////////////////////////////////
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 //////////////////////////////////////////////////////////////////////////////
48 //////////////////////////////////////////////////////////////////////////////
50 class CAliasTreeOwner
;
52 class CAliasTreeOwnerLocator
55 static CAliasTreeOwnerLocator
* getInstance();
57 CAliasTreeOwnerLocator() {}
58 static CAliasTreeOwnerLocator
* _Instance
;
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
);
66 std::map
<uint32
, CAliasTreeOwner
*> _EntitiesByAlias
;
67 std::map
<std::string
, CAliasTreeOwner
*> _EntitiesByName
;
71 : public NLMISC::CDbgRefCount
<CAliasTreeOwner
>
77 CAliasDiff(uint32 alias
);
78 virtual ~CAliasDiff() { }
79 bool operator ()(CAliasTreeOwner
const* other
) const;
84 explicit CAliasTreeOwner(CAIAliasDescriptionNode
* aliasTree
);
85 explicit CAliasTreeOwner(uint32 alias
, std::string
const& name
);
86 virtual ~CAliasTreeOwner();
88 /// @name Virtual interface
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
);
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(); }
119 NLMISC::CSmartPtr
<CAIAliasDescriptionNode
> _AliasTree
;
121 static std::vector
<NLMISC::CDbgPtr
<CAliasTreeOwner
> > _CurrentOwnerList
;
124 /****************************************************************************/
125 /* Inlined methods */
126 /****************************************************************************/
128 //////////////////////////////////////////////////////////////////////////////
129 // CAliasTreeOwner //
130 //////////////////////////////////////////////////////////////////////////////
133 CAliasTreeOwner::CAliasDiff::CAliasDiff(uint32 alias
)
139 bool CAliasTreeOwner::CAliasDiff::operator()(CAliasTreeOwner
const* other
) const
141 return other
->getAlias()!=_Alias
;
145 CAliasTreeOwner::CAliasTreeOwner(CAIAliasDescriptionNode
* aliasTree
)
147 , _Name(std::string())
148 , _AliasTree(aliasTree
)
152 CAliasTreeOwnerLocator::getInstance()->addEntity(aliasTree
->getAlias(), aliasTree
->getName(), this);
161 CAliasTreeOwner::CAliasTreeOwner(uint32 alias
, std::string
const& name
)
166 CAliasTreeOwnerLocator::getInstance()->addEntity(_Alias
, _Name
, this);
170 CAliasTreeOwner::~CAliasTreeOwner()
172 CAliasTreeOwnerLocator::getInstance()->delEntity(getAlias(), getName(), this);
176 CAIAliasDescriptionNode
* CAliasTreeOwner::getAliasNode() const
182 uint32
CAliasTreeOwner::getAlias() const
185 return _AliasTree
->getAlias();
191 std::string
CAliasTreeOwner::getAliasString() const
194 return LigoConfig
.aliasToString(_AliasTree
->getAlias());
196 return LigoConfig
.aliasToString(_Alias
);
200 std::string
const& CAliasTreeOwner::getName() const
203 return _AliasTree
->getName();
209 void CAliasTreeOwner::setName(std::string
const& name
)
211 // should be able to change the alias tree node name?
218 CAliasTreeOwnerLocator::getInstance()->delEntity(_Alias
, _Name
, this);
220 CAliasTreeOwnerLocator::getInstance()->addEntity(_Alias
, _Name
, this);
224 std::string
CAliasTreeOwner::getAliasFullName() const
227 return _AliasTree
->fullName();
229 return getName(); // to upgrade...
233 IAliasCont
* CAliasTreeOwner::getAliasCont(AITYPES::TAIType type
)
239 CAliasTreeOwner
* CAliasTreeOwner::createChild(IAliasCont
* cont
, CAIAliasDescriptionNode
* aliasTree
)
245 void CAliasTreeOwner::updateDependencies(CAIAliasDescriptionNode
const& aliasTree
, CAliasTreeOwner
* aliasTreeOwner
)