table_configurator.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "table_configurator.h"
00016
00017 #include <basis/astring.h>
00018 #include <basis/functions.h>
00019 #include <structures/string_array.h>
00020 #include <structures/string_table.h>
00021
00022 using namespace basis;
00023 using namespace structures;
00024
00025 namespace configuration {
00026
00027 #undef LOG
00028 #define LOG(to_print) printf("%s::%s: %s\n", static_class_name(), func, astring(to_print).s())
00029
00030 class table_o_string_tables : public symbol_table<string_table>
00031 {
00032 public:
00033 };
00034
00036
00037 table_configurator::table_configurator(treatment_of_defaults behavior)
00038 : configurator(behavior),
00039 _real_table(new table_o_string_tables)
00040 {}
00041
00042 table_configurator::table_configurator(const table_configurator &to_copy)
00043 : configurator(to_copy.behavior()),
00044 _real_table(new table_o_string_tables)
00045 { *this = to_copy; }
00046
00047 table_configurator::~table_configurator()
00048 {
00049 WHACK(_real_table);
00050 }
00051
00052 table_configurator &table_configurator::operator =
00053 (const table_configurator &to_copy)
00054 {
00055 if (this == &to_copy) return *this;
00056 reset();
00057 string_array sects;
00058 const_cast<table_configurator &>(to_copy).sections(sects);
00059 for (int sectindy = 0; sectindy < sects.length(); sectindy++) {
00060
00061 astring curr_section = sects[sectindy];
00062 string_table entries;
00063 const_cast<table_configurator &>(to_copy).get_section(curr_section, entries);
00064 put_section(curr_section, entries);
00065 }
00066
00067 return *this;
00068 }
00069
00070 void table_configurator::reset() { _real_table->reset(); }
00071
00072 bool table_configurator::section_exists(const astring §ion)
00073 { return !!_real_table->find(section); }
00074
00075 void table_configurator::sections(string_array &to_fill)
00076 {
00077 to_fill.reset();
00078 for (int i = 0; i < _real_table->symbols(); i++)
00079 to_fill += _real_table->name(i);
00080 }
00081
00082 bool table_configurator::delete_section(const astring §ion)
00083 { return _real_table->whack(section) == common::OKAY; }
00084
00085 bool table_configurator::delete_entry(const astring §ion,
00086 const astring &ent)
00087 {
00088 string_table *sect = _real_table->find(section);
00089 if (!sect) return false;
00090 return sect->whack(ent) == common::OKAY;
00091 }
00092
00093 bool table_configurator::put(const astring §ion,
00094 const astring &entry, const astring &to_store)
00095 {
00096 if (!to_store.length()) return delete_entry(section, entry);
00097 else if (!entry.length()) return delete_section(section);
00098 string_table *sect = _real_table->find(section);
00099 if (!sect) {
00100
00101 _real_table->add(section, string_table());
00102 sect = _real_table->find(section);
00103 }
00104 sect->add(entry, to_store);
00105 return true;
00106 }
00107
00108 bool table_configurator::get(const astring §ion,
00109 const astring &entry, astring &found)
00110 {
00111 found = "";
00112 string_table *sect = _real_table->find(section);
00113 if (!sect) return false;
00114 astring *looked = sect->find(entry);
00115 if (!looked) return false;
00116 found = *looked;
00117 return true;
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
00170 bool table_configurator::get_section(const astring §ion,
00171 string_table &info)
00172 {
00174 info.reset();
00175 string_table *sect = _real_table->find(section);
00176 if (!sect) return false;
00177 for (int i = 0; i < sect->symbols(); i++)
00178 info.add(sect->name(i), (*sect)[i]);
00179 return true;
00180 }
00181
00182 bool table_configurator::put_section(const astring §ion,
00183 const string_table &info)
00184 {
00186 string_table *sect = _real_table->find(section);
00187 if (!sect) {
00188
00189 _real_table->add(section, string_table());
00190 sect = _real_table->find(section);
00191 }
00192 *sect = info;
00193 return true;
00194 }
00195
00196 }
00197