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

Overview

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 🧡

Releases(28.01.2022)
Owner
Sanya
🥶️
Sanya
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

Taylor C. Richberger 981 Jun 23, 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

Taylor C. Richberger 896 Aug 31, 2021
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

André Müller 886 Jun 25, 2022
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.

GPUOpen Effects 174 Jun 26, 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

Cyandev 8 Mar 12, 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

null 31 Jun 19, 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

null 9 Jun 13, 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

Viktor Chlumský 5 Feb 7, 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

Alexander Sago 1 Oct 31, 2021
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

Eric Radman 2.3k Jun 28, 2022
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

z-shell 25 Jun 9, 2022
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

leo-arch 511 Jun 24, 2022
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

null 1.1k Jul 2, 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

The Washington Post 51 May 26, 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

null 1 Oct 19, 2021
This is a terminal made using C language.

CommandConsole As the name suggests this is a terminal like software. Like a normal terminal in linux or command prompt in windows, it also works like

Shreejan Dolai 9 Feb 14, 2022
Linux Shell Implementation In C - Language

Linux-Shell ASSIGNMENT 2 Name : Naman Anand Roll no : 200101070 SUBJECT : CS242 ASSIGNMENT : 2 COMPILING AND FOR RUNNING COMMANDS :-> 1)gcc -o 2001010

Naman  Anand 18 Jun 24, 2022
Spitfire is a basic terminal language that can exicute code via the terminal.

Spitfire is a basic terminal language that can exicute code via the terminal. It is easy to learn and runs fast, considering that its just a 300 line c++ file.

jhomas tefferson 0 Nov 18, 2021
Linux Shell Implementation In C - Language

Linux-Mini-Shell This is a C code for Linux Shell (a mini version). The code is designed to work properly in LINUX terminal. To compile the code and r

Akshat Mittal 1 Jun 25, 2022