uniunwrapgen.cc

00001 /*
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 2002 Net Integration Technologies, Inc.
00004  * 
00005  * A totally evil UniConfGen that "unwraps" a UniConf object by turning it
00006  * back into a UniConfGen.  See uniunwrapgen.h.
00007  */
00008 #include "uniconfroot.h"
00009 #include "uniunwrapgen.h"
00010 #include "wvlinkerhack.h"
00011 
00012 WV_LINK(UniUnwrapGen);
00013 
00014 
00015 UniUnwrapGen::UniUnwrapGen(const UniConf &inner)
00016 {
00017     refreshing = committing = false;
00018     setinner(inner);
00019 }
00020 
00021 
00022 UniUnwrapGen::~UniUnwrapGen()
00023 {
00024     UniConfRoot *root = xinner.rootobj();
00025     if (root)
00026         root->mounts.del_callback(this);
00027 }
00028 
00029 
00030 void UniUnwrapGen::setinner(const UniConf &inner)
00031 {
00032     UniConfRoot *root = xinner.rootobj();
00033     if (root)
00034         root->mounts.del_callback(this);
00035 
00036     xinner = inner;
00037     xfullkey = xinner.fullkey();
00038 
00039     root = xinner.rootobj();
00040     if (root)
00041     {
00042         UniConfGenCallback cb(this, &UniUnwrapGen::gencallback);
00043         root->mounts.add_callback(this, cb);
00044     }
00045 }
00046 
00047 
00048 UniConf UniUnwrapGen::_sub(const UniConfKey &key)
00049 {
00050     if (key.isempty())
00051         return xinner;
00052     else
00053         return xinner[key];
00054 }
00055 
00056 
00057 void UniUnwrapGen::commit()
00058 {
00059     if (!committing)
00060     {
00061         committing = true;
00062         xinner.commit();
00063         committing = false;
00064     }
00065 }
00066 
00067 
00068 bool UniUnwrapGen::refresh()
00069 {
00070     if (!refreshing)
00071     {
00072         refreshing = true;
00073         bool ret = xinner.refresh();
00074         refreshing = false;
00075         return ret;
00076     }
00077     return true;
00078 }
00079 
00080 
00081 void UniUnwrapGen::prefetch(const UniConfKey &key, bool recursive)
00082 {
00083     _sub(key).prefetch(recursive);
00084 }
00085 
00086 
00087 WvString UniUnwrapGen::get(const UniConfKey &key)
00088 {
00089     return _sub(key).getme();
00090 }
00091 
00092 
00093 void UniUnwrapGen::set(const UniConfKey &key, WvStringParm value)
00094 {
00095     _sub(key).setme(value);
00096 }
00097 
00098 
00099 void UniUnwrapGen::setv(const UniConfPairList &pairs)
00100 {
00101     // Extremely evil.  This pokes directly into UniMountGen, because we
00102     // don't want to expose setv to users.
00103     xinner.rootobj()->mounts.setv(pairs);
00104 }
00105 
00106 
00107 bool UniUnwrapGen::exists(const UniConfKey &key)
00108 {
00109     return _sub(key).exists();
00110 }
00111 
00112 
00113 bool UniUnwrapGen::haschildren(const UniConfKey &key)
00114 {
00115     return _sub(key).haschildren();
00116 }
00117 
00118 
00119 bool UniUnwrapGen::isok()
00120 {
00121     IUniConfGen *gen = xinner.whichmount();
00122     return gen ? gen->isok() : false;
00123 }
00124 
00125 
00126 class UniUnwrapGen::Iter : public UniConfGen::Iter
00127 {
00128     UniConf::Iter i;
00129     
00130 public:
00131     Iter(const UniConf &cfg)
00132         : i(cfg)
00133         { }
00134     virtual ~Iter()
00135         { }
00136     
00137     /***** Overridden members *****/
00138     virtual void rewind() { i.rewind(); }
00139     virtual bool next() { return i.next(); }
00140     virtual UniConfKey key() const { return i->key(); }
00141     virtual WvString value() const { return i->getme(); }
00142 };
00143 
00144 
00145 class UniUnwrapGen::RecursiveIter : public UniConfGen::Iter
00146 {
00147     UniConf::RecursiveIter i;
00148     
00149 public:
00150     RecursiveIter(const UniConf &cfg)
00151         : i(cfg)
00152         { }
00153     virtual ~RecursiveIter()
00154         { }
00155     
00156     /***** Overridden members *****/
00157     virtual void rewind() { i.rewind(); }
00158     virtual bool next() { return i.next(); }
00159     virtual UniConfKey key() const { return i->key(); }
00160     virtual WvString value() const { return i->getme(); }
00161 };
00162 
00163 
00164 UniConfGen::Iter *UniUnwrapGen::iterator(const UniConfKey &key)
00165 {
00166     return new Iter(_sub(key));
00167 }
00168 
00169 
00170 UniConfGen::Iter *UniUnwrapGen::recursiveiterator(const UniConfKey &key)
00171 {
00172     return new RecursiveIter(_sub(key));
00173 }
00174 
00175 
00176 void UniUnwrapGen::gencallback(const UniConfKey &key, WvStringParm value)
00177 {
00178     WvString subkey;
00179     if (xfullkey.suborsame(key, subkey))
00180         delta(subkey, value);
00181 }

Generated on Thu May 25 21:51:02 2006 for WvStreams by  doxygen 1.4.6