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