22template<
typename TAllocator,
typename T,
typename TNodeHandler, Recycling TRecycling>
103 +
reinterpret_cast<std::size_t
>(key.
parent) * 29;
195 if( childIt->
name.
key.
template Equals<NC>( childName ) )
197 childIt= childIt->
next();
205 return childIt != tree->
nodeTable.end() ? &childIt.Value()
215 while(
p !=
nullptr )
232 while(
p !=
nullptr )
254 template<
typename... TArgs>
259 auto childCreation= tree->
nodeTable.EmplaceIfNotExistent(
NodeKey(
this, childName),
260 std::forward<TArgs>(args)...);
261 NodeBase* child= &childCreation.first.Value();
263 if( childCreation.second )
265 TNodeHandler::InitializeNode( *tree, *
static_cast<Node*
>(child ) );
270 return std::make_pair( child, childCreation.second );
284 "STRINGTREE",
"This node has no children to remove")
286 "STRINGTREE",
"The given node is not a child of this node.")
291 auto handle= tree->
nodeTable.Extract( *child );
293 TNodeHandler::FreeNode( *tree, handle.Value() );
311 count+= child->deleteChildren( tree );
313 TNodeHandler::FreeNode( *tree, handle.Value() );
314 child= child->next();
340 static constexpr int STACK_SIZE= 32;
345 nStack[0] = childNode;
346 while( childNode->
parent != maxParent )
348 childNode= childNode->
parent;
349 if( childNode ==
nullptr)
355 assemblePath( target, childNode, maxParent, separatorChar );
358 nStack[sp++]= childNode;
364 if( nStack[sp]->
parent !=
nullptr )
366 if( target.CharAtEnd() != separatorChar
367 && nStack[sp]->
parent != maxParent )
368 target << separatorChar;
370 target << nStack[sp]->
name.
key;
373 target << separatorChar;
401 template<
typename... TArgs>
404 ,
data ( std::forward<TArgs>(args)... )
412 template<
typename... TArgs>
415 ,
data ( std::forward<TArgs>(args)... )
459 typename NodeKey::ValueDescriptor,
460 typename NodeKey::Hash,
461 typename NodeKey::EqualTo,
480 template<
bool TConst>
484 using cmTree = std::conditional_t<!TConst, StringTreeBase, const StringTreeBase>;
487 using cmNodeBase = std::conditional_t<!TConst, NodeBase, const NodeBase>;
490 using cmNode = std::conditional_t<!TConst, Node, const Node>;
552 if( path.CharAtStart() ==
tree->separator )
554 path.ConsumeChars( 1 );
555 while( actNode->parent != nullptr )
556 actNode= actNode->parent;
563 while(path.ConsumeChar( tree->separator ) )
567 return static_cast<cmNode*>(actNode);
570 NameType name=path.template Substring<NC>(0, path.IndexOfOrLength(tree->separator));
573 if( name.Length() == 2 && name[0] ==
'.' && name[1] ==
'.' )
577 if( actNode->parent != nullptr )
578 actNode= actNode->parent;
581 else if( name.Length() != 1 || name[0] !=
'.' )
583 cmNodeBase* child= actNode->findChild( tree, name );
584 if( child == nullptr )
585 return static_cast<cmNode*>(actNode);
590 path.ConsumeChars( name.Length() );
611 template<
typename... TArgs,
bool TRequires= !TConst >
613 std::pair<cmNodeBase*, integer>
616 std::pair<cmNodeBase*, integer> result= std::make_pair(
node, 0 );
622 if( rest.CharAtStart() ==
tree->separator )
624 rest.ConsumeChars( 1 );
625 while( actNode->parent !=
nullptr )
626 actNode= actNode->parent;
633 while(rest.ConsumeChar(
tree->separator ) )
639 rest.IndexOfOrLength(
tree->separator ) );
643 if( childName[0] ==
'.' )
646 if( childName.
Length() == 1 )
648 if( childName.
Length() == 2 && childName[1] !=
'.' )
650 if ( !actNode->isRoot() )
651 actNode= actNode->parent;
656 auto childCreation= actNode->findOrCreateChild(
tree, childName,
657 std::forward<TArgs>(args)... );
659 if( childCreation.second )
662 actNode= childCreation.first;
663 rest.ConsumeChars( childName.
Length() + 1);
693 template<
typename TSharedRecycler= SharedRecyclerType>
694 requires ( !std::same_as<TSharedRecycler , void> )
706 template<
typename TSharedRecycler= SharedRecyclerType>
707 requires (!std::same_as<TSharedRecycler, void>)
726 && ( name.
Length() == 1 || ( name[1] ==
'.'
727 && name.
Length() == 2 ) ) )
730 ALIB_WARNING(
"STRINGTREE",
"Illegal child name \"{}\".", name )
constexpr integer Length() const
constexpr bool IsEmpty() const
integer IndexOf(TChar needle, integer startIdx=0) const
std::size_t Hashcode() const
#define ALIB_WARNINGS_UNINITIALIZED_OFF
#define ALIB_ASSERT(cond, domain)
#define ALIB_WARNINGS_RESTORE
#define ALIB_WARNING(domain,...)
#define ALIB_ASSERT_ERROR(cond, domain,...)
Detail namespace of module ALib Containers.
@ Enabled
Caching is enabled.
lang::uinteger uinteger
Type alias in namespace alib.
strings::TSubstring< character > Substring
Type alias in namespace alib.
NodeList children
The hook to the doubly linked list of children.
strings::TAString< CharacterType, lang::HeapAllocator > & assemblePath(strings::TAString< CharacterType, lang::HeapAllocator > &target, const NodeBase *childNode, const NodeBase *maxParent, CharacterType separatorChar) const
NodeBase(NodeBase *pParent, const NameType &pName)
NodeBase(const NodeKey &pKey)
uinteger qtyChildren
The number of children currently stored in this node.
uinteger deleteChild(StringTreeBase *tree, NodeBase *child)
NodeBase * findChild(StringTreeBase *tree, const NameType &childName)
std::pair< NodeBase *, bool > findOrCreateChild(StringTreeBase *tree, const NameType &childName, TArgs &&... args)
uinteger deleteChildren(StringTreeBase *tree)
int distance(const NodeBase *other) const
Equality functor for nodes in field nodeTable.
bool operator()(const NodeKey &lhs, const NodeKey &rhs) const
Hash functor for nodes hashed in field nodeTable.
std::size_t operator()(const NodeKey &key) const
ValueDescriptor for hash table nodeTable.
NodeKey & Key(NodeBase &src) const
NodeKey(NodeBase *pParent, const NameType &pName)
Node(const Node &)=delete
Deleted copy constructor.
T data
The templated custom data object stored with each node.
Node(const NodeKey &pKey, TArgs &&... args)
Node(Node &&)=delete
Deleted move constructor.
Node(NodeBase *pParent, const NameType &pName, TArgs &&... args)
TCursorBase() noexcept
Default constructor. Creates an invalid (uninitialized) object.
TCursorBase(cmTree *pTree, cmNode *pNode) noexcept
std::conditional_t<!TConst, NodeBase, const NodeBase > cmNodeBase
Constant or mutable version of type NodeBase, depending on template parameter TConst
std::pair< cmNodeBase *, integer > followPathCreate(const NameType &path, TArgs &&... args)
TCursorBase(const TCursorBase &) noexcept=default
Trivial default copy constructor.
std::conditional_t<!TConst, Node, const Node > cmNode
Constant or mutable version of type Node, depending on template parameter TConst
cmNode * followPath(SubstringType &path) const
std::conditional_t<!TConst, StringTreeBase, const StringTreeBase > cmTree
Constant or mutable version of the base tree type, depending on template parameter TConst
TCursorBase(TCursorBase &&) noexcept=default
Trivial default move constructor.
TAllocator & GetAllocator() noexcept
typename strings::TSubstring< CharacterType > SubstringType
lang::BidiListHook< NodeBase > NodeList
Alias shortcut for a bidirectional list of Node elements.
StringTreeBase(TAllocator &allocator, TSharedRecycler &pRecycler, CharacterType pathSeparator)
typename decltype(nodeTable)::SharedRecyclerType SharedRecyclerType
typename TNodeHandler::CharacterType CharacterType
StringTreeBase(TSharedRecycler &pRecycler, CharacterType pathSeparator)
typename TNodeHandler::NameStringType NameStorageType
StringTreeBase(TAllocator &allocator, CharacterType pathSeparator)
const strings::TString< CharacterType > NameType
The string-type of node names and paths if provided externally for comparison.
HashTable< TAllocator, typename NodeKey::ValueDescriptor, typename NodeKey::Hash, typename NodeKey::EqualTo, lang::Caching::Enabled, TRecycling > nodeTable
bool checkChildName(const NameType &name) const
TCursorBase< false > CursorBase
The mutable version of type StringTreeBase::TCursorBase<TConst>.
TCursorBase< true > ConstCursorBase
The constant version of type StringTreeBase::TCursorBase<TConst>.
void remove() noexcept
Unhooks this node from a list.
void next(SidiNodeBase *p)
integer count(SidiNodeBase *end=nullptr) const noexcept
NameType key
The name to compare when just keys are used.
NameStorageType storage
The name when stored in the hashtable.
NodeNameUnion(const NodeNameUnion &n)
Copy constructor.
~NodeNameUnion()
Destructor.
NodeNameUnion(const NameType &n)
Constructor taking a key string.
~RootNodeSpacer()
Destructor.
Node root
Full version of the root node, without initialization of member T.
RootNodeSpacer()
Explicitly implement otherwise implicitly deleted constructor.
NodeBase rootBase
Base version of the root node, which becomes initialized.