/usr/include/wvstreams/uniconftree.h is in libwvstreams-dev 4.6.1-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | /* -*- Mode: C++ -*-
* Worldvisions Weaver Software:
* Copyright (C) 1997-2002 Net Integration Technologies, Inc.
*
* UniConf low-level tree storage abstraction.
*/
#ifndef __UNICONFTREE_H
#define __UNICONFTREE_H
#include "uniconfkey.h"
#include "unihashtree.h"
#include "wvtr1.h"
/**
* A recursively composed dictionary for tree-structured
* data indexed by UniConfKey.
*
* Someday this could be further abstracted into a generic WvTreeDict.
*
* "Sub" is the name of the concrete subclass of UniConfTree.
*/
template<class Sub>
class UniConfTree : public UniHashTreeBase
{
public:
typedef wv::function<void(const Sub*, void*)> Visitor;
typedef wv::function<bool(const Sub*, const Sub*)> Comparator;
/** Creates a node and links it to a subtree, if parent is non-NULL */
UniConfTree(Sub *parent, const UniConfKey &key) :
UniHashTreeBase(parent, key)
{ }
/** Destroy this node's contents and children. */
~UniConfTree()
{ zap(); }
/** Returns a pointer to the parent node, or NULL if there is none. */
Sub *parent() const
{ return static_cast<Sub*>(this->xparent); }
/** Reparents this node. */
void setparent(Sub *parent)
{ UniHashTreeBase::_setparent(parent); }
/** Returns a pointer to the root node of the tree. */
Sub *root() const
{ return static_cast<Sub*>(UniHashTreeBase::_root()); }
/**
* Returns full path of this node relative to an ancestor.
* If ancestor is NULL, returns the root.
*/
UniConfKey fullkey(const Sub *ancestor = NULL) const
{ return UniHashTreeBase::_fullkey(ancestor); }
/**
* Finds the sub-node with the specified key.
* If key.isempty(), returns this node.
*/
Sub *find(const UniConfKey &key) const
{ return static_cast<Sub*>(UniHashTreeBase::_find(key)); }
/**
* Finds the direct child node with the specified key.
*
* If key.numsegments() == 1, then performs the same task
* as find(key), but a little faster. Otherwise returns NULL.
*/
Sub *findchild(const UniConfKey &key) const
{ return static_cast<Sub*>(UniHashTreeBase::_findchild(key)); }
/**
* Removes the node for the specified key from the tree
* and deletes it along with any of its children.
*
* If the key is UniConfKey::EMPTY, deletes this object.
*/
void remove(const UniConfKey &key)
{ delete find(key); }
/** Removes and deletes all children of this node. */
void zap()
{
if (!(this->xchildren))
return;
// set xchildren to NULL first so that the zap() will happen faster
// otherwise, each child will attempt to unlink itself uselessly
typename UniHashTreeBase::Container *oldchildren = this->xchildren;
this->xchildren = NULL;
// delete all children
typename UniHashTreeBase::Container::Iter i(*oldchildren);
for (i.rewind(); i.next();)
delete static_cast<Sub*>(i.ptr());
delete oldchildren;
}
/**
* Performs a traversal on this tree using the specified
* visitor function and traversal type(s).
* "visitor" is the tree visitor function
* "userdata" is userdata for the tree visitor function
*/
void visit(const Visitor &visitor, void *userdata,
bool preorder = true, bool postorder = false) const
{
_recursive_unsorted_visit(this, reinterpret_cast<
const typename UniHashTreeBase::BaseVisitor&>(visitor), userdata,
preorder, postorder);
}
/**
* Compares this tree with another using the specified comparator
* function.
* Comparison of a subtree ends when the comparator returns false.
* "comparator" is the value compare function
* "userdata" is userdata for the compare function
* Returns: true if the comparison function returned true each time
*/
bool compare(const Sub *other, const Comparator &comparator)
{
return _recursivecompare(this, other, reinterpret_cast<
const typename UniHashTreeBase::BaseComparator&>(comparator));
}
/**
* An iterator that walks over all elements on one level of a
* UniConfTree.
*/
class Iter : public UniHashTreeBase::Iter
{
public:
typedef typename UniHashTreeBase::Iter MyBase;
/** Creates an iterator over the specified tree. */
Iter(Sub &tree) : UniHashTreeBase::Iter(tree)
{ }
/** Returns a pointer to the current node. */
Sub *ptr() const
{ return static_cast<Sub*>(MyBase::ptr()); }
WvIterStuff(Sub);
};
};
/** A plain UniConfTree that holds keys and values. */
class UniConfValueTree : public UniConfTree<UniConfValueTree>
{
WvString xvalue; /*!< the value of this entry */
public:
UniConfValueTree(UniConfValueTree *parent,
const UniConfKey &key, WvStringParm value)
: UniConfTree<UniConfValueTree>(parent, key), xvalue(value)
{ }
/** Returns the value field. */
const WvString &value() const
{ return xvalue; }
/** Sets the value field. */
void setvalue(WvStringParm value)
{ xvalue = value; }
};
#endif // __UNICONFTREE_H
|