/YAIP

Yet another INI parser, written in C++

Primary LanguageC++GNU Lesser General Public License v3.0LGPL-3.0

YAIP - Yet another INI parser

Badges

License: LGPL v3 Version GitHub forks GitHub issues Open Source Love svg1 Language

General information

YAIP is distributed under the terms of the GNU LESSER GENERAL PUBLIC LICENSE, version 3.0. The text of the license is included in the file LICENSE.TXT in the project root.

Requirements

To use YAIP you need to have an modern C++11 compiler. See the used parts at the section Implementation Details. Tested with Visual Studio 2019.

Supported Platforms

Supported platforms are all platforms where the code compiles and the tests run without any error. A raw CMake configuration exists and is working for

  • nmake - the command line make system of Microsoft
  • make - the default Unix make system

Motivation

Searching for INI parsers for C++ fires up a lot of them. Most of them come with a lot of stuff/classes around, some of them as library. Only a few of them offers plain classes. Also only a few of them are portable. And I'm missing the usage of modern C++ like own templates and the usage of the STL. I like to improve my C++ skills so I decided to write my own INI file parser.

Implementation Details

  • Convenience typedefs for datatypes are done in their corresponding classes, e. g. the smartpointer net::derpaul::yaip::IniEntryPtr in the class file of net::derpaul::yaip::IniEntry.
  • Detection of section and key/value pair while reading is done using regular expressions, see also regular expression.
  • The internal data storage methods are based on std::string.
  • Templated methods are used for other datatypes calling converters from and to std::string.

Used tools

Extension

To extend the capabilities with currently not supported datatypes, the extension is very simple. Just extend the class net::derpaul::yaip::Convert with conversion methods from/to your data type.

Doxygen Documentation

A doxygen documentation can be generated, the config file is located in the doxygen subfolder.

API Overview

File related actions

  • Load INI file
/**
 * Load and parse INI file into internal structures
 * \param Filename Full qualified filename of the INI file
 * \return true on success otherwise false
 */
bool INIFileLoad(std::string Filename);
  • Save INI file
/**
 * Save internal structures to INI file
 * \param Filename Full qualified filename of the INI file
 * \return true on success otherwise false
 */
bool INIFileSave(std::string Filename);
  • Does INI file exists
/**
 * Check if given INI file exists
 * \param Filename Full qualified filename of the INI file
 * \return true if file exists otherwise false
 */
bool INIFileExist(const std::string &Filename) const;
  • Delete INI file
/**
 * Delete given INI file
 * \param Filename Full qualified filename of the INI file
 * \return true if file is deleted otherwise false
 */
bool INIFileDelete(const std::string &Filename) const;

Section related actions

  • Get a list of all sections
/**
 * Get all sections of the INI file
 * \return Vector with a std::strings for each section
 */
tVectorString SectionListGet(void) const;
  • Delete a section
/**
 * Remove section completely from internal data structure
 * \param Section Specified section
 */
void SectionKill(const std::string &Section);
  • Check if section is empty
/**
 * Check if section contains data
 * \param Section Specified section
 * \return true for empty section otherwise false
 */
bool SectionEmpty(const std::string &Section) const;

Key related actions

  • Get a list of keys of a section
/**
 * Get all keys of a section of the INI file
 * \param Section Specified section
 * \return Vector with a std::strings for each key
 */
tVectorString SectionKeyListGet(const std::string &Section) const;
  • Get a value of a section/key combination - Note: This is a templated method and requires in any case a default value.
/**
 * Templated method to retrieve a value of the specified section/key combination
 * \param Section Specified section
 * \param Key Specified key
 * \param Default Specified default value in case key does not exist
 * \return Returns either the default value or the value of the existing section/key combination
 */
template<typename VariableType>
VariableType SectionKeyValueGet(const std::string &Section, const std::string &Key, const VariableType &Default);
  • Set a value of a section/key combination - Note: This is a templated method and may require a cast.
/**
 * Templated method to set a value of the specified section/key combination
 * \param Section Specified section
 * \param Key Specified key
 * \param Value Specified value to set
 * \return true on success otherwise false
 */
template<typename VariableType>
bool SectionKeyValueSet(const std::string &Section, const std::string &Key, const VariableType &Value);
  • Delete a key
/**
 * Remove key completely from section of internal data structure
 * \param Section Specified section
 * \param Key Specified key
 */
void SectionKeyKill(const std::string &Section, const std::string &Key);
  • Set/Clear a key value and keep an empty key
/**
 * Clear a key value
 * \param Section Specified section
 * \param Key Specified key
 * \return true on success otherwise false
 */
bool SectionKeyValueClear(const std::string &Section, const std::string &Key);

ToDo's

  • The implementation has to be checked against the inofficial specification at Wikipedia and the tests have to satisfiy the specification.
  • Add tests for untested classes.