00001 /* 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 1997-2002 Net Integration Technologies, Inc. 00004 * 00005 * A "key" for looking things up in a WvHConf. 00006 * 00007 * See wvhconf.h. 00008 */ 00009 #include "wvhconf.h" 00010 00011 00012 // null constructor: let people fill it by hand later 00013 WvHConfKey::WvHConfKey() 00014 { 00015 // leave it empty 00016 } 00017 00018 00019 // string-style hierarchical key (separated by '/' characters) 00020 // ...maybe I'll extend this later to support old-style [section]entry syntax. 00021 WvHConfKey::WvHConfKey(const WvString &key) 00022 { 00023 split(key, "/"); 00024 if (count() == 1 && !*first()) 00025 zap(); 00026 } 00027 00028 00029 // string-style hierarchical key (separated by '/' characters) 00030 // ...maybe I'll extend this later to support old-style [section]entry syntax. 00031 WvHConfKey::WvHConfKey(const char *key) 00032 { 00033 split(key, "/"); 00034 if (count() == 1 && !*first()) 00035 zap(); 00036 } 00037 00038 00039 // old-style 2-level key: /section/entry. 00040 WvHConfKey::WvHConfKey(const WvString §ion, const WvString &entry) 00041 { 00042 append(new WvString(section), true); 00043 append(new WvString(entry), true); 00044 } 00045 00046 00047 // copy an old key to this key, stripping the leading components. 00048 // This isn't a very efficient copy operation, but maybe that's okay... 00049 WvHConfKey::WvHConfKey(const WvHConfKey &key, int offset) 00050 { 00051 int count = 0; 00052 Iter i(key); 00053 00054 for (count = 0, i.rewind(); count < offset && i.next(); count++) 00055 ; // do nothing; just skipping stuff. 00056 if (!i.cur()) 00057 return; 00058 while (i.next()) 00059 append(new WvString(*i), true); 00060 } 00061 00062 00063 WvString WvHConfKey::printable() const 00064 { 00065 if (isempty() || (count()==1 && !*first())) 00066 return "/"; 00067 else 00068 return join("/"); 00069 } 00070 00071