Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
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 2005/04/08: Ethan Tira-Thompson
00044     -Switched data storage to STL map, replacing the previous O(n^2) config file
00045      parsing, now approx O(n lg n) (actually a little better - O((s*p) lg (s+p)))
00046 -------------------------------------------------------------------------------
00047 */
00048 
00049 #ifndef CONFIG_H
00050 #define CONFIG_H
00051 
00052 /*!
00053   @file config.h
00054   @brief Header file for Config class definitions.
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 
00062 #include <string>
00063 #include <map>
00064 
00065 #include "utils.h"
00066 #ifdef use_namespace
00067 namespace ROBOOP {  
00068   using namespace NEWMAT;
00069 #endif
00070   //! @brief RCS/CVS version.
00071   static const char header_config_rcsid[] __UNUSED__ = "$Id: config.h,v 1.15 2007/11/11 23:57:24 ejt Exp $";
00072 
00073 //! @brief Return when can not open file.
00074 #define CAN_NOT_OPEN_FILE                     -1
00075 
00076 //! @brief Return when can not create a file.
00077 #define CAN_NOT_CREATE_FILE                   -2
00078 
00079 //! @brief Return when a section or parameter does not exist.
00080 #define SECTION_OR_PARAMETER_DOES_NOT_EXIST   -3
00081 
00082 
00083 //! @brief Handle configuration files.
00084 /*! The file syntax used is:
00085  *  - <tt>[</tt><i>section_name</i><tt>]</tt>
00086  *  - one or more entries for that section:<br>
00087  *    <i>field_name</i><tt>:</tt> <i>value</i>
00088  *
00089  *  White space is ignored, but a newline must follow each section or field entry
00090  *
00091  *  The minimal entries required to avoid warnings are (can be any order):
00092  *  - <tt>[</tt><i>chain_name</i><tt>]</tt><br>
00093  *    - <tt>Name: </tt> - a string identifier
00094  *    - <tt>DH: </tt> - whether or not the chain specification is standard Denavit-Hartenberg (non-zero), or modified Denavit-Hartenberg (0)
00095  *    - <tt>Fix: </tt> - ?
00096  *    - <tt>MinPara: </tt> - ?
00097  *    - <tt>dof: </tt> - number of links in the chain
00098  *    - <tt>Motor: </tt> - ?
00099  *    - <tt>Stl: </tt> - ?
00100  *  - For each link <i>N</i>: 1..<i>dof</i><br>
00101  *    <tt>[</tt><i>chain_name</i><tt>_LINK</tt><i>N</i><tt>]</tt>
00102  *    - <tt>joint_type: </tt> - revolute (0), prismatic (1)
00103  *    - <tt>theta: </tt> - DH theta parameter
00104  *    - <tt>d: </tt> - DH d parameter
00105  *    - <tt>a: </tt> - DH a parameter
00106  *    - <tt>alpha: </tt> - DH alpha parameter
00107  *    - <tt>theta_min: </tt> - minimum achievable joint position
00108  *    - <tt>theta_max: </tt> - maximum achievable joint position
00109  *    - <tt>m: </tt> - mass of link
00110  *    - <tt>cx: </tt> - x position of center of gravity for link
00111  *    - <tt>cy: </tt> - y position of center of gravity for link
00112  *    - <tt>cz: </tt> - z position of center of gravity for link
00113  *    - <tt>Ixx: </tt> - xx entry of inertia matrix
00114  *    - <tt>Ixy: </tt> - xy entry of inertia matrix
00115  *    - <tt>Ixz: </tt> - xz entry of inertia matrix
00116  *    - <tt>Iyy: </tt> - yy entry of inertia matrix
00117  *    - <tt>Iyz: </tt> - yz entry of inertia matrix
00118  *    - <tt>Izz: </tt> - zz entry of inertia matrix
00119  *
00120  *  Additional entries may be defined, but will be silently ignored.
00121  */
00122 class Config {
00123 public:
00124    Config() : conf(), filename() {}
00125    Config(const std::string & filename_,bool doRead=false);
00126    Config(const Config & x);
00127    Config & operator=(const Config & x);
00128    short read_conf();
00129    void print();
00130 
00131    bool section_exists(const std::string& section) const;
00132    bool parameter_exists(const std::string& section, const std::string& parameter) const;
00133 
00134    short select_string(const std::string section, const std::string parameter,
00135                        std::string & value) const;
00136    short select_bool(const std::string section, const std::string parameter,
00137                      bool & value) const;
00138    short select_short(const std::string section, const std::string parameter,
00139                       short & value) const;
00140    short select_int(const std::string section, const std::string parameter,
00141                     int & value) const;
00142    short select_float(const std::string section, const std::string parameter,
00143           float & value) const;
00144    short select_double(const std::string section, const std::string parameter,
00145                        double & value) const;
00146    short select_real(const std::string section, const std::string parameter,
00147                        Real & value) const;
00148 
00149    short write_conf(const std::string name, const std::string file_title,
00150                     const int space_between_column);
00151    void add_string(const std::string section, const std::string parameter,
00152                    const std::string value);
00153    void add_bool(const std::string section, const std::string parameter,
00154                  const bool value);
00155    void add_int(const std::string section, const std::string parameter,
00156                 const int value);
00157    void add_float(const std::string section, const std::string parameter,
00158                    const float value);
00159    void add_double(const std::string section, const std::string parameter,
00160                    const double value);
00161    void add_real(const std::string section, const std::string parameter,
00162                    const Real value);
00163 
00164 private:
00165   //! holds configuration data - a map from section name to sub-map of parameters to values
00166   typedef std::map<std::string, std::map<std::string, std::string> > confdata_t;
00167    
00168    confdata_t conf;   //!< Data store from/to configuration file.
00169    std::string filename;  //!< Configuration file name.
00170 };
00171 
00172 #ifdef use_namespace
00173 }
00174 #endif
00175 
00176 #endif 
00177 
00178 
00179 
00180 
00181 
00182 
00183 
00184 
00185 
00186 
00187 
00188 
00189 
00190 
00191 
00192 
00193 
00194 

ROBOOP v1.21a
Generated Thu Nov 22 00:51:28 2007 by Doxygen 1.5.4