8 #include "uniconfroot.h"
9 #include "uniconfgen.h"
17 : xroot(root), xfullkey(fullkey)
30 : xroot(other.xroot), xfullkey(other.xfullkey)
52 return xroot->mounts.exists(xfullkey);
58 return xroot->mounts.haschildren(xfullkey);
64 xroot->mounts.prefetch(xfullkey, recursive);
70 WvString value = xroot->mounts.get(xfullkey);
79 return xroot->mounts.str2int(
getme(), defvalue);
85 xroot->mounts.set(xfullkey, value);
110 for (i.rewind(); i.next(); )
112 UniConf dst2 = dst[i->fullkey(*
this)];
114 dst2.
setme(i->getme());
121 return xroot->mounts.refresh();
127 xroot->mounts.commit();
133 return xroot->mounts.mount(xfullkey, moniker,
refresh);
139 return xroot->mounts.mountgen(xfullkey, gen,
refresh);
145 return xroot->mounts.unmount(gen,
commit);
151 return xroot->mounts.ismountpoint(xfullkey);
157 return xroot->mounts.whichmount(xfullkey, mountpoint);
164 return gen && gen->
isok();
171 xroot->add_callback(cookie, xfullkey, callback, recurse);
177 xroot->del_callback(cookie, xfullkey, recurse);
183 xroot->add_setbool(xfullkey, flag, recurse);
189 xroot->del_setbool(xfullkey, flag, recurse);
195 xroot->mounts.hold_delta();
201 xroot->mounts.unhold_delta();
207 xroot->mounts.clear_delta();
213 xroot->mounts.flush_delta();
220 for (it.rewind(); it.next(); )
223 if (everything || !!value)
224 stream.print(
"%s = %s\n", it->fullkey(), value);
254 :
IterBase(_top), pathead(pattern.first()),
255 pattail(pattern.removefirst()), subit(NULL), it(NULL), recit(NULL)
273 UniConf::XIter::~XIter()
279 void UniConf::XIter::cleanup()
299 void UniConf::XIter::rewind()
304 if (pathead.isempty())
307 ready = current.exists();
317 ready = current.exists();
328 current = top[pathead];
329 if (pattail.isempty())
333 ready = current.exists();
344 inline bool UniConf::XIter::qnext()
348 bool found = subit->next();
367 void UniConf::XIter::enter(
const UniConf &child)
374 bool UniConf::XIter::next()
384 if (it && it->next())
394 if (recit && recit->next())
411 UniConf::SortedIterBase::SortedIterBase(
const UniConf &
root,
412 UniConf::SortedIterBase::Comparator comparator)
413 : IterBase(
root), xcomparator(comparator), xkeys()
418 UniConf::SortedIterBase::~SortedIterBase()
431 static UniConf::SortedIterBase::Comparator innercomparator = NULL;
435 return innercomparator(a, b) < 0;
439 void UniConf::SortedIterBase::_purge()
441 count = xkeys.size();
446 void UniConf::SortedIterBase::_rewind()
449 count = xkeys.size();
452 innercomparator = xcomparator;
453 std::sort(xkeys.begin(), xkeys.end(), wrapcomparator);
457 bool UniConf::SortedIterBase::next()
461 current = xkeys[index];
An implementation base class for key iterators.
bool refresh() const
Refreshes information about this key recursively.
UniConfKey removefirst(int n=1) const
Returns the path formed by removing the first n segments of this path.
void commit() const
Commits information about this key recursively.
UniConf()
Creates a NULL UniConf handle, useful for reporting errors.
This iterator walks over all children that match a wildcard pattern.
void setmeint(int value) const
Stores an integer value for this key into the registry.
int compareto(const UniConfKey &other) const
Compares two paths lexicographically.
void del_callback(void *cookie, bool recurse=true) const
Cancels notification requested using add_callback().
Iter(const UniConf &_top)
Creates an iterator over the direct children of a branch.
virtual ~UniConf()
Destroys the UniConf handle.
IUniConfGen * mountgen(IUniConfGen *gen, bool refresh=true) const
Mounts a generator at this key.
void add_callback(void *cookie, const UniConfCallback &callback, bool recurse=true) const
Requests notification when any of the keys covered by the recursive depth specification change by inv...
bool isok() const
Returns true if the generator at this key isok().
void remove() const
Removes this key and all of its children from the registry.
UniConf instances function as handles to subtrees of a UniConf tree and expose a high-level interface...
void prefetch(bool recursive) const
See UniConfGen::prefetch().
UniConfKey subkey(const UniConfKey &key) const
If this UniConfKey is a subkey of 'key', then return the subkey portion.
UniConf root() const
Returns a handle to the root of the tree.
WvString getme(WvStringParm defvalue=WvString::null) const
Fetches the string value for this key from the registry.
void dump(WvStream &stream, bool everything=false) const
Prints the entire contents of this subtree to a stream.
void unmount(IUniConfGen *gen, bool commit) const
Unmounts the generator providing this key and destroys it.
void flush_delta()
Flushes the list of pending notifications by sending them.
static int defcomparator(const UniConf &a, const UniConf &b)
Default comparator.
void add_setbool(bool *flag, bool recurse=true) const
Requests notification when any of the keys covered by the recursive depth specification change by set...
WvString is an implementation of a simple and efficient printable-string class.
An abstract data container that backs a UniConf tree.
UniConfRoot * rootobj() const
Returns a pointer to the UniConfRoot that manages this node.
bool isnull() const
returns true if this string is null
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
void del_setbool(bool *flag, bool recurse=true) const
Cancels notification requested using add_setbool().
void copy(const UniConf &dst, bool force) const
Equivalent to "cp -r" in a standard unix filesystem.
bool isempty() const
Returns true if this path has zero segments (also known as root).
UniConfKey first(int n=1) const
Returns the path formed by the n first segments of this path.
int getmeint(int defvalue=0) const
Fetches the integer value for this key from the registry.
void setme(WvStringParm value) const
Stores a string value for this key into the registry.
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
IUniConfGen * mount(WvStringParm moniker, bool refresh=true) const
Mounts a generator at this key using a moniker.
RecursiveIter(const UniConf &_top)
Creates a recursive iterator over a branch.
virtual bool isok()=0
Determines if the generator is usable and working properly.
UniConfKey fullkey() const
Returns the full path of this node, starting at the root.
An iterator that's always empty.
void hold_delta()
Pauses notifications until matched with a call to unhold_delta().
XIter(const UniConf &_top, const UniConfKey &pattern)
Creates a wildcard iterator.
bool haschildren() const
Returns true if this key has children.
bool iswild() const
Returns true if the key contains a wildcard.
Represents the root of a hierarhical registry consisting of pairs of UniConfKeys and associated strin...
bool ismountpoint() const
Determines if any generators are mounted at this key.
void move(const UniConf &dst) const
Equivalent to "mv" in a standard unix filesystem.
This iterator walks through all immediate children of a UniConf node.
bool exists() const
Without fetching its value, returns true if this key exists.
void clear_delta()
Clears the list of pending notifications without sending them.
void unhold_delta()
Resumes notifications when each hold_delta() has been matched.
This iterator performs depth-first traversal of a subtree.
void append(const UniConfKey &other)
Appends a path to this path.
static UniConfKey RECURSIVE_ANY
IUniConfGen * whichmount(UniConfKey *mountpoint=NULL) const
Finds the generator that owns this key.