tomwalters@280: // Copyright 2006-2010, Willem van Engen, Thomas Walters tomwalters@268: // tomwalters@268: // AIM-C: A C++ implementation of the Auditory Image Model tomwalters@268: // http://www.acousticscale.org/AIMC tomwalters@268: // tomwalters@318: // Licensed under the Apache License, Version 2.0 (the "License"); tomwalters@318: // you may not use this file except in compliance with the License. tomwalters@318: // You may obtain a copy of the License at tomwalters@268: // tomwalters@318: // http://www.apache.org/licenses/LICENSE-2.0 tomwalters@268: // tomwalters@318: // Unless required by applicable law or agreed to in writing, software tomwalters@318: // distributed under the License is distributed on an "AS IS" BASIS, tomwalters@318: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. tomwalters@318: // See the License for the specific language governing permissions and tomwalters@318: // limitations under the License. tomwalters@268: tomwalters@280: /*! tomwalters@280: * \file tomwalters@280: * \brief Main parameters store tomwalters@280: * tomwalters@280: * \author Willem van Engen tomwalters@280: * \author Thomas Walters tomwalters@280: * \date created 2006/09/21 tomwalters@296: * \version \$Id$ tomwalters@280: */ tomwalters@268: tomwalters@283: #ifndef AIMC_SUPPORT_PARAMETERS_H_ tomwalters@283: #define AIMC_SUPPORT_PARAMETERS_H_ tomwalters@268: tomwalters@273: #include tomwalters@273: tomwalters@268: #include "Support/SimpleIni.h" tomwalters@268: tomwalters@268: namespace aimc { tomwalters@268: /*! tomwalters@268: * \class Parameters "Support/Parameters.h" tomwalters@268: * \brief Main parameter store for parameters tomwalters@268: */ tomwalters@268: class Parameters { tomwalters@280: public: tomwalters@268: Parameters(); tomwalters@268: ~Parameters(); tomwalters@268: tomwalters@268: /*! tomwalters@268: * \brief Load parameter file tomwalters@268: * \param sParamFilename Filename of parameter file to read tomwalters@268: * \return true on succes, false on error tomwalters@268: * tomwalters@268: */ tomwalters@268: bool Load(const char *sParamFilename); tomwalters@268: tomwalters@268: /*! \brief Save Parameter File tomwalters@268: * \param sParamFilename Filename of parameter file to save tomwalters@268: * \return true on success, false on error tomwalters@268: */ tomwalters@268: bool Save(const char *sParamFilename); tomwalters@268: tomwalters@268: /*! tomwalters@268: * \brief Load parameter file and merge parameters with current, overwriting tomwalters@268: * duplicates. tomwalters@268: * \param sParamFilename Filename of parameter file to read tomwalters@268: * \return true on succes, false on error tomwalters@268: */ tomwalters@268: bool Merge(const char *sParamFilename); tomwalters@268: tomwalters@268: /*! \brief Get a parameter, setting it with a default value if it is not tomwalters@268: * already set tomwalters@268: * \param sName Name of parameter tomwalters@268: * \param val Value of the parameter tomwalters@268: */ tomwalters@268: const char * DefaultString(const char* sName, const char *val); tomwalters@268: tomwalters@268: /*! \overload tomwalters@268: */ tomwalters@268: int DefaultInt(const char* sName, int val); tomwalters@268: tomwalters@268: /*! \overload tomwalters@268: */ tomwalters@268: unsigned int DefaultUInt(const char* sName, unsigned int val); tomwalters@268: tomwalters@268: /*! \overload tomwalters@268: */ tomwalters@268: float DefaultFloat(const char* sName, float val); tomwalters@268: tomwalters@268: /*! \overload tomwalters@268: */ tomwalters@268: bool DefaultBool(const char* sName, bool val); tomwalters@268: tomwalters@268: tomwalters@268: /*! \brief Set a parameter tomwalters@268: * \param sName Name of parameter tomwalters@268: * \param val Value of parameter tomwalters@268: */ tomwalters@268: void SetString(const char *sName, const char *val); tomwalters@268: tomwalters@268: /*! \overload tomwalters@268: */ tomwalters@268: void SetInt(const char *sName, int val); tomwalters@268: tomwalters@268: /*! \overload tomwalters@268: */ tomwalters@268: void SetUInt(const char *sName, unsigned int val); tomwalters@268: tomwalters@268: /*! \overload tomwalters@268: */ tomwalters@268: void SetFloat(const char *sName, float val); tomwalters@268: tomwalters@268: /*! \overload tomwalters@268: */ tomwalters@268: void SetBool(const char *sName, bool val); tomwalters@268: tomwalters@268: /*! \brief Get the value of a parameter tomwalters@268: * \param sName Name of parameter tomwalters@268: * \return Value of parameter tomwalters@268: * tomwalters@268: * The specified parameter _must_ exist. So put every parameter you may tomwalters@268: * possibly require into the default parameter file. This method returns tomwalters@268: * the empty string when a value doesn't exist, but that is only to keep tomwalters@268: * the application from crashing: don't count on it. tomwalters@268: * You can use IsSet() however to check for a parameter's existence. tomwalters@268: */ tomwalters@268: const char *GetString(const char *sName); tomwalters@268: tomwalters@268: /*! \overload tomwalters@268: */ tomwalters@268: int GetInt(const char *sName); tomwalters@268: tomwalters@268: /*! \overload tomwalters@268: */ tomwalters@268: unsigned int GetUInt(const char *sName); tomwalters@268: tomwalters@268: /*! \overload tomwalters@268: */ tomwalters@268: float GetFloat(const char *sName); tomwalters@268: tomwalters@268: /*! \overload tomwalters@268: */ tomwalters@268: bool GetBool(const char *sName); tomwalters@268: tomwalters@268: /*! \brief Returns if the parameters exists or not tomwalters@268: * \param sName Name of parameter tomwalters@268: * \return true if exists, false if not tomwalters@268: */ tomwalters@268: bool IsSet(const char *sName); tomwalters@268: tomwalters@268: /*! \brief Sets a parameter assignment from a string tomwalters@268: * \param sCmd String to parse tomwalters@268: * \return true if parsing succeeded, false if an error occured. tomwalters@268: * tomwalters@268: * This function parses a string like "foo.bar=50" and sets the parameter tomwalters@268: * accordingly. Use this function to parse parameter assignments as given tomwalters@268: * by the user, for example on the command-line or in a parameter file. tomwalters@268: */ tomwalters@268: bool Parse(const char *sCmd); tomwalters@268: tomwalters@268: /*! \brief Delete a parameter. GetSection may not return correctly after tomwalters@268: * this call, so it may not be possible to repopulate the parameter grid tomwalters@268: * after deleting a parameter tomwalters@268: * \param sName Parameter name tomwalters@268: * \return true on success tomwalters@268: */ tomwalters@268: bool Delete(const char *sName); tomwalters@268: tomwalters@273: /*! \brief Append parameters to a string tomwalters@273: * \param sName pointer to a string tomwalters@273: * \return true on success tomwalters@273: */ tomwalters@280: std::string WriteString(); tomwalters@273: tomwalters@280: /*! \brief Maximum length of a parameter name in characters tomwalters@280: */ tomwalters@268: static const unsigned int MaxParamNameLength = 128; tomwalters@268: tomwalters@280: protected: tomwalters@268: /*! tomwalters@268: * \brief Load parameter file tomwalters@268: * \param sParamFilename Filename of parameter file to read tomwalters@268: * \return true on succes, false on error tomwalters@268: */ tomwalters@268: bool LoadFile(const char *sParamFilename); tomwalters@268: /*! tomwalters@268: * \brief Load parameter file and merge parameters with current, tomwalters@268: * overwriting duplicates. tomwalters@268: * \param sParamFilename Filename of parameter file to read tomwalters@268: * \return true on succes, false on error tomwalters@268: */ tomwalters@268: bool MergeFile(const char *sParamFilename); tomwalters@268: tomwalters@268: /*! \brief Default ini-section to use tomwalters@268: * tomwalters@268: * Since SimpleIni is an ini-parser but we don't want the sections, tomwalters@268: * we use the empty section. This gives use the behaviour desired. tomwalters@268: */ tomwalters@268: static const char *m_SDefaultIniSection; tomwalters@268: tomwalters@280: /*! \brief Parameter file object tomwalters@280: */ tomwalters@268: CSimpleIniCase *m_pIni; tomwalters@280: /*! \brief \c preset.include nesting counter to avoid loops tomwalters@280: */ tomwalters@268: unsigned int m_iNestCount; tomwalters@280: /*! \brief maximum value m_iNestCount may reach tomwalters@280: */ tomwalters@268: static const unsigned int m_iNestCountMaximum = 16; tomwalters@268: }; tomwalters@268: } tomwalters@268: tomwalters@283: #endif // AIMC_SUPPORT_PARAMETERS_H_ tomwalters@268: