1 #include "unitransactiongen.h"
2 #include "uniconftree.h"
3 #include "unilistiter.h"
58 bool was_null_or_empty;
89 bool next() {
return i.next(); }
108 : root(_root), section(_section), base(_base),
109 doing_i1(
true), i1(*root), i2(base->
iterator(section))
134 if (i1->mode == NEWVALUE ||
135 i1->mode == NEWNODE ||
136 (i1->mode == NEWTREE && i1->newtree))
152 if (!node || node->mode == BLANK)
176 if (i1->mode == NEWVALUE)
178 else if (i1->mode == NEWTREE)
179 return i1->newtree->value();
203 : root(NULL), base(_base)
225 return base->
get(key);
226 else if (node->mode == NEWTREE)
236 return subnode->
value();
238 return WvString::null;
245 if (node->mode == NEWVALUE)
246 return node->newvalue;
248 return (node->mode == NEWNODE && !value) ? WvString::empty : value;
256 root = set_change(root, key, 0, value);
263 UniConfPairList::Iter i(pairs);
264 for (i.rewind(); i.next(); )
265 root = set_change(root, i->
key(), 0, i->value());
320 else if (node->mode == NEWTREE)
356 base->
set(section, newcontents->
value());
374 for (i.rewind(); i.next();)
381 if (node->mode == NEWTREE)
385 if (node->newtree == NULL)
386 base->
set(section, WvString::null);
392 else if (node->mode == NEWVALUE)
395 base->
set(section, node->newvalue);
397 else if (node->mode == NEWNODE)
400 if (!base->
exists(section))
403 base->
set(section, WvString::empty);
411 for (i.rewind(); i.next();)
434 if (!newcontents || newcontents->
value() != value)
435 delta(section, value);
440 for (i.rewind(); i.next();)
443 if (!base->
exists(subkey))
448 (
void*)&data,
false,
true);
469 if (node->mode == NEWTREE)
471 if (!base->
exists(section))
473 if (node->newtree != NULL)
476 node->newtree->
visit(
479 (
void *)&data,
false,
true);
488 if (node->mode != BLANK)
489 value = base->
get(section);
491 if (node->mode == NEWVALUE &&
493 value != node->newvalue)
494 delta(section, value);
497 for (i.rewind(); i.next();)
500 if (node->mode != BLANK && value.
isnull())
501 delta(section, WvString::null);
515 else if (node->mode == NEWTREE)
525 if (node->mode == NEWVALUE)
529 else if (node->mode == NEWNODE)
534 if (node->was_null_or_empty && !value)
536 node->was_null_or_empty = !value;
539 delta(key, WvString::empty);
596 delta(key, WvString::null);
617 parent->mode = BLANK;
621 parent->mode = NEWNODE;
624 parent->was_null_or_empty = !curr;
626 delta(nodekey, WvString::empty);
635 parent->mode = NEWTREE;
642 parent->mode = NEWVALUE;
644 if (base->
get(key) != value)
675 (
void *)&data,
false,
true);
679 return subnode == node ? NULL : node;
708 if (value != subnode->
value())
726 delta(key, WvString::null);
741 return create_change(NULL, key, seg, value);
742 else if (node->mode == NEWTREE)
744 node->newtree = set_value(node->newtree, key, seg, value);
751 if (subnode->mode == BLANK && !value.isnull())
755 subnode->mode = NEWNODE;
758 subnode->was_null_or_empty = !curr;
760 delta(nodekey, WvString::empty);
769 create_change(subnode, key, seg, value);
772 else if (next->mode == NEWTREE)
774 next->newtree = set_value(next->newtree,
785 if (subnode->mode != BLANK || base->
exists(key))
788 subnode->mode = NEWTREE;
789 subnode->newtree = 0;
791 else if (subnode->mode == NEWVALUE)
793 if (subnode->newvalue != value)
795 subnode->newvalue = value;
799 else if (subnode->mode == BLANK)
801 if (base->
get(key) != value)
803 subnode->mode = NEWVALUE;
804 subnode->newvalue =
WvString(value);
809 if ((!currval != !value) && (currval != value))
811 subnode->mode = NEWVALUE;
812 subnode->newvalue =
WvString(value);
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 WvString value() const =0
Returns the value of the current key.
void apply_values(UniConfValueTree *newcontents, const UniConfKey §ion)
A recursive helper function for apply_changes().
virtual WvString get(const UniConfKey &key)
Fetches a string value for a key from the registry.
virtual void flush_buffers()
Flushes any commitment/notification buffers .
virtual WvString get(const UniConfKey &key)=0
Fetches a string value for a key from the registry.
void cancel_changes(UniConfChangeTree *node, const UniConfKey §ion)
A recursive helper function for refresh().
An iterator that iterates through a constant list of keys.
~UniTransactionGen()
Destroys the UniTransactionGen and the underlying generator.
virtual UniConfKey key() const =0
Returns the current key.
virtual Iter * iterator(const UniConfKey &key)
Returns an iterator over the children of the specified key.
void apply_changes(UniConfChangeTree *node, const UniConfKey §ion)
A recursive helper function for commit().
void cancel_values(UniConfValueTree *newcontents, const UniConfKey §ion)
A recursive helper function for cancel_changes().
void unhold_delta()
Resumes notifications when each hold_delta() has been matched.
A recursively composed dictionary for tree-structured data indexed by UniConfKey.
void deletion_simulator(const UniConfKey &key)
A recursive helper function for create_change().
WvString is an implementation of a simple and efficient printable-string class.
bool next()
Seeks to the next element in the sequence.
void rewind()
Rewinds the iterator.
An abstract data container that backs a UniConf tree.
Sub * findchild(const UniConfKey &key) const
Finds the direct child node with the specified key.
const UniConfKey & key() const
Returns the key field.
const WvString & value() const
Returns the value field.
void visit(const Visitor &visitor, void *userdata, bool preorder=true, bool postorder=false) const
Performs a traversal on this tree using the specified visitor function and traversal type(s).
bool isnull() const
returns true if this string is null
UniConfValueTree * create_value(UniConfValueTree *parent, const UniConfKey &key, int seg, WvStringParm value)
Four functions to implement the functionality of set() so that it isn't two pages long.
WvString value() const
Returns the value of the current key.
void gencallback(const UniConfKey &key, WvStringParm value)
The callback function for the underlying generator.
virtual void set(const UniConfKey &key, WvStringParm value)
Stores a string value for a key into the registry.
void rewind()
Rewinds the iterator.
void deletion_visitor(const UniConfValueTree *node, void *userdata)
A UniConfTree visitor function for set_value(), cancel_values(), and cancel_changes().
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
void setvalue(WvStringParm value)
Sets the value field.
A type-safe version of WvMonikerBase that lets you provide create functions for object types other th...
A UniConfGen that represents pending transactions to another generator.
virtual bool refresh()
Refreshes information about a key recursively.
void delta(const UniConfKey &key, WvStringParm value)
Call this when a key's value or children have possibly changed.
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.
UniConfChangeTree * parent() const
Returns a pointer to the parent node, or NULL if there is none.
UniConfKey key() const
Returns the current key.
virtual void commit()
Commits any changes.
WvString value() const
Returns the value of the current key.
virtual void rewind()=0
Rewinds the iterator.
void zap()
Removes and deletes all children of this node.
virtual void del_callback(void *cookie)=0
Removes a callback for change notification.
UniConfKey fullkey(const Sub *ancestor=NULL) const
Returns full path of this node relative to an ancestor.
virtual bool isok()=0
Determines if the generator is usable and working properly.
UniTransactionGen(IUniConfGen *_base)
Constructs a UniTransactionGen for the given underlying generator, which must be non-null.
virtual Iter * iterator(const UniConfKey &key)=0
Returns an iterator over the children of the specified key.
virtual bool refresh()=0
Refreshes information about a key recursively.
void deletion_simulator2(const UniConfKey &key)
A recursive helper function for set_change().
UniConfKey key() const
Returns the current key.
A plain UniConfTree that holds keys and values.
bool hastrailingslash() const
Returns true if the key has a trailing slash.
virtual bool next()=0
Seeks to the next element in the sequence.
UniConfKey segment(int n) const
Returns the specified segment of the path.
An iterator that's always empty.
bool next()
Seeks to the next element in the sequence.
virtual void add_callback(void *cookie, const UniConfGenCallback &callback)=0
Adds a callback for change notification.
Sub * find(const UniConfKey &key) const
Finds the sub-node with the specified key.
UniConfKey last(int n=1) const
Returns the path formed by the n last segments of this path.
void autofill(IUniConfGen::Iter *source)
Automatically fill the contents of this iterator by calling add() for each element of the 'source' it...
int numsegments() const
Returns the number of segments in this path.
void hold_delta()
Pauses notifications until matched with a call to unhold_delta().
virtual bool isok()
Determines if the generator is usable and working properly.
virtual void setv(const UniConfPairList &pairs)
Stores multiple key-value pairs into the registry.
An abstract iterator over keys and values in a generator.