configurator.cpp

Go to the documentation of this file.
00001 #ifndef CONFIGURATOR_IMPLEMENTATION_FILE
00002 #define CONFIGURATOR_IMPLEMENTATION_FILE
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : configurator                                                      *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2000-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "configurator.h"
00019 #include "string_table.h"
00020 
00021 #include <basis/istring.h>
00022 #include <basis/string_array.h>
00023 #include <basis/set.cpp>
00024 
00025 configurator::~configurator() {}
00026 
00027 istring configurator::load(const istring &section, const istring &entry,
00028         const istring &default_string)
00029 {
00030   istring to_return;
00031   if (!get(section, entry, to_return)) {
00032     to_return = default_string;
00033     if (_behavior == AUTO_STORE) put(section, entry, to_return);
00034       // save the entry back if we're in autostore mode.
00035   }
00036   return to_return;
00037 }
00038 
00039 bool configurator::store(const istring &section, const istring &entry,
00040     const istring &to_store)
00041 { return put(section, entry, to_store); }
00042 
00043 bool configurator::store(const istring &section, const istring &entry,
00044     int value)
00045 {
00046   return store(section, entry, istring(istring::SPRINTF, "%d", value));
00047 }
00048 
00049 void configurator::sections(string_array &list)
00050 {
00051   // default implementation does nothing.
00052   list = string_array();
00053 }
00054 
00055 void configurator::section_set(string_set &list)
00056 {
00057   string_array temp;
00058   sections(temp);
00059   list = temp;
00060 }
00061 
00062 int configurator::load(const istring &section, const istring &entry,
00063     int def_value)
00064 {
00065   istring value_string;
00066   if (!get(section, entry, value_string)) {
00067     if (_behavior == AUTO_STORE) store(section, entry, def_value);
00068     return def_value;
00069   }
00070   return value_string.convert(def_value);
00071 }
00072 
00073 bool configurator::section_exists(const istring &section)
00074 {
00075   string_table infos;
00076   // heavy-weight call here...
00077   return get_section(section, infos);
00078 }
00079 
00080 
00081 #endif //CONFIGURATOR_IMPLEMENTATION_FILE
00082 

Generated on Fri Nov 28 04:29:12 2008 for HOOPLE Libraries by  doxygen 1.5.1