Giter Club home page Giter Club logo

cxxini's Introduction

License Issues GitHub pull requests


A simple single-header C++11 INI reading and writing library.

Clone with

$ git clone --recurse-submodules https://github.com/lordoftrident/cxxini

Table of contents

Documentation

This library provides a single class ini::record, which inherits from ini::sections, which is a std::map<std::string, std::map<std::string, std::string>>, so it has all of its functionality.

Constructing

You can construct a record either by using initializer lists, index operator or string literals.

Initializer-lists

With the constructor

ini::record rec({
	{ini::default_section, { // ini::default_section is the unnamed section at the
		{"foo", "bar"},      // top of an ini file and is the same as []
	}},

	{"food-ratings", {
		{"salmon",       "10"},
		{"fish n chips", "8"},
		{"pizza",        "9"},
	}},
});

Or you can use assignment

auto rec = ini::record({
	// ...
});

Index operator

ini::record rec;
rec[ini::default_section]["foo"] = "bar";

rec["food-ratings"]["salmon"]       = "10";
rec["food-ratings"]["fish n chips"] = "8";
rec["food-ratings"]["pizza"]        = "9";

String literals

ini::record rec("foo = bar\n"
                "\n"
                "[food-ratings]\n"
                "salmon       = 10\n"
                "fish n chips = 8\n"
                "pizza        = 9\n");

Writing

For writing, you can use the stringify method to return an std::string

ini::record rec;
rec[ini::default_section]["foo"] = "bar";

std::cout << rec.stringify() << std::endl;

or you can use << to insert it into a stream (this just calls stringify under the hood)

ini::record rec;
rec[ini::default_section]["foo"] = "bar";

std::cout << rec << std::endl;

Reading

Reading from a string

ini::record rec;
rec.parse("foo = bar");

from a file

ini::record rec;

std::ifstream file("test.ini");
rec.parse(file);

The return value of parse is 0 if there was no error, otherwise its the number of the line at which the error occured (starting at 1)

you can also use the >> operator to read from a file

ini::record rec;

std::ifstream file("test.ini");
file >> rec;

Examples

Examples can be found in the examples folder. To build them, first bootstrap the builder with

$ cc build.c -o build

(you can also use a C++ compiler for it)

and then build

$ ./build

The binaries will be outputted into bin.

Quickstart

Either copy the header file cxxini.hh into your project, or you can use git submodules:

$ git submodule add https://github.com/LordOfTrident/cxxini

Bugs

If you find any bugs, please create an issue and report them.

cxxini's People

Contributors

lordoftrident avatar

Stargazers

yeti avatar  avatar

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.