2020-03-12 15:23:25 +00:00
|
|
|
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
|
|
|
|
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
|
|
|
|
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
|
2020-04-10 16:46:00 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-03-12 15:23:25 +00:00
|
|
|
|
2020-01-04 14:21:38 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
//# Note: most of these would be included transitively but
|
|
|
|
//# they're listed explicitly here because this file
|
|
|
|
//# is used as the source for generate_single_header.py.
|
|
|
|
|
2020-04-10 16:46:00 +00:00
|
|
|
#include "toml_preprocessor.h"
|
2020-01-04 14:21:38 +00:00
|
|
|
#include "toml_common.h"
|
2020-01-11 21:15:24 +00:00
|
|
|
#include "toml_date_time.h"
|
2020-01-12 15:37:02 +00:00
|
|
|
#include "toml_print_to_stream.h"
|
2020-01-04 14:21:38 +00:00
|
|
|
#include "toml_node.h"
|
|
|
|
#include "toml_value.h"
|
2020-01-22 21:29:46 +00:00
|
|
|
#include "toml_array.h"
|
|
|
|
#include "toml_table.h"
|
2020-01-04 14:21:38 +00:00
|
|
|
#include "toml_node_view.h"
|
2020-03-01 14:56:40 +00:00
|
|
|
#include "toml_utf8_generated.h"
|
2020-01-11 21:15:24 +00:00
|
|
|
#include "toml_utf8.h"
|
2020-01-04 14:21:38 +00:00
|
|
|
#include "toml_formatter.h"
|
2020-01-06 18:21:16 +00:00
|
|
|
#include "toml_default_formatter.h"
|
|
|
|
#include "toml_json_formatter.h"
|
2020-04-10 16:46:00 +00:00
|
|
|
|
2020-04-09 08:13:12 +00:00
|
|
|
#if TOML_PARSER
|
|
|
|
#include "toml_parse_error.h"
|
|
|
|
#include "toml_utf8_streams.h"
|
|
|
|
#include "toml_parser.h"
|
|
|
|
#endif // TOML_PARSER
|
2020-04-10 16:46:00 +00:00
|
|
|
|
2020-03-02 10:14:54 +00:00
|
|
|
#if TOML_IMPLEMENTATION
|
2020-04-09 08:13:12 +00:00
|
|
|
#include "toml_node.hpp"
|
|
|
|
#include "toml_array.hpp"
|
|
|
|
#include "toml_table.hpp"
|
|
|
|
#include "toml_default_formatter.hpp"
|
2020-04-10 16:46:00 +00:00
|
|
|
|
2020-04-09 08:13:12 +00:00
|
|
|
#if TOML_PARSER
|
|
|
|
#include "toml_parser.hpp"
|
|
|
|
#endif // TOML_PARSER
|
2020-04-10 16:46:00 +00:00
|
|
|
|
2020-04-09 08:13:12 +00:00
|
|
|
#if !TOML_ALL_INLINE
|
|
|
|
#include "toml_instantiations.hpp"
|
|
|
|
#endif // !TOML_ALL_INLINE
|
2020-04-10 16:46:00 +00:00
|
|
|
|
2020-04-09 08:13:12 +00:00
|
|
|
#endif // TOML_IMPLEMENTATION
|
2020-03-02 10:14:54 +00:00
|
|
|
|
2020-02-18 21:29:59 +00:00
|
|
|
// macro hygiene
|
2020-01-04 14:21:38 +00:00
|
|
|
#if TOML_UNDEF_MACROS
|
2020-04-09 08:13:12 +00:00
|
|
|
#undef TOML_INT_CHARCONV
|
|
|
|
#undef TOML_FLOAT_CHARCONV
|
2020-03-22 10:02:56 +00:00
|
|
|
#undef TOML_GNU_ATTR
|
2020-01-04 14:21:38 +00:00
|
|
|
#undef TOML_PUSH_WARNINGS
|
2020-01-07 15:52:50 +00:00
|
|
|
#undef TOML_DISABLE_SWITCH_WARNINGS
|
|
|
|
#undef TOML_DISABLE_INIT_WARNINGS
|
2020-04-08 13:33:57 +00:00
|
|
|
#undef TOML_DISABLE_VTABLE_WARNINGS
|
2020-01-04 14:21:38 +00:00
|
|
|
#undef TOML_DISABLE_ALL_WARNINGS
|
|
|
|
#undef TOML_POP_WARNINGS
|
|
|
|
#undef TOML_ALWAYS_INLINE
|
|
|
|
#undef TOML_ASSUME
|
|
|
|
#undef TOML_UNREACHABLE
|
|
|
|
#undef TOML_INTERFACE
|
|
|
|
#undef TOML_EMPTY_BASES
|
2020-01-07 15:52:50 +00:00
|
|
|
#undef TOML_CPP_VERSION
|
2020-01-04 14:21:38 +00:00
|
|
|
#undef TOML_CPP
|
|
|
|
#undef TOML_MAY_THROW
|
|
|
|
#undef TOML_NO_DEFAULT_CASE
|
|
|
|
#undef TOML_CONSTEVAL
|
|
|
|
#undef TOML_LIKELY
|
|
|
|
#undef TOML_UNLIKELY
|
|
|
|
#undef TOML_NODISCARD_CTOR
|
2020-01-06 18:21:16 +00:00
|
|
|
#undef TOML_MAKE_VERSION
|
2020-01-04 14:21:38 +00:00
|
|
|
#undef TOML_LANG_EFFECTIVE_VERSION
|
|
|
|
#undef TOML_LANG_HIGHER_THAN
|
|
|
|
#undef TOML_LANG_AT_LEAST
|
2020-04-02 21:39:21 +00:00
|
|
|
#undef TOML_LANG_UNRELEASED
|
2020-01-04 14:21:38 +00:00
|
|
|
#undef TOML_STRING_PREFIX_1
|
|
|
|
#undef TOML_STRING_PREFIX
|
|
|
|
#undef TOML_UNDEF_MACROS
|
2020-02-20 21:08:20 +00:00
|
|
|
#undef TOML_RELOPS_REORDERING
|
|
|
|
#undef TOML_ASYMMETRICAL_EQUALITY_OPS
|
2020-03-01 14:56:40 +00:00
|
|
|
#undef TOML_ALL_INLINE
|
|
|
|
#undef TOML_IMPLEMENTATION
|
2020-04-09 08:13:12 +00:00
|
|
|
#undef TOML_EXTERNAL_LINKAGE
|
|
|
|
#undef TOML_INTERNAL_LINKAGE
|
|
|
|
#undef TOML_INTERNAL_NAMESPACE
|
2020-03-12 15:23:25 +00:00
|
|
|
#undef TOML_COMPILER_EXCEPTIONS
|
2020-03-23 15:55:32 +00:00
|
|
|
#undef TOML_TRIVIAL_ABI
|
2020-03-28 16:56:59 +00:00
|
|
|
#undef TOML_ABI_NAMESPACES
|
2020-04-10 16:46:00 +00:00
|
|
|
#undef TOML_ABI_NAMESPACE_START
|
|
|
|
#undef TOML_ABI_NAMESPACE_END
|
2020-03-28 16:56:59 +00:00
|
|
|
#undef TOML_PARSER_TYPENAME
|
2020-01-04 14:21:38 +00:00
|
|
|
#endif
|
2020-02-18 21:29:59 +00:00
|
|
|
|
|
|
|
/// \mainpage toml++
|
|
|
|
///
|
2020-04-02 21:39:21 +00:00
|
|
|
/// \image html banner_small.png width=1280px
|
2020-02-26 23:28:20 +00:00
|
|
|
///
|
2020-02-20 21:08:20 +00:00
|
|
|
/// \tableofcontents
|
2020-02-18 21:29:59 +00:00
|
|
|
///
|
2020-02-20 21:08:20 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
2020-02-18 21:29:59 +00:00
|
|
|
///
|
2020-02-20 21:08:20 +00:00
|
|
|
/// \section mainpage-features Features
|
2020-04-03 13:33:02 +00:00
|
|
|
/// - [TOML v1.0.0-rc.1](https://github.com/toml-lang/toml/blob/master/versions/en/toml-v1.0.0-rc.1.md),
|
|
|
|
/// plus optional support for some unreleased TOML features
|
2020-02-23 11:13:18 +00:00
|
|
|
/// - C++17 (plus some C++20 features where available, e.g. experimental support for char8_t strings)
|
2020-02-20 21:08:20 +00:00
|
|
|
/// - Proper UTF-8 handling (incl. BOM)
|
|
|
|
/// - Works with or without exceptions
|
|
|
|
/// - Doesn't require RTTI
|
2020-02-25 21:11:40 +00:00
|
|
|
/// - First-class support for serializing to JSON
|
2020-03-28 16:56:59 +00:00
|
|
|
/// - Tested on Clang, GCC and MSVC (VS2019)
|
|
|
|
/// - Tested on x64, x86 and ARM
|
2020-02-20 21:08:20 +00:00
|
|
|
///
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
///
|
|
|
|
/// \section mainpage-adding-lib Adding toml++ to your project
|
2020-02-23 11:13:18 +00:00
|
|
|
/// It's header-only library so really all you have to do is clone
|
|
|
|
/// [the repository](https://github.com/marzer/tomlplusplus/) from GitHub and set your include paths.
|
|
|
|
/// There's some minor configuration you can do to customize some basic library functionality, but that's totally
|
2020-04-10 16:46:00 +00:00
|
|
|
/// optional.
|
|
|
|
/// \see \ref configuration
|
2020-02-23 11:13:18 +00:00
|
|
|
///
|
2020-02-20 21:08:20 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
///
|
|
|
|
/// \section mainpage-api-documentation API Documentation
|
2020-02-23 11:13:18 +00:00
|
|
|
/// You're looking at it! Browse the docs using the links at the top of the page.
|
|
|
|
/// You can search from anywhere by pressing the TAB key.
|
2020-02-20 21:08:20 +00:00
|
|
|
///
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
///
|
|
|
|
/// \section mainpage-example Basic examples
|
|
|
|
///
|
|
|
|
///////////////////////////////////
|
|
|
|
///
|
|
|
|
/// \subsection mainpage-example-parsing-files Parsing TOML files
|
|
|
|
/// toml++ works whether you have exceptions enabled or not. For the most part the usage is the same,
|
|
|
|
/// the main difference being how parsing errors are reported to the caller. When exceptions are enabled
|
2020-02-23 11:13:18 +00:00
|
|
|
/// a successful call to a parsing function simply returns a toml::table, whereas a failed call sees a toml::parse_error
|
|
|
|
/// thrown directly from the site of the error:
|
2020-02-18 21:29:59 +00:00
|
|
|
/// \cpp
|
|
|
|
/// #include <iostream>
|
2020-02-20 21:08:20 +00:00
|
|
|
/// #include <fstream> //required for parse_file()
|
2020-02-18 21:29:59 +00:00
|
|
|
/// #include <toml++/toml.h>
|
2020-02-20 21:08:20 +00:00
|
|
|
/// using namespace std::string_view_literals;
|
2020-02-18 21:29:59 +00:00
|
|
|
///
|
|
|
|
/// int main()
|
|
|
|
/// {
|
2020-02-20 21:08:20 +00:00
|
|
|
/// toml::table tbl;
|
|
|
|
/// try
|
|
|
|
/// {
|
|
|
|
/// tbl = toml::parse_file("configuration.toml");
|
|
|
|
/// }
|
|
|
|
/// catch (const toml::parse_error& err)
|
|
|
|
/// {
|
|
|
|
/// std::cerr
|
2020-04-02 21:39:21 +00:00
|
|
|
/// << "Error parsing file '" << *err.source().path
|
|
|
|
/// << "':\n" << err.description()
|
|
|
|
/// << "\n (" << err.source().begin << ")\n";
|
2020-02-20 21:08:20 +00:00
|
|
|
/// return 1;
|
|
|
|
/// }
|
|
|
|
///
|
|
|
|
/// do_stuff_with_your_config(tbl);
|
|
|
|
/// return 0;
|
|
|
|
/// }
|
|
|
|
///
|
|
|
|
/// \ecpp
|
|
|
|
///
|
2020-02-23 11:13:18 +00:00
|
|
|
/// When exceptions are disabled parsing functions return a toml::parse_result instead and it is up to the caller
|
2020-02-20 21:08:20 +00:00
|
|
|
/// to check if parsing has been successful by examining the return value:
|
|
|
|
/// \cpp
|
|
|
|
/// #include <iostream>
|
|
|
|
/// #include <fstream> //required for parse_file()
|
|
|
|
/// #include <toml++/toml.h>
|
|
|
|
/// using namespace std::string_view_literals;
|
|
|
|
///
|
|
|
|
/// int main()
|
|
|
|
/// {
|
|
|
|
/// toml::parse_result tbl = toml::parse_file("configuration.toml");
|
|
|
|
/// if (!tbl)
|
|
|
|
/// {
|
|
|
|
/// std::cerr
|
2020-04-02 21:39:21 +00:00
|
|
|
/// << "Error parsing file '" << *tbl.error().source().path
|
|
|
|
/// << "':\n" << tbl.error().description()
|
|
|
|
/// << "\n (" << tbl.error().source().begin << ")\n";
|
2020-02-20 21:08:20 +00:00
|
|
|
/// return 1;
|
|
|
|
/// }
|
|
|
|
///
|
|
|
|
/// do_stuff_with_your_config(tbl); //toml::parse_result is convertible to toml::table
|
|
|
|
/// return 0;
|
|
|
|
/// }
|
|
|
|
/// \ecpp
|
2020-02-22 14:10:32 +00:00
|
|
|
///
|
2020-02-25 21:11:40 +00:00
|
|
|
/// Instances of toml::parse_error can be printed directly to streams:
|
|
|
|
/// \cpp
|
|
|
|
/// try
|
|
|
|
/// {
|
|
|
|
/// auto tbl = toml::parse("enabled = trUe"sv); //fails; TOML booleans are case-sensitive
|
|
|
|
/// }
|
|
|
|
/// catch (const toml::parse_error & err)
|
|
|
|
/// {
|
2020-04-02 21:39:21 +00:00
|
|
|
/// std::cerr << "Parsing failed:\n" << err << "\n";
|
2020-02-25 21:11:40 +00:00
|
|
|
/// return 1;
|
|
|
|
/// }
|
|
|
|
/// \ecpp
|
|
|
|
///
|
|
|
|
/// \out
|
|
|
|
/// Parsing failed:
|
|
|
|
/// Encountered unexpected character while parsing boolean; expected 'true', saw 'trU'
|
|
|
|
/// (error occurred at line 1, column 13)
|
|
|
|
/// \eout
|
|
|
|
///
|
|
|
|
/// If the default error formatting is not be suitable for your use-case you can access the error's
|
|
|
|
/// toml::source_region and description directly from the error object (as in the examples above).
|
|
|
|
///
|
2020-02-22 14:10:32 +00:00
|
|
|
/// \see
|
|
|
|
/// - toml::parse_file()
|
|
|
|
/// - toml::parse_result
|
2020-02-25 21:11:40 +00:00
|
|
|
/// - toml::parse_error
|
|
|
|
/// - toml::source_region
|
|
|
|
/// - toml::source_position
|
2020-02-20 21:08:20 +00:00
|
|
|
///
|
|
|
|
///////////////////////////////////
|
|
|
|
///
|
2020-02-25 21:11:40 +00:00
|
|
|
/// \subsection mainpage-example-parsing-strings Parsing TOML directly from strings and streams
|
|
|
|
/// Strings and std::istreams can be read directly using toml::parse():
|
2020-02-20 21:08:20 +00:00
|
|
|
/// \cpp
|
|
|
|
/// #include <iostream>
|
2020-02-25 21:11:40 +00:00
|
|
|
/// #include <sstream>
|
2020-02-20 21:08:20 +00:00
|
|
|
/// #include <toml++/toml.h>
|
|
|
|
/// using namespace std::string_view_literals;
|
|
|
|
///
|
|
|
|
/// int main()
|
|
|
|
/// {
|
|
|
|
/// static constexpr auto source = R"(
|
|
|
|
/// [library]
|
|
|
|
/// name = "toml++"
|
2020-04-02 21:39:21 +00:00
|
|
|
/// authors = ["Mark Gillard <mark.gillard@outlook.com.au>"]
|
2020-02-20 21:08:20 +00:00
|
|
|
///
|
|
|
|
/// [dependencies]
|
|
|
|
/// cpp = 17
|
|
|
|
/// )"sv;
|
2020-02-25 21:11:40 +00:00
|
|
|
///
|
|
|
|
/// // parse directly from a string view:
|
|
|
|
/// {
|
|
|
|
/// auto tbl = toml::parse(source);
|
2020-04-02 21:39:21 +00:00
|
|
|
/// std::cout << tbl << "\n";
|
2020-02-25 21:11:40 +00:00
|
|
|
/// }
|
|
|
|
///
|
|
|
|
/// // parse from a string stream:
|
|
|
|
/// {
|
|
|
|
/// std::stringstream ss{ std::string{ source } };
|
|
|
|
/// auto tbl = toml::parse(ss);
|
2020-04-02 21:39:21 +00:00
|
|
|
/// std::cout << tbl << "\n";
|
2020-02-25 21:11:40 +00:00
|
|
|
/// }
|
|
|
|
///
|
2020-02-20 21:08:20 +00:00
|
|
|
/// return 0;
|
|
|
|
/// }
|
|
|
|
/// \ecpp
|
|
|
|
///
|
|
|
|
/// \out
|
|
|
|
/// [dependencies]
|
|
|
|
/// cpp = 17
|
|
|
|
///
|
|
|
|
/// [library]
|
|
|
|
/// authors = ["Mark Gillard <mark@notarealwebsite.com>"]
|
|
|
|
/// name = "toml++"
|
2020-02-25 21:11:40 +00:00
|
|
|
///
|
|
|
|
/// ... exactly as above, but twice
|
2020-02-20 21:08:20 +00:00
|
|
|
/// \eout
|
2020-02-25 21:11:40 +00:00
|
|
|
///
|
2020-04-03 13:33:02 +00:00
|
|
|
/// The error-handling semantics are the same as for toml::parse_file.
|
|
|
|
///
|
2020-02-22 14:10:32 +00:00
|
|
|
/// \see toml::parse()
|
2020-02-20 21:08:20 +00:00
|
|
|
///
|
|
|
|
///////////////////////////////////
|
|
|
|
///
|
|
|
|
/// \subsection mainpage-example-manipulations Traversing and manipulating data
|
2020-02-26 23:28:20 +00:00
|
|
|
/// A TOML document is a tree of values, arrays and tables, represented as the toml::value, toml::array
|
|
|
|
/// and toml::table, respectively. All three inherit from toml::node, and can be easily accessed via
|
|
|
|
/// the toml::node_view:
|
2020-02-20 21:08:20 +00:00
|
|
|
/// \cpp
|
|
|
|
/// #include <iostream>
|
|
|
|
/// #include <toml++/toml.h>
|
|
|
|
/// using namespace std::string_view_literals;
|
|
|
|
///
|
|
|
|
/// int main()
|
|
|
|
/// {
|
|
|
|
/// static constexpr auto source = R"(
|
|
|
|
/// numbers = [ 1, 2, 3, "four", 5.0 ]
|
|
|
|
/// vegetables = [ "tomato", "onion", "mushroom", "lettuce" ]
|
|
|
|
/// minerals = [ "quartz", "iron", "copper", "diamond" ]
|
|
|
|
///
|
|
|
|
/// [animals]
|
|
|
|
/// cats = [ "tiger", "lion", "puma" ]
|
|
|
|
/// birds = [ "macaw", "pigeon", "canary" ]
|
|
|
|
/// fish = [ "salmon", "trout", "carp" ]
|
|
|
|
///
|
|
|
|
/// )"sv;
|
|
|
|
/// auto tbl = toml::parse(source);
|
|
|
|
///
|
2020-02-26 23:28:20 +00:00
|
|
|
/// // get a view of the element 'numbers'
|
2020-02-20 21:08:20 +00:00
|
|
|
/// auto numbers = tbl["numbers"];
|
2020-04-02 21:39:21 +00:00
|
|
|
/// std::cout << "table has 'numbers': " << !!numbers << "\n";
|
|
|
|
/// std::cout << "numbers is a: " << numbers.type() << "\n";
|
|
|
|
/// std::cout << "numbers: " << numbers << "\n";
|
2020-02-26 23:28:20 +00:00
|
|
|
///
|
|
|
|
/// // get the underlying array object to do some more advanced stuff
|
|
|
|
/// if (auto arr = numbers.as_array())
|
2020-02-20 21:08:20 +00:00
|
|
|
/// {
|
2020-02-26 23:28:20 +00:00
|
|
|
/// for (auto& elem : *arr)
|
2020-02-20 21:08:20 +00:00
|
|
|
/// {
|
2020-02-26 23:28:20 +00:00
|
|
|
/// // visitation helps deal with the polymorphic nature of TOML data
|
2020-02-29 20:34:08 +00:00
|
|
|
/// elem.visit([](auto&& el) noexcept
|
2020-02-20 21:08:20 +00:00
|
|
|
/// {
|
2020-02-26 23:28:20 +00:00
|
|
|
/// if constexpr (toml::is_number<decltype(el)>)
|
|
|
|
/// (*el)++;
|
|
|
|
/// else if constexpr (toml::is_string<decltype(el)>)
|
|
|
|
/// el = "five"sv;
|
2020-02-20 21:08:20 +00:00
|
|
|
/// });
|
|
|
|
/// }
|
2020-02-26 23:28:20 +00:00
|
|
|
///
|
|
|
|
/// // arrays are very similar to std::vector
|
|
|
|
/// arr->push_back(7);
|
|
|
|
/// arr->emplace_back<toml::array>(8, 9);
|
2020-04-02 21:39:21 +00:00
|
|
|
/// std::cout << "numbers: " << numbers << "\n";
|
2020-02-20 21:08:20 +00:00
|
|
|
/// }
|
|
|
|
///
|
2020-02-26 23:28:20 +00:00
|
|
|
/// // node-views can be chained to quickly query deeper
|
2020-04-02 21:39:21 +00:00
|
|
|
/// std::cout << "cats: " << tbl["animals"]["cats"] << "\n";
|
|
|
|
/// std::cout << "fish[1]: " << tbl["animals"]["fish"][1] << "\n";
|
2020-02-26 23:28:20 +00:00
|
|
|
///
|
|
|
|
/// // ...even if the element doesn't exist
|
2020-04-02 21:39:21 +00:00
|
|
|
/// std::cout << "dinosaurs: " << tbl["animals"]["dinosaurs"] << "\n"; //no dinosaurs :(
|
2020-02-20 21:08:20 +00:00
|
|
|
///
|
|
|
|
/// return 0;
|
|
|
|
/// }
|
|
|
|
/// \ecpp
|
|
|
|
///
|
|
|
|
/// \out
|
|
|
|
/// table has 'numbers': true
|
2020-02-26 23:28:20 +00:00
|
|
|
/// numbers is an: array
|
|
|
|
/// numbers: [1, 2, 3, "four", 5.0]
|
|
|
|
/// numbers: [2, 3, 4, "five", 6.0, 7, [8, 9]]
|
|
|
|
/// cats: ["tiger", "lion", "puma"]
|
|
|
|
/// fish[1]: "trout"
|
|
|
|
/// dinosaurs:
|
2020-02-20 21:08:20 +00:00
|
|
|
/// \eout
|
|
|
|
///
|
2020-02-22 14:10:32 +00:00
|
|
|
/// \see
|
|
|
|
/// - toml::node
|
2020-04-01 12:53:10 +00:00
|
|
|
/// - toml::node_view
|
2020-02-26 23:28:20 +00:00
|
|
|
/// - toml::value
|
2020-02-22 14:10:32 +00:00
|
|
|
/// - toml::array
|
|
|
|
/// - toml::table
|
2020-02-20 21:08:20 +00:00
|
|
|
///
|
|
|
|
///////////////////////////////////
|
|
|
|
///
|
|
|
|
/// \subsection mainpage-example-serialization Serializing as TOML and JSON
|
|
|
|
/// \cpp
|
|
|
|
/// #include <iostream>
|
|
|
|
/// #include <toml++/toml.h>
|
|
|
|
///
|
|
|
|
/// int main()
|
|
|
|
/// {
|
2020-02-18 21:29:59 +00:00
|
|
|
/// auto tbl = toml::table{{
|
|
|
|
/// { "lib", "toml++" },
|
|
|
|
/// { "cpp", toml::array{ 17, 20, "and beyond" } },
|
2020-04-03 13:33:02 +00:00
|
|
|
/// { "toml", toml::array{ "1.0.0-rc.1", "and beyond" } },
|
2020-02-18 21:29:59 +00:00
|
|
|
/// { "repo", "https://github.com/marzer/tomlplusplus/" },
|
|
|
|
/// { "author", toml::table{{
|
|
|
|
/// { "name", "Mark Gillard" },
|
|
|
|
/// { "github", "https://github.com/marzer" },
|
|
|
|
/// { "twitter", "https://twitter.com/marzer8789" }
|
|
|
|
/// }}
|
|
|
|
/// },
|
|
|
|
/// }};
|
2020-02-20 21:08:20 +00:00
|
|
|
///
|
2020-04-01 12:53:10 +00:00
|
|
|
/// // serializing as TOML is just writing it to a stream
|
2020-04-02 21:39:21 +00:00
|
|
|
/// std::cout << "###### TOML ######" << "\n\n";
|
|
|
|
/// std::cout << tbl << "\n\n";
|
2020-04-01 12:53:10 +00:00
|
|
|
///
|
|
|
|
/// // serializing as JSON is _also_ just writing it to a stream, but via a json_formatter:
|
2020-04-02 21:39:21 +00:00
|
|
|
/// std::cout << "###### JSON ######" << "\n\n";
|
|
|
|
/// std::cout << toml::json_formatter{ tbl } << "\n\n";
|
2020-02-18 21:29:59 +00:00
|
|
|
/// return 0;
|
|
|
|
/// }
|
|
|
|
/// \ecpp
|
2020-02-20 21:08:20 +00:00
|
|
|
///
|
2020-02-18 21:29:59 +00:00
|
|
|
/// \out
|
2020-02-20 21:08:20 +00:00
|
|
|
/// ###### TOML ######
|
2020-04-02 21:39:21 +00:00
|
|
|
///
|
2020-02-20 21:08:20 +00:00
|
|
|
/// cpp = [17, 20, "and beyond"]
|
2020-02-18 21:29:59 +00:00
|
|
|
/// lib = "toml++"
|
|
|
|
/// repo = "https://github.com/marzer/tomlplusplus/"
|
2020-04-03 13:33:02 +00:00
|
|
|
/// toml = ["1.0.0-rc.1", "and beyond"]
|
2020-02-18 21:29:59 +00:00
|
|
|
///
|
|
|
|
/// [author]
|
|
|
|
/// github = "https://github.com/marzer"
|
|
|
|
/// name = "Mark Gillard"
|
|
|
|
/// twitter = "https://twitter.com/marzer8789"
|
2020-02-20 21:08:20 +00:00
|
|
|
///
|
|
|
|
/// ###### JSON ######
|
2020-04-02 21:39:21 +00:00
|
|
|
///
|
2020-02-20 21:08:20 +00:00
|
|
|
/// {
|
|
|
|
/// "author" : {
|
|
|
|
/// "github" : "https://github.com/marzer",
|
|
|
|
/// "name" : "Mark Gillard",
|
|
|
|
/// "twitter" : "https://twitter.com/marzer8789"
|
|
|
|
/// },
|
|
|
|
/// "cpp" : [
|
|
|
|
/// 17,
|
|
|
|
/// 20,
|
|
|
|
/// "and beyond"
|
|
|
|
/// ],
|
|
|
|
/// "lib" : "toml++",
|
|
|
|
/// "repo" : "https://github.com/marzer/tomlplusplus/",
|
|
|
|
/// "toml" : [
|
2020-04-03 13:33:02 +00:00
|
|
|
/// "1.0.0-rc.1",
|
2020-02-20 21:08:20 +00:00
|
|
|
/// "and beyond"
|
|
|
|
/// ]
|
|
|
|
/// }
|
2020-02-18 21:29:59 +00:00
|
|
|
/// \eout
|
2020-02-22 14:10:32 +00:00
|
|
|
/// \see
|
|
|
|
/// - toml::default_formatter
|
|
|
|
/// - toml::json_formatter
|
2020-02-20 21:08:20 +00:00
|
|
|
///
|
2020-04-01 12:53:10 +00:00
|
|
|
///////////////////////////////////
|
|
|
|
///
|
|
|
|
/// \subsection mainpage-example-speed-up-compilation Speeding up compilation
|
|
|
|
/// Because `toml++` is a header-only library of nontrivial size you might find that compilation times noticeably
|
|
|
|
/// increase after you add it to your project, especially if you add the library's header somewhere that's visible from
|
|
|
|
/// a large number of translation units. You can counter this by disabling 'all inline' mode and explicitly controlling
|
|
|
|
/// where the library's implementation is compiled.
|
|
|
|
///
|
|
|
|
/// <strong>Step 1: Set `TOML_ALL_INLINE` to `0` before including `toml++`</strong>
|
|
|
|
///
|
|
|
|
/// This must be the same everywhere, so either set it as a global `#define` in your build system, or
|
|
|
|
/// do it manually before including toml++ in some global header that's used everywhere in your project:
|
|
|
|
/// \cpp
|
|
|
|
/// // global_header_that_includes_toml++.h
|
|
|
|
///
|
|
|
|
/// #define TOML_ALL_INLINE 0
|
|
|
|
/// #include <toml.hpp>
|
|
|
|
/// \ecpp
|
|
|
|
///
|
|
|
|
/// <strong>Step 2: Define `TOML_IMPLEMENTATION` before including `toml++` in one specific translation unit</strong>
|
|
|
|
///
|
|
|
|
/// \cpp
|
|
|
|
/// // some_code_file.cpp
|
|
|
|
///
|
|
|
|
/// #define TOML_IMPLEMENTATION
|
|
|
|
/// #include "global_header_that_includes_toml++.h"
|
|
|
|
/// \ecpp
|
|
|
|
///
|
2020-04-10 16:46:00 +00:00
|
|
|
/// Additionally, if all you need to do is serialize some code-generated TOML and don't actually need the parser at all,
|
|
|
|
/// you can `#define TOML_PARSER 0`.
|
|
|
|
///
|
2020-02-20 21:08:20 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
///
|
|
|
|
/// \section mainpage-contributing Contributing
|
2020-04-01 12:53:10 +00:00
|
|
|
/// Contributions are very welcome! Either by [reporting issues](https://github.com/marzer/tomlplusplus/issues)
|
|
|
|
/// or submitting pull requests. If you wish to submit a pull request,
|
|
|
|
/// please see [CONTRIBUTING](https://github.com/marzer/tomlplusplus/blob/master/CONTRIBUTING.md)
|
2020-02-25 21:11:40 +00:00
|
|
|
/// for all the details you need to get going.
|
2020-02-20 21:08:20 +00:00
|
|
|
///
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
///
|
|
|
|
/// \section mainpage-license License
|
|
|
|
///
|
2020-02-23 11:13:18 +00:00
|
|
|
/// toml++ is licensed under the terms of the MIT license - see
|
|
|
|
/// [LICENSE](https://github.com/marzer/tomlplusplus/blob/master/LICENSE).
|
2020-02-20 21:08:20 +00:00
|
|
|
///
|
2020-02-26 23:28:20 +00:00
|
|
|
/// \m_class{m-note m-default}
|
|
|
|
///
|
2020-03-12 15:23:25 +00:00
|
|
|
/// If you're using the single-header version of the library you don't need to explicitly distribute the license file;
|
|
|
|
/// it is embedded in the preamble at the top of the header.
|
2020-02-27 17:52:10 +00:00
|
|
|
///
|
2020-04-01 12:53:10 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
///
|
|
|
|
/// \section mainpage-contact Contacting the author
|
|
|
|
/// For bug reports and feature requests please consider using the
|
|
|
|
/// [GitHub issues](https://github.com/marzer/tomlplusplus/issues) system. For anything else though you're welcome
|
|
|
|
/// to reach out via other means. In order of likely response speed:
|
|
|
|
/// - Twitter: [marzer8789](https://twitter.com/marzer8789)
|
|
|
|
/// - Email: [mark.gillard@outlook.com.au](mailto:mark.gillard@outlook.com.au)
|
|
|
|
/// - Facebook: [marzer](https://www.facebook.com/marzer)
|
|
|
|
/// - LinkedIn: [marzer](https://www.linkedin.com/in/marzer/)
|
|
|
|
///
|