[hard fork] the existing library is written by some orange site/reddit lurking midwit incapable of adding custom types. on the other hand, they have no problem filling the repo with ~70klocs of third party shit, tests, fuzzers that in all reality arent going to catch any real bugs, and autogenerated project files.
Go to file
Mark Gillard b024ee6dc2 added tests for copying and insertion (closes #49)
also:
- added tests to catch any regressions of pull/50
- moved UTF-8 decoder copyright notice
- cleaned up static assert messages
2020-08-02 12:20:41 +03:00
.circleci fixed narrowing conversion warnings when constructing int values from unsigned 2020-07-20 00:40:55 +03:00
.github moved the unicode function generator stuff to another repo 2020-08-01 22:37:39 +03:00
cmake Add the Cmake configuration files support (#22) [skip ci] 2020-04-07 18:33:00 +03:00
docs fixed source information being copied when copying nodes 2020-07-30 23:31:08 +03:00
examples added insert, emplace, push_back etc. compatibility with node_views 2020-07-28 01:21:41 +03:00
extern updating submodules 2020-06-25 17:44:43 +03:00
include/toml++ added tests for copying and insertion (closes #49) 2020-08-02 12:20:41 +03:00
python moved the unicode function generator stuff to another repo 2020-08-01 22:37:39 +03:00
tests added tests for copying and insertion (closes #49) 2020-08-02 12:20:41 +03:00
vs added tests for copying and insertion (closes #49) 2020-08-02 12:20:41 +03:00
.editorconfig string value serialization now emits literals where possible (closes #43) 2020-07-14 20:50:24 +03:00
.gitattributes expanded allowable conversion semantics of value and value_or 2020-07-17 16:33:56 +03:00
.gitignore documentation improvements 2020-07-02 20:17:23 +03:00
.gitmodules fixed BOM check causing EOF on very short iostream inputs 2020-06-25 17:33:01 +03:00
CODE_OF_CONDUCT.md Added code of conduct [skip ci] 2020-02-24 22:01:54 +02:00
CONTRIBUTING.md fixed source information being copied when copying nodes 2020-07-30 23:31:08 +03:00
LICENSE added tests for copying and insertion (closes #49) 2020-08-02 12:20:41 +03:00
meson_options.txt fixed some multi-line string parsing issues 2020-04-13 23:23:11 +03:00
meson.build improved support for __fp16, _Float16 and __float128 2020-07-25 20:50:24 +03:00
README.md fixed source information being copied when copying nodes 2020-07-30 23:31:08 +03:00
toml.hpp added tests for copying and insertion (closes #49) 2020-08-02 12:20:41 +03:00

banner
Releases C++17 C++20 TOML MIT license CircleCI Mentioned in Awesome C++

toml++ homepage

This README is fine, but the toml++ homepage is better.


Library features

  • Header-only
  • Supports the latest TOML release (v1.0.0-rc.1), plus optional support for some unreleased TOML language features
  • C++17 (plus some C++20 features where available, e.g. experimental support for char8_t strings)
  • Proper UTF-8 handling (incl. BOM)
  • Works with or without exceptions
  • Doesn't require RTTI
  • First-class support for serializing to JSON
  • Tested on Clang (6+), GCC (7+) and MSVC (VS2019)
  • Tested on x64, x86 and ARM

Basic usage

The following example favours brevity. If you'd prefer full API documentation and lots of specific code snippets instead, visit the project homepage

Given a TOML file configuration.toml containing the following:

[library]
name = "toml++"
authors = ["Mark Gillard <mark.gillard@outlook.com.au>"]

[dependencies]
cpp = 17

Reading it in C++ is easy with toml++:

#include <toml.hpp>
#include <fstream> //required for toml::parse_file()

auto config = toml::parse_file( "configuration.toml" );

// get key-value pairs
std::string_view library_name = config["library"]["name"].value_or(""sv);
std::string_view library_author = config["library"]["authors"][0].value_or(""sv);
int64_t depends_on_cpp_version = config["dependencies"]["cpp"].value_or(0);

// modify the data
config.insert_or_assign("alternatives", toml::array{
    "cpptoml",
    "toml11",
    "Boost.TOML"
});

// iterate & visit over the data
for (auto&& [k, v] : config)
{
    v.visit([](auto& node) noexcept
    {
        std::cout << node << std::endl;
        if constexpr (toml::is_string<decltype(node)>)
            do_something_with_string_values(node);
    });
}

// re-serialize as TOML
std::cout << config << std::endl;

// re-serialize as JSON
std::cout << toml::json_formatter{ config } << std::endl;


You'll find some more code examples in the examples directory, and plenty more as part of the API documentation.


Adding toml++ to your project

toml++ comes in two flavours: Single-header and Regular. The API is the same for both.

🍦 Single-header flavour

  1. Drop toml.hpp wherever you like in your source tree
  2. There is no step two

🍨 Regular flavour

  1. Add tomlplusplus/include to your include paths
  2. #include <toml++/toml.h>

"What about build system X, or package manager Y?"

Currently there's support for use as a meson submodule. That's the extent of my knowledge in this area; clearly an area of opportunity! If you would like me to add support for a particular build system or package manager please let me know by making a feature request. Better still, if you have the skills and motivation to add support yourself, I'd welcome a pull request with a smile and open arms!

Conan

toml++ is available through the Conan-Center-Index. You simply need to add tomlplusplus/2.0.0 to your conanfile to include this in your project. The default options are set for the single-header flavour, however specifying the option "multiple_headers": True is available.


Configuration

A number of configurable options are exposed in the form of preprocessor #defines. Most likely you won't need to mess with these at all, but if you do, set them before including toml++.

Option Type Default Description
TOML_HEADER_ONLY boolean 1 Disable this to explicitly control where toml++'s implementation is compiled (e.g. as part of a library).
TOML_API define undefined API annotation to add to public symbols (e.g. __declspec(dllexport) on Windows).
TOML_ASSERT(expr) function macro assert(expr)
(or undefined)
Sets the assert function used by the library.
TOML_CONFIG_HEADER string literal undefined Includes the given header file before the rest of the library.
TOML_EXCEPTIONS boolean per your compiler's settings Sets whether the library uses exceptions.
TOML_IMPLEMENTATION define undefined Define this to enable compilation of the library's implementation. Meaningless if TOML_HEADER_ONLY is 1.
TOML_LARGE_FILES boolean 0 Uses 32-bit integers for line and column indices (instead of 16-bit).
TOML_OPTIONAL_TYPE type name undefined Overrides the optional<T> type used by the library if you need something better than std::optional.
TOML_PARSER boolean 1 Disable this to prevent inclusion of the parser-related parts of the library if you don't need them.
TOML_SMALL_FLOAT_TYPE type name undefined If your codebase has an additional 'small' float type (e.g. half-precision), this tells toml++ about it.
TOML_SMALL_INT_TYPE type name undefined If your codebase has an additional 'small' integer type (e.g. 24-bits), this tells toml++ about it.
TOML_UNRELEASED_FEATURES boolean 0 Enables support for unreleased TOML language features not yet part of a numbered version.
TOML_WINDOWS_COMPAT boolean 1 on Windows Enables support for transparent conversion between wide and narrow strings in some places when building for Windows.

A number of these have ABI implications; the library uses inline namespaces to prevent you from accidentally linking incompatible combinations together.


TOML Language Support

At any given time the library aims to support whatever the most recently-released version of TOML is, with opt-in support for a number of unreleased features from the TOML master and some sane cherry-picks from the TOML issues list where the discussion strongly indicates inclusion in a near-future release.

The library advertises the most recent numbered language version it fully supports via the preprocessor defines TOML_LANG_MAJOR, TOML_LANG_MINOR and TOML_LANG_PATCH.

🔸 Unreleased language features:

  • #516: Allow newlines and trailing commas in inline tables
  • #562: Allow hex floating-point values
  • #644: Support + in key names
  • #671: Local time of day format should support 09:30 as opposed to 09:30:00
  • #687: Relax bare key restrictions to allow additional unicode characters
  • #709: Include an \xHH escape code sequence

#define TOML_UNRELEASED_FEATURES 1 to enable these features (see Configuration).

🔹 TOML v1.0.0-rc.1:

All features supported, including:

  • #356: Allow leading zeros in the exponent part of a float
  • #567: Control characters are not permitted in comments
  • #571: Allow raw tabs inside strings
  • #665: Make arrays heterogeneous

🔹 TOML v0.5.0:

All features supported.


Contributing

Contributions are very welcome! Either by reporting issues or submitting pull requests. If you wish to submit a pull request, please see CONTRIBUTING for all the details you need to get going.


License and Attribution

toml++ is licensed under the terms of the MIT license - see LICENSE.

UTF-8 decoding is performed using a state machine based on Bjoern Hoehrmann's 'Flexible and Economical UTF-8 Decoder'.

With thanks to:

  • @bjadamson - Reported some bugs and helped design a new feature
  • @bobfang1992 - Reported a bug and created a wrapper in python
  • @GiulioRomualdi - Added cmake+meson support
  • @levicki - Helped design some new features
  • @mosra - Created the awesome m.css used to generate the API docs
  • @ned14 - Reported a bunch of bugs and helped design some new features
  • @okureta - Reported a bug
  • @prince-chrismc - Added toml++ to ConanCenter, and fixed some typos
  • @rbrugo - Helped design a new feature
  • @Reedbeta - Added additional Visual Studio debugger native visualizers
  • @shdnx - Fixed a bug on GCC 8.2.0 and some meson config issues
  • @traversaro - Added vcpkg support and reported a bunch of bugs
  • @ximion - Added support for installation with meson
  • @whiterabbit963 - Fixed a bug with value_or conversions

Contact

For bug reports and feature requests please consider using the issues system here on GitHub. For anything else though you're welcome to reach out via other means. In order of likely response time: