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{
16protected:
17 WvConfigSection::Iter i;
18
19public:
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
31static IUniConfGen *creator(WvStringParm s, IObject*)
32{
33 return new UniWvConfGen(new WvConf(s));
34}
35
36static WvMoniker<IUniConfGen> reg("wvconf", creator);
37
38
39void 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
52UniWvConfGen::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
60UniWvConfGen::~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
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
89void 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
118UniWvConfGen::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.
An abstract data container that backs a UniConf tree.
An abstract iterator over keys and values in a generator.
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...
int numsegments() const
Returns the number of segments in this path.
UniConfKey first(int n=1) const
Returns the path formed by the n first segments of this path.
UniConfKey last(int n=1) const
Returns the path formed by the n last segments of this path.
A wrapper class for the wvconf iters to provide a UniConfGen iter.
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.
virtual bool haschildren(const UniConfKey &key)
Returns true if a key has children.
virtual WvString get(const UniConfKey &key)
Fetches a string value for a key from the registry.
virtual void setv(const UniConfPairList &pairs)
Stores multiple key-value pairs into the registry.
virtual void set(const UniConfKey &key, WvStringParm value)
Stores a string value for a key into the registry.
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...
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
A type-safe version of WvMonikerBase that lets you provide create functions for object types other th...
WvString is an implementation of a simple and efficient printable-string class.