X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=util%2Fepist%2Fconfig.cc;h=461778e5f952958b8eb0ada2689f29729364a7ec;hb=97019b8b77f7e6450d87b057bcb6eae43e9f3e2b;hp=0df15e9c9ab0e260ad269f1a101c6517f12b855b;hpb=cc5bde6d00892cf27fcb6e4e0b4974bcecca265f;p=chaz%2Fopenbox diff --git a/util/epist/config.cc b/util/epist/config.cc index 0df15e9c..461778e5 100644 --- a/util/epist/config.cc +++ b/util/epist/config.cc @@ -20,6 +20,10 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#ifdef HAVE_CONFIG_H +# include "../../config.h" +#endif // HAVE_CONFIG_H + #include "config.hh" using std::string; @@ -28,38 +32,60 @@ Config::Config() {} Config::~Config() { - ItemList::const_iterator it = items.begin(), end = items.end(); - for (; it != end; ++it) - delete *it; - items.clear(); + // deallocate memory for the 3 lists + BoolItemList::const_iterator b_it, b_end = bool_items.end(); + for (b_it = bool_items.begin(); b_it != b_end; ++b_it) + delete *b_it; + bool_items.clear(); + + NumberItemList::const_iterator n_it, n_end = number_items.end(); + for (n_it = number_items.begin(); n_it != n_end; ++n_it) + delete *n_it; + number_items.clear(); + + StringItemList::const_iterator s_it, s_end = string_items.end(); + for (s_it = string_items.begin(); s_it != s_end; ++s_it) + delete *s_it; + string_items.clear(); } -const string &Config::getStringValue(Config::ItemType type) const +bool Config::getValue(Config::StringType type, string &ret) const { - ItemList::const_iterator it = items.begin(), end = items.end(); + StringItemList::const_iterator it = string_items.begin(), end = string_items.end(); for (; it != end; ++it) { - if ((*it)->getType() == type) - return (*it)->getStringValue(); + if ((*it)->type == type) { + ret = (*it)->value; + return true; + } } + return false; } -int Config::getNumberValue(Config::ItemType type) const +bool Config::getValue(Config::NumberType type, int &ret) const { - ItemList::const_iterator it = items.begin(), end = items.end(); + NumberItemList::const_iterator it = number_items.begin(), end = number_items.end(); for (; it != end; ++it) { - if ((*it)->getType() == type) - return (*it)->getNumberValue(); + if ((*it)->type == type) { + ret = (*it)->value; + return true; + } } - - return 0; + return false; } -void Config::addOption(ConfigItem *item) +bool Config::getValue(Config::BoolType type, bool &ret) const { - items.push_back(item); + BoolItemList::const_iterator it = bool_items.begin(), end = bool_items.end(); + for (; it != end; ++it) { + if ((*it)->type == type) { + ret = (*it)->value; + return true; + } + } + return false; } @@ -67,21 +93,77 @@ void Config::addOption(const std::string &name, const std::string &value) { const struct { const char *name; - Config::ItemType type; + Config::BoolType type; + } + bool_options[] = { + { "stackedcycling", Config::stackedCycling }, + { "stackedcyclingraise", Config::stackedCyclingRaise }, + { "", NUM_BOOL_TYPES } + }; + + const struct { + const char *name; + Config::StringType type; + } + string_options[] = { + { "", NUM_STRING_TYPES } + }; + + const struct { + const char *name; + Config::NumberType type; } - options[] = { - { "notype", Config::noType }, - { "chaintimeout", Config::chainTimeout }, - { "workspacecolumns", Config::workspaceColumns }, - { "", numTypes } + number_options[] = { + { "chaintimeout", chainTimeout }, + { "workspacecolumns", workspaceColumns }, + { "", NUM_NUMBER_TYPES } }; + // if it's bool option, add it to the bool_items list size_t i = 0; - while (options[i].type != numTypes) { - if (strcasecmp(name.c_str(), options[i].name) == 0) { - ConfigItem *item = new ConfigItem(options[i].type, value); - items.push_back(item); - break; + while (bool_options[i].type != NUM_BOOL_TYPES) { + if (strcasecmp(name.c_str(), bool_options[i].name) == 0) { + BoolItem *item = new BoolItem; + const char *tmp = value.c_str(); + + item->type = bool_options[i].type; + + if (strcasecmp(tmp, "true") == 0 || strcasecmp(tmp, "1") == 0 || + strcasecmp(tmp, "on") == 0) + item->value = true; + else + item->value = false; + + bool_items.push_back(item); + return; + } + i++; + } + + // if it's a string, add it to the string_items list + i = 0; + while (string_options[i].type != NUM_STRING_TYPES) { + if (strcasecmp(name.c_str(), string_options[i].name) == 0) { + StringItem *item = new StringItem; + item->type = string_options[i].type; + item->value = value; + + string_items.push_back(item); + return; + } + i++; + } + + // if it's a number, add it to the number_items list + i = 0; + while (number_options[i].type != NUM_NUMBER_TYPES) { + if (strcasecmp(name.c_str(), number_options[i].name) == 0) { + NumberItem *item = new NumberItem; + item->type = number_options[i].type; + item->value = atoi( value.c_str() ); + + number_items.push_back(item); + return; } i++; }