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@268: // This program is free software: you can redistribute it and/or modify
tomwalters@268: // it under the terms of the GNU General Public License as published by
tomwalters@268: // the Free Software Foundation, either version 3 of the License, or
tomwalters@268: // (at your option) any later version.
tomwalters@268: //
tomwalters@268: // This program is distributed in the hope that it will be useful,
tomwalters@268: // but WITHOUT ANY WARRANTY; without even the implied warranty of
tomwalters@268: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
tomwalters@268: // GNU General Public License for more details.
tomwalters@268: //
tomwalters@268: // You should have received a copy of the GNU General Public License
tomwalters@268: // along with this program. If not, see .
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: