tomwalters@0: // Copyright 2006-2010, Willem van Engen tomwalters@0: // tomwalters@0: // AIM-C: A C++ implementation of the Auditory Image Model tomwalters@0: // http://www.acousticscale.org/AIMC tomwalters@0: // tomwalters@0: // This program is free software: you can redistribute it and/or modify tomwalters@0: // it under the terms of the GNU General Public License as published by tomwalters@0: // the Free Software Foundation, either version 3 of the License, or tomwalters@0: // (at your option) any later version. tomwalters@0: // tomwalters@0: // This program is distributed in the hope that it will be useful, tomwalters@0: // but WITHOUT ANY WARRANTY; without even the implied warranty of tomwalters@0: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the tomwalters@0: // GNU General Public License for more details. tomwalters@0: // tomwalters@0: // You should have received a copy of the GNU General Public License tomwalters@0: // along with this program. If not, see . tomwalters@0: tomwalters@0: //! tomwalters@0: //! \file tomwalters@0: //! \brief Main parameters store tomwalters@0: //! tomwalters@0: //! \author Willem van Engen tomwalters@0: //! \date created 2006/09/21 tomwalters@0: //! \version \$Id: Parameters.h 4 2010-02-03 18:44:58Z tcw $ tomwalters@0: tomwalters@0: #ifndef _AIMC_SUPPORT_PARAMETERS_H_ tomwalters@0: #define _AIMC_SUPPORT_PARAMETERS_H_ tomwalters@0: tomwalters@0: // If not _WINDOWS, please compile in Support/ConvertUTF.c tomwalters@0: #ifdef _UNICODE tomwalters@0: // Here we want to use the ANSI version of all the non wxWidgets stuff, but tomwalters@0: // convert stribngs to Unicode when used in wxWidgets. This allows all the tomwalters@0: // string handling in the non-GUI version to use ANSI text only, but to pass tomwalters@0: // unicode text to the GUI tomwalters@0: #undef _UNICODE tomwalters@0: #include "Support/SimpleIni.h" tomwalters@0: #define _UNICODE tomwalters@0: #else tomwalters@0: #include "Support/SimpleIni.h" tomwalters@0: #endif 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@0: 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@0: //! \brief Maximum length of a parameter name in characters tomwalters@0: static const unsigned int MaxParamNameLength = 128; tomwalters@0: tomwalters@0: 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@0: //! \brief Parameter file object tomwalters@0: CSimpleIniCase *m_pIni; tomwalters@0: //! \brief \c preset.include nesting counter to avoid loops tomwalters@0: unsigned int m_iNestCount; tomwalters@0: //! \brief maximum value m_iNestCount may reach tomwalters@0: static const unsigned int m_iNestCountMaximum = 16; tomwalters@0: }; tomwalters@0: } tomwalters@0: tomwalters@0: #endif // _AIMC_SUPPORT_PARAMETERS_H_ tomwalters@0: