00001 /* -*- Mode: C++ -*- 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 2002 Net Integration Technologies, Inc. 00004 * 00005 * UniConfKeys are paths in the UniConf hierarchy. 00006 */ 00007 #ifndef __UNICONFKEY_H 00008 #define __UNICONFKEY_H 00009 00010 #include "wvstring.h" 00011 #include "wvlinklist.h" 00012 00013 00014 // The Python headers try to #define ANY as void. If we're building Python 00015 // wrappers, get rid of that. 00016 #undef ANY 00017 00018 00042 class UniConfKey 00043 { 00044 WvString path; 00045 00046 public: 00047 static UniConfKey EMPTY; 00048 static UniConfKey ANY; 00049 static UniConfKey RECURSIVE_ANY; 00052 UniConfKey(); 00053 00062 UniConfKey(WvStringParm key) 00063 { init(key); } 00064 00074 UniConfKey(const char *key) 00075 { init(key); } 00076 00078 UniConfKey(int key) 00079 { init(key); } 00080 00085 UniConfKey(const UniConfKey &other); 00086 00092 UniConfKey(const UniConfKey &path, const UniConfKey &key); 00093 00098 void append(const UniConfKey &other); 00099 00104 void prepend(const UniConfKey &other); 00105 00110 bool isempty() const; 00111 00113 bool iswild() const; 00114 00124 int numsegments() const; 00125 00131 UniConfKey segment(int i) const; 00132 00138 UniConfKey pop(int n = 1); 00139 00145 UniConfKey first(int n = 1) const; 00146 00152 UniConfKey last(int n = 1) const; 00153 00160 UniConfKey removefirst(int n = 1) const; 00161 00168 UniConfKey removelast(int n = 1) const; 00169 00176 UniConfKey range(int i, int j) const; 00177 00189 WvString printable() const; 00190 operator WvString() const 00191 { return printable(); } 00192 00196 const char *cstr() const 00197 { return printable(); } 00198 00203 UniConfKey &operator= (const UniConfKey &other); 00204 00212 int compareto(const UniConfKey &other) const; 00213 00224 bool matches(const UniConfKey &pattern) const; 00225 00226 00231 bool suborsame(const UniConfKey &key) const; 00232 00238 bool operator== (const UniConfKey &other) const 00239 { return compareto(other) == 0; } 00240 00246 bool operator!= (const UniConfKey &other) const 00247 { return ! (*this == other); } 00248 00254 bool operator< (const UniConfKey &other) const 00255 { return compareto(other) < 0; } 00256 00257 class Iter; 00258 00259 protected: 00260 void init(WvStringParm key); 00261 }; 00262 00263 00264 DeclareWvList(UniConfKey); 00265 00267 class UniConfKey::Iter 00268 { 00269 const UniConfKey &key; 00270 int seg, max; 00271 UniConfKey curseg; 00272 00273 public: 00274 Iter(const UniConfKey &_key) : key(_key) 00275 { } 00276 00277 void rewind() 00278 { seg = -1; max = key.numsegments(); } 00279 00280 bool cur() 00281 { return seg >= 0 && seg < max; } 00282 00283 bool next() 00284 { seg++; curseg = key.segment(seg); return cur(); } 00285 00286 const UniConfKey *ptr() const 00287 { return &curseg; } 00288 00289 WvIterStuff(const UniConfKey); 00290 }; 00291 00292 #endif // __UNICONFKEY_H