feisty meow concerns codebase  2.140
configlet.h
Go to the documentation of this file.
1 #ifndef CONFIGLET_CLASS
2 #define CONFIGLET_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : configlet *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 2001-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
17 
18 #include "configurator.h"
19 
20 #include <basis/astring.h>
21 #include <basis/contracts.h>
22 
23 namespace configuration {
24 
26 
32 class configlet : public virtual basis::root_object
33 {
34 public:
37  configlet(const configlet &to_copy);
38 
39  virtual ~configlet();
40 
41  DEFINE_CLASS_NAME("configlet");
42 
43  configlet &operator =(const configlet &to_copy);
44 
45  const basis::astring &section() const;
47  const basis::astring &entry() const;
49 
50  void section(const basis::astring &new_section) const;
52  void entry(const basis::astring &new_entry) const;
54 
55  virtual bool load(configurator &config) = 0;
57 
63  virtual bool store(configurator &config) const = 0;
65 
66  virtual configlet *duplicate() const = 0;
68 
70 private:
71  basis::astring *_section;
72  basis::astring *_entry;
73 };
74 
76 
78 
85 {
86 public:
90  string_configlet(const string_configlet &to_copy);
91  virtual ~string_configlet();
92 
94 
95  const basis::astring &current_value() const;
96  const basis::astring &default_value() const;
97 
98  void current_value(const basis::astring &new_current);
99  void default_value(const basis::astring &new_default);
100 
101  virtual bool load(configurator &config);
102  virtual bool store(configurator &config) const;
103 
104  configlet *duplicate() const;
105 
106 private:
107  basis::astring *_current;
108  basis::astring *_default;
109 };
110 
112 
114 
115 class int_configlet : public configlet
116 {
117 public:
119  int current_value = 0, int default_value = 0);
120  virtual ~int_configlet();
121 
122  int current_value() const { return _current; }
123 
124  virtual void current_value(int new_current);
126 
127  int default_value() const { return _default; }
128  void default_value(int new_default) { _default = new_default; }
129 
130  virtual bool load(configurator &config);
131  virtual bool store(configurator &config) const;
132 
133  configlet *duplicate() const;
134 
135 private:
136  int _current;
137  int _default;
138 };
139 
141 
143 
151 {
152 public:
154  int current_value, int default_value, int minimum, int maximum);
155  virtual ~bounded_int_configlet();
156 
157  virtual void current_value(int new_current);
158 
159  int minimum() const { return _minimum; }
160  int maximum() const { return _maximum; }
161 
162  void minimum(int new_min) { _minimum = new_min; }
163  void maximum(int new_max) { _maximum = new_max; }
164 
165  configlet *duplicate() const;
166 
167 private:
168  int _minimum;
169  int _maximum;
170 };
171 
172 } //namespace.
173 
174 #endif
175 
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
static const astring & empty_string()
useful wherever empty strings are needed, e.g., function defaults.
Definition: astring.cpp:128
Stores an integer in a configuration repository with range checking.
Definition: configlet.h:151
bounded_int_configlet(const basis::astring &section, const basis::astring &entry, int current_value, int default_value, int minimum, int maximum)
Definition: configlet.cpp:153
configlet * duplicate() const
a virtual copy constructor for configlets.
Definition: configlet.cpp:173
Represents an atom of configuration info.
Definition: configlet.h:33
DEFINE_CLASS_NAME("configlet")
configlet & operator=(const configlet &to_copy)
Definition: configlet.cpp:45
const basis::astring & section() const
observes the section of this configlet.
Definition: configlet.cpp:53
configlet(const basis::astring &section, const basis::astring &entry)
creates a configlet that lives in the "section" at the "entry".
Definition: configlet.cpp:29
virtual configlet * duplicate() const =0
a virtual copy constructor for configlets.
virtual bool store(configurator &config) const =0
writes the configlet's information out to the "config".
const basis::astring & entry() const
observes the entry name of this configlet.
Definition: configlet.cpp:55
virtual bool load(configurator &config)=0
retrieves the configlet's information from the "config".
Provides a base class for configuration repositories.
Definition: configurator.h:34
Stores a simple integer in a configuration repository.
Definition: configlet.h:116
int_configlet(const basis::astring &section, const basis::astring &entry, int current_value=0, int default_value=0)
Definition: configlet.cpp:122
void default_value(int new_default)
Definition: configlet.h:128
virtual bool store(configurator &config) const
writes the configlet's information out to the "config".
Definition: configlet.cpp:145
configlet * duplicate() const
a virtual copy constructor for configlets.
Definition: configlet.cpp:148
virtual bool load(configurator &config)
retrieves the configlet's information from the "config".
Definition: configlet.cpp:135
a string_configlet holds onto a character string value.
Definition: configlet.h:85
const basis::astring & current_value() const
Definition: configlet.cpp:94
virtual bool store(configurator &config) const
writes the configlet's information out to the "config".
Definition: configlet.cpp:114
virtual bool load(configurator &config)
retrieves the configlet's information from the "config".
Definition: configlet.cpp:104
configlet * duplicate() const
a virtual copy constructor for configlets.
Definition: configlet.cpp:117
string_configlet & operator=(const string_configlet &to_copy)
Definition: configlet.cpp:85
string_configlet(const basis::astring &section, const basis::astring &entry, const basis::astring &current_value=basis::astring::empty_string(), const basis::astring &default_value=basis::astring::empty_string())
Definition: configlet.cpp:65
const basis::astring & default_value() const
Definition: configlet.cpp:96