8000 GitHub - blackline1/inifile-cpp: A header-only and easy to use Ini file parser for C++.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

blackline1/inifile-cpp

 
 

Repository files navigation

Inifile-cpp

License Travis Status Appveyor Status

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.

About

A header-only and easy to use Ini file parser for C++.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 96.5%
  • CMake 3.5%
0