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/>.
17 #ifndef ALIAS_TREE_ROOT_H
18 #define ALIAS_TREE_ROOT_H
20 #include "nel/misc/string_mapper.h"
21 #include "child_container.h"
26 typedef std::vector
<NLMISC::TStringId
> TStringIdList
;
27 TStringIdList _RelatedFiles
;
30 class CMarkTagForDelete
33 CMarkTagForDelete(NLMISC::TStringId
const& fileId
);
34 virtual ~CMarkTagForDelete() { }
35 void operator()(CAliasTreeRoot
* const treeRoot
) const;
37 NLMISC::TStringId
const& _fileId
;
44 CDeleteTagged(CAliasCont
<T
>& container
)
45 : _Container(container
)
48 virtual ~CDeleteTagged()
51 void operator()(T
* const treeRoot
) const
56 if (!treeRoot
->isRegisteredByFiles())
57 this->_Container
.removeChildByIndex(treeRoot
->getChildIndex());
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;
76 CAliasTreeRoot::CAliasTreeRoot(std::string
const& filename
)
78 NLMISC::TStringId
const stringId
= NLMISC::CStringMapper::map(filename
);
79 if (isRegisteredForFile(stringId
))
81 registerForFile(stringId
);
85 CAliasTreeRoot::CAliasTreeRoot(NLMISC::TStringId filename
)
87 if (isRegisteredForFile(filename
))
89 registerForFile(filename
);
93 void CAliasTreeRoot::registerForFile(NLMISC::TStringId
const& filename
)
95 _RelatedFiles
.push_back(filename
);
99 void CAliasTreeRoot::registerForFile(std::string
const& filename
)
101 NLMISC::TStringId
const stringId
= NLMISC::CStringMapper::map(filename
);
102 registerForFile(stringId
);
106 bool CAliasTreeRoot::isRegisteredForFile(NLMISC::TStringId
const& filename
) const
108 for (TStringIdList::const_iterator it
=_RelatedFiles
.begin(), itEnd
=_RelatedFiles
.end(); it
!=itEnd
; ++it
)
115 void CAliasTreeRoot::unRegisterForFile(NLMISC::TStringId
const& filename
)
118 nlassert(isRegisteredForFile(filename
));
120 for (TStringIdList::iterator it
=_RelatedFiles
.begin(), itEnd
=_RelatedFiles
.end(); it
!=itEnd
; ++it
)
125 *it
= _RelatedFiles
.back();
126 _RelatedFiles
.pop_back();
132 bool CAliasTreeRoot::isRegisteredByFiles() const
134 return _RelatedFiles
.size()!=0;
138 CAliasTreeRoot::CMarkTagForDelete::CMarkTagForDelete(NLMISC::TStringId
const& fileId
)
144 void CAliasTreeRoot::CMarkTagForDelete::operator()(CAliasTreeRoot
* const treeRoot
) const
149 if (treeRoot
->isRegisteredForFile(_fileId
))
150 treeRoot
->unRegisterForFile(_fileId
);