CfgManipulator is a fast and powerful tool for working with configuration files for the C++ language

CfgManipulator Build Status

CfgManipulator is a fast and powerful tool for working with configuration files for the C++ language. It can read, create strings and sections, change the value of a string and much more.

Before starting, you should have installed

  • GCC 4.8 or higher

It can

  • Read the value of the strings and change it.
  • Create sections.
  • Format the file in its own style.
  • Detect errors.
  • Create strings and sections.
  • Read a string value and convert it to various data types.

How to use

  • Clone this repo.
  • Copy the files CfgManipulator.cpp and CfgManipulaor.hpp to your project folder.
  • Include the CfgManipulator.hpp file in your project.
  • Compile CfgManipulator.cpp along with other source files.

Demonstration

Demonstration

Code example

using namespace std; CfgManipulator::CfgFile settings; int main() { settings.open("settings.cfg"); /* You can also create a configuration file class and open it in one line: * CfgManipulator::CfgFile settings("settings.cfg"); */ cout << settings.read_int32("int32") << endl << settings.read_int64("int64") << endl << settings.read_bool("bool") << endl << settings.read_double("double") << endl; settings.create_string("line", "value"); settings.create_section("section"); settings.create_string("section", "line", "value"); cout << settings.read("line") << endl; cout << settings.read("section", "line"); settings.change_value("line", "another_value"); settings.change_value("section", "line", "another_value"); /* Let's say you have changed the value of a string and want to add changes to a file, * then you will need to call "overwrite" function. */ settings.overwrite(); settings.close(); return EXIT_SUCCESS; }">
//main.cpp

#include "CfgManipulator.hpp"

#include <iostream>

using namespace std;

CfgManipulator::CfgFile settings;

int main() {
    settings.open("settings.cfg");

    /* You can also create a configuration file class and open it in one line:
     * CfgManipulator::CfgFile settings("settings.cfg");
    */

   cout << settings.read_int32("int32") << endl
        << settings.read_int64("int64") << endl
        << settings.read_bool("bool") << endl
        << settings.read_double("double") << endl;

    settings.create_string("line", "value");

    settings.create_section("section");

    settings.create_string("section", "line", "value");

    cout << settings.read("line") << endl;

    cout << settings.read("section", "line");

    settings.change_value("line", "another_value");

    settings.change_value("section", "line", "another_value");

    /* Let's say you have changed the value of a string and want to add changes to a file, 
     * then you will need to call "overwrite" function.
    */
    settings.overwrite();

    settings.close();

    return EXIT_SUCCESS;
}
# settings.cfg

int32 = "2147483647"
int64 = "9223372036854775807"
bool = "true"
double = "0.5"
line = "value" # comment

[section]
    line = "value" # comment

Compiling

  • g++ -std=c++11 -Wall -Werror main.cpp CfgManipulator.cpp

Explanations of functions

Function Explanation
void CfgFile::open(const std::string &path) Opens the configuration file.
void CfgFile::close() Closes the configuration file.
bool CfgFile::is_open() Returns true if the file is open, false if closed.
std::string CfgFile::read(const string &key) Reads the value of a string.
std::string CfgFile::read(const std::string &section, const std::string &key) Reads the value of a string from a specific section.
std::string CfgFile::get_path() Returns the path to the file.
void CfgFile::change_value(const string &key, const string &value) Changes the value of a string.
void CfgFile::change_value(const string &section, const string &key, const string &value) Changes the value of a string from a specific section.
void CfgFile::create_string(const std::string &key, const std::string &value) Creates a new string in the file.
void CfgFile::create_string(const std::string &section, const std::string &key, const std::string &value) Creates a new string in a specific section.
void CfgFile::create_section(const std::string &section) Creates a new section.
void CfgFile::overwrite() Overwrites the file.
std::int32_t CfgFile::read_int32(const string &key) Reads a string and converts its value to int32.
std::int64_t CfgFile::read_int64(const string &key) Reads a string and converts its value to int64.
bool CfgFile::read_bool(string str) Reads a string and converts its value to boolean.
double CfgFile::read_double(const string &key) Reads a string and converts its value to double.

Features that will be added in the future

  • Arrays

28.01.2022

  • Added the ability to create sections and strings.
  • Added the ability to convert string value into various data types
  • Fixed bugs.

License: MIT

If you like this project, give it a star 🧡

Similar Resources

A utility for running arbitrary commands when files change

Event Notify Test Runner A utility for running arbitrary commands when files change. Uses kqueue(2) or inotify(7) to avoid polling. entr was written t

Dec 1, 2022

The KISS file manager: CLI-based, ultra-lightweight, lightning fast, and written in C

 The KISS file manager: CLI-based, ultra-lightweight, lightning fast, and written in C

CliFM is a CLI-based, shell-like (non-curses) and KISS terminal file manager written in C: simple, fast, and lightweight as hell

Nov 22, 2022

Zinit is a flexible and fast Zshell plugin manager

Zinit is a flexible and fast Zshell plugin manager

zinit Note: Sebastian Gniazdowski, the original zinit dev, deleted zdharma randomly. This is a reliable fork / place for the continuation of the proje

Nov 29, 2022

Bootloader recovery and updater tool for StarFive JH17x0 SoCs.

Bootloader  recovery and updater tool for StarFive JH17x0 SoCs.

JH71xx-tools Bootloader recovery and updater tool for StarFive JH7100 SoCs.

May 1, 2022

A command line tool for numerically computing Out-of-time-ordered correlations for N=4 supersymmetric Yang-Mills theory and Beta deformed N=4 SYM.

A command line tool to compute OTOC for N=4 supersymmetric Yang–Mills theory This is a command line tool to numerically compute Out-of-time-ordered co

Oct 16, 2021

Tool that generates unit test by C/C++ source code, trying to reach all branches and maximize code coverage

What is UTBotCpp? UTBotCpp generates test cases by code, trying to cover maximum statements and execution paths. We treat source code as source of tru

Nov 18, 2022

FastReport.Cloud console tool for Linux and perhaps some other OSes

FastReport Cloud console shell This is a simple console shell to FastReport Cloud service. Prerequests GNU packages for build shell: curl-development

Feb 10, 2022

An extremely fast FEC filing parser written in C

FastFEC A C program to stream and parse FEC filings, writing output to CSV. This project is in early stages but works on a wide variety of filings and

Nov 3, 2022

Creation of a sudoku in a terminal with the C language.

hack-fest-2021-sudoku Creation of a sudoku in a terminal with the C language. Genesis The idea of creating this project is multiple : first of all, I

Nov 16, 2022
A simple header-only C++ argument parser library. Supposed to be flexible and powerful, and attempts to be compatible with the functionality of the Python standard argparse library (though not necessarily the API).

args Note that this library is essentially in maintenance mode. I haven't had the time to work on it or give it the love that it deserves. I'm not add

Dec 2, 2022
A simple header-only C++ argument parser library. Supposed to be flexible and powerful, and attempts to be compatible with the functionality of the Python standard argparse library (though not necessarily the API).

args Note that this library is essentially in maintenance mode. I haven't had the time to work on it or give it the love that it deserves. I'm not add

Aug 31, 2021
Simple command line tool that processes image files using the FidelityFX Super Resolution (FSR) or Contrast Adaptive Sharpening (CAS) shader systems.

Simple command line tool that processes image files using the FidelityFX Super Resolution (FSR) or Contrast Adaptive Sharpening (CAS) shader systems.

Nov 20, 2022
A command-line tool to extract dylib files from the dyld shared cache file.

DyldExtractor A command-line tool to extract dylib files from the dyld shared cache file. Starting with macOS 11, standalone binaries of system librar

Sep 13, 2022
easy to use, powerful & expressive command line argument parsing for modern C++ / single header / usage & doc generation

clipp - command line interfaces for modern C++ Easy to use, powerful and expressive command line argument handling for C++11/14/17 contained in a sing

Nov 29, 2022
C++ lib and CLI for playing media files on a Chromecast

castr - a CLI and C++ library to cast media files to Chromecast devices using the built in Default Media Receiver

Oct 31, 2022
Simple command line utilities for extracting data from Fallout 4 and 76 files

fo76utils Simple command line utilities for extracting data from Fallout 4 and 76 files. baunpack - list the contents of, or extract from .BA2 archive

Oct 18, 2022
Flexible and fast Z-shell plugin manager that will allow installing everything from GitHub and other sites.
Flexible and fast Z-shell plugin manager that will allow installing everything from GitHub and other sites.

ZINIT News Zinit Wiki Quick Start Install Automatic Installation (Recommended) Manual Installation Usage Introduction Plugins and snippets Upgrade Zin

Nov 15, 2022
A single-class C++ library for reading animated GIF files

EasyGifReader EasyGifReader is a single-class C++ library that aims to simplify reading an animated GIF file. It is built on top of and depends on gif

Nov 17, 2022
Simple command line tools to create/extract X4 .cat+.dat files

x4cat Simple command line tools to to create/extract X4 .cat+.dat files x4encat Usage: x4encat <archive name> Looks for a directory named <archive nam

Oct 31, 2021