Git Product home page Git Product logo

initfile's Introduction

Inifile-cpp

Inifile-cpp is a simple and easy to use header-only ini file en- and decoder for C++.

Install

Install the headers using the CMake build system:

cd <path-to-repo>
git submodule update --init --recursive
mkdir build
cd build
cmake ..
make install

or simply copy the header file into your project and include it directly.

Usage

Inifile-cpp allows loading data from any std::istream and requires a single function call or use the overloaded constructor.

#include <inicpp.h>

int main()
{
	// create istream object "is" ...

	// use function
	ini::IniFile myIni;
	myIni.decode(is);

	// or use constructor
	// ini::IniFile myIni(is);
}

For convenience there is also a load() function that expects a file name and parses the content of that file.

Sections and fields parsed from the stream can be accessed using the index operator [] and then be converted to various native types.

bool myBool = myIni["Foo"]["myBool"].as<bool>();
std::string myStr = myIni["Foo"]["myStr"].as<std::string>();
int myInt = myIni["Foo"]["myInt"].as<int>();
unsigned int myUInt = myIni["Foo"]["myUInt"].as<unsigned int>();
float myFloat = myIni["Foo"]["myFloat"].as<float>();
double myDouble = myIni["Foo"]["myDouble"].as<double>();

Natively supported types are:

  • const char *
  • std::string
  • int
  • unsigned int
  • bool
  • float
  • double

Custom type conversions can be added by implementing a explicit cast operator for IniField.

Values can be assigned to ini fileds just by using the assignment operator. The content of the inifile can then be written to any std::ostream object.

#include <inicpp.h>

int main()
{
	// create ostream object "os" ...

	ini::IniFile myIni;

	myIni["Foo"]["myInt"] = 1;
	myIni["Foo"]["myStr"] = "Hello world";
	myIni["Foo"]["myBool"] = true;
	myIni["Bar"]["myDouble"] = 1.2;

	myIni.encode(os);
}

For convenience there is also a save() function that expects a file name and writes the ini file to that file.

initfile's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.