Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / alias_tree_root.h
blob9867329542b0fbd1eec33871f91de901e13b8777
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 ALIAS_TREE_ROOT_H
18 #define ALIAS_TREE_ROOT_H
20 #include "nel/misc/string_mapper.h"
21 #include "child_container.h"
22 #include <string>
24 class CAliasTreeRoot
26 typedef std::vector<NLMISC::TStringId> TStringIdList;
27 TStringIdList _RelatedFiles;
29 public:
30 class CMarkTagForDelete
32 public:
33 CMarkTagForDelete(NLMISC::TStringId const& fileId);
34 virtual ~CMarkTagForDelete() { }
35 void operator()(CAliasTreeRoot* const treeRoot) const;
36 private:
37 NLMISC::TStringId const& _fileId;
40 template <class T>
41 class CDeleteTagged
43 public:
44 CDeleteTagged(CAliasCont<T>& container)
45 : _Container(container)
48 virtual ~CDeleteTagged()
51 void operator()(T* const treeRoot) const
53 if (!treeRoot)
54 return;
56 if (!treeRoot->isRegisteredByFiles())
57 this->_Container.removeChildByIndex(treeRoot->getChildIndex());
59 private:
60 CCont<T>& _Container;
63 public:
64 CAliasTreeRoot(std::string const& filename);
65 CAliasTreeRoot(NLMISC::TStringId filename);
67 void registerForFile(NLMISC::TStringId const& filename);
68 void registerForFile(std::string const& filename);
69 bool isRegisteredForFile(NLMISC::TStringId const& filename) const;
70 void unRegisterForFile(NLMISC::TStringId const& filename);
72 bool isRegisteredByFiles() const;
75 inline
76 CAliasTreeRoot::CAliasTreeRoot(std::string const& filename)
78 NLMISC::TStringId const stringId = NLMISC::CStringMapper::map(filename);
79 if (isRegisteredForFile(stringId))
80 return;
81 registerForFile(stringId);
84 inline
85 CAliasTreeRoot::CAliasTreeRoot(NLMISC::TStringId filename)
87 if (isRegisteredForFile(filename))
88 return;
89 registerForFile(filename);
92 inline
93 void CAliasTreeRoot::registerForFile(NLMISC::TStringId const& filename)
95 _RelatedFiles.push_back(filename);
98 inline
99 void CAliasTreeRoot::registerForFile(std::string const& filename)
101 NLMISC::TStringId const stringId = NLMISC::CStringMapper::map(filename);
102 registerForFile(stringId);
105 inline
106 bool CAliasTreeRoot::isRegisteredForFile(NLMISC::TStringId const& filename) const
108 for (TStringIdList::const_iterator it=_RelatedFiles.begin(), itEnd=_RelatedFiles.end(); it!=itEnd; ++it)
109 if (*it==filename)
110 return true;
111 return false;
114 inline
115 void CAliasTreeRoot::unRegisterForFile(NLMISC::TStringId const& filename)
117 #if !FINAL_VERSION
118 nlassert(isRegisteredForFile(filename));
119 #endif
120 for (TStringIdList::iterator it=_RelatedFiles.begin(), itEnd=_RelatedFiles.end(); it!=itEnd; ++it)
122 if (*it!=filename)
123 continue;
125 *it = _RelatedFiles.back();
126 _RelatedFiles.pop_back();
127 return;
131 inline
132 bool CAliasTreeRoot::isRegisteredByFiles() const
134 return _RelatedFiles.size()!=0;
137 inline
138 CAliasTreeRoot::CMarkTagForDelete::CMarkTagForDelete(NLMISC::TStringId const& fileId)
139 :_fileId(fileId)
143 inline
144 void CAliasTreeRoot::CMarkTagForDelete::operator()(CAliasTreeRoot* const treeRoot) const
146 if (!treeRoot)
147 return;
149 if (treeRoot->isRegisteredForFile(_fileId))
150 treeRoot->unRegisterForFile(_fileId);
153 #endif