WvStreams
uniconfroot.h
1 /* -*- Mode: C++ -*-
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  *
5  * Defines the root management class for UniConf.
6  */
7 #ifndef __UNICONFROOT_H
8 #define __UNICONFROOT_H
9 
10 #include "uniconf.h"
11 #include "uniconftree.h"
12 #include "unimountgen.h"
13 
14 
20 {
21 public:
22  void *cookie;
23  bool recurse;
24  UniConfCallback cb;
25 
26  UniWatchInfo(void *_cookie, bool _recurse, UniConfCallback _cb)
27  : cookie(_cookie), recurse(_recurse), cb(_cb) { }
28 
30  bool recursive()
31  { return recurse; }
32 
34  void notify(const UniConf &cfg, const UniConfKey &key)
35  { cb(cfg, key); }
36 
38  bool operator== (const UniWatchInfo &other) const
39  { return other.cookie == cookie; }
40 };
41 DeclareWvList(UniWatchInfo);
42 
43 
48 class UniWatchInfoTree : public UniConfTree<UniWatchInfoTree>
49 {
50 public:
51  UniWatchInfoList watches;
52 
56 
58  bool isessential()
59  { return haschildren() || ! watches.isempty(); }
60 };
61 
62 
73 class UniConfRoot : public UniConf
74 {
75  friend class UniConf;
76  friend class UniConf::Iter;
77  friend class UniConf::RecursiveIter;
78 
79  UniWatchInfoTree watchroot;
80 
82  UniConfRoot(const UniConfRoot &other);
83 
84 public:
86  UniConfRoot();
87 
93  UniConfRoot(WvStringParm moniker, bool refresh = true);
94 
100  UniConfRoot(UniConfGen *gen, bool refresh = true);
101 
103  ~UniConfRoot();
104 
109  void add_callback(void *cookie, const UniConfKey &key,
110  const UniConfCallback &callback, bool recurse = true);
111 
115  void del_callback(void *cookie, const UniConfKey &key,
116  bool recurse = true);
117 
122  void add_setbool(const UniConfKey &key, bool *flag, bool recurse = true);
123 
127  void del_setbool(const UniConfKey &key, bool *flag, bool recurse = true);
128 
129 private:
136  void check(UniWatchInfoTree *node, const UniConfKey &key, int segleft);
137 
143  void deletioncheck(UniWatchInfoTree *node, const UniConfKey &key);
144 
146  void prune(UniWatchInfoTree *node);
147 
149  void gen_callback(const UniConfKey &key, WvStringParm value);
150 
151 protected:
152  friend class UniUnwrapGen;
153  UniMountGen mounts;
154 
155 public:
157  static void setbool_callback(bool *flag, const UniConf &,
158  const UniConfKey &)
159  { *flag = true; }
160 
161 };
162 
163 #endif //__UNICONFROOT_H
UniConf::refresh
bool refresh() const
Refreshes information about this key recursively.
Definition: uniconf.cc:119
UniConfRoot::del_setbool
void del_setbool(const UniConfKey &key, bool *flag, bool recurse=true)
Cancels notification requested using add_setbool().
Definition: uniconfroot.cc:136
UniConfRoot::add_callback
void add_callback(void *cookie, const UniConfKey &key, const UniConfCallback &callback, bool recurse=true)
Requests notification when any of the keys covered by the recursive depth specification change by inv...
Definition: uniconfroot.cc:87
UniConfRoot::UniConfRoot
UniConfRoot()
Creates an empty UniConf tree with no mounted stores.
Definition: uniconfroot.cc:14
UniWatchInfo
Definition: uniconfroot.h:19
UniConf
UniConf instances function as handles to subtrees of a UniConf tree and expose a high-level interface...
Definition: uniconf.h:50
UniConfTree
A recursively composed dictionary for tree-structured data indexed by UniConfKey.
Definition: uniconftree.h:23
UniConfRoot::setbool_callback
static void setbool_callback(bool *flag, const UniConf &, const UniConfKey &)
Internal callback for setbool style notifications.
Definition: uniconfroot.h:157
UniHashTreeBase::key
const UniConfKey & key() const
Returns the key field.
Definition: unihashtree.h:40
UniWatchInfoTree
Definition: uniconfroot.h:48
UniConfKey
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
Definition: uniconfkey.h:38
UniConfKey::EMPTY
static UniConfKey EMPTY
Definition: uniconfkey.h:171
UniConfTree< UniWatchInfoTree >::parent
UniWatchInfoTree * parent() const
Returns a pointer to the parent node, or NULL if there is none.
Definition: uniconftree.h:40
UniUnwrapGen
Deprecated: a UniConfGen that delegates all requests to an inner UniConf.
Definition: uniunwrapgen.h:33
UniConfGen
A default implementation of IUniConfGen, providing various handy features that save trouble when impl...
Definition: uniconfgen.h:199
UniWatchInfoTree::isessential
bool isessential()
Returns true if the node should not be pruned.
Definition: uniconfroot.h:58
UniConfRoot::del_callback
void del_callback(void *cookie, const UniConfKey &key, bool recurse=true)
Cancels notification requested using add_callback().
Definition: uniconfroot.cc:106
UniHashTreeBase::haschildren
bool haschildren() const
Returns true if the node has children.
Definition: unihashtree.cc:114
UniMountGen
The UniMountTree implementation realized as a UniConfGen.
Definition: unimountgen.h:17
UniConfRoot::~UniConfRoot
~UniConfRoot()
Destroys the UniConf tree along with all uncommitted data.
Definition: uniconfroot.cc:70
UniConfRoot::add_setbool
void add_setbool(const UniConfKey &key, bool *flag, bool recurse=true)
Requests notification when any of the keys covered by the recursive depth specification change by set...
Definition: uniconfroot.cc:128
UniConfRoot
Represents the root of a hierarhical registry consisting of pairs of UniConfKeys and associated strin...
Definition: uniconfroot.h:73
UniWatchInfo::recursive
bool recursive()
Returns watch recursion.
Definition: uniconfroot.h:30
UniConf::Iter
This iterator walks through all immediate children of a UniConf node.
Definition: uniconf.h:435
UniConf::key
UniConfKey key() const
Returns the path of this node relative to its parent.
Definition: uniconf.h:111
UniWatchInfo::operator==
bool operator==(const UniWatchInfo &other) const
Equality test.
Definition: uniconfroot.h:38
UniWatchInfo::notify
void notify(const UniConf &cfg, const UniConfKey &key)
Notifies that a key has changed.
Definition: uniconfroot.h:34
UniConf::RecursiveIter
This iterator performs depth-first traversal of a subtree.
Definition: uniconf.h:466