00001 #ifndef TABLE_CONFIGURATOR_IMPLEMENTATION_FILE
00002 #define TABLE_CONFIGURATOR_IMPLEMENTATION_FILE
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "string_table.h"
00019 #include "table_configurator.h"
00020
00021 #include <basis/function.h>
00022 #include <basis/istring.h>
00023 #include <basis/log_base.h>
00024 #include <basis/string_array.h>
00025
00026 #undef LOG
00027 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger(), s)
00028
00029 class table_o_string_tables : public symbol_table<string_table>
00030 {
00031 public:
00032 };
00033
00035
00036 table_configurator::table_configurator(treatment_of_defaults behavior)
00037 : configurator(behavior),
00038 _real_table(new table_o_string_tables)
00039 {}
00040
00041 table_configurator::table_configurator(const table_configurator &to_copy)
00042 : configurator(to_copy.behavior()),
00043 _real_table(new table_o_string_tables)
00044 { *this = to_copy; }
00045
00046 table_configurator::~table_configurator()
00047 {
00048 WHACK(_real_table);
00049 }
00050
00051 table_configurator &table_configurator::operator =
00052 (const table_configurator &to_copy)
00053 {
00054 if (this == &to_copy) return *this;
00055 reset();
00056 string_array sects;
00057 const_cast<table_configurator &>(to_copy).sections(sects);
00058 for (int sectindy = 0; sectindy < sects.length(); sectindy++) {
00059
00060 istring curr_section = sects[sectindy];
00061 string_table entries;
00062 const_cast<table_configurator &>(to_copy).get_section(curr_section, entries);
00063 put_section(curr_section, entries);
00064 }
00065
00066 return *this;
00067 }
00068
00069 void table_configurator::reset() { _real_table->reset(); }
00070
00071 bool table_configurator::section_exists(const istring §ion)
00072 { return !!_real_table->find(section); }
00073
00074 void table_configurator::sections(string_array &to_fill)
00075 {
00076 to_fill.reset();
00077 for (int i = 0; i < _real_table->symbols(); i++)
00078 to_fill += _real_table->name(i);
00079 }
00080
00081 bool table_configurator::delete_section(const istring §ion)
00082 { return _real_table->whack(section) == common::OKAY; }
00083
00084 bool table_configurator::delete_entry(const istring §ion,
00085 const istring &ent)
00086 {
00087 string_table *sect = _real_table->find(section);
00088 if (!sect) return false;
00089 return sect->whack(ent) == common::OKAY;
00090 }
00091
00092 bool table_configurator::put(const istring §ion,
00093 const istring &entry, const istring &to_store)
00094 {
00095 if (!to_store.length()) return delete_entry(section, entry);
00096 else if (!entry.length()) return delete_section(section);
00097 string_table *sect = _real_table->find(section);
00098 if (!sect) {
00099
00100 _real_table->add(section, string_table());
00101 sect = _real_table->find(section);
00102 }
00103 sect->add(entry, to_store);
00104 return true;
00105 }
00106
00107 bool table_configurator::get(const istring §ion,
00108 const istring &entry, istring &found)
00109 {
00110 found = "";
00111 string_table *sect = _real_table->find(section);
00112 if (!sect) return false;
00113 istring *looked = sect->find(entry);
00114 if (!looked) return false;
00115 found = *looked;
00116 return true;
00117 }
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 bool table_configurator::get_section(const istring §ion,
00170 string_table &info)
00171 {
00172 FUNCDEF("get_section");
00173 info.reset();
00174 string_table *sect = _real_table->find(section);
00175 if (!sect) return false;
00176 for (int i = 0; i < sect->symbols(); i++)
00177 info.add(sect->name(i), (*sect)[i]);
00178 return true;
00179 }
00180
00181 bool table_configurator::put_section(const istring §ion,
00182 const string_table &info)
00183 {
00184 FUNCDEF("put_section");
00185 string_table *sect = _real_table->find(section);
00186 if (!sect) {
00187
00188 _real_table->add(section, string_table());
00189 sect = _real_table->find(section);
00190 }
00191 *sect = info;
00192 return true;
00193 }
00194
00195
00196 #endif //TABLE_CONFIGURATOR_IMPLEMENTATION_FILE
00197