Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

cfgsection.cc

Go to the documentation of this file.
00001 /*
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  *
00005  * Implementation of the WvConfigSection class. 
00006  *
00007  * Created:     Sept 28 1997            D. Coombs
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     // the WvConfigEntryList destructor automatically deletes all its
00022     // entries, so no need to worry about doing that.
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     // need to delete the entry?
00057     if (!value || !value[0])
00058     {
00059         if (e) unlink(e);
00060         return;
00061     }
00062 
00063     // otherwise, add the entry requested
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 }

Generated on Sat Feb 21 21:05:19 2004 for WvStreams by doxygen 1.3.5