annotate trunk/src/Support/Parameters.h @ 706:f8e90b5d85fd tip

Delete CARFAC code from this repository. It has been moved to https://github.com/google/carfac Please email me with your github username to get access. I've also created a new mailing list to discuss CARFAC development: https://groups.google.com/forum/#!forum/carfac-dev
author ronw@google.com
date Thu, 18 Jul 2013 20:56:51 +0000
parents 30dde71d0230
children
rev   line source
tomwalters@280 1 // Copyright 2006-2010, Willem van Engen, Thomas Walters
tomwalters@268 2 //
tomwalters@268 3 // AIM-C: A C++ implementation of the Auditory Image Model
tomwalters@268 4 // http://www.acousticscale.org/AIMC
tomwalters@268 5 //
tomwalters@318 6 // Licensed under the Apache License, Version 2.0 (the "License");
tomwalters@318 7 // you may not use this file except in compliance with the License.
tomwalters@318 8 // You may obtain a copy of the License at
tomwalters@268 9 //
tomwalters@318 10 // http://www.apache.org/licenses/LICENSE-2.0
tomwalters@268 11 //
tomwalters@318 12 // Unless required by applicable law or agreed to in writing, software
tomwalters@318 13 // distributed under the License is distributed on an "AS IS" BASIS,
tomwalters@318 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tomwalters@318 15 // See the License for the specific language governing permissions and
tomwalters@318 16 // limitations under the License.
tomwalters@268 17
tomwalters@280 18 /*!
tomwalters@280 19 * \file
tomwalters@280 20 * \brief Main parameters store
tomwalters@280 21 *
tomwalters@280 22 * \author Willem van Engen <cnbh@willem.engen.nl>
tomwalters@280 23 * \author Thomas Walters <tom@acousticscale.org>
tomwalters@280 24 * \date created 2006/09/21
tomwalters@296 25 * \version \$Id$
tomwalters@280 26 */
tomwalters@268 27
tomwalters@283 28 #ifndef AIMC_SUPPORT_PARAMETERS_H_
tomwalters@283 29 #define AIMC_SUPPORT_PARAMETERS_H_
tomwalters@268 30
tomwalters@273 31 #include <string>
tomwalters@273 32
tomwalters@268 33 #include "Support/SimpleIni.h"
tomwalters@268 34
tomwalters@268 35 namespace aimc {
tomwalters@268 36 /*!
tomwalters@268 37 * \class Parameters "Support/Parameters.h"
tomwalters@268 38 * \brief Main parameter store for parameters
tomwalters@268 39 */
tomwalters@268 40 class Parameters {
tomwalters@280 41 public:
tomwalters@268 42 Parameters();
tomwalters@268 43 ~Parameters();
tomwalters@268 44
tomwalters@268 45 /*!
tomwalters@268 46 * \brief Load parameter file
tomwalters@268 47 * \param sParamFilename Filename of parameter file to read
tomwalters@268 48 * \return true on succes, false on error
tomwalters@268 49 *
tomwalters@268 50 */
tomwalters@268 51 bool Load(const char *sParamFilename);
tomwalters@268 52
tomwalters@268 53 /*! \brief Save Parameter File
tomwalters@268 54 * \param sParamFilename Filename of parameter file to save
tomwalters@268 55 * \return true on success, false on error
tomwalters@268 56 */
tomwalters@268 57 bool Save(const char *sParamFilename);
tomwalters@268 58
tomwalters@268 59 /*!
tomwalters@268 60 * \brief Load parameter file and merge parameters with current, overwriting
tomwalters@268 61 * duplicates.
tomwalters@268 62 * \param sParamFilename Filename of parameter file to read
tomwalters@268 63 * \return true on succes, false on error
tomwalters@268 64 */
tomwalters@268 65 bool Merge(const char *sParamFilename);
tomwalters@268 66
tomwalters@268 67 /*! \brief Get a parameter, setting it with a default value if it is not
tomwalters@268 68 * already set
tomwalters@268 69 * \param sName Name of parameter
tomwalters@268 70 * \param val Value of the parameter
tomwalters@268 71 */
tomwalters@268 72 const char * DefaultString(const char* sName, const char *val);
tomwalters@268 73
tomwalters@268 74 /*! \overload
tomwalters@268 75 */
tomwalters@268 76 int DefaultInt(const char* sName, int val);
tomwalters@268 77
tomwalters@268 78 /*! \overload
tomwalters@268 79 */
tomwalters@268 80 unsigned int DefaultUInt(const char* sName, unsigned int val);
tomwalters@268 81
tomwalters@268 82 /*! \overload
tomwalters@268 83 */
tomwalters@268 84 float DefaultFloat(const char* sName, float val);
tomwalters@268 85
tomwalters@268 86 /*! \overload
tomwalters@268 87 */
tomwalters@268 88 bool DefaultBool(const char* sName, bool val);
tomwalters@268 89
tomwalters@268 90
tomwalters@268 91 /*! \brief Set a parameter
tomwalters@268 92 * \param sName Name of parameter
tomwalters@268 93 * \param val Value of parameter
tomwalters@268 94 */
tomwalters@268 95 void SetString(const char *sName, const char *val);
tomwalters@268 96
tomwalters@268 97 /*! \overload
tomwalters@268 98 */
tomwalters@268 99 void SetInt(const char *sName, int val);
tomwalters@268 100
tomwalters@268 101 /*! \overload
tomwalters@268 102 */
tomwalters@268 103 void SetUInt(const char *sName, unsigned int val);
tomwalters@268 104
tomwalters@268 105 /*! \overload
tomwalters@268 106 */
tomwalters@268 107 void SetFloat(const char *sName, float val);
tomwalters@268 108
tomwalters@268 109 /*! \overload
tomwalters@268 110 */
tomwalters@268 111 void SetBool(const char *sName, bool val);
tomwalters@268 112
tomwalters@268 113 /*! \brief Get the value of a parameter
tomwalters@268 114 * \param sName Name of parameter
tomwalters@268 115 * \return Value of parameter
tomwalters@268 116 *
tomwalters@268 117 * The specified parameter _must_ exist. So put every parameter you may
tomwalters@268 118 * possibly require into the default parameter file. This method returns
tomwalters@268 119 * the empty string when a value doesn't exist, but that is only to keep
tomwalters@268 120 * the application from crashing: don't count on it.
tomwalters@268 121 * You can use IsSet() however to check for a parameter's existence.
tomwalters@268 122 */
tomwalters@268 123 const char *GetString(const char *sName);
tomwalters@268 124
tomwalters@268 125 /*! \overload
tomwalters@268 126 */
tomwalters@268 127 int GetInt(const char *sName);
tomwalters@268 128
tomwalters@268 129 /*! \overload
tomwalters@268 130 */
tomwalters@268 131 unsigned int GetUInt(const char *sName);
tomwalters@268 132
tomwalters@268 133 /*! \overload
tomwalters@268 134 */
tomwalters@268 135 float GetFloat(const char *sName);
tomwalters@268 136
tomwalters@268 137 /*! \overload
tomwalters@268 138 */
tomwalters@268 139 bool GetBool(const char *sName);
tomwalters@268 140
tomwalters@268 141 /*! \brief Returns if the parameters exists or not
tomwalters@268 142 * \param sName Name of parameter
tomwalters@268 143 * \return true if exists, false if not
tomwalters@268 144 */
tomwalters@268 145 bool IsSet(const char *sName);
tomwalters@268 146
tomwalters@268 147 /*! \brief Sets a parameter assignment from a string
tomwalters@268 148 * \param sCmd String to parse
tomwalters@268 149 * \return true if parsing succeeded, false if an error occured.
tomwalters@268 150 *
tomwalters@268 151 * This function parses a string like "foo.bar=50" and sets the parameter
tomwalters@268 152 * accordingly. Use this function to parse parameter assignments as given
tomwalters@268 153 * by the user, for example on the command-line or in a parameter file.
tomwalters@268 154 */
tomwalters@268 155 bool Parse(const char *sCmd);
tomwalters@268 156
tomwalters@268 157 /*! \brief Delete a parameter. GetSection may not return correctly after
tomwalters@268 158 * this call, so it may not be possible to repopulate the parameter grid
tomwalters@268 159 * after deleting a parameter
tomwalters@268 160 * \param sName Parameter name
tomwalters@268 161 * \return true on success
tomwalters@268 162 */
tomwalters@268 163 bool Delete(const char *sName);
tomwalters@268 164
tomwalters@273 165 /*! \brief Append parameters to a string
tomwalters@273 166 * \param sName pointer to a string
tomwalters@273 167 * \return true on success
tomwalters@273 168 */
tomwalters@280 169 std::string WriteString();
tomwalters@273 170
tomwalters@280 171 /*! \brief Maximum length of a parameter name in characters
tomwalters@280 172 */
tomwalters@268 173 static const unsigned int MaxParamNameLength = 128;
tomwalters@268 174
tomwalters@280 175 protected:
tomwalters@268 176 /*!
tomwalters@268 177 * \brief Load parameter file
tomwalters@268 178 * \param sParamFilename Filename of parameter file to read
tomwalters@268 179 * \return true on succes, false on error
tomwalters@268 180 */
tomwalters@268 181 bool LoadFile(const char *sParamFilename);
tomwalters@268 182 /*!
tomwalters@268 183 * \brief Load parameter file and merge parameters with current,
tomwalters@268 184 * overwriting duplicates.
tomwalters@268 185 * \param sParamFilename Filename of parameter file to read
tomwalters@268 186 * \return true on succes, false on error
tomwalters@268 187 */
tomwalters@268 188 bool MergeFile(const char *sParamFilename);
tomwalters@268 189
tomwalters@268 190 /*! \brief Default ini-section to use
tomwalters@268 191 *
tomwalters@268 192 * Since SimpleIni is an ini-parser but we don't want the sections,
tomwalters@268 193 * we use the empty section. This gives use the behaviour desired.
tomwalters@268 194 */
tomwalters@268 195 static const char *m_SDefaultIniSection;
tomwalters@268 196
tomwalters@280 197 /*! \brief Parameter file object
tomwalters@280 198 */
tomwalters@268 199 CSimpleIniCase *m_pIni;
tomwalters@280 200 /*! \brief \c preset.include nesting counter to avoid loops
tomwalters@280 201 */
tomwalters@268 202 unsigned int m_iNestCount;
tomwalters@280 203 /*! \brief maximum value m_iNestCount may reach
tomwalters@280 204 */
tomwalters@268 205 static const unsigned int m_iNestCountMaximum = 16;
tomwalters@268 206 };
tomwalters@268 207 }
tomwalters@268 208
tomwalters@283 209 #endif // AIMC_SUPPORT_PARAMETERS_H_
tomwalters@268 210