### Installing pytomlpp Python Wrapper Source: https://marzer.github.io/tomlplusplus/index This snippet shows the command to install the pytomlpp Python wrapper library, which provides a fast, natively-compiled TOML parser for Python, leveraging the toml++ library. ```shell pip install pytomlpp ``` -------------------------------- ### Adding tomlplusplus via Meson Source: https://marzer.github.io/tomlplusplus/index Demonstrates how to install and use tomlplusplus with the Meson build system. It includes commands for wrapping the package and for declaring it as a dependency. ```shell meson wrap install tomlplusplus After that, you can use it like a regular dependency: tomlplusplus_dep = dependency('tomlplusplus') ``` -------------------------------- ### Integrating tomlplusplus with Meson Source: https://marzer.github.io/tomlplusplus/v3.3.0/index This example shows how to install tomlplusplus using Meson's wrap system and then use it as a dependency in a Meson build file. It simplifies dependency management for Meson projects. ```meson tomlplusplus_dep = dependency('tomlplusplus') ``` -------------------------------- ### Adding tomlplusplus via Vcpkg Source: https://marzer.github.io/tomlplusplus/index A simple command to install the tomlplusplus library using the Vcpkg package manager. ```shell vcpkg install tomlplusplus ``` -------------------------------- ### YAML Configuration Example for tomlplusplus Source: https://marzer.github.io/tomlplusplus/v3.1.0/index This snippet illustrates the equivalent configuration in YAML format for the tomlplusplus project, mirroring the structure found in the JSON example. ```yaml 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: - '1.0.0' - 'and beyond' ``` -------------------------------- ### Example of TOML configuration file Source: https://marzer.github.io/tomlplusplus/v3.3.0/index This is an example of a TOML configuration file, showcasing basic key-value pairs, nested tables, and arrays of values. This format is commonly used for configuration files and is processed by libraries like toml++. ```toml 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: - '1.0.0' - 'and beyond' ``` -------------------------------- ### Install pytomlpp using pip (Python) Source: https://marzer.github.io/tomlplusplus/v2.5.0/index This command installs the `pytomlpp` Python wrapper library, which provides a fast, natively-compiled TOML parser for Python, built around the toml++ C++ library. ```shell pip install pytomlpp ``` -------------------------------- ### Example: Convert TOML to YAML using yaml_formatter Source: https://marzer.github.io/tomlplusplus/classtoml_1_1yaml__formatter Demonstrates how to parse a TOML string and then format it as YAML using the toml::yaml_formatter class. This example shows the basic usage for converting a valid TOML structure to its YAML representation. ```cpp auto some_toml = toml::parse(R"( [fruit] apple.color = "red" apple.taste.sweet = true [fruit.apple.texture] smooth = true )"sv); std::cout << toml::yaml_formatter{ some_toml } << "\n"; ``` -------------------------------- ### Adding tomlplusplus via Tipi.build Source: https://marzer.github.io/tomlplusplus/index Instructions for incorporating tomlplusplus into a tipi.build project by adding a specific entry to the '.tipi/deps' file. ```json { "marzer/tomlplusplus": { } } ``` -------------------------------- ### Add toml++ via Meson Source: https://marzer.github.io/tomlplusplus/v3.4.0/index Install the toml++ wrap for Meson and use it as a dependency in your Meson build system. ```meson meson wrap install tomlplusplus tomlplusplus_dep = dependency('tomlplusplus') ``` -------------------------------- ### Adding tomlplusplus via Git Submodules Source: https://marzer.github.io/tomlplusplus/index Instructions for including tomlplusplus in a project as a Git submodule, specifying the repository URL and the destination directory. ```shell git submodule add --depth 1 https://github.com/marzer/tomlplusplus.git tomlplusplus ``` -------------------------------- ### Parsing Strings and IOStreams Source: https://marzer.github.io/tomlplusplus/index Shows how to parse TOML data directly from a string or an istream using `toml::parse()`. Includes exception handling. ```APIDOC ## POST /parse ### Description Parses TOML data from a string or an input stream. Returns a `toml::table` on success or throws `toml::parse_error` on failure. ### Method POST ### Endpoint `/parse` ### Parameters #### Query Parameters - **sourceType** (string) - Required - Specifies whether the input is a 'string' or 'stream'. #### Request Body - **content** (string) - Required - The TOML content to parse, if `sourceType` is 'string'. - **stream** (ReadableStream) - Required - The input stream containing TOML data, if `sourceType` is 'stream'. ### Request Example ```cpp #include #include #include using namespace std::string_view_literals; int main() { static constexpr std::string_view some_toml = R"( [library] name = "toml++" authors = ["Mark Gillard "] cpp = 17 )"sv; try { // parse directly from a string view: { toml::table tbl = toml::parse(some_toml); std::cout << tbl << "\n"; } // parse from a string stream: { std::stringstream ss{ std::string{ some_toml } }; toml::table tbl = toml::parse(ss); std::cout << tbl << "\n"; } } catch (const toml::parse_error& err) { std::cerr << "Parsing failed:\n" << err << "\n"; return 1; } return 0; } ``` ### Response #### Success Response (200) - **table** (toml::table) - The parsed TOML data. #### Response Example ```json { "table": { "library": { "name": "toml++", "authors": ["Mark Gillard "], "cpp": 17 } } } ``` #### Error Response (400) - **error** (string) - A message describing the parsing error. #### Error Example ```json { "error": "Parsing failed: ..." } ``` ``` -------------------------------- ### Parsing Files Source: https://marzer.github.io/tomlplusplus/index Demonstrates how to parse a TOML file using `toml::parse_file()`. It includes error handling for `toml::parse_error`. ```APIDOC ## POST /parse/file ### Description Parses a TOML file and returns a `toml::table`. Handles `toml::parse_error` if parsing fails. ### Method POST ### Endpoint `/parse/file` ### Parameters #### Path Parameters - **filePath** (string) - Required - The path to the TOML file to parse. ### Request Body This endpoint does not strictly require a request body, but a file path must be provided, typically via a form submission or query parameter if not directly in the URL. ### Request Example ```cpp #include #include int main(int argc, char** argv) { toml::table tbl; try { tbl = toml::parse_file(argv[1]); std::cout << tbl << "\n"; } catch (const toml::parse_error& err) { std::cerr << "Parsing failed:\n" << err << "\n"; return 1; } return 0; } ``` ### Response #### Success Response (200) - **table** (toml::table) - The parsed TOML data. #### Response Example ```json { "table": { "key": "value" } } ``` #### Error Response (400) - **error** (string) - A message describing the parsing error. #### Error Example ```json { "error": "Parsing failed: ..." } ``` ``` -------------------------------- ### Integrate toml++ with DDS (package.json5) Source: https://marzer.github.io/tomlplusplus/v2.4.0/index This example shows how to declare tomlpp version 2.4.0 as a dependency in a package.json5 file, commonly used in environments that leverage DDS for package management. ```json depends: [ 'tomlpp^2.4.0', ] ``` -------------------------------- ### Parsing TOML and getting source position (C++) Source: https://marzer.github.io/tomlplusplus/structtoml_1_1source__position This snippet demonstrates parsing a TOML file and retrieving the source position of a specific node. It uses `toml::parse_file` to load the TOML content and then accesses the `source().begin()` method of a retrieved node to get its starting position. The output shows the line and column number where the node was defined. ```cpp auto table = toml::parse_file("config.toml"sv); std::cout << "The node 'description' was defined at "sv << table.get("description")->source().begin() << "\n"; ``` -------------------------------- ### Parse TOML String and Get Value Source (C++) Source: https://marzer.github.io/tomlplusplus/structtoml_1_1source__region Shows how to parse a TOML string and retrieve the source region information for a specific key ('bar'). It then prints a formatted string indicating where the value was found in the source. This example utilizes toml::parse and the source() method to pinpoint the location of data within the parsed string. ```cpp auto tbl = toml::parse("bar = 42", "config.toml"); std::cout << "The value for 'bar' was found on "sv << tbl.get("bar")->source() << "\n"; ``` -------------------------------- ### Value Retrieval Functions for tomlplusplus node_view Source: https://marzer.github.io/tomlplusplus/v2.4.0/classtoml_1_1node__view These functions retrieve the underlying data from a node view. They include getting a raw reference, getting the value as an optional type, getting the exact value, or getting the value with a default if it's not present. ```cpp template auto ref() const → decltype(auto) noexcept Gets a raw reference to the viewed node's underlying data. template auto value() const → optional noexcept Gets the value contained by the referenced node. template auto value_exact() const → optional noexcept Gets the value contained by the referenced node. template auto value_or(T&& default_value) const → auto noexcept Gets the raw value contained by the referenced node, or a default. ``` -------------------------------- ### Safely Get Node with get() Source: https://marzer.github.io/tomlplusplus/v3.2.0/classtoml_1_1table The `get(key)` methods retrieve a pointer to the node associated with the given key. They return `nullptr` if the key is not found, providing a non-throwing way to access elements. Overloads support `std::string_view` and `std::wstring_view`. ```cpp auto get(std::string_view key) -> node* noexcept; auto get(std::string_view key) const -> const node* noexcept; auto get(std::wstring_view key) -> node*; auto get(std::wstring_view key) const -> const node*; // Example usage: if (node_ptr = root.get("optional_key")) { // Key exists, process node_ptr } ``` -------------------------------- ### Constructor Source: https://marzer.github.io/tomlplusplus/v3.4.0/classtoml_1_1table Constructs a `toml::table` with initial key-value pairs. ```APIDOC ## `toml::table::table(std::initializer_list kvps)` ### Description Constructs a table with one or more initial key-value pairs. ### Method Constructor ### Parameters #### Request Body - **kvps** (std::initializer_list) - Required - A list of key-value pairs used to initialize the table. ### Request Example ```cpp auto tbl = toml::table{ { "foo", 1 }, { "bar", 2.0 }, { "kek", "three" } }; std::cout << tbl << "\n"; ``` ### Response #### Success Response (200) N/A (Constructor) #### Response Example ```json { foo = 1, bar = 2.0, kek = "three" } ``` ``` -------------------------------- ### Construct toml::table with Initial Key-Value Pairs Source: https://marzer.github.io/tomlplusplus/classtoml_1_1table Demonstrates how to construct a toml::table using an initializer list of key-value pairs. This method allows for the creation of a table with predefined content. The output shows the formatted TOML representation of the constructed table. ```cpp auto tbl = toml::table{ { "foo", 1 }, { "bar", 2.0 }, { "kek", "three" } }; std::cout << tbl << "\n"; ``` -------------------------------- ### get() Source: https://marzer.github.io/tomlplusplus/v3.0.1/classtoml_1_1table The `get()` methods retrieves the node at a specific key. Various overloads are provided for both string_view and wstring_view, const and non-const. ```APIDOC ## get(std::string_view key) noexcept ### Description Gets the node at a specific key. ### Method GET ### Endpoint toml::table::get(std::string_view key) noexcept ### Parameters #### Path Parameters - **key** (std::string_view) - Required - The node's key. ### Response #### Success Response (200) - **node*** (node*) - A pointer to the node at the specified key, or nullptr. ### Request Example ```cpp auto tbl = toml::table{ { "a", 42, }, { "b", "is the meaning of life, apparently." } }; std::cout << R"(node ["a"] exists: )"sv << !!arr.get("a") << "\n"; std::cout << R"(node ["b"] exists: )"sv << !!arr.get("b") << "\n"; std::cout << R"(node ["c"] exists: )"sv << !!arr.get("c") << "\n"; if (auto val = arr.get("a")) std::cout << R"(node ["a"] was an )"sv << val->type() << "\n"; ``` ### Response #### Success Response (200) - **node*** (node*) - A pointer to the node at the specified key, or nullptr. #### Response Example ``` node ["a"] exists: true node ["b"] exists: true node ["c"] exists: false node ["a"] was an integer ``` ## get(std::string_view key) const noexcept ### Description Gets the node at a specific key (const overload). ### Method GET ### Endpoint toml::table::get(std::string_view key) const noexcept ### Parameters #### Path Parameters - **key** (std::string_view) - Required - The node's key. ### Response #### Success Response (200) - **const node*** (const node*) - A pointer to the node at the specified key, or nullptr. ## get(std::wstring_view key) ### Description Gets the node at a specific key. ### Method GET ### Endpoint toml::table::get(std::wstring_view key) ### Parameters #### Path Parameters - **key** (std::wstring_view) - Required - The node's key. ### Response #### Success Response (200) - **node*** (node*) - A pointer to the node at the specified key, or nullptr. ## get(std::wstring_view key) const ### Description Gets the node at a specific key (const overload). ### Method GET ### Endpoint toml::table::get(std::wstring_view key) const ### Parameters #### Path Parameters - **key** (std::wstring_view) - Required - The node's key. ### Response #### Success Response (200) - **const node*** (const node*) - A pointer to the node at the specified key, or nullptr. ``` -------------------------------- ### Constructors, Destructors, and Conversion Operators Source: https://marzer.github.io/tomlplusplus/v3.4.0/classtoml_1_1value Information on how to construct, copy, move, and assign toml::value objects. ```APIDOC ## Constructors, Destructors, Conversion Operators ### `value(Args && ... args) explicit noexcept(…)` Constructs a TOML value. ### `value(const value& other) noexcept` Copy constructor. ### `value(const value& other, value_flags flags) noexcept` Copy constructor with flags override. ### `value(value&& other) noexcept` Move constructor. ### `value(value&& other, value_flags flags) noexcept` Move constructor with flags override. ``` -------------------------------- ### Serialize Data to TOML, JSON, and YAML with C++ Source: https://marzer.github.io/tomlplusplus/v3.0.1/index Demonstrates serializing a C++ toml::table into TOML, JSON, and YAML formats using overloaded stream operators and dedicated formatters. This example shows how to create a toml::table with nested structures and then output it to standard output in different serialization formats. ```cpp #include #include int main() { auto tbl = toml::table{ { "lib", "toml++" }, { "cpp", toml::array{ 17, 20, "and beyond" } }, { "toml", toml::array{ "1.0.0", "and beyond" } }, { "repo", "https://github.com/marzer/tomlplusplus/" }, { "author", toml::table{ { "name", "Mark Gillard" }, { "github", "https://github.com/marzer" }, { "twitter", "https://twitter.com/marzer8789" } } }, }; // serializing as TOML std::cout << "###### TOML ######" << "\n\n"; std::cout << tbl << "\n\n"; // serializing as JSON using toml::json_formatter: std::cout << "###### JSON ######" << "\n\n"; std::cout << toml::json_formatter{ tbl } << "\n\n"; // serializing as YAML using toml::yaml_formatter: std::cout << "###### YAML ######" << "\n\n"; std::cout << toml::yaml_formatter{ tbl } << "\n\n"; return 0; } ``` -------------------------------- ### Get Raw Value Reference Source: https://marzer.github.io/tomlplusplus/v2.4.0/classtoml_1_1value The `ref()` function template is used to get a raw reference to a value node's underlying data. It supports lvalue, rvalue, and const lvalue references, and requires specifying the expected type `T`. ```cpp template auto ref() & → impl::unwrap_node& noexcept Gets a raw reference to a value node's underlying data. template auto ref() && → impl::unwrap_node&& noexcept Gets a raw reference to a value node's underlying data (rvalue overload). template auto ref() const & → const impl::unwrap_node& noexcept Gets a raw reference to a value node's underlying data (const lvalue overload). ``` -------------------------------- ### C++ Type Casting: Get Specific Node Type Source: https://marzer.github.io/tomlplusplus/classtoml_1_1value Attempts to get a pointer to the node as a more specific node type. Overloads exist for both non-const and const access. Returns a pointer to the wrapped node if successful, otherwise `nullptr` or a pointer to a different node type. ```cpp template auto as() → impl::wrap_node* noexcept Gets a pointer to the node as a more specific node type. template auto as() const → const impl::wrap_node* noexcept Gets a pointer to the node as a more specific node type (const overload). auto as_boolean() → value* final noexcept Returns a pointer to the value if it is a value, otherwise `nullptr`. auto as_boolean() const → const value* final noexcept Returns a const-qualified pointer to the value if it is a value, otherwise `nullptr`. auto as_date() → value* final noexcept Returns a pointer to the value if it is a value, otherwise `nullptr`. auto as_date() const → const value* final noexcept Returns a const-qualified pointer to the value if it is a value, otherwise `nullptr`. auto as_date_time() → value* final noexcept Returns a pointer to the value if it is a value, otherwise `nullptr`. auto as_date_time() const → const value* final noexcept Returns a const-qualified pointer to the value if it is a value, otherwise `nullptr`. auto as_floating_point() → value* final noexcept Returns a pointer to the value if it is a value, otherwise `nullptr`. auto as_floating_point() const → const value* final noexcept Returns a const-qualified pointer to the value if it is a value, otherwise `nullptr`. auto as_integer() → value* final noexcept Returns a pointer to the value if it is a value, otherwise `nullptr`. auto as_integer() const → const value* final noexcept Returns a const-qualified pointer to the value if it is a value, otherwise `nullptr`. auto as_string() → value* final noexcept Returns a pointer to the value if it is a value, otherwise `nullptr`. auto as_string() const → const value* final noexcept Returns a const-qualified pointer to the value if it is a value, otherwise `nullptr`. auto as_time() → value