00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "wvconf.h"
00011
00012
00013 WvConfigSection::WvConfigSection(const WvString &_name)
00014 : name(_name)
00015 {
00016 name.unique();
00017 }
00018
00019
00020 WvConfigSection::~WvConfigSection()
00021 {
00022
00023
00024 }
00025
00026
00027 WvConfigEntry *WvConfigSection::operator[] (const WvString &ename)
00028 {
00029 Iter i(*this);
00030
00031 for (i.rewind(); i.next();)
00032 {
00033 if (strcasecmp(i().name, ename) == 0)
00034 return &i();
00035 }
00036
00037 return NULL;
00038 }
00039
00040
00041 const char *WvConfigSection::get(const WvString &entry, const char *def_val)
00042 {
00043 WvConfigEntry *e = (*this)[entry];
00044 return e ? (const char *)e->value : def_val;
00045 }
00046
00047
00048 void WvConfigSection::set(const WvString &entry, const WvString &value)
00049 {
00050 WvConfigEntry *e = (*this)[entry];
00051
00052
00053 if (!value || !value[0])
00054 {
00055 if (e) unlink(e);
00056 return;
00057 }
00058
00059
00060 if (e)
00061 {
00062 e->set(value);
00063 e->value.unique();
00064 }
00065 else
00066 append(new WvConfigEntry(entry, value), true);
00067 }
00068
00069
00070 void WvConfigSection::quick_set(const WvString &entry, const WvString &value)
00071 {
00072 append(new WvConfigEntry(entry, value), true);
00073 }
00074
00075
00076 void WvConfigSection::dump(WvStream &fp)
00077 {
00078 Iter i(*this);
00079
00080 for (i.rewind(); i.next(); )
00081 {
00082 WvConfigEntry &e = i;
00083 if (e.value && e.value[0])
00084 fp.print("%s = %s\n", e.name, e.value);
00085 else
00086 fp.print("%s =\n", e.name);
00087 }
00088 }