00001 #ifndef CONFIGLET_IMPLEMENTATION_FILE
00002 #define CONFIGLET_IMPLEMENTATION_FILE
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "configlet.h"
00019 #include "configurator.h"
00020
00021 #include <basis/function.h>
00022 #include <basis/istring.h>
00023
00024 const istring bogus_default = "OOPS: not supposed to ever be seen. d'oh!";
00025
00027
00028 configlet::configlet(const istring §ion, const istring &entry)
00029 : _section(new istring(section)),
00030 _entry(new istring(entry))
00031 {}
00032
00033 configlet::configlet(const configlet &to_copy)
00034 : object_base(),
00035 _section(new istring(*to_copy._section)),
00036 _entry(new istring(*to_copy._entry))
00037 {}
00038
00039 configlet::~configlet()
00040 {
00041 WHACK(_section);
00042 WHACK(_entry);
00043 }
00044
00045 configlet &configlet::operator =(const configlet &to_copy)
00046 {
00047 if (this == &to_copy) return *this;
00048 *_section = *to_copy._section;
00049 *_entry = *to_copy._entry;
00050 return *this;
00051 }
00052
00053 const istring &configlet::section() const { return *_section; }
00054
00055 const istring &configlet::entry() const { return *_entry; }
00056
00057 void configlet::section(const istring &new_section) const
00058 { *_section = new_section; }
00059
00060 void configlet::entry(const istring &new_entry) const
00061 { *_entry = new_entry; }
00062
00064
00065 string_configlet::string_configlet(const istring §ion, const istring &entry,
00066 const istring ¤t_value, const istring &default_value)
00067 : configlet(section, entry),
00068 _current(new istring(current_value)),
00069 _default(new istring(default_value))
00070 {}
00071
00072 string_configlet::string_configlet(const string_configlet &to_copy)
00073 : object_base(),
00074 configlet(to_copy.section(), to_copy.entry()),
00075 _current(new istring(*to_copy._current)),
00076 _default(new istring(*to_copy._default))
00077 {
00078 }
00079
00080 string_configlet::~string_configlet()
00081 {
00082 WHACK(_current);
00083 WHACK(_default);
00084 }
00085
00086 string_configlet &string_configlet::operator =(const string_configlet &to_copy)
00087 {
00088 if (this == &to_copy) return *this;
00089 (configlet &)*this = to_copy;
00090 *_current = *to_copy._current;
00091 *_default = *to_copy._default;
00092 return *this;
00093 }
00094
00095 const istring &string_configlet::current_value() const { return *_current; }
00096
00097 const istring &string_configlet::default_value() const { return *_default; }
00098
00099 void string_configlet::current_value(const istring &new_current)
00100 { *_current = new_current; }
00101
00102 void string_configlet::default_value(const istring &new_default)
00103 { *_default = new_default; }
00104
00105 bool string_configlet::load(configurator &config)
00106 {
00107 if (config.get(section(), entry(), *_current)) return true;
00108
00109 *_current = *_default;
00110 if (config.behavior() == configurator::AUTO_STORE)
00111 config.put(section(), entry(), *_current);
00112 return false;
00113 }
00114
00115 bool string_configlet::store(configurator &config) const
00116 { return config.put(section(), entry(), *_current); }
00117
00118 configlet *string_configlet::duplicate() const
00119 { return new string_configlet(section(), entry(), *_current, *_default); }
00120
00122
00123 int_configlet::int_configlet(const istring §ion, const istring &entry,
00124 int current_value, int default_value)
00125 : configlet(section, entry),
00126 _current(current_value),
00127 _default(default_value)
00128 {
00129 }
00130
00131 int_configlet::~int_configlet() {}
00132
00133 void int_configlet::current_value(int new_current)
00134 { _current = new_current; }
00135
00136 bool int_configlet::load(configurator &config)
00137 {
00138 istring temp;
00139 bool to_return = config.get(section(), entry(), temp);
00140
00141 int temp_c = config.load(section(), entry(), _default);
00142 current_value(temp_c);
00143 return to_return;
00144 }
00145
00146 bool int_configlet::store(configurator &config) const
00147 { return config.store(section(), entry(), _current); }
00148
00149 configlet *int_configlet::duplicate() const
00150 { return new int_configlet(*this); }
00151
00153
00154 bounded_int_configlet::bounded_int_configlet(const istring §ion,
00155 const istring &entry, int current_value, int default_value,
00156 int minimum, int maximum)
00157 : int_configlet(section, entry, current_value, default_value),
00158 _minimum(minimum),
00159 _maximum(maximum)
00160 {
00161 }
00162
00163 bounded_int_configlet::~bounded_int_configlet() {}
00164
00165 void bounded_int_configlet::current_value(int new_current)
00166 {
00167 if (new_current < _minimum)
00168 new_current = default_value();
00169 if (new_current > _maximum)
00170 new_current = default_value();
00171 int_configlet::current_value(new_current);
00172 }
00173
00174 configlet *bounded_int_configlet::duplicate() const
00175 { return new bounded_int_configlet(*this); }
00176
00177
00178 #endif //CONFIGLET_IMPLEMENTATION_FILE
00179