8#ifndef HPP_ALIB_MONOMEM_DETAIL_STRINGTREEBASE
9#define HPP_ALIB_MONOMEM_DETAIL_STRINGTREEBASE 1
11#if !defined(HPP_ALIB_MONOMEM_STRINGTREE)
12# error "ALib sources with ending '.inl' must not be included from outside."
15#if !defined(HPP_ALIB_MONOMEM_HASHTABLE)
19#if !defined(HPP_ALIB_LANG_BIDILIST)
23#if !defined (HPP_ALIB_STRINGS_SUBSTRING)
28# if !defined(HPP_ALIB_CAMP_MESSAGE_REPORT)
33#if !defined (_GLIBCXX_VECTOR) && !defined(_VECTOR_)
37#if !defined (_GLIBCXX_ALGORITHM) && !defined(_ALGORITHM_)
41namespace alib {
namespace monomem {
65template<
typename T,
typename TNodeMa
intainer,
typename TRecycling>
156 std::size_t result= 8175383ul;
161 + std::size_t( *act++ );
164 result+=
reinterpret_cast<std::size_t
>(key.
parent) * 29;
166 return std::size_t( result );
275 if( childIt->
name.
key.
template Equals<false>( childName ) )
277 childIt= childIt->
next();
285 return childIt != tree->
nodeTable.end() ? &childIt.Value()
297 while( p !=
nullptr )
319 template<
typename... TArgs>
324 auto childCreation= tree->
nodeTable.EmplaceIfNotExistent(
NodeKey(
this, childName),
325 std::forward<TArgs>(args)...);
326 NodeBase* child= &childCreation.first.Value();
328 if( childCreation.second )
330 TNodeMaintainer::InitializeNode( *tree, *
static_cast<Node*
>(child ) );
335 return std::make_pair( child, childCreation.second );
352 "This node has no children to remove")
354 "The given node is not a child of this node.")
359 auto handle= tree->
nodeTable.Extract( *child );
361 TNodeMaintainer::FreeNode( *tree, handle.Value() );
383 TNodeMaintainer::FreeNode( *tree, handle.Value() );
384 child= child->next();
409 static constexpr int STACK_SIZE= 32;
414 nStack[0] = childNode;
415 while( childNode->
parent != maxParent )
417 childNode= childNode->
parent;
418 if( childNode ==
nullptr)
424 assemblePath( target, childNode, maxParent, separatorChar );
427 nStack[sp++]= childNode;
433 if( nStack[sp]->parent !=
nullptr )
436 && nStack[sp]->
parent != maxParent )
437 target << separatorChar;
439 target << nStack[sp]->
name.
key;
442 target << separatorChar;
474 template<
typename... TArgs>
477 ,
data ( std::forward<TArgs>(args)... )
487 template<
typename... TArgs>
490 ,
data ( std::forward<TArgs>(args)... )
559 template<
bool TConst>
632 if( path.CharAtStart() ==
tree->separator )
634 path.ConsumeChars( 1 );
635 while( actNode->parent !=
nullptr )
636 actNode= actNode->parent;
643 while(path.ConsumeChar(
tree->separator ) )
653 if( name.
Length() == 2 && name[0] ==
'.' && name[1] ==
'.' )
657 if( actNode->parent !=
nullptr )
658 actNode= actNode->parent;
661 else if( name.
Length() != 1 || name[0] !=
'.' )
663 cmNode* child= actNode->findChild(
tree, name );
664 if( child ==
nullptr )
670 path.ConsumeChars( name.
Length() );
674 #if defined(ALIB_DOX)
693 template<
typename... TArgs,
bool TEnableIf= !TConst >
696 template<
typename... TArgs,
bool TEnableIf= !TConst >
697 ATMP_T_IF(std::pair<cmNode* ALIB_COMMA integer>, TEnableIf)
700 std::pair<cmNode*, integer> result= std::make_pair(
node, 0 );
701 cmNode*& actNode= result.first;
706 if( rest.CharAtStart() ==
tree->separator )
708 rest.ConsumeChars( 1 );
709 while( actNode->parent !=
nullptr )
710 actNode= actNode->parent;
717 while(rest.ConsumeChar(
tree->separator ) )
723 rest.IndexOfOrLength(
tree->separator ) );
727 if( childName[0] ==
'.' )
730 if( childName.
Length() == 1 )
732 if( childName.
Length() == 2 && childName[1] !=
'.' )
734 if ( !actNode->isRoot() )
735 actNode= actNode->parent;
740 auto childCreation= actNode->findOrCreateChild(
tree, childName,
741 std::forward<TArgs>(args)... );
743 if( childCreation.second )
746 actNode= childCreation.first;
747 rest.ConsumeChars( childName.
Length() + 1);
796 && ( name.
Length() == 1 || ( name[1] ==
'.'
797 && name.
Length() == 2 ) ) )
800 ALIB_WARNING(
"MONOMEM/STRINGTREE",
"Illegal child name {!Q}", name )
integer IndexOf(TChar needle, integer startIdx=0) const
constexpr bool IsEmpty() const
constexpr integer Length() const
constexpr const TChar * Buffer() const
#define ATMP_IF_T_F( Cond, T, F)
#define ALIB_WARNING(...)
#define ALIB_WARNINGS_UNINITIALIZED_OFF
#define ALIB_WARNINGS_RESTORE
#define ALIB_ASSERT_ERROR(cond,...)
#define ALIB_ASSERT(cond)
#define ATMP_T_IF(T, Cond)
@ Enabled
Caching is enabled.
lang::uinteger uinteger
Type alias in namespace alib.
characters::character character
Type alias in namespace alib.
void pushEnd(TElement *elem)
void next(SidiNodeBase *p)
uinteger deleteChild(StringTreeBase *tree, NodeBase *child)
AString & assemblePath(AString &target, const NodeBase *childNode, const NodeBase *maxParent, character separatorChar) const
uinteger deleteChildren(StringTreeBase *tree)
NodeBase(const NodeKey &pKey)
NodeBase * findChild(StringTreeBase *tree, const NameType &childName)
NodeBase(NodeBase *pParent, const NameType &pName)
std::pair< NodeBase *, bool > findOrCreateChild(StringTreeBase *tree, const NameType &childName, TArgs &&... args)
NodeKey & Key(NodeBase &src) const
bool operator()(const NodeKey &lhs, const NodeKey &rhs) const
std::size_t operator()(const NodeKey &key) const
NodeKey(NodeBase *pParent, const NameType &pName)
Node(NodeBase *pParent, const NameType &pName, TArgs &&... args)
Node(const Node &)=delete
Node(const NodeKey &pKey, TArgs &&... args)
cmNode * followPath(SubstringType &path) const
TCursorBase(const TCursorBase &) noexcept=default
ATMP_IF_T_F(!TConst, StringTreeBase, const StringTreeBase) cmTree
TCursorBase(cmTree *pTree, cmNode *pNode) noexcept
TCursorBase(TCursorBase &&) noexcept=default
ATMP_IF_T_F(!TConst, NodeBase, const NodeBase) cmNode
std::pair< cmNode *, integer > followPathCreate(const NameType &path, TArgs &&... args)
typename decltype(nodeTable)::TSharedRecycler TSharedRecycler
typename TNodeMaintainer::CharacterType CharacterType
typename TNodeMaintainer::NameStringType NameStorageType
bool checkChildName(const NameType &name) const
StringTreeBase(MonoAllocator *allocator, TSharedRecycler &pRecycler, CharacterType pathSeparator)
StringTreeBase(MonoAllocator *allocator, CharacterType pathSeparator)
typename strings::TString< typename TNodeMaintainer::CharacterType > ValueType
typename strings::TSubstring< CharacterType > SubstringType
monomem::HashTable< Node, Node, NodeKey, void, typename NodeKey::Hash, typename NodeKey::EqualTo, typename NodeKey::Access, lang::Caching::Enabled, TRecycling > nodeTable
NameType key
The name to compare when just keys are used.
NodeNameUnion(const NodeNameUnion &n)
NodeNameUnion(const NameType &n)
NameStorageType storage
The name when stored in the hashtable.
NodeBase rootBase
Base version of the root node, which becomes initialized.
Node root
Full version of the root node, without initialization of member T.