Homepage Demos Overview Downloads Tutorials Reference
Credits

config.h

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2003-2004  Etienne Lachance
00003 
00004 This library is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU Lesser General Public License as
00006 published by the Free Software Foundation; either version 2.1 of the
00007 License, or (at your option) any later version.
00008 
00009 This library is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU Lesser General Public License for more details.
00013 
00014 You should have received a copy of the GNU Lesser General Public
00015 License along with this library; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 
00019 Report problems and direct all questions to:
00020 
00021 email: etienne.lachance@polytml.ca or richard.gourdeau@polymtl.ca
00022 -------------------------------------------------------------------------------
00023 Revision_history:
00024 
00025 2004/07/01: Etienne Lachance
00026    -Added doxygen documentation.
00027 
00028 2004/07/01: Ethan Tira-Thompson
00029     -Added support for newmat's use_namespace #define, using ROBOOP namespace
00030     -Added dependance on utils.h because we need to get the use_namespace setting
00031 
00032 2004/07/13: Ethan Tira-Thompson
00033     -Added a select_real and add_real function for type indepence of Real
00034     -Added functions to test for sections and parameters existance
00035 
00036 2004/07/23: Ethan Tira-Thompson
00037     -Fixed potentially uninitialized variables and some other warnings
00038 
00039 2004/09/01: Ethan Tira-Thompson
00040     -Added optional parameter to constructor so you can automatically read_conf
00041     -select_* functions are now const
00042 -------------------------------------------------------------------------------
00043 */
00044 
00045 #ifndef CONFIG_H
00046 #define CONFIG_H
00047 
00048 /*!
00049   @file config.h
00050   @brief Header file for Config class definitions.
00051 */
00052 
00053 //! @brief RCS/CVS version.
00054 static const char header_config_rcsid[] = "$Id: config.h,v 1.9 2004/09/01 19:51:04 ejt Exp $";
00055 
00056 
00057 #ifdef _MSC_VER                  // Microsoft
00058 #pragma warning (disable:4786)  // Disable decorated name truncation warnings 
00059 #pragma warning (disable:4503)  // Disable decorated name truncation warnings 
00060 #endif
00061 #include <iostream>
00062 #include <string>
00063 #include <iomanip>
00064 #include <fstream>
00065 #ifdef __WATCOMC__
00066 #include <strstrea.h>
00067 #else
00068 #include <sstream>
00069 #endif
00070 #include <vector>
00071 
00072 #include "utils.h"
00073 #ifdef use_namespace
00074 namespace ROBOOP {
00075   using namespace NEWMAT;
00076 #endif
00077 
00078 //! @brief Return when can not open file.
00079 #define CAN_NOT_OPEN_FILE                     -1
00080 
00081 //! @brief Return when can not create a file.
00082 #define CAN_NOT_CREATE_FILE                   -2
00083 
00084 //! @brief Return when a section or parameter does not exist.
00085 #define SECTION_OR_PARAMETER_DOES_NOT_EXIST   -3
00086 
00087 #ifndef __WATCOMC__
00088 using namespace std;
00089 #endif
00090 
00091 
00092 //! @brief Basic data element used in Config class.
00093 typedef struct Data{
00094    Data() : section(), parameter(), value() {}
00095    string section;
00096    string parameter;
00097    string value;
00098 } Data;
00099 
00100 //! @brief Configuration data type.
00101 typedef vector< Data > Conf_data;
00102 
00103 //! @brief Handle configuration files.
00104 class Config {
00105 public:
00106    Config() : conf(), filename() {}
00107    Config(const string & filename_,bool doRead=false);
00108    Config(const Config & x);
00109    Config & operator=(const Config & x);
00110    short read_conf();
00111    void print();
00112 
00113    bool section_exists(const string& section) const;
00114    bool parameter_exists(const string& section, const string& parameter) const;
00115 
00116    short select_string(const string section, const string parameter,
00117                        string & value) const;
00118    short select_bool(const string section, const string parameter,
00119                      bool & value) const;
00120    short select_short(const string section, const string parameter,
00121                       short & value) const;
00122    short select_int(const string section, const string parameter,
00123                     int & value) const;
00124    short select_float(const string section, const string parameter,
00125           float & value) const;
00126    short select_double(const string section, const string parameter,
00127                        double & value) const;
00128    short select_real(const string section, const string parameter,
00129                        Real & value) const;
00130 
00131    short write_conf(const string name, const string file_title,
00132                     const int space_between_column);
00133    void add_string(const string section, const string parameter,
00134                    const string value);
00135    void add_bool(const string section, const string parameter,
00136                  const bool value);
00137    void add_int(const string section, const string parameter,
00138                 const int value);
00139    void add_float(const string section, const string parameter,
00140                    const float value);
00141    void add_double(const string section, const string parameter,
00142                    const double value);
00143    void add_real(const string section, const string parameter,
00144                    const Real value);
00145 
00146 private:
00147    Conf_data conf;   //!< Data store from/to configuration file.
00148    string filename;  //!< Configuration file name.
00149 };
00150 
00151 #ifdef use_namespace
00152 }
00153 #endif
00154 
00155 #endif 
00156 
00157 
00158 
00159 
00160 
00161 
00162 
00163 
00164 
00165 
00166 
00167 
00168 
00169 
00170 
00171 
00172 
00173 

ROBOOP v1.21a
Generated Tue Nov 23 16:35:51 2004 by Doxygen 1.3.9.1