From 32f5f761bc8e960293b4f4feaf973dd0da26d0f8 Mon Sep 17 00:00:00 2001 From: Mehmet Samet Duman Date: Sun, 5 Apr 2026 17:37:54 +0300 Subject: NOISSUE Project Tick Handbook is Released! Assisted-by: Claude:Opus-4.6-High Signed-off-by: Mehmet Samet Duman --- docs/handbook/tomlplusplus/node-system.md | 625 ++++++++++++++++++++++++++++++ 1 file changed, 625 insertions(+) create mode 100644 docs/handbook/tomlplusplus/node-system.md (limited to 'docs/handbook/tomlplusplus/node-system.md') diff --git a/docs/handbook/tomlplusplus/node-system.md b/docs/handbook/tomlplusplus/node-system.md new file mode 100644 index 0000000000..c34b531385 --- /dev/null +++ b/docs/handbook/tomlplusplus/node-system.md @@ -0,0 +1,625 @@ +# toml++ — Node System + +## Overview + +The node system is the core of toml++'s data model. Every element in a TOML document — tables, arrays, and leaf values — is represented as a `toml::node`. This document covers the base class interface, `node_view` for safe access, type checking mechanisms, value retrieval strategies, and visitation patterns. + +--- + +## `toml::node` — The Base Class + +`toml::node` is an abstract base class (`TOML_ABSTRACT_INTERFACE`) declared in `include/toml++/impl/node.hpp`. It cannot be instantiated directly; only its derived classes (`table`, `array`, `value`) can. + +### Source Tracking + +Every node stores a `source_region` tracking its origin in the parsed document: + +```cpp +class node +{ + private: + source_region source_{}; + + public: + const source_region& source() const noexcept; +}; +``` + +For programmatically-constructed nodes, `source()` returns a default-constructed region (all zeros). For parsed nodes, it contains the file path and begin/end line/column. + +### Lifetime + +```cpp + protected: + node() noexcept; + node(const node&) noexcept; // copies source_region + node(node&&) noexcept; // moves source_region + node& operator=(const node&) noexcept; + node& operator=(node&&) noexcept; + + public: + virtual ~node() noexcept; +``` + +Constructors are protected — you create nodes by constructing `table`, `array`, or `value` objects. + +--- + +## Type Checking + +### Virtual Type Checks + +Every `node` provides a full set of virtual type-checking methods: + +```cpp +virtual node_type type() const noexcept = 0; + +virtual bool is_table() const noexcept = 0; +virtual bool is_array() const noexcept = 0; +virtual bool is_array_of_tables() const noexcept; +virtual bool is_value() const noexcept = 0; +virtual bool is_string() const noexcept = 0; +virtual bool is_integer() const noexcept = 0; +virtual bool is_floating_point() const noexcept = 0; +virtual bool is_number() const noexcept = 0; +virtual bool is_boolean() const noexcept = 0; +virtual bool is_date() const noexcept = 0; +virtual bool is_time() const noexcept = 0; +virtual bool is_date_time() const noexcept = 0; +``` + +`is_number()` returns `true` for both integers and floating-point values. + +`is_array_of_tables()` returns `true` only for arrays where every element is a table. + +### Template Type Check: `is()` + +```cpp +template +bool is() const noexcept; +``` + +Accepts any TOML node or value type. Uses `if constexpr` internally to dispatch: + +```cpp +node.is() // equivalent to node.is_table() +node.is() // equivalent to node.is_array() +node.is() // equivalent to node.is_string() +node.is() // equivalent to node.is_integer() +node.is() // equivalent to node.is_floating_point() +node.is() // equivalent to node.is_boolean() +node.is() // equivalent to node.is_date() +node.is() // equivalent to node.is_time() +node.is() // equivalent to node.is_date_time() +``` + +You can also use the wrapped `value` type: +```cpp +node.is>() // same as node.is() +``` + +The `impl::unwrap_node` trait unwraps `value` → `T` and `node_view` → `T`. + +### Compile-Time Type Traits + +The `toml` namespace provides type traits usable with `if constexpr`: + +```cpp +// Type traits for use in generic/template code +toml::is_table // true if val is table or node_view of table +toml::is_array // true if val is array or node_view of array +toml::is_string // true if val is value +toml::is_integer // true if val is value +toml::is_floating_point // true if val is value +toml::is_number // integer or floating-point +toml::is_boolean // true if val is value +toml::is_date // true if val is value +toml::is_time // true if val is value