[sword-devel] Compile problems with new config stuff

Troy A. Griffitts sword-devel@crosswire.org
Thu, 15 Mar 2001 20:56:48 -0700

	Thanks for the fix.  Still works for me, so if you guys are happy, I'm
in.  I don't know if you realize what the new feature is that is causing
the compile troubles of the past few days, but...

It used to be our configurator class SWConfig used a map<string,
map<string, string>> to store INI style entries, and it made for easy
stuff like:

SWConfig myConfig("./myConfig.conf");

myConfig.Sections["Section1"]["Entry1"] = "Value1";

Well, this easy syntax went away when we had to move the structure to:
map<string, multimap<string, string>>.  This was needed because we store
more than entry for some things, e.g.


multimaps lets this happen, whereas map will overwrite the previous
entry; however, multimap doesn't include nice [] operators, so we had to
use iterator = myConfig.Sections["Section1"].find("Entry1"), and check
for it != to end() and then grab it->second, ugh... Not very nice
looking anymore...

Well, now the new features:

SWConfig now has an operator[](const char *), so you can leave off the
'Sections' part, e.g.

myConfig["Section1"]["Entry1"] = "Value1";

and the BIG one... we now have a multimapwithdefault subclass of
multimap that implements the same behaviour as the map::operator [].  It
merely finds the FIRST entry with the name and returns it (or creates
one if it doesn't exist.  We still have to use find_*(key_type &) for
multi-entries like 'GlobalOptionsFilter', but for the MAJORITY of
entries we can now use the nice syntax like:

myConfig["Section1"]["Entry1"] = "Value1";


string entry1 = myConfig["Section1"]["Entry1"];

Hope this explains a little bit of why we changed stuff.