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
23namespace configuration {
24
26
32class configlet : public virtual basis::root_object
33{
34public:
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
70private:
71 basis::astring *_section;
72 basis::astring *_entry;
73};
74
76
78
85{
86public:
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
106private:
107 basis::astring *_current;
108 basis::astring *_default;
109};
110
112
114
116{
117public:
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
135private:
136 int _current;
137 int _default;
138};
139
141
143
151{
152public:
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
167private:
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
configlet * duplicate() const
a virtual copy constructor for configlets.
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
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.
Stores a simple integer in a configuration repository.
Definition configlet.h:116
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".
configlet * duplicate() const
a virtual copy constructor for configlets.
virtual bool load(configurator &config)
retrieves the configlet's information from the "config".
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".
virtual bool load(configurator &config)
retrieves the configlet's information from the "config".
configlet * duplicate() const
a virtual copy constructor for configlets.
string_configlet & operator=(const string_configlet &to_copy)
Definition configlet.cpp:85
const basis::astring & default_value() const
Definition configlet.cpp:96