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