1#line 1 "S:/jenkins/workspace/ECP/ufe/ufe-full-python3.11-windows/ufe/include/trie.imp.h"
27 : fComponent(component), fParent(), fChildren(), fHasData(false),
39 UFE_ASSERT_MSG(fChildren.find(child->component()) == fChildren.end(),
40 "Child trie node already exists.");
42 fChildren[child->component()] = child;
45 child->setParent(this->shared_from_this());
52 fChildren.erase(child->component());
54 child->setParent(
Ptr());
69 return fParent.lock();
75 return fChildren.find(component) != fChildren.end();
81 typename Children::const_iterator
const found = fChildren.find(component);
82 return found == fChildren.end() ?
Ptr() : found->second;
88 std::vector<PathComponent> ret;
89 ret.reserve(fChildren.size());
90 for (
auto c : fChildren)
92 ret.emplace_back(c.first);
100 std::size_t sz = size();
109 if ( hasData() || 0 == sz) {
122 typename Children::const_iterator
const next = fChildren.begin();
123 return next->second->closestCommonAncestor(depth);
129 return fChildren.size();
135 return std::accumulate(
136 fChildren.begin(), fChildren.end(), std::size_t(1),
137 [](std::size_t treeSize,
const typename Children::value_type& child) {
138 return treeSize+child.second->treeSize();
158 "Cannot rename child trie node, not found in parent.");
159 auto self = this->shared_from_this();
162 fComponent = component;
169 auto oldParent = parent();
170 if (newParent == oldParent)
172 UFE_ASSERT_MSG(!newParent->contains(component),
"Cannot reparent child trie node, new component already exists in new parent.");
173 UFE_ASSERT_MSG(oldParent->contains(fComponent),
"Cannot reparent child trie node, not found in parent.");
174 auto self = this->shared_from_this();
175 oldParent->remove(self);
176 fComponent = component;
177 newParent->add(self);
222 rhs.fRoot = std::make_shared< TrieNode<T> >();
228 fRoot = std::move(rhs.fRoot);
229 rhs.fRoot = std::make_shared< TrieNode<T> >();
247 child = std::make_shared< TrieNode<T> >(c);
248 trieNode->
add(child);
271 if (trieNode && trieNode->
hasData())
294 return bool(find(
path));
298template<
bool INCLUDE_ANCESTOR>
305 if (ancestorPath.
empty()) {
326 return INCLUDE_ANCESTOR ? true : !trieNode->
empty();
332 return containsDescendantHelper<false>(ancestorPath);
338 return containsDescendantHelper<true>(ancestorPath);
342template<
bool INCLUDE_DESCENDANT>
349 if (descendantPath.
empty()) {
356 auto pathEndIt = descendantPath.
cend();
360 if (!INCLUDE_DESCENDANT) {
361 pathEndIt = std::prev(pathEndIt);
363 for (
auto pathIt = descendantPath.
cbegin(); pathIt != pathEndIt; ++pathIt) {
386 return containsAncestorHelper<false>(descendantPath);
392 return containsAncestorHelper<true>(descendantPath);
398 return root()->closestCommonAncestor(-1);
424 while (child->
empty() && !child->
hasData() && child != root()) {
440 trieNode->
move(newPath.
back(), newParentNode);
441 cleanUpNode(oldParentNode);
455 return root()->treeSize();
461 return root()->empty();
Constant string representation with fixed space and O(1) comparison.
Identify an object or 3D path in the scene.
PathComponent back() const
Components::const_iterator cbegin() const
Iteration interface on PathComponents.
Components::const_iterator cend() const
Node for Universal Front End trie.
bool containsAncestor(const Path &path) const
TrieNode< T >::Ptr add(const Path &path, const T &data)
TrieNode< T >::Ptr node(const Path &path) const
bool containsDescendant(const Path &path) const
bool containsAncestorInclusive(const Path &path) const
TrieNode< T >::Ptr find(const Path &path) const
Trie & operator=(const Trie &)=delete
TrieNode< T >::Ptr createNode(const Path &path)
bool containsDescendantHelper(const Path &path) const
int closestCommonAncestor() const
void cleanUpNode(const typename TrieNode< T >::Ptr &node)
bool contains(const Path &path) const
TrieNode< T >::Ptr move(const Path &oldPath, const Path &newPath)
TrieNode< T >::Ptr root() const
TrieNode< T >::Ptr remove(const Path &)
bool containsAncestorHelper(const Path &path) const
bool containsDescendantInclusive(const Path &path) const
void remove(const Ptr &child)
void add(const Ptr &child)
void rename(const PathComponent &component)
std::shared_ptr< TrieNode > Ptr
void setParent(Ptr parent)
void move(const PathComponent &component, const Ptr &newParent)
void setData(const T &data)
std::size_t treeSize() const
std::weak_ptr< TrieNode > ParentPtr
int closestCommonAncestor(int depth) const
std::vector< PathComponent > childrenComponents() const
Ptr operator[](const PathComponent &child) const
PathComponent component() const
bool contains(const PathComponent &child) const
std::shared_ptr< ObservableSelection > Ptr
Path path(const std::string &pathString)
#define UFE_ASSERT_MSG(EXPR, MSG)
#define UFE_ASSERT_COMPILED(CODE)