1 /*****************************************************************************\
3 * Name : configurator *
4 * Author : Chris Koeritz *
6 *******************************************************************************
7 * Copyright (c) 2000-$now By Author. This program is free software; you can *
8 * redistribute it and/or modify it under the terms of the GNU General Public *
9 * License as published by the Free Software Foundation; either version 2 of *
10 * the License or (at your option) any later version. This is online at: *
11 * http://www.fsf.org/copyleft/gpl.html *
12 * Please send any updates to: fred@gruntose.com *
13 \*****************************************************************************/
15 #include "configurator.h"
17 #include <basis/astring.h>
18 #include <structures/string_table.h>
19 #include <structures/set.h>
21 using namespace basis;
22 using namespace structures;
24 namespace configuration {
26 configurator::~configurator() {}
28 astring configurator::load(const astring §ion, const astring &entry,
29 const astring &default_string)
32 if (!get(section, entry, to_return)) {
33 to_return = default_string;
34 if (_behavior == AUTO_STORE) put(section, entry, to_return);
35 // save the entry back if we're in autostore mode.
40 bool configurator::store(const astring §ion, const astring &entry,
41 const astring &to_store)
42 { return put(section, entry, to_store); }
44 bool configurator::store(const astring §ion, const astring &entry,
47 return store(section, entry, astring(astring::SPRINTF, "%d", value));
50 void configurator::sections(string_array &list)
52 // default implementation does nothing.
53 list = string_array();
56 void configurator::section_set(string_set &list)
63 int configurator::load(const astring §ion, const astring &entry,
67 if (!get(section, entry, value_string)) {
68 if (_behavior == AUTO_STORE) store(section, entry, def_value);
71 return value_string.convert(def_value);
74 bool configurator::section_exists(const astring §ion)
77 // heavy-weight call here...
78 return get_section(section, infos);