2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 * UniConf low-level tree storage abstraction.
7 #ifndef __UNIHASHTREE_H
8 #define __UNIHASHTREE_H
10 #include "uniconfkey.h"
12 #include "wvscatterhash.h"
14 class UniHashTreeBase
;
16 // parameters: a node (won't be NULL), userdata
17 typedef wv::function
<void(const UniHashTreeBase
*,
18 void*)> UniHashTreeBaseVisitor
;
19 // parameters: 1st node (may be NULL), 2nd node (may be NULL), userdata
20 typedef wv::function
<bool(const UniHashTreeBase
*,
21 const UniHashTreeBase
*)> UniHashTreeBaseComparator
;
28 static const UniConfKey
*get_key(const UniHashTreeBase
*obj
)
29 { return &obj
->key(); }
32 typedef WvScatterHash
<UniHashTreeBase
, UniConfKey
, Accessor
> Container
;
33 typedef UniHashTreeBaseVisitor BaseVisitor
;
34 typedef UniHashTreeBaseComparator BaseComparator
;
39 /** Returns the key field. */
40 const UniConfKey
&key() const
43 /** Returns true if the node has children. */
44 bool haschildren() const;
47 UniHashTreeBase(UniHashTreeBase
*parent
, const UniConfKey
&key
);
49 UniConfKey
_fullkey(const UniHashTreeBase
*ancestor
= NULL
) const;
50 UniHashTreeBase
*_find(const UniConfKey
&key
) const;
51 UniHashTreeBase
*_findchild(const UniConfKey
&key
) const;
53 static bool _recursivecompare(
54 const UniHashTreeBase
*a
, const UniHashTreeBase
*b
,
55 const UniHashTreeBaseComparator
&comparator
);
57 static void _recursive_unsorted_visit(
58 const UniHashTreeBase
*a
,
59 const UniHashTreeBaseVisitor
&visitor
, void *userdata
,
60 bool preorder
, bool postorder
);
62 UniHashTreeBase
*xparent
; /*!< the parent of this subtree */
63 Container
*xchildren
; /*!< the hash table of children */
66 void _setparent(UniHashTreeBase
*parent
);
67 UniHashTreeBase
*_root() const;
69 /** Called by a child to link itself to this node. */
70 void link(UniHashTreeBase
*node
);
72 /** Called by a child to unlink itself from this node. */
73 void unlink(UniHashTreeBase
*node
);
75 UniConfKey xkey
; /*!< the name of this entry */
78 class Iter
: public Container::Iter
81 Iter(UniHashTreeBase
&b
) : Container::Iter(*b
.xchildren
) { }
86 #endif //__UNIHASHTREE_H