#pragma once #include "toml_common.h" namespace toml { class TOML_INTERFACE node { private: friend class impl::parser; friend class impl::formatter; source_region rgn{}; protected: node(node&& other) noexcept : rgn{ std::move(other.rgn) } {} node& operator= (node&& rhs) noexcept { rgn = std::move(rhs.rgn); return *this; } template [[nodiscard]] TOML_ALWAYS_INLINE node_of* reinterpret_as() noexcept { return reinterpret_cast*>(this); } template [[nodiscard]] TOML_ALWAYS_INLINE const node_of* reinterpret_as() const noexcept { return reinterpret_cast*>(this); } public: node() noexcept = default; node(const node&) = delete; node& operator= (const node&) = delete; virtual ~node() noexcept = default; [[nodiscard]] virtual bool is_value() const noexcept { return false; } [[nodiscard]] virtual bool is_string() const noexcept { return false; } [[nodiscard]] virtual bool is_integer() const noexcept { return false; } [[nodiscard]] virtual bool is_floating_point() const noexcept { return false; } [[nodiscard]] virtual bool is_boolean() const noexcept { return false; } [[nodiscard]] virtual bool is_date() const noexcept { return false; } [[nodiscard]] virtual bool is_time() const noexcept { return false; } [[nodiscard]] virtual bool is_date_time() const noexcept { return false; } [[nodiscard]] virtual bool is_array() const noexcept { return false; } [[nodiscard]] virtual bool is_table() const noexcept { return false; } [[nodiscard]] virtual bool is_array_of_tables() const noexcept { return false; } template [[nodiscard]] bool is() const noexcept { using type = T; static_assert( impl::is_value_or_node, "Template type parameter must be one of the basic value types, a toml::table, or a toml::array" ); if constexpr (std::is_same_v) return is_string(); else if constexpr (std::is_same_v) return is_integer(); else if constexpr (std::is_same_v) return is_floating_point(); else if constexpr (std::is_same_v) return is_boolean(); else if constexpr (std::is_same_v) return is_date(); else if constexpr (std::is_same_v) return is_time(); else if constexpr (std::is_same_v) return is_date_time(); else if constexpr (std::is_same_v) return is_array(); else if constexpr (std::is_same_v) return is_table(); } [[nodiscard]] virtual value* as_string() noexcept { return nullptr; } [[nodiscard]] virtual value* as_integer() noexcept { return nullptr; } [[nodiscard]] virtual value* as_floating_point() noexcept { return nullptr; } [[nodiscard]] virtual value* as_boolean() noexcept { return nullptr; } [[nodiscard]] virtual value* as_date() noexcept { return nullptr; } [[nodiscard]] virtual value