项目作者: dzilles

项目描述 :
Simple, lightweight C++ configuration/ini file parser for Linux.
高级语言: C++
项目地址: git://github.com/dzilles/configparser.git
创建时间: 2020-11-23T23:39:39Z
项目社区:https://github.com/dzilles/configparser

开源协议:MIT License

下载


configparser

Simple, lightweight C++ configuration/ini file parser for Linux.

Installation

Inside the main folder execute:

1) cmake .
2) make
3) make test

The following command will install the library in the paths defined by the environment variables $LIBDIR and $INCLUDEDIR.

4) make install

Usage

A minimal example of a CMake project using the configparser can be found in the examples folder:
The CMakeLists.txt of a project using the configparser may look like this:

  1. set(example_source
  2. example.cpp)
  3. # Find the library
  4. find_library(configparser
  5. NAME configparser
  6. HINTS [${LIBDIR} ${INCLUDEDIR}]
  7. )
  8. add_executable(example ${example_source})
  9. # and link to executable defined in example.cpp
  10. target_link_libraries(example configparser)

The example configuration file:

  1. ; comment 1
  2. [Section1]
  3. example1 = string
  4. example2 = 4
  5. example3 = true
  6. example4 = string1, string2, string3
  7. example5 = true, false, true
  8. example6 = "test!?$§"
  9. ; comment 2
  10. [Section2]
  11. example1 = 1, 2, 3, 4
  12. example2 = 5.1, 6.3, 7.5

The main function of the example project can be found in the file example.cpp.
The configuration file entries can be read out as follows:

  1. // Include the configparser header
  2. #include "configparser.hpp"
  3. int main() {
  4. string path = "config.ini";
  5. // Initialize the parser with a path to the configuration file
  6. ConfigParser parser = ConfigParser(path);
  7. // Read the configuration file entries:
  8. //
  9. // It is possible to read a single entry,
  10. string c11 = parser.aConfig<string>("Section1", "example1");
  11. // a whole vector
  12. vector<string> c14 = parser.aConfigVec<string>("Section1", "example4");
  13. // or a single entry of a vector
  14. double c222 = parser.aConfig<double>("Section2", "example2", 2);
  15. }