00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2011 University of Malaga | 00007 | | 00008 | This software was written by the Machine Perception and Intelligent | 00009 | Robotics Lab, University of Malaga (Spain). | 00010 | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> | 00011 | | 00012 | This file is part of the MRPT project. | 00013 | | 00014 | MRPT is free software: you can redistribute it and/or modify | 00015 | it under the terms of the GNU General Public License as published by | 00016 | the Free Software Foundation, either version 3 of the License, or | 00017 | (at your option) any later version. | 00018 | | 00019 | MRPT is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 00022 | GNU General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU General Public License | 00025 | along with MRPT. If not, see <http://www.gnu.org/licenses/>. | 00026 | | 00027 +---------------------------------------------------------------------------+ */ 00028 #ifndef CLoadableOptions_H 00029 #define CLoadableOptions_H 00030 00031 #include <mrpt/utils/utils_defs.h> 00032 #include <mrpt/utils/CConfigFileBase.h> 00033 #include <mrpt/utils/CStream.h> 00034 #include <mrpt/system/os.h> 00035 00036 /*--------------------------------------------------------------- 00037 Class 00038 ---------------------------------------------------------------*/ 00039 namespace mrpt 00040 { 00041 namespace utils 00042 { 00043 /** This is a virtual base class for sets of options than can be loaded from and/or saved to configuration plain-text files. 00044 * \todo Automatize this class thru a proxy auxiliary class where variables are registered from pointers, etc... 00045 */ 00046 class BASE_IMPEXP CLoadableOptions 00047 { 00048 protected: 00049 00050 /** Used to print variable info from dumpToTextStream with the macro LOADABLEOPTS_DUMP_VAR */ 00051 static void dumpVar_int( CStream &out, const char *varName, int v ); 00052 static void dumpVar_float( CStream &out, const char *varName, float v ); 00053 static void dumpVar_double( CStream &out, const char *varName, double v ); 00054 static void dumpVar_bool( CStream &out, const char *varName, bool v ); 00055 static void dumpVar_string( CStream &out, const char *varName, const std::string &v ); 00056 00057 00058 public: 00059 /** This method load the options from a ".ini"-like file or memory-stored string list. 00060 * Only those parameters found in the given "section" and having 00061 * the same name that the variable are loaded. Those not found in 00062 * the file will stay with their previous values (usually the default 00063 * values loaded at initialization). An example of an ".ini" file: 00064 * \code 00065 * [section] 00066 * resolution=0.10 ; blah blah... 00067 * modeSelection=1 ; 0=blah, 1=blah,... 00068 * \endcode 00069 * 00070 * \sa loadFromConfigFileName, saveToConfigFile 00071 */ 00072 virtual void loadFromConfigFile( 00073 const mrpt::utils::CConfigFileBase &source, 00074 const std::string §ion) = 0; 00075 00076 /** Behaves like loadFromConfigFile, but you can pass directly a file name and a temporary CConfigFile object will be created automatically to load the file. 00077 * \sa loadFromConfigFile 00078 */ 00079 void loadFromConfigFileName( 00080 const std::string &config_file, 00081 const std::string §ion); 00082 00083 /** This method saves the options to a ".ini"-like file or memory-stored string list. 00084 * \sa loadFromConfigFile, saveToConfigFileName 00085 */ 00086 virtual void saveToConfigFile( 00087 mrpt::utils::CConfigFileBase &source, 00088 const std::string §ion) /*= 0*/ 00089 { 00090 THROW_EXCEPTION("The child class does not implement this method."); 00091 } 00092 00093 00094 /** Behaves like saveToConfigFile, but you can pass directly a file name and a temporary CConfigFile object will be created automatically to save the file. 00095 * \sa saveToConfigFile, loadFromConfigFileName 00096 */ 00097 void saveToConfigFileName( 00098 const std::string &config_file, 00099 const std::string §ion); 00100 00101 /** This method must display clearly all the contents of the structure in textual form, sending it to a CStream. 00102 */ 00103 void dumpToConsole() const; 00104 00105 /** This method must display clearly all the contents of the structure in textual form, sending it to a CStream. 00106 */ 00107 virtual void dumpToTextStream( CStream &out) const = 0; 00108 00109 /** Virtual destructor 00110 */ 00111 virtual ~CLoadableOptions() 00112 { 00113 } 00114 00115 }; // End of class def. 00116 00117 /** Macro for dumping a variable to a stream, within the method "dumpToTextStream(out)" (Variable types are: int, double, float, bool, string */ 00118 #define LOADABLEOPTS_DUMP_VAR(variableName,variableType) { dumpVar_##variableType(out, #variableName,static_cast<variableType>(variableName)); } 00119 00120 /** Macro for dumping a variable to a stream, transforming the argument from radians to degrees. */ 00121 #define LOADABLEOPTS_DUMP_VAR_DEG(variableName) { dumpVar_double(out, #variableName,RAD2DEG(static_cast<double>(variableName))); } 00122 00123 } // End of namespace 00124 } // end of namespace 00125 #endif
Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:40:17 UTC 2011 |