7 #include "unimountgen.h"
11 #include "unilistiter.h"
12 #include "wvstringtable.h"
36 if (has_subkey(key, NULL))
39 return WvString::null;
42 return found->gen->get(trimkey(found->key, key));
51 found->gen->set(trimkey(found->key, key), value);
59 UniConfPairList pairs;
72 UniGenMountPairsDict mountpairs(mounts.count());
75 MountList::Iter m(mounts);
76 for (m.rewind(); m.next(); )
81 UniConfPairList::Iter pair(pairs);
82 for (pair.rewind(); pair.next(); )
90 mountpairs[found->key]->pairs.add(trimmed,
true);
94 UniGenMountPairsDict::Iter i(mountpairs);
95 for (i.rewind(); i.next(); )
96 i->mount->gen->setv(i->pairs);
104 if (found && found->gen->exists(trimkey(found->key, key)))
109 return has_subkey(key, found);
117 if (found && found->gen->haschildren(trimkey(found->key, key)))
123 return has_subkey(key, found);
127 bool UniMountGen::has_subkey(
const UniConfKey &key, UniGenMount *found)
129 MountList::Iter i(mounts);
130 for (i.rewind(); i.next(); )
132 if (key.
suborsame(i->key) && key < i->key)
141 if (found && (i->gen == found->gen))
155 MountList::Iter i(mounts);
156 for (i.rewind(); i.next(); )
157 result = result && i->gen->refresh();
168 MountList::Iter i(mounts);
169 for (i.rewind(); i.next();)
177 WvStringParm moniker,
bool refresh)
183 assert(gen &&
"Moniker doesn't get us a generator!");
185 if (gen && !gen->
exists(
"/"))
198 gen->
add_callback(
this, wv::bind(&UniMountGen::gencallback,
this,
199 newgen->key, _1, _2));
209 mounts.prepend(newgen,
true);
224 MountList::Iter i(mounts);
226 for (i.rewind(); i.next() && i->gen != gen; )
251 for (i.rewind(); i.next() && i->gen != next; )
253 if (key.
suborsame(i->key) && key != i->key)
264 void UniMountGen::zap()
266 while (!mounts.isempty())
267 unmount(mounts.first()->gen,
false);
274 MountList::Iter i(mounts);
276 for (i.rewind(); i.next(); )
278 if (i->key.suborsame(key))
281 *mountpoint = i->key;
292 MountList::Iter i(mounts);
294 for (i.rewind(); i.next(); )
305 return strcmp(*l, *r);
312 return found->gen->iterator(trimkey(found->key, key));
320 MountList::Iter i(mounts);
322 for (i.rewind(); i.next(); )
336 WvStringTable::Sorter s(t, &::wvstrcmp);
337 for (s.rewind(); s.next();)
352 return found->gen->recursiveiterator(trimkey(found->key, key));
361 MountList::Iter i(mounts);
362 for (i.rewind(); i.next(); )
364 if (i->key.suborsame(key))
375 int num_found_mounts = 0;
378 MountList::Iter i(mounts);
379 for (i.rewind(); i.next(); )
382 if (i->key.suborsame(key) && !foundmount)
384 foundmount = i.ptr();
394 if (num_found_mounts == 1 && foundmount)
408 void UniMountGen::makemount(
const UniConfKey &key)
415 for (i.rewind(); i.next(); )
418 if (
get(points).isnull())
425 UniGenMount *found = findmount(points.
removelast());
429 if (found->gen->get(trimkey(found->key, key)).isnull())
430 found->gen->set(trimkey(found->key, key),
"");
virtual ~UniMountGen()
Destroys the UniConf tree along with all uncommitted data.
virtual bool ismountpoint(const UniConfKey &key)
Determines if a key is a mountpoint.
virtual void set(const UniConfKey &key, WvStringParm value)=0
Stores a string value for a key into the registry.
virtual bool exists(const UniConfKey &key)=0
Without fetching its value, returns true if a key exists.
virtual IUniConfGen * mount(const UniConfKey &key, WvStringParm moniker, bool refresh)
Mounts a generator at a key using a moniker.
virtual WvString get(const UniConfKey &key)
Fetches a string value for a key from the registry.
virtual bool refresh()
Refreshes information about a key recursively.
UniConfKey removelast(int n=1) const
Returns the path formed by removing the last n segments of this path.
UniMountGen()
Creates an empty UniConf tree with no mounted stores.
An iterator that iterates through a constant list of keys.
void add(const UniConfKey &k, WvStringParm v=WvString::null)
Add a key/value pair to the list that gets returned by this iterator.
virtual Iter * recursiveiterator(const UniConfKey &key)
Like iterator(), but the returned iterator is recursive, that is, it will return children of the imme...
::UniListIter ListIter
An iterator over a constant list of keys (see below)
virtual void setv(const UniConfPairList &pairs)
Stores multiple key-value pairs into the registry.
virtual IUniConfGen * whichmount(const UniConfKey &key, UniConfKey *mountpoint)
Finds the generator that owns a key.
virtual bool haschildren(const UniConfKey &key)
Returns true if a key has children.
void unhold_delta()
Resumes notifications when each hold_delta() has been matched.
WvString is an implementation of a simple and efficient printable-string class.
An abstract data container that backs a UniConf tree.
An iterator over the segments of a key.
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
virtual void commit()
Commits any changes.
bool suborsame(const UniConfKey &key) const
Returns true if 'key' is a the same, or a subkey, of this UniConfKey.
virtual void unmount(IUniConfGen *gen, bool commit)
Unmounts the generator at a key and releases it.
void delta(const UniConfKey &key, WvStringParm value)
Call this when a key's value or children have possibly changed.
virtual IUniConfGen * mountgen(const UniConfKey &key, IUniConfGen *gen, bool refresh)
Mounts a generator at a key.
virtual void commit()=0
Commits any changes.
UniConfKey first(int n=1) const
Returns the path formed by the n first segments of this path.
virtual Iter * recursiveiterator(const UniConfKey &key)
Like iterator(), but the returned iterator is recursive, that is, it will return children of the imme...
virtual void set(const UniConfKey &key, WvStringParm value)
Stores a string value for a key into the registry.
virtual bool exists(const UniConfKey &key)
Without fetching its value, returns true if a key exists.
virtual void del_callback(void *cookie)=0
Removes a callback for change notification.
virtual bool refresh()=0
Refreshes information about a key recursively.
virtual void add_callback(void *cookie, const UniConfGenCallback &callback)=0
Adds a callback for change notification.
virtual Iter * iterator(const UniConfKey &key)
Returns an iterator over the children of the specified key.
UniConfKey last(int n=1) const
Returns the path formed by the n last segments of this path.
int numsegments() const
Returns the number of segments in this path.
Represents a simple key-value pair.
void hold_delta()
Pauses notifications until matched with a call to unhold_delta().
void append(const UniConfKey &other)
Appends a path to this path.
An abstract iterator over keys and values in a generator.