Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

unihashtree.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  * 
00005  * UniConf low-level tree storage abstraction.
00006  */
00007 #ifndef __UNIHASHTREE_H
00008 #define __UNIHASHTREE_H
00009 
00010 #include "uniconfkey.h"
00011 #include "wvcallback.h"
00012 #include "wvscatterhash.h"
00013 
00014 class UniHashTreeBase;
00015 
00016 // parameters: 1st node (may be NULL), 2nd node (may be NULL), userdata
00017 typedef WvCallback<bool, const UniHashTreeBase *, 
00018         const UniHashTreeBase *, void *> UniHashTreeBaseComparator;
00019 
00020 class UniHashTreeBase
00021 {
00022 protected:
00023     UniConfKey xkey;   /*!< the name of this entry */
00024     UniHashTreeBase *xparent; /*!< the parent of this subtree */
00025 
00026     struct Accessor
00027     {
00028         static const UniConfKey *get_key(const UniHashTreeBase *obj)
00029             { return &obj->key(); }
00030     };
00031 
00032     typedef WvScatterHash<UniHashTreeBase, UniConfKey, Accessor> Container;
00033     typedef UniHashTreeBaseComparator BaseComparator;
00034     Container *xchildren; /*!< the hash table of children */
00035 
00036     UniHashTreeBase(UniHashTreeBase *parent, const UniConfKey &key);
00037 
00038 public:
00039     ~UniHashTreeBase();
00040 
00041 protected:
00042     void _setparent(UniHashTreeBase *parent);
00043     
00044     UniHashTreeBase *_root() const;
00045     UniConfKey _fullkey(const UniHashTreeBase *ancestor = NULL) const;
00046     UniHashTreeBase *_find(const UniConfKey &key) const;
00047     UniHashTreeBase *_findchild(const UniConfKey &key) const;
00048 
00049     static void _recursivecompare(
00050         const UniHashTreeBase *a, const UniHashTreeBase *b,
00051         const UniHashTreeBaseComparator &comparator, void *userdata);
00052 
00053 public:
00054     class Iter : public Container::Iter
00055     {
00056     public:
00057         Iter(UniHashTreeBase &b) : Container::Iter(*b.xchildren) { }
00058     };
00059     friend class Iter;
00060 
00061     /** Returns the key field. */
00062     const UniConfKey &key() const
00063         { return xkey; }
00064 
00065     /** Returns true if the node has children. */
00066     bool haschildren() const;
00067 
00068 private:
00069     /** Called by a child to link itself to this node. */
00070     void link(UniHashTreeBase *node);
00071 
00072     /** Called by a child to unlink itself from this node. */
00073     void unlink(UniHashTreeBase *node);
00074 };
00075 
00076 #endif //__UNIHASHTREE_H

Generated on Wed Dec 15 15:08:10 2004 for WvStreams by  doxygen 1.3.9.1