WvStreams
uniwvconfgen.cc
1 /*
2  * Worldvisions Weaver Software:
3  * Copyright (C) 2002 Net Integration Technologies, Inc.
4  *
5  * A generator to make a UniConf object out of a WvConf.
6  */
7 #include "wvconf.h"
8 #include "uniwvconfgen.h"
9 #include "wvmoniker.h"
10 
15 {
16 protected:
17  WvConfigSection::Iter i;
18 
19 public:
21 
22  /***** Overridden members *****/
23 
24  virtual void rewind();
25  virtual bool next();
26  virtual UniConfKey key() const;
27  virtual WvString value() const;
28 };
29 
30 
31 static IUniConfGen *creator(WvStringParm s, IObject*)
32 {
33  return new UniWvConfGen(new WvConf(s));
34 }
35 
36 static WvMoniker<IUniConfGen> reg("wvconf", creator);
37 
38 
39 void UniWvConfGen::notify(void *userdata, WvStringParm section,
40  WvStringParm entry, WvStringParm oldval,
41  WvStringParm newval)
42 {
43  UniConfKey key(section, entry);
44 
45  tempvalue = newval;
46  tempkey = &key;
47  delta(key, newval);
48  tempkey = NULL;
49 }
50 
51 
52 UniWvConfGen::UniWvConfGen(WvConf *_cfg):
53  tempkey(NULL), tempvalue(), cfg(_cfg)
54 {
55  cfg->add_callback(wv::bind(&UniWvConfGen::notify, this, _1, _2, _3, _4, _5),
56  NULL, "", "", this);
57 }
58 
59 
60 UniWvConfGen::~UniWvConfGen()
61 {
62  if (cfg)
63  delete cfg;
64 }
65 
66 
68 {
69  if (tempkey && key == *tempkey)
70  return tempvalue;
71  else
72  return cfg->get(key.first(), key.last(key.numsegments() - 1));
73 }
74 
75 
76 void UniWvConfGen::set(const UniConfKey &key, WvStringParm value)
77 {
78  WvString section = key.first();
79  WvString keyname = key.last(key.numsegments() - 1);
80 
81  WvConfigSection *sect = (*cfg)[section];
82  if (value == WvString::null && sect)
83  cfg->delete_section(key);
84  else
85  cfg->set(section, keyname, value);
86 }
87 
88 
89 void UniWvConfGen::setv(const UniConfPairList &pairs)
90 {
91  setv_naive(pairs);
92 }
93 
94 
96 {
97  WvConfigSection *sect = (*cfg)[key];
98  if (sect)
99  return true;
100  return false;
101 }
102 
103 
105 {
106  WvConfigSection *sect = (*cfg)[key];
107 
108  if (sect)
109  return new WvConfIter(sect);
110  else
111  return NULL;
112 }
113 
114 
115 
116 /***** UniWvConfGen::WvConfIter *****/
117 
118 UniWvConfGen::WvConfIter::WvConfIter(WvConfigSection *sect)
119  : i(*sect)
120 {
121 }
122 
123 
125 {
126  i.rewind();
127 }
128 
129 
131 {
132  return i.next();
133 }
134 
135 
137 {
138  return i->name;
139 }
140 
141 
143 {
144  return i->value;
145 }
The basic interface which is included by all other XPLC interfaces and objects.
Definition: IObject.h:65
An abstract data container that backs a UniConf tree.
Definition: uniconfgen.h:40
An abstract iterator over keys and values in a generator.
Definition: uniconfgen.h:324
void delta(const UniConfKey &key, WvStringParm value)
Call this when a key's value or children have possibly changed.
Definition: uniconfgen.cc:77
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
Definition: uniconfkey.h:39
int numsegments() const
Returns the number of segments in this path.
Definition: uniconfkey.h:287
UniConfKey first(int n=1) const
Returns the path formed by the n first segments of this path.
Definition: uniconfkey.h:314
UniConfKey last(int n=1) const
Returns the path formed by the n last segments of this path.
Definition: uniconfkey.h:324
A wrapper class for the wvconf iters to provide a UniConfGen iter.
Definition: uniwvconfgen.cc:15
virtual UniConfKey key() const
Returns the current key.
virtual bool next()
Seeks to the next element in the sequence.
virtual void rewind()
Rewinds the iterator.
virtual WvString value() const
Returns the value of the current key.
A UniConf generator for backwards compatibility with WvConf.
Definition: uniwvconfgen.h:18
virtual bool haschildren(const UniConfKey &key)
Returns true if a key has children.
Definition: uniwvconfgen.cc:95
virtual WvString get(const UniConfKey &key)
Fetches a string value for a key from the registry.
Definition: uniwvconfgen.cc:67
virtual void setv(const UniConfPairList &pairs)
Stores multiple key-value pairs into the registry.
Definition: uniwvconfgen.cc:89
virtual void set(const UniConfKey &key, WvStringParm value)
Stores a string value for a key into the registry.
Definition: uniwvconfgen.cc:76
virtual Iter * iterator(const UniConfKey &key)
Returns an iterator over the children of the specified key.
WvConf configuration file management class: used to read/write config files that are formatted in the...
Definition: wvconf.h:105
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
Definition: wvstring.h:94
A type-safe version of WvMonikerBase that lets you provide create functions for object types other th...
Definition: wvmoniker.h:62
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:330