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 abstract data container that backs a UniConf tree.
virtual bool isok()=0
Determines if the generator is usable and working properly.
An iterator that's always empty.
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
UniConfKey subkey(const UniConfKey &key) const
If this UniConfKey is a subkey of 'key', then return the subkey portion.
UniConfKey removefirst(int n=1) const
Returns the path formed by removing the first n segments of this path.
int compareto(const UniConfKey &other) const
Compares two paths lexicographically.
bool iswild() const
Returns true if the key contains a wildcard.
static UniConfKey RECURSIVE_ANY
void append(const UniConfKey &other)
Appends a path to this path.
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.
Represents the root of a hierarhical registry consisting of pairs of UniConfKeys and associated strin...
An implementation base class for key iterators.
This iterator walks through all immediate children of a UniConf node.
Iter(const UniConf &_top)
Creates an iterator over the direct children of a branch.
This iterator performs depth-first traversal of a subtree.
RecursiveIter(const UniConf &_top)
Creates a recursive iterator over a branch.
static int defcomparator(const UniConf &a, const UniConf &b)
Default comparator.
This iterator walks over all children that match a wildcard pattern.
XIter(const UniConf &_top, const UniConfKey &pattern)
Creates a wildcard iterator.
UniConf instances function as handles to subtrees of a UniConf tree and expose a high-level interface...
void commit() const
Commits information about this key recursively.
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...
void remove() const
Removes this key and all of its children from the registry.
void prefetch(bool recursive) const
See UniConfGen::prefetch().
UniConf root() const
Returns a handle to the root of the tree.
void clear_delta()
Clears the list of pending notifications without sending them.
void move(const UniConf &dst) const
Equivalent to "mv" in a standard unix filesystem.
int getmeint(int defvalue=0) const
Fetches the integer value for this key from the registry.
bool haschildren() const
Returns true if this key has children.
void setme(WvStringParm value) const
Stores a string value for this key into the registry.
bool exists() const
Without fetching its value, returns true if this key exists.
void unmount(IUniConfGen *gen, bool commit) const
Unmounts the generator providing this key and destroys it.
UniConf()
Creates a NULL UniConf handle, useful for reporting errors.
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...
void del_setbool(bool *flag, bool recurse=true) const
Cancels notification requested using add_setbool().
bool refresh() const
Refreshes information about this key recursively.
UniConfRoot * rootobj() const
Returns a pointer to the UniConfRoot that manages this node.
IUniConfGen * mount(WvStringParm moniker, bool refresh=true) const
Mounts a generator at this key using a moniker.
IUniConfGen * whichmount(UniConfKey *mountpoint=NULL) const
Finds the generator that owns this key.
UniConfKey fullkey() const
Returns the full path of this node, starting at the root.
void flush_delta()
Flushes the list of pending notifications by sending them.
void del_callback(void *cookie, bool recurse=true) const
Cancels notification requested using add_callback().
void copy(const UniConf &dst, bool force) const
Equivalent to "cp -r" in a standard unix filesystem.
bool isok() const
Returns true if the generator at this key isok().
void dump(WvStream &stream, bool everything=false) const
Prints the entire contents of this subtree to a stream.
void unhold_delta()
Resumes notifications when each hold_delta() has been matched.
void setmeint(int value) const
Stores an integer value for this key into the registry.
virtual ~UniConf()
Destroys the UniConf handle.
void hold_delta()
Pauses notifications until matched with a call to unhold_delta().
bool ismountpoint() const
Determines if any generators are mounted at this key.
WvString getme(WvStringParm defvalue=WvString::null) const
Fetches the string value for this key from the registry.
IUniConfGen * mountgen(IUniConfGen *gen, bool refresh=true) const
Mounts a generator at this key.
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
bool isnull() const
returns true if this string is null
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
WvString is an implementation of a simple and efficient printable-string class.