Make WvStreams compile with gcc 4.4.
[wvstreams.git] / include / unihashtree.h
blob470890b12d8a44a425e4cc7816e703f8c73cc86c
1 /* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4 *
5 * UniConf low-level tree storage abstraction.
6 */
7 #ifndef __UNIHASHTREE_H
8 #define __UNIHASHTREE_H
10 #include "uniconfkey.h"
11 #include "wvtr1.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;
23 class UniHashTreeBase
25 protected:
26 struct Accessor
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;
36 public:
37 ~UniHashTreeBase();
39 /** Returns the key field. */
40 const UniConfKey &key() const
41 { return xkey; }
43 /** Returns true if the node has children. */
44 bool haschildren() const;
46 protected:
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 */
65 private:
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 */
77 protected:
78 class Iter : public Container::Iter
80 public:
81 Iter(UniHashTreeBase &b) : Container::Iter(*b.xchildren) { }
83 friend class Iter;
86 #endif //__UNIHASHTREE_H