annotate src/Support/Parameters.h @ 0:582cbe817f2c

- Initial add of support code and modules. Not everything is working yet.
author tomwalters
date Fri, 12 Feb 2010 12:31:23 +0000
parents
children bc394a985042
rev   line source
tomwalters@0 1 // Copyright 2006-2010, Willem van Engen
tomwalters@0 2 //
tomwalters@0 3 // AIM-C: A C++ implementation of the Auditory Image Model
tomwalters@0 4 // http://www.acousticscale.org/AIMC
tomwalters@0 5 //
tomwalters@0 6 // This program is free software: you can redistribute it and/or modify
tomwalters@0 7 // it under the terms of the GNU General Public License as published by
tomwalters@0 8 // the Free Software Foundation, either version 3 of the License, or
tomwalters@0 9 // (at your option) any later version.
tomwalters@0 10 //
tomwalters@0 11 // This program is distributed in the hope that it will be useful,
tomwalters@0 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
tomwalters@0 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
tomwalters@0 14 // GNU General Public License for more details.
tomwalters@0 15 //
tomwalters@0 16 // You should have received a copy of the GNU General Public License
tomwalters@0 17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
tomwalters@0 18
tomwalters@0 19 //!
tomwalters@0 20 //! \file
tomwalters@0 21 //! \brief Main parameters store
tomwalters@0 22 //!
tomwalters@0 23 //! \author Willem van Engen <cnbh@willem.engen.nl>
tomwalters@0 24 //! \date created 2006/09/21
tomwalters@0 25 //! \version \$Id: Parameters.h 4 2010-02-03 18:44:58Z tcw $
tomwalters@0 26
tomwalters@0 27 #ifndef _AIMC_SUPPORT_PARAMETERS_H_
tomwalters@0 28 #define _AIMC_SUPPORT_PARAMETERS_H_
tomwalters@0 29
tomwalters@0 30 // If not _WINDOWS, please compile in Support/ConvertUTF.c
tomwalters@0 31 #ifdef _UNICODE
tomwalters@0 32 // Here we want to use the ANSI version of all the non wxWidgets stuff, but
tomwalters@0 33 // convert stribngs to Unicode when used in wxWidgets. This allows all the
tomwalters@0 34 // string handling in the non-GUI version to use ANSI text only, but to pass
tomwalters@0 35 // unicode text to the GUI
tomwalters@0 36 #undef _UNICODE
tomwalters@0 37 #include "Support/SimpleIni.h"
tomwalters@0 38 #define _UNICODE
tomwalters@0 39 #else
tomwalters@0 40 #include "Support/SimpleIni.h"
tomwalters@0 41 #endif
tomwalters@0 42
tomwalters@0 43 namespace aimc {
tomwalters@0 44 /*!
tomwalters@0 45 * \class Parameters "Support/Parameters.h"
tomwalters@0 46 * \brief Main parameter store for parameters
tomwalters@0 47 */
tomwalters@0 48 class Parameters {
tomwalters@0 49 public:
tomwalters@0 50 Parameters();
tomwalters@0 51 ~Parameters();
tomwalters@0 52
tomwalters@0 53 /*!
tomwalters@0 54 * \brief Load parameter file
tomwalters@0 55 * \param sParamFilename Filename of parameter file to read
tomwalters@0 56 * \return true on succes, false on error
tomwalters@0 57 *
tomwalters@0 58 */
tomwalters@0 59 bool Load(const char *sParamFilename);
tomwalters@0 60
tomwalters@0 61 /*! \brief Save Parameter File
tomwalters@0 62 * \param sParamFilename Filename of parameter file to save
tomwalters@0 63 * \return true on success, false on error
tomwalters@0 64 */
tomwalters@0 65 bool Save(const char *sParamFilename);
tomwalters@0 66
tomwalters@0 67 /*!
tomwalters@0 68 * \brief Load parameter file and merge parameters with current, overwriting
tomwalters@0 69 * duplicates.
tomwalters@0 70 * \param sParamFilename Filename of parameter file to read
tomwalters@0 71 * \return true on succes, false on error
tomwalters@0 72 */
tomwalters@0 73 bool Merge(const char *sParamFilename);
tomwalters@0 74
tomwalters@0 75 /*! \brief Get a parameter, setting it with a default value if it is not
tomwalters@0 76 * already set
tomwalters@0 77 * \param sName Name of parameter
tomwalters@0 78 * \param val Value of the parameter
tomwalters@0 79 */
tomwalters@0 80 const char * DefaultString(const char* sName, const char *val);
tomwalters@0 81
tomwalters@0 82 /*! \overload
tomwalters@0 83 */
tomwalters@0 84 int DefaultInt(const char* sName, int val);
tomwalters@0 85
tomwalters@0 86 /*! \overload
tomwalters@0 87 */
tomwalters@0 88 unsigned int DefaultUInt(const char* sName, unsigned int val);
tomwalters@0 89
tomwalters@0 90 /*! \overload
tomwalters@0 91 */
tomwalters@0 92 float DefaultFloat(const char* sName, float val);
tomwalters@0 93
tomwalters@0 94 /*! \overload
tomwalters@0 95 */
tomwalters@0 96 bool DefaultBool(const char* sName, bool val);
tomwalters@0 97
tomwalters@0 98
tomwalters@0 99 /*! \brief Set a parameter
tomwalters@0 100 * \param sName Name of parameter
tomwalters@0 101 * \param val Value of parameter
tomwalters@0 102 */
tomwalters@0 103 void SetString(const char *sName, const char *val);
tomwalters@0 104
tomwalters@0 105 /*! \overload
tomwalters@0 106 */
tomwalters@0 107 void SetInt(const char *sName, int val);
tomwalters@0 108
tomwalters@0 109 /*! \overload
tomwalters@0 110 */
tomwalters@0 111 void SetUInt(const char *sName, unsigned int val);
tomwalters@0 112
tomwalters@0 113 /*! \overload
tomwalters@0 114 */
tomwalters@0 115 void SetFloat(const char *sName, float val);
tomwalters@0 116
tomwalters@0 117 /*! \overload
tomwalters@0 118 */
tomwalters@0 119 void SetBool(const char *sName, bool val);
tomwalters@0 120
tomwalters@0 121 /*! \brief Get the value of a parameter
tomwalters@0 122 * \param sName Name of parameter
tomwalters@0 123 * \return Value of parameter
tomwalters@0 124 *
tomwalters@0 125 * The specified parameter _must_ exist. So put every parameter you may
tomwalters@0 126 * possibly require into the default parameter file. This method returns
tomwalters@0 127 * the empty string when a value doesn't exist, but that is only to keep
tomwalters@0 128 * the application from crashing: don't count on it.
tomwalters@0 129 * You can use IsSet() however to check for a parameter's existence.
tomwalters@0 130 */
tomwalters@0 131 const char *GetString(const char *sName);
tomwalters@0 132
tomwalters@0 133 /*! \overload
tomwalters@0 134 */
tomwalters@0 135 int GetInt(const char *sName);
tomwalters@0 136
tomwalters@0 137 /*! \overload
tomwalters@0 138 */
tomwalters@0 139 unsigned int GetUInt(const char *sName);
tomwalters@0 140
tomwalters@0 141 /*! \overload
tomwalters@0 142 */
tomwalters@0 143 float GetFloat(const char *sName);
tomwalters@0 144
tomwalters@0 145 /*! \overload
tomwalters@0 146 */
tomwalters@0 147 bool GetBool(const char *sName);
tomwalters@0 148
tomwalters@0 149 /*! \brief Returns if the parameters exists or not
tomwalters@0 150 * \param sName Name of parameter
tomwalters@0 151 * \return true if exists, false if not
tomwalters@0 152 */
tomwalters@0 153 bool IsSet(const char *sName);
tomwalters@0 154
tomwalters@0 155 /*! \brief Sets a parameter assignment from a string
tomwalters@0 156 * \param sCmd String to parse
tomwalters@0 157 * \return true if parsing succeeded, false if an error occured.
tomwalters@0 158 *
tomwalters@0 159 * This function parses a string like "foo.bar=50" and sets the parameter
tomwalters@0 160 * accordingly. Use this function to parse parameter assignments as given
tomwalters@0 161 * by the user, for example on the command-line or in a parameter file.
tomwalters@0 162 */
tomwalters@0 163 bool Parse(const char *sCmd);
tomwalters@0 164
tomwalters@0 165 /*! \brief Delete a parameter. GetSection may not return correctly after
tomwalters@0 166 * this call, so it may not be possible to repopulate the parameter grid
tomwalters@0 167 * after deleting a parameter
tomwalters@0 168 * \param sName Parameter name
tomwalters@0 169 * \return true on success
tomwalters@0 170 */
tomwalters@0 171 bool Delete(const char *sName);
tomwalters@0 172
tomwalters@0 173 //! \brief Maximum length of a parameter name in characters
tomwalters@0 174 static const unsigned int MaxParamNameLength = 128;
tomwalters@0 175
tomwalters@0 176 protected:
tomwalters@0 177 /*!
tomwalters@0 178 * \brief Load parameter file
tomwalters@0 179 * \param sParamFilename Filename of parameter file to read
tomwalters@0 180 * \return true on succes, false on error
tomwalters@0 181 */
tomwalters@0 182 bool LoadFile(const char *sParamFilename);
tomwalters@0 183 /*!
tomwalters@0 184 * \brief Load parameter file and merge parameters with current,
tomwalters@0 185 * overwriting duplicates.
tomwalters@0 186 * \param sParamFilename Filename of parameter file to read
tomwalters@0 187 * \return true on succes, false on error
tomwalters@0 188 */
tomwalters@0 189 bool MergeFile(const char *sParamFilename);
tomwalters@0 190
tomwalters@0 191 /*! \brief Default ini-section to use
tomwalters@0 192 *
tomwalters@0 193 * Since SimpleIni is an ini-parser but we don't want the sections,
tomwalters@0 194 * we use the empty section. This gives use the behaviour desired.
tomwalters@0 195 */
tomwalters@0 196 static const char *m_SDefaultIniSection;
tomwalters@0 197
tomwalters@0 198 //! \brief Parameter file object
tomwalters@0 199 CSimpleIniCase *m_pIni;
tomwalters@0 200 //! \brief \c preset.include nesting counter to avoid loops
tomwalters@0 201 unsigned int m_iNestCount;
tomwalters@0 202 //! \brief maximum value m_iNestCount may reach
tomwalters@0 203 static const unsigned int m_iNestCountMaximum = 16;
tomwalters@0 204 };
tomwalters@0 205 }
tomwalters@0 206
tomwalters@0 207 #endif // _AIMC_SUPPORT_PARAMETERS_H_
tomwalters@0 208