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 
21 using namespace basis;
22 using namespace structures;
23 
24 namespace configuration {
25 
26 configurator::~configurator() {}
27 
28 astring 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 
40 bool configurator::store(const astring &section, const astring &entry,
41  const astring &to_store)
42 { return put(section, entry, to_store); }
43 
44 bool configurator::store(const astring &section, const astring &entry,
45  int value)
46 {
47  return store(section, entry, astring(astring::SPRINTF, "%d", value));
48 }
49 
50 void configurator::sections(string_array &list)
51 {
52  // default implementation does nothing.
53  list = string_array();
54 }
55 
56 void configurator::section_set(string_set &list)
57 {
58  string_array temp;
59  sections(temp);
60  list = temp;
61 }
62 
63 int 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 
74 bool configurator::section_exists(const astring &section)
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:757
An array of strings with some additional helpful methods.
Definition: string_array.h:32
A simple object that wraps a templated set of strings.
Definition: set.h:168
Provides a symbol_table that holds strings as the content.
Definition: string_table.h:32
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
string_array(1, math_list))) const char *addr_list[]