00001
00002
00003
00004
00005
00006
00007
#include "wvconf.h"
00008
#include "uniwvconfgen.h"
00009
#include "wvmoniker.h"
00010
00011
00012 static UniConfGen *
creator(
WvStringParm s,
IObject *,
void *obj)
00013 {
00014
if (!obj)
00015 obj =
new WvConf(s);
00016
00017
00018
return new UniWvConfGen(*(
WvConf *)obj);
00019 }
00020
00021
static WvMoniker<UniConfGen> reg(
"wvconf", creator);
00022
00023
00024
void UniWvConfGen::notify(
void *userdata,
WvStringParm section,
00025
WvStringParm entry,
WvStringParm oldval,
00026
WvStringParm newval)
00027 {
00028
UniConfKey key(section, entry);
00029
00030 tempvalue = newval;
00031 tempkey = &key;
00032 delta(key, newval);
00033 tempkey = NULL;
00034 }
00035
00036
00037 UniWvConfGen::UniWvConfGen(
WvConf &_cfg):
00038 tempkey(NULL), tempvalue(), cfg(_cfg)
00039 {
00040
cfg.
add_callback(
WvConfCallback(
this, &UniWvConfGen::notify), NULL,
00041
"",
"",
this);
00042 }
00043
00044
00045 WvString UniWvConfGen::get(
const UniConfKey &key)
00046 {
00047
if (tempkey && key == *tempkey)
00048
return tempvalue;
00049
else
00050
return cfg.
get(key.first(), key.last(key.numsegments() - 1));
00051 }
00052
00053
00054 void UniWvConfGen::set(
const UniConfKey &key,
WvStringParm value)
00055 {
00056
WvString section = key.
first();
00057
WvString keyname = key.
last(key.
numsegments() - 1);
00058
00059
WvConfigSection *sect =
cfg[section];
00060
if (value == WvString::null && sect)
00061 cfg.delete_section(key);
00062
else
00063 cfg.
set(section, keyname, value);
00064 }
00065
00066
00067 bool UniWvConfGen::haschildren(
const UniConfKey &key)
00068 {
00069
WvConfigSection *sect =
cfg[key];
00070
if (sect)
00071
return true;
00072
return false;
00073 }
00074
00075
00076 UniWvConfGen::Iter *
UniWvConfGen::iterator(
const UniConfKey &key)
00077 {
00078
WvConfigSection *sect =
cfg[key];
00079
00080
if (sect)
00081
return new WvConfIter(sect);
00082
else
00083
return new UniConfGen::NullIter();
00084 }
00085
00086
00087
00088
00089
00090 UniWvConfGen::WvConfIter::WvConfIter(
WvConfigSection *sect)
00091 : i(*sect)
00092 {
00093 }
00094
00095
00096 void UniWvConfGen::WvConfIter::rewind()
00097 {
00098
i.rewind();
00099 }
00100
00101
00102 bool UniWvConfGen::WvConfIter::next()
00103 {
00104
return i.next();
00105 }
00106
00107
00108 UniConfKey UniWvConfGen::WvConfIter::key()
const
00109
{
00110
return i->name;
00111 }