All Projects → mayah → Tinytoml

mayah / Tinytoml

Licence: bsd-2-clause
A header only C++11 library for parsing TOML

Labels

Projects that are alternatives of or similar to Tinytoml

Mconfig
MCONFIG is a lightweight Golang library for integrating configs files like (json, yml, toml) and environment variables into one config struct.
Stars: ✭ 28 (-81.7%)
Mutual labels:  toml
Better Toml
toml extension for vs code editor
Stars: ✭ 60 (-60.78%)
Mutual labels:  toml
Devshell
Per project developer environments
Stars: ✭ 129 (-15.69%)
Mutual labels:  toml
Configr
Implements the JSON, INI, YAML and TOML parser, for R setting and writing of configuration file.
Stars: ✭ 38 (-75.16%)
Mutual labels:  toml
Unpuzzled
A colorful CLI library with variable provenance.
Stars: ✭ 57 (-62.75%)
Mutual labels:  toml
Config Lite
A super simple & flexible & useful config module.
Stars: ✭ 78 (-49.02%)
Mutual labels:  toml
Toml Parser
simple toml parser
Stars: ✭ 13 (-91.5%)
Mutual labels:  toml
Rq
Record Query - A tool for doing record analysis and transformation
Stars: ✭ 1,808 (+1081.7%)
Mutual labels:  toml
Re Txt
converts text-formats from one to another, it is very useful if you want to re-format a json file to yaml, toml to yaml, csv to yaml, ... etc
Stars: ✭ 59 (-61.44%)
Mutual labels:  toml
Datafiles
A file-based ORM for Python dataclasses.
Stars: ✭ 113 (-26.14%)
Mutual labels:  toml
Tommy
A single-file TOML reader and writer for C#
Stars: ✭ 44 (-71.24%)
Mutual labels:  toml
Resticprofile
Configuration profiles for restic backup
Stars: ✭ 48 (-68.63%)
Mutual labels:  toml
Night Config
Powerful java configuration library for toml, yaml, hocon, json and in-memory configurations
Stars: ✭ 93 (-39.22%)
Mutual labels:  toml
Go Toml
Go library for the TOML language
Stars: ✭ 952 (+522.22%)
Mutual labels:  toml
Toml To Go
Translates TOML into a Go type in your browser instantly
Stars: ✭ 134 (-12.42%)
Mutual labels:  toml
Yunmai Data Extract
Extract your data from the Yunmai weighing scales cloud API so you can use it elsewhere
Stars: ✭ 21 (-86.27%)
Mutual labels:  toml
To.ml
OCaml library for TOML
Stars: ✭ 68 (-55.56%)
Mutual labels:  toml
Fig
A minimalist Go configuration library
Stars: ✭ 142 (-7.19%)
Mutual labels:  toml
Taplo
A TOML toolkit written in Rust
Stars: ✭ 136 (-11.11%)
Mutual labels:  toml
Staert
Merge your configuration sources
Stars: ✭ 108 (-29.41%)
Mutual labels:  toml

tinytoml

A header only C++11 library for parsing TOML.

Build Status

This parser is based on TOML v0.4.0. This library is distributed under simplified BSD License.

Introduction

tinytoml is a tiny TOML parser for C++11 with following properties:

  • header file only
  • C++11 library friendly (array is std::vector, table is std::map, time is std::chrono::system_clock::time_point).
  • no external dependencies (note: we're using cmake for testing, but it's not required to use this library).

We'd like to keep this library as handy as possible.

Prerequisite

  • C++11 compiler
  • C++11 libraries.

I've only checked this library works with recent clang++ (3.5) and g++ (4.7). I didn't check this with cl.exe. Acutally I'm using this library on my Linux app and Mac app. However, I haven't written Windows app yet.

How to use

Copy include/toml/toml.h into your project, and include it from your source. That's all.

Example code

// Parse foo.toml. If foo.toml is valid, pr.valid() should be true.
// If not valid, pr.errorReason will contain the parser error reason.
std::ifstream ifs("foo.toml");
toml::ParseResult pr = toml::parse(ifs);

if (!pr.valid()) {
    cout << pr.errorReason << endl;
    return;
}

// Note for users from older version:
// Since toml::Parser has a state, I don't recommend to use it directly any more.
// So, I've moved toml::Parser to toml::internal::Parser.
// Using toml::parse() is recommended.

// pr.value is the parsed value.
const toml::Value& v = pr.value;

// You can find a value by find().
// If found, non-null pointer will be returned.
// You can check the type of value with is().
// You can get the inner value by as().
const toml::Value* x = v.find("foo.bar.baz");
if (x && x->is<std::string>()) {
    cout << x->as<string>() << endl;
} else if (x && x->is<int>()) {
    cout << x->as<int>() << endl;
}

// Note: the inner value of integer value is actually int64_t,
// however, you can use 'int' for convenience.
toml::Value* z = ...;
int x = z->as<int>();
int64_t y = z->as<int64_t>();
// toml::Array is actually std::vector<toml::Value>.
// So, you can use range based for, etc.
const toml::Array& ar = z->as<toml::Array>();
for (const toml::Value& v : ar) {
    ...
}

// For convenience way, you can use get() when you're sure that the value exists
// and you know the value type.
// If type error occurred, std::runtime_error is raised.
toml::Value v = ...;
cout << v.get<string>("foo.bar") << endl;

// For array type, you can also use get<std::vector<int>>() etc.
// Note that a fresh vector<int> is allocated.
std::vector<int> vs = v.get<std::vector<int>>();

// If you need to check value existence or type, you should use find().

How to test

The directory 'src' contains a few tests. We're using google testing framework, and cmake.

$ mkdir -p out/Debug; cd out/Debug
$ cmake ../../src
$ make
$ make test

'src' also contains a small example for how to use this.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].