Main MRPT website > C++ reference
MRPT logo
CLoadableOptions.h
Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                       http://www.mrpt.org/                                |
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          * \ingroup mrpt_base_grp
00046          */
00047         class BASE_IMPEXP  CLoadableOptions
00048         {
00049         protected:
00050 
00051                 /** Used to print variable info from dumpToTextStream with the macro LOADABLEOPTS_DUMP_VAR */
00052                 static void dumpVar_int( CStream &out, const char *varName, int v );
00053                 static void dumpVar_float( CStream &out, const char *varName, float v );
00054                 static void dumpVar_double( CStream &out, const char *varName, double v );
00055                 static void dumpVar_bool( CStream &out, const char *varName, bool v );
00056                 static void dumpVar_string( CStream &out, const char *varName, const std::string &v );
00057 
00058 
00059         public:
00060                 /** This method load the options from a ".ini"-like file or memory-stored string list.
00061                  *   Only those parameters found in the given "section" and having
00062                  *   the same name that the variable are loaded. Those not found in
00063                  *   the file will stay with their previous values (usually the default
00064                  *   values loaded at initialization). An example of an ".ini" file:
00065                  *  \code
00066                  *  [section]
00067                  *      resolution=0.10         ; blah blah...
00068                  *      modeSelection=1         ; 0=blah, 1=blah,...
00069                  *  \endcode
00070                  *
00071                  * \sa loadFromConfigFileName, saveToConfigFile
00072                  */
00073                 virtual void  loadFromConfigFile(
00074                         const mrpt::utils::CConfigFileBase      &source,
00075                         const std::string               &section) = 0;
00076 
00077                 /** Behaves like loadFromConfigFile, but you can pass directly a file name and a temporary CConfigFile object will be created automatically to load the file.
00078                   * \sa loadFromConfigFile
00079                   */
00080                 void  loadFromConfigFileName(
00081                         const std::string               &config_file,
00082                         const std::string               &section);
00083 
00084                 /** This method saves the options to a ".ini"-like file or memory-stored string list.
00085                  * \sa loadFromConfigFile, saveToConfigFileName
00086                  */
00087                 virtual void  saveToConfigFile(
00088                         mrpt::utils::CConfigFileBase    &source,
00089                         const std::string               &section) /*= 0*/
00090                         {
00091                                 THROW_EXCEPTION("The child class does not implement this method.");
00092                         }
00093 
00094 
00095                 /** Behaves like saveToConfigFile, but you can pass directly a file name and a temporary CConfigFile object will be created automatically to save the file.
00096                   * \sa saveToConfigFile, loadFromConfigFileName
00097                   */
00098                 void  saveToConfigFileName(
00099                         const std::string               &config_file,
00100                         const std::string               &section);
00101 
00102                 /** This method must display clearly all the contents of the structure in textual form, sending it to a CStream.
00103                   */
00104                 void  dumpToConsole() const;
00105 
00106                 /** This method must display clearly all the contents of the structure in textual form, sending it to a CStream.
00107                   */
00108                 virtual void  dumpToTextStream( CStream         &out) const = 0;
00109 
00110         /** Virtual destructor
00111           */
00112         virtual ~CLoadableOptions()
00113                 {
00114                 }
00115 
00116         }; // End of class def.
00117 
00118         /** Macro for dumping a variable to a stream, within the method "dumpToTextStream(out)" (Variable types are: int, double, float, bool, string  */
00119         #define LOADABLEOPTS_DUMP_VAR(variableName,variableType) { dumpVar_##variableType(out, #variableName,static_cast<variableType>(variableName)); }
00120 
00121         /** Macro for dumping a variable to a stream, transforming the argument from radians to degrees.  */
00122         #define LOADABLEOPTS_DUMP_VAR_DEG(variableName) { dumpVar_double(out, #variableName,RAD2DEG(static_cast<double>(variableName))); }
00123 
00124         } // End of namespace
00125 } // end of namespace
00126 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011