From a3ea256d00e5aac45574c7c8b076b60630f73a95 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 24 Jul 2025 09:15:17 +0100 Subject: feat! refactor! Breaking changes of the NeBuild system. Working on a TOML backend, refactored source code namespace. And add 'toml++' vendor library. See commit details. Signed-off-by: Amlal El Mahrouss --- vendor/toml++/impl/node_view.hpp | 839 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 839 insertions(+) create mode 100644 vendor/toml++/impl/node_view.hpp (limited to 'vendor/toml++/impl/node_view.hpp') diff --git a/vendor/toml++/impl/node_view.hpp b/vendor/toml++/impl/node_view.hpp new file mode 100644 index 0000000..fb63025 --- /dev/null +++ b/vendor/toml++/impl/node_view.hpp @@ -0,0 +1,839 @@ +//# This file is a part of toml++ and is subject to the the terms of the MIT license. +//# Copyright (c) Mark Gillard +//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text. +// SPDX-License-Identifier: MIT +#pragma once + +#include "std_vector.hpp" +#include "std_initializer_list.hpp" +#include "print_to_stream.hpp" +#include "node.hpp" +#include "header_start.hpp" +TOML_DISABLE_ARITHMETIC_WARNINGS; + +TOML_NAMESPACE_START +{ + /// \brief A view of a node. + /// + /// \detail A node_view is like a std::optional (if such a construct were legal), with lots of + /// toml-specific stuff built-in. It _may_ represent a node, and allows you to do many of the + /// same operations that you'd do on nodes directly, as well as easily traversing the node tree by creating + /// subviews (via node_view::operator[]). \cpp + /// + /// auto tbl = toml::parse(R"( + /// + /// title = "my hardware store" + /// + /// [[products]] + /// name = "Hammer" + /// sku = 738594937 + /// keywords = [ "hammer", "construction", "build" ] + /// + /// [[products]] + /// name = "Nail" + /// sku = 284758393 + /// color = "gray" + /// + /// )"sv); + /// + /// std::cout << tbl["title"] << "\n"; + /// std::cout << tbl["products"][0]["name"] << "\n"; + /// std::cout << tbl["products"][0]["keywords"] << "\n"; + /// std::cout << tbl["products"][0]["keywords"][2] << "\n"; + /// + /// tbl["products"][0]["keywords"].as_array()->push_back("heavy"); + /// std::cout << tbl["products"][0]["keywords"] << "\n"; + /// std::cout << "has product[2]: "sv << !!tbl["products"][2] << "\n"; + /// std::cout << "product[2]: "sv << tbl["products"][2] << "\n"; + /// \ecpp + /// + /// \out + /// "my hardware store" + /// "Hammer" + /// [ "hammer", "construction", "build" ] + /// "build" + /// [ "hammer", "construction", "build", "heavy" ] + /// has product[2]: false + /// product[2]: + /// \eout + template + class TOML_TRIVIAL_ABI node_view + { + static_assert(impl::is_one_of, + "A toml::node_view<> must wrap toml::node or const toml::node."); + + public: + /// \brief The node type being viewed - either `node` or `const node`. + using viewed_type = ViewedType; + + private: + template + friend class node_view; + + mutable viewed_type* node_ = nullptr; + + public: + /// \brief Constructs an empty node view. + TOML_NODISCARD_CTOR + node_view() noexcept = default; + + /// \brief Constructs node_view of a specific node. + TOML_NODISCARD_CTOR + explicit node_view(viewed_type* node) noexcept // + : node_{ node } + {} + + /// \brief Constructs node_view of a specific node. + TOML_NODISCARD_CTOR + explicit node_view(viewed_type& node) noexcept // + : node_{ &node } + {} + + /// \brief Copy constructor. + TOML_NODISCARD_CTOR + node_view(const node_view&) noexcept = default; + + /// \brief Move constructor. + TOML_NODISCARD_CTOR + node_view(node_view&&) noexcept = default; + + /// \brief Copy-assignment operator. + node_view& operator=(const node_view&) & noexcept = default; + + /// \brief Move-assignment operator. + node_view& operator=(node_view&&) & noexcept = default; + + /// \brief Returns true if the view references a node. + TOML_PURE_INLINE_GETTER + explicit operator bool() const noexcept + { + return node_ != nullptr; + } + + /// \brief Returns the node that's being referenced by the view. + TOML_PURE_INLINE_GETTER + viewed_type* node() const noexcept + { + return node_; + } + + /// \name Type checks + /// @{ + + /// \brief Returns the type identifier for the viewed node. + TOML_PURE_GETTER + node_type type() const noexcept + { + return node_ ? node_->type() : node_type::none; + } + + /// \brief Returns true if the viewed node is a toml::table. + TOML_PURE_GETTER + bool is_table() const noexcept + { + return node_ && node_->is_table(); + } + + /// \brief Returns true if the viewed node is a toml::array. + TOML_PURE_GETTER + bool is_array() const noexcept + { + return node_ && node_->is_array(); + } + + /// \brief Returns true if the viewed node is a toml::value<>. + TOML_PURE_GETTER + bool is_value() const noexcept + { + return node_ && node_->is_value(); + } + + /// \brief Returns true if the viewed node is a toml::value. + TOML_PURE_GETTER + bool is_string() const noexcept + { + return node_ && node_->is_string(); + } + + /// \brief Returns true if the viewed node is a toml::value. + TOML_PURE_GETTER + bool is_integer() const noexcept + { + return node_ && node_->is_integer(); + } + + /// \brief Returns true if the viewed node is a toml::value. + TOML_PURE_GETTER + bool is_floating_point() const noexcept + { + return node_ && node_->is_floating_point(); + } + + /// \brief Returns true if the viewed node is a toml::value or toml::value. + TOML_PURE_GETTER + bool is_number() const noexcept + { + return node_ && node_->is_number(); + } + + /// \brief Returns true if the viewed node is a toml::value. + TOML_PURE_GETTER + bool is_boolean() const noexcept + { + return node_ && node_->is_boolean(); + } + + /// \brief Returns true if the viewed node is a toml::value. + TOML_PURE_GETTER + bool is_date() const noexcept + { + return node_ && node_->is_date(); + } + + /// \brief Returns true if the viewed node is a toml::value