Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

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(const WvString &_name)
00014         : name(_name)
00015 {
00016     name.unique();
00017 }
00018 
00019 
00020 WvConfigSection::~WvConfigSection()
00021 {
00022     // the WvConfigEntryList destructor automatically deletes all its
00023     // entries, so no need to worry about doing that.
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     // need to delete the entry?
00053     if (!value || !value[0])
00054     {
00055         if (e) unlink(e);
00056         return;
00057     }
00058 
00059     // otherwise, add the entry requested
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 }

Generated on Sun Aug 25 02:29:28 2002 for WvStreams by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002