Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

wvhconf.h

Go to the documentation of this file.
00001 /*
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  * 
00005  * WvHConf is the new, improved, hierarchical version of WvConf.  It stores
00006  * strings in a hierarchy and can load/save them from "various places."
00007  */
00008 #ifndef __WVHCONF_H
00009 #define __WVHCONF_H
00010 
00011 #include "wvhashtable.h"
00012 #include "wvstringlist.h"
00013 
00014 class WvStream;
00015 class WvHConf;
00016 class WvHConfDict;
00017 
00022 class WvHConfKey : public WvStringList
00023 {
00024 public:
00025     WvHConfKey();
00026     WvHConfKey(const char *key);
00027     WvHConfKey(const WvString &key);
00028     WvHConfKey(const WvString &section, const WvString &entry);
00029     WvHConfKey(const WvHConfKey &key, int offset = 0);
00030     
00031     WvString printable() const;
00032     operator WvString () const { return printable(); }
00033     
00034     WvHConfKey skip(int offset) const
00035         { return WvHConfKey(*this, offset); }
00036 };
00037 
00038 
00044 class WvHConfGen
00045 {
00046 public:
00047     WvHConfGen() {}
00048     virtual ~WvHConfGen();
00049     
00050     // both of these functions may return NULL if the object "shouldn't"
00051     // exist.
00052     virtual WvHConf *make_tree(WvHConf *parent, const WvHConfKey &key);
00053     virtual WvHConf *make_obj(WvHConf *parent, const WvString &name);
00054     
00055     virtual void update(WvHConf *h);
00056     
00057     // the default load/save functions don't do anything... you might not
00058     // need them to.
00059     virtual void load();
00060     virtual void save();
00061 };
00062 
00063 
00072 class WvHConf
00073 {
00074 public:
00075     WvHConf *parent;       // the 'parent' of this subtree
00076     WvString name;         // the name of this entry
00077 private:
00078     WvString value;        // the contents of this entry
00079 public:    
00080     WvHConfDict *children; // list of all child nodes of this node (subkeys)
00081     WvHConf *defaults;     // a tree possibly containing default values
00082     WvHConfGen *generator; // subtree generator for this tree
00083     
00084 public:
00085     bool 
00086         // the 'dirty' flags are set true by set() and can be cleared by
00087         // the tree's generator object, if it cares.
00088         child_dirty:1,     // some data in the subtree has dirty=1
00089         dirty:1,           // this data is unsaved
00090         
00091         // the 'notify' flags are set true by set() and can be cleared by
00092         // an external notification system, if there is one.
00093         child_notify:1,    // some data in the subtree has notify=1
00094         notify:1,          // this data changed - notify interested parties
00095         
00096         // the 'obsolete' flags can be set true by the generator, if it cares.
00097         // In that case the generator should also clear them upon request.
00098         child_obsolete:1,  // some data in the subtree has obsolete=1
00099         obsolete:1;        // need to re-autogen this data before next use
00100         
00101     
00102     WvHConf();
00103     WvHConf(WvHConf *_parent, const WvString &_name);
00104     ~WvHConf();
00105     void init();
00106     
00107     WvHConf *top();
00108     WvHConfKey full_key() const;
00109     
00110     WvHConf *gen_top();
00111     WvHConfKey gen_full_key() const;
00112     
00113     WvHConf *find(const WvHConfKey &key);
00114     WvHConf *find_make(const WvHConfKey &key);
00115     WvHConf &operator[](const WvHConfKey &key) { return *find_make(key); }
00116     
00117     WvHConf *find_default(WvHConfKey *_k = NULL) const;
00118     
00119     // exactly the same as find_make() and operator[]... hmm.
00120     // Unnecessary?
00121     WvHConf &get(const WvHConfKey &key)
00122         { return *find_make(key); }
00123     
00124     // another convenience function, suspiciously similar to cfg[key] = v.
00125     // Also unnecessary?
00126     void set(const WvHConfKey &key, const WvString &v)
00127         { get(key).set(v); }
00128     
00129     // Reassign the 'value' of this object to something.
00130     void set_without_notify(const WvString &s);
00131     void set(const WvString &s);
00132     void do_notify();
00133     const WvHConf &operator= (const WvString &s) { set(s); return *this; }
00134     const WvHConf &operator= (const WvHConf &s) { set(s); return *this; }
00135     
00136     // retrieve the value.  Normally you don't need to call printable()
00137     // explicitly, since the WvString cast operator does it for you.
00138     const WvString& printable() const;
00139     operator const WvString& () const { return printable(); }
00140     bool operator! () const { return !printable(); }
00141     int num() const { return printable().num(); }
00142     
00143     // load/save the entire tree (including subtrees).
00144     // Only save if the data is marked 'dirty'.
00145     void load();
00146     void save();
00147     
00148     // a handy function to print a copy of this subtree to a stream.
00149     void dump(WvStream &s);
00150 };
00151 
00152 DeclareWvDict(WvHConf, WvString, name);
00153 
00154 
00155 #endif // __WVHCONF_H

Generated on Sun Aug 25 02:29:31 2002 for WvStreams by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002