WvStreams
|
00001 /* 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 2002 Net Integration Technologies, Inc. 00004 * 00005 * A generator to make a UniConf object out of a WvConf. 00006 */ 00007 #include "wvconf.h" 00008 #include "uniwvconfgen.h" 00009 #include "wvmoniker.h" 00010 00014 class UniWvConfGen::WvConfIter : public UniConfGen::Iter 00015 { 00016 protected: 00017 WvConfigSection::Iter i; 00018 00019 public: 00020 WvConfIter(WvConfigSection *sect); 00021 00022 /***** Overridden members *****/ 00023 00024 virtual void rewind(); 00025 virtual bool next(); 00026 virtual UniConfKey key() const; 00027 virtual WvString value() const; 00028 }; 00029 00030 00031 static IUniConfGen *creator(WvStringParm s, IObject*) 00032 { 00033 return new UniWvConfGen(new WvConf(s)); 00034 } 00035 00036 static WvMoniker<IUniConfGen> reg("wvconf", creator); 00037 00038 00039 void UniWvConfGen::notify(void *userdata, WvStringParm section, 00040 WvStringParm entry, WvStringParm oldval, 00041 WvStringParm newval) 00042 { 00043 UniConfKey key(section, entry); 00044 00045 tempvalue = newval; 00046 tempkey = &key; 00047 delta(key, newval); 00048 tempkey = NULL; 00049 } 00050 00051 00052 UniWvConfGen::UniWvConfGen(WvConf *_cfg): 00053 tempkey(NULL), tempvalue(), cfg(_cfg) 00054 { 00055 cfg->add_callback(wv::bind(&UniWvConfGen::notify, this, _1, _2, _3, _4, _5), 00056 NULL, "", "", this); 00057 } 00058 00059 00060 UniWvConfGen::~UniWvConfGen() 00061 { 00062 if (cfg) 00063 delete cfg; 00064 } 00065 00066 00067 WvString UniWvConfGen::get(const UniConfKey &key) 00068 { 00069 if (tempkey && key == *tempkey) 00070 return tempvalue; 00071 else 00072 return cfg->get(key.first(), key.last(key.numsegments() - 1)); 00073 } 00074 00075 00076 void UniWvConfGen::set(const UniConfKey &key, WvStringParm value) 00077 { 00078 WvString section = key.first(); 00079 WvString keyname = key.last(key.numsegments() - 1); 00080 00081 WvConfigSection *sect = (*cfg)[section]; 00082 if (value == WvString::null && sect) 00083 cfg->delete_section(key); 00084 else 00085 cfg->set(section, keyname, value); 00086 } 00087 00088 00089 void UniWvConfGen::setv(const UniConfPairList &pairs) 00090 { 00091 setv_naive(pairs); 00092 } 00093 00094 00095 bool UniWvConfGen::haschildren(const UniConfKey &key) 00096 { 00097 WvConfigSection *sect = (*cfg)[key]; 00098 if (sect) 00099 return true; 00100 return false; 00101 } 00102 00103 00104 UniWvConfGen::Iter *UniWvConfGen::iterator(const UniConfKey &key) 00105 { 00106 WvConfigSection *sect = (*cfg)[key]; 00107 00108 if (sect) 00109 return new WvConfIter(sect); 00110 else 00111 return NULL; 00112 } 00113 00114 00115 00116 /***** UniWvConfGen::WvConfIter *****/ 00117 00118 UniWvConfGen::WvConfIter::WvConfIter(WvConfigSection *sect) 00119 : i(*sect) 00120 { 00121 } 00122 00123 00124 void UniWvConfGen::WvConfIter::rewind() 00125 { 00126 i.rewind(); 00127 } 00128 00129 00130 bool UniWvConfGen::WvConfIter::next() 00131 { 00132 return i.next(); 00133 } 00134 00135 00136 UniConfKey UniWvConfGen::WvConfIter::key() const 00137 { 00138 return i->name; 00139 } 00140 00141 00142 WvString UniWvConfGen::WvConfIter::value() const 00143 { 00144 return i->value; 00145 }