00001
00002
00003
00004
00005
00006
00007 #include <wvassert.h>
00008
00009 #include "unifastregetgen.h"
00010 #include "uniconftree.h"
00011 #include "wvmoniker.h"
00012
00013
00014
00015 static IUniConfGen *creator(WvStringParm s)
00016 {
00017 return new UniFastRegetGen(wvcreate<IUniConfGen>(s));
00018 }
00019
00020 static WvMoniker<IUniConfGen> reg("fast-reget", creator);
00021
00022
00023 UniFastRegetGen::UniFastRegetGen(IUniConfGen *_inner)
00024 : UniFilterGen(_inner)
00025 {
00026 tree = new UniConfValueTree(NULL, "/", UniFilterGen::get("/"));
00027 }
00028
00029
00030 UniFastRegetGen::~UniFastRegetGen()
00031 {
00032 if (tree)
00033 {
00034 delete tree;
00035 tree = NULL;
00036 }
00037 }
00038
00039
00040 void UniFastRegetGen::gencallback(const UniConfKey &key, WvStringParm value)
00041 {
00042 if (!tree)
00043 return;
00044
00045 UniConfValueTree *t = tree->find(key);
00046 if (t)
00047 t->setvalue(value);
00048 UniFilterGen::gencallback(key, value);
00049 }
00050
00051
00052 WvString UniFastRegetGen::get(const UniConfKey &key)
00053 {
00054 if (!tree)
00055 {
00056 wvassert(tree, "key: '%s'", key);
00057 abort();
00058 }
00059
00060 UniConfValueTree *t = tree->find(key);
00061 if (!t)
00062 {
00063 get(key.removelast());
00064 t = tree->find(key.removelast());
00065 assert(t);
00066
00067 WvString value;
00068 if (!t->value().isnull())
00069 value = UniFilterGen::get(key);
00070 new UniConfValueTree(t, key.last(), value);
00071 return value;
00072 }
00073 else
00074 return t->value();
00075 }
00076
00077
00078 bool UniFastRegetGen::exists(const UniConfKey &key)
00079 {
00080
00081
00082 return !!get(key);
00083 }
00084
00085
00086 bool UniFastRegetGen::haschildren(const UniConfKey &key)
00087 {
00088 if (!tree)
00089 {
00090 wvassert(tree, "key: '%s'", key);
00091 abort();
00092 }
00093
00094
00095 UniConfValueTree *t = tree->find(key);
00096 if (t && t->value().isnull())
00097 return false;
00098 return UniFilterGen::haschildren(key);
00099 }