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 */ 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.11 2004/12/22 19:18:48 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 /*! The file syntax used is: 00105 * - <tt>[</tt><i>section_name</i><tt>]</tt> 00106 * - one or more entries for that section:<br> 00107 * <i>field_name</i><tt>:</tt> <i>value</i> 00108 * 00109 * White space is ignored, but a newline must follow each section or field entry 00110 * 00111 * The minimal entries required to avoid warnings are (can be any order): 00112 * - <tt>[</tt><i>chain_name</i><tt>]</tt><br> 00113 * - <tt>Name: </tt> - a string identifier 00114 * - <tt>DH: </tt> - whether or not the chain specification is standard Denavitt-Hartenberg (non-zero), or modified Denavitt-Hartenberg (0) 00115 * - <tt>Fix: </tt> - ? 00116 * - <tt>MinPara: </tt> - ? 00117 * - <tt>dof: </tt> - number of links in the chain 00118 * - <tt>Motor: </tt> - ? 00119 * - <tt>Stl: </tt> - ? 00120 * - For each link <i>N</i>: 1..<i>dof</i><br> 00121 * <tt>[</tt><i>chain_name</i><tt>_LINK</tt><i>N</i><tt>]</tt> 00122 * - <tt>joint_type: </tt> - revolute (0), prismatic (1) 00123 * - <tt>theta: </tt> - DH theta parameter 00124 * - <tt>d: </tt> - DH d parameter 00125 * - <tt>a: </tt> - DH a parameter 00126 * - <tt>alpha: </tt> - DH alpha parameter 00127 * - <tt>theta_min: </tt> - minimum achievable joint position 00128 * - <tt>theta_max: </tt> - maximum achievable joint position 00129 * - <tt>m: </tt> - mass of link 00130 * - <tt>cx: </tt> - x position of center of gravity for link 00131 * - <tt>cy: </tt> - y position of center of gravity for link 00132 * - <tt>cz: </tt> - z position of center of gravity for link 00133 * - <tt>Ixx: </tt> - xx entry of inertia matrix 00134 * - <tt>Ixy: </tt> - xy entry of inertia matrix 00135 * - <tt>Ixz: </tt> - xz entry of inertia matrix 00136 * - <tt>Iyy: </tt> - yy entry of inertia matrix 00137 * - <tt>Iyz: </tt> - yz entry of inertia matrix 00138 * - <tt>Izz: </tt> - zz entry of inertia matrix 00139 * 00140 * Additional entries may be defined, but will be silently ignored. 00141 */ 00142 class Config { 00143 public: 00144 Config() : conf(), filename() {} 00145 Config(const string & filename_,bool doRead=false); 00146 Config(const Config & x); 00147 Config & operator=(const Config & x); 00148 short read_conf(); 00149 void print(); 00150 00151 bool section_exists(const string& section) const; 00152 bool parameter_exists(const string& section, const string& parameter) const; 00153 00154 short select_string(const string section, const string parameter, 00155 string & value) const; 00156 short select_bool(const string section, const string parameter, 00157 bool & value) const; 00158 short select_short(const string section, const string parameter, 00159 short & value) const; 00160 short select_int(const string section, const string parameter, 00161 int & value) const; 00162 short select_float(const string section, const string parameter, 00163 float & value) const; 00164 short select_double(const string section, const string parameter, 00165 double & value) const; 00166 short select_real(const string section, const string parameter, 00167 Real & value) const; 00168 00169 short write_conf(const string name, const string file_title, 00170 const int space_between_column); 00171 void add_string(const string section, const string parameter, 00172 const string value); 00173 void add_bool(const string section, const string parameter, 00174 const bool value); 00175 void add_int(const string section, const string parameter, 00176 const int value); 00177 void add_float(const string section, const string parameter, 00178 const float value); 00179 void add_double(const string section, const string parameter, 00180 const double value); 00181 void add_real(const string section, const string parameter, 00182 const Real value); 00183 00184 private: 00185 Conf_data conf; //!< Data store from/to configuration file. 00186 string filename; //!< Configuration file name. 00187 }; 00188 00189 #ifdef use_namespace 00190 } 00191 #endif 00192 00193 #endif 00194 00195 00196 00197 00198 00199 00200 00201 00202 00203 00204 00205 00206 00207 00208 00209 00210 00211 |
ROBOOP v1.21a |
Generated Tue Jan 4 15:42:24 2005 by Doxygen 1.4.0 |