Homepage | Demos | Overview | Downloads | Tutorials | Reference | Credits |
config.hGo 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.14 2005/07/26 03:22:09 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 #ifndef __WATCOMC__ 00083 using namespace std; 00084 #endif 00085 00086 00087 //! @brief Handle configuration files. 00088 /*! The file syntax used is: 00089 * - <tt>[</tt><i>section_name</i><tt>]</tt> 00090 * - one or more entries for that section:<br> 00091 * <i>field_name</i><tt>:</tt> <i>value</i> 00092 * 00093 * White space is ignored, but a newline must follow each section or field entry 00094 * 00095 * The minimal entries required to avoid warnings are (can be any order): 00096 * - <tt>[</tt><i>chain_name</i><tt>]</tt><br> 00097 * - <tt>Name: </tt> - a string identifier 00098 * - <tt>DH: </tt> - whether or not the chain specification is standard Denavit-Hartenberg (non-zero), or modified Denavit-Hartenberg (0) 00099 * - <tt>Fix: </tt> - ? 00100 * - <tt>MinPara: </tt> - ? 00101 * - <tt>dof: </tt> - number of links in the chain 00102 * - <tt>Motor: </tt> - ? 00103 * - <tt>Stl: </tt> - ? 00104 * - For each link <i>N</i>: 1..<i>dof</i><br> 00105 * <tt>[</tt><i>chain_name</i><tt>_LINK</tt><i>N</i><tt>]</tt> 00106 * - <tt>joint_type: </tt> - revolute (0), prismatic (1) 00107 * - <tt>theta: </tt> - DH theta parameter 00108 * - <tt>d: </tt> - DH d parameter 00109 * - <tt>a: </tt> - DH a parameter 00110 * - <tt>alpha: </tt> - DH alpha parameter 00111 * - <tt>theta_min: </tt> - minimum achievable joint position 00112 * - <tt>theta_max: </tt> - maximum achievable joint position 00113 * - <tt>m: </tt> - mass of link 00114 * - <tt>cx: </tt> - x position of center of gravity for link 00115 * - <tt>cy: </tt> - y position of center of gravity for link 00116 * - <tt>cz: </tt> - z position of center of gravity for link 00117 * - <tt>Ixx: </tt> - xx entry of inertia matrix 00118 * - <tt>Ixy: </tt> - xy entry of inertia matrix 00119 * - <tt>Ixz: </tt> - xz entry of inertia matrix 00120 * - <tt>Iyy: </tt> - yy entry of inertia matrix 00121 * - <tt>Iyz: </tt> - yz entry of inertia matrix 00122 * - <tt>Izz: </tt> - zz entry of inertia matrix 00123 * 00124 * Additional entries may be defined, but will be silently ignored. 00125 */ 00126 class Config { 00127 public: 00128 Config() : conf(), filename() {} 00129 Config(const string & filename_,bool doRead=false); 00130 Config(const Config & x); 00131 Config & operator=(const Config & x); 00132 short read_conf(); 00133 void print(); 00134 00135 bool section_exists(const string& section) const; 00136 bool parameter_exists(const string& section, const string& parameter) const; 00137 00138 short select_string(const string section, const string parameter, 00139 string & value) const; 00140 short select_bool(const string section, const string parameter, 00141 bool & value) const; 00142 short select_short(const string section, const string parameter, 00143 short & value) const; 00144 short select_int(const string section, const string parameter, 00145 int & value) const; 00146 short select_float(const string section, const string parameter, 00147 float & value) const; 00148 short select_double(const string section, const string parameter, 00149 double & value) const; 00150 short select_real(const string section, const string parameter, 00151 Real & value) const; 00152 00153 short write_conf(const string name, const string file_title, 00154 const int space_between_column); 00155 void add_string(const string section, const string parameter, 00156 const string value); 00157 void add_bool(const string section, const string parameter, 00158 const bool value); 00159 void add_int(const string section, const string parameter, 00160 const int value); 00161 void add_float(const string section, const string parameter, 00162 const float value); 00163 void add_double(const string section, const string parameter, 00164 const double value); 00165 void add_real(const string section, const string parameter, 00166 const Real value); 00167 00168 private: 00169 //! holds configuration data - a map from section name to sub-map of parameters to values 00170 typedef map<string, map<string, string> > confdata_t; 00171 00172 confdata_t conf; //!< Data store from/to configuration file. 00173 string filename; //!< Configuration file name. 00174 }; 00175 00176 #ifdef use_namespace 00177 } 00178 #endif 00179 00180 #endif 00181 00182 00183 00184 00185 00186 00187 00188 00189 00190 00191 00192 00193 00194 00195 00196 00197 00198 |
ROBOOP v1.21a |
Generated Tue Aug 16 16:32:14 2005 by Doxygen 1.4.4 |