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