This is a header only implementation of the ini file parser with modern C++.
cmake . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
cd build && ctest -C Release --output-on-failure
Add the following code in your CMakeLists.txt file.
FetchContent_Declare(
Ini-cpp
GIT_REPOSITORY [email protected]:penglei0/Ini-cpp.git
GIT_TAG v1.0.0)
set(BUILD_INI_TESTING
OFF
CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(Ini-cpp)
message("Ini_cpp source directory is :" ${Ini-cpp_SOURCE_DIR})
message("Ini_cpp binary directory is :" ${Ini-cpp_BINARY_DIR})
include_directories(${Ini-cpp_SOURCE_DIR}/include)
#include <settings.h>
constexpr const char path[] = "/etc/cfg/my_settings.ini";
using MySettings = Settings<path>;
auto& settings = MySettings::GetInstance();
// string
settings.SetValue<std::string>("string.key1", "value1");
// float
settings.SetValue<float>("float.key1", 1.1);
// get operation with no default value.
auto value = settings.GetValue<std::string>("string.key1");
// get operation with default value.
value = settings.GetValue<std::string>("string.key1", "default_value");
// get operation with format args. `GetValue2` version.
value = settings.GetValue2<std::string>("default_value", "%s%d", "string.key",1);