uniconfkey.h

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 
00116     bool hastrailingslash() const;
00117 
00127     int numsegments() const;
00128 
00134     UniConfKey segment(int i) const;
00135 
00141     UniConfKey pop(int n = 1);
00142     
00148     UniConfKey first(int n = 1) const;
00149 
00155     UniConfKey last(int n = 1) const;
00156 
00163     UniConfKey removefirst(int n = 1) const;
00164 
00171     UniConfKey removelast(int n = 1) const;
00172 
00179     UniConfKey range(int i, int j) const;
00180 
00192     WvString printable() const;
00193     operator WvString() const
00194         { return printable(); }
00195     
00199     const char *cstr() const
00200         { return printable(); }
00201 
00206     UniConfKey &operator= (const UniConfKey &other);
00207 
00215     int compareto(const UniConfKey &other) const;
00216 
00227     bool matches(const UniConfKey &pattern) const;
00228 
00229 
00233     bool suborsame(const UniConfKey &key) const;
00234     bool suborsame(const UniConfKey &key, WvString &subkey) const;
00235 
00241     UniConfKey subkey(const UniConfKey &key) const;
00242 
00248     bool operator== (const UniConfKey &other) const
00249         { return compareto(other) == 0; }
00250         
00256     bool operator!= (const UniConfKey &other) const
00257         { return ! (*this == other); }
00258 
00264     bool operator< (const UniConfKey &other) const
00265         { return compareto(other) < 0; }
00266 
00267     class Iter;
00268 
00269 protected:
00270     void init(WvStringParm key);
00271 };
00272 
00273 
00274 DeclareWvList(UniConfKey);
00275 
00277 class UniConfKey::Iter
00278 {
00279     const UniConfKey &key;
00280     int seg, max;
00281     UniConfKey curseg;
00282     
00283 public:
00284     Iter(const UniConfKey &_key) : key(_key) 
00285         { }
00286 
00287     void rewind()
00288         { seg = -1; max = key.numsegments(); }
00289     
00290     bool cur()
00291         { return seg >= 0 && seg < max; }
00292     
00293     bool next()
00294         { seg++; curseg = key.segment(seg); return cur(); }
00295     
00296     const UniConfKey *ptr() const
00297         { return &curseg; }
00298     
00299     WvIterStuff(const UniConfKey);
00300 };
00301 
00302 #endif // __UNICONFKEY_H

Generated on Mon Feb 5 10:54:28 2007 for WvStreams by  doxygen 1.5.1