feisty meow concerns codebase 2.140
configurator.cpp
Go to the documentation of this file.
1/*****************************************************************************\
2* *
3* Name : configurator *
4* Author : Chris Koeritz *
5* *
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\*****************************************************************************/
14
15#include "configurator.h"
16
17#include <basis/astring.h>
19#include <structures/set.h>
20
21using namespace basis;
22using namespace structures;
23
24namespace configuration {
25
27
28astring configurator::load(const astring &section, const astring &entry,
29 const astring &default_string)
30{
31 astring to_return;
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.
36 }
37 return to_return;
38}
39
40bool configurator::store(const astring &section, const astring &entry,
41 const astring &to_store)
42{ return put(section, entry, to_store); }
43
44bool configurator::store(const astring &section, const astring &entry,
45 int value)
46{
47 return store(section, entry, astring(astring::SPRINTF, "%d", value));
48}
49
51{
52 // default implementation does nothing.
53 list = string_array();
54}
55
57{
58 string_array temp;
59 sections(temp);
60 list = temp;
61}
62
63int configurator::load(const astring &section, const astring &entry,
64 int def_value)
65{
66 astring value_string;
67 if (!get(section, entry, value_string)) {
68 if (_behavior == AUTO_STORE) store(section, entry, def_value);
69 return def_value;
70 }
71 return value_string.convert(def_value);
72}
73
75{
76 string_table infos;
77 // heavy-weight call here...
78 return get_section(section, infos);
79}
80
81} //namespace.
82
Provides a dynamically resizable ASCII character string.
Definition astring.h:35
int convert(int default_value) const
Converts the string into a corresponding integer.
Definition astring.cpp:760
bool store(const basis::astring &section, const basis::astring &entry, const basis::astring &to_store)
a synonym for put.
virtual bool put(const basis::astring &section, const basis::astring &entry, const basis::astring &to_store)=0
Places an item into the configuration store.
virtual bool get_section(const basis::astring &formal(section), structures::string_table &formal(found))
retrieves an entire "section", if supported by the derived object.
virtual bool get(const basis::astring &section, const basis::astring &entry, basis::astring &found)=0
Retrieves an item from the configuration store.
void section_set(structures::string_set &list)
similar to above, but stores section names into a set.
virtual void sections(structures::string_array &list)
retrieves the section names into "list".
virtual bool section_exists(const basis::astring &section)
returns true if the "section" is found in the configurator.
basis::astring load(const basis::astring &section, const basis::astring &entry, const basis::astring &default_value)
a synonym for get that implements the auto-store behavior.
An array of strings with some additional helpful methods.
A simple object that wraps a templated set of strings.
Definition set.h:168
Provides a symbol_table that holds strings as the content.
The guards collection helps in testing preconditions and reporting errors.
Definition array.h:30
A dynamic container class that holds any kind of object via pointers.
Definition amorph.h:55