Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

unicachegen.cc

Go to the documentation of this file.
00001 /*
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 2002 Net Integration Technologies, Inc.
00004  * 
00005  * A UniConf generator that stores keys in memory.
00006  */
00007 #include "uniconf.h"
00008 #include "unicachegen.h"
00009 #include "wvmoniker.h"
00010 
00011 // if 'obj' is non-NULL and is a UniConfGen, wrap that; otherwise wrap the
00012 // given moniker.
00013 static UniConfGen *creator(WvStringParm s, IObject *obj, void *)
00014 {
00015     UniConfGen *gen = NULL;
00016 
00017     if (obj)
00018         gen = mutate<UniConfGen>(obj);
00019     if (!gen)
00020         gen = wvcreate<UniConfGen>(s);
00021 
00022     return new UniCacheGen(gen);
00023 }
00024 
00025 static WvMoniker<UniConfGen> reg("cache", creator);
00026 
00027 
00028 /***** UniCacheGen *****/
00029 
00030 UniCacheGen::UniCacheGen(UniConfGen *_inner)
00031     : log("UniCache", WvLog::Debug1), inner(_inner)
00032 {
00033     loadtree();
00034 
00035     if (inner)
00036         inner->setcallback(UniConfGenCallback(this,
00037             &UniCacheGen::deltacallback), NULL);
00038 }
00039 
00040 
00041 UniCacheGen::~UniCacheGen()
00042 {
00043     delete inner;
00044 }
00045 
00046 
00047 void UniCacheGen::loadtree(const UniConfKey &key)
00048 {
00049     UniConfGen::Iter *i = inner->iterator(key);
00050 
00051     if (!i)
00052         return;
00053 
00054     for (i->rewind(); i->next(); )
00055     {
00056         WvString newkey("%s/%s", key, (*i).key());
00057         WvString value(inner->get(newkey));
00058 
00059         if (!!value)
00060             UniTempGen::set(newkey, value);
00061 
00062         if (inner->haschildren(newkey))
00063             loadtree(newkey);
00064     }
00065 
00066     delete i;
00067 }
00068 
00069 
00070 void UniCacheGen::deltacallback(const UniConfKey &key, WvStringParm value,
00071                                 void *userdata)
00072 {
00073     UniTempGen::set(key, value);
00074 }
00075 
00076 
00077 void UniCacheGen::set(const UniConfKey &key, WvStringParm value)
00078 {
00079     inner->set(key, value);
00080 }

Generated on Sat Feb 21 21:05:19 2004 for WvStreams by doxygen 1.3.5