00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2009 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 a ".ini" file 00044 */ 00045 class MRPTDLLIMPEXP CLoadableOptions 00046 { 00047 protected: 00048 00049 /** Used to print variable info from dumpToTextStream with the macro LOADABLEOPTS_DUMP_VAR */ 00050 static void dumpVar_int( CStream &out, const char *varName, int v ); 00051 static void dumpVar_float( CStream &out, const char *varName, float v ); 00052 static void dumpVar_double( CStream &out, const char *varName, double v ); 00053 static void dumpVar_bool( CStream &out, const char *varName, bool v ); 00054 static void dumpVar_string( CStream &out, const char *varName, const std::string &v ); 00055 00056 00057 public: 00058 /** This method load the options from a ".ini"-like file or memory-stored string list. 00059 * Only those parameters found in the given "section" and having 00060 * the same name that the variable are loaded. Those not found in 00061 * the file will stay with their previous values (usually the default 00062 * values loaded at initialization). An example of an ".ini" file: 00063 * \code 00064 * [section] 00065 * resolution=0.10 ; blah blah... 00066 * modeSelection=1 ; 0=blah, 1=blah,... 00067 * \endcode 00068 */ 00069 virtual void loadFromConfigFile( 00070 const mrpt::utils::CConfigFileBase &source, 00071 const std::string §ion) = 0; 00072 00073 /** This method must display clearly all the contents of the structure in textual form, sending it to a CStream. 00074 */ 00075 void dumpToConsole() const; 00076 00077 /** This method must display clearly all the contents of the structure in textual form, sending it to a CStream. 00078 */ 00079 virtual void dumpToTextStream( CStream &out) const = 0; 00080 00081 /** Virtual destructor 00082 */ 00083 virtual ~CLoadableOptions() 00084 { 00085 } 00086 00087 }; // End of class def. 00088 00089 /** Macro for dumping a variable to a stream, within the method "dumpToTextStream(out)" (Variable types are: int, double, float, bool, string */ 00090 #define LOADABLEOPTS_DUMP_VAR(variableName,variableType) { dumpVar_##variableType(out, #variableName,static_cast<variableType>(variableName)); } 00091 00092 } // End of namespace 00093 } // end of namespace 00094 #endif
Page generated by Doxygen 1.5.9 for MRPT 0.7.1 SVN: at Mon Aug 17 22:27:43 EDT 2009 |