From f17a26c2289a71020fd325138fd75a425e934775 Mon Sep 17 00:00:00 2001 From: fktn Date: Sat, 21 Oct 2023 21:38:46 +0900 Subject: [PATCH 01/48] implemented basic_node ctor with std::initializer_list --- include/fkYAML/detail/meta/node_traits.hpp | 17 +++ include/fkYAML/detail/node_ref_storage.hpp | 131 +++++++++++++++++++++ include/fkYAML/node.hpp | 61 +++++++++- test/unit_test/test_node_class.cpp | 30 ++++- 4 files changed, 235 insertions(+), 4 deletions(-) create mode 100644 include/fkYAML/detail/node_ref_storage.hpp diff --git a/include/fkYAML/detail/meta/node_traits.hpp b/include/fkYAML/detail/meta/node_traits.hpp index bd7db3df..e5ad99a3 100644 --- a/include/fkYAML/detail/meta/node_traits.hpp +++ b/include/fkYAML/detail/meta/node_traits.hpp @@ -74,6 +74,23 @@ struct is_basic_node< { }; +/////////////////////////////////// +// is_node_ref_storage traits +/////////////////////////////////// + +template +class node_ref_storage; + +template +struct is_node_ref_storage : std::false_type +{ +}; + +template +struct is_node_ref_storage> : std::true_type +{ +}; + /////////////////////////////////////////////////////// // basic_node conversion API representative types /////////////////////////////////////////////////////// diff --git a/include/fkYAML/detail/node_ref_storage.hpp b/include/fkYAML/detail/node_ref_storage.hpp new file mode 100644 index 00000000..7c5282f5 --- /dev/null +++ b/include/fkYAML/detail/node_ref_storage.hpp @@ -0,0 +1,131 @@ +/** + * _______ __ __ __ _____ __ __ __ + * | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library + * | __| _ < \_ _/| ___ | _ | |___ version 0.1.2 + * |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML + * + * SPDX-FileCopyrightText: 2023 Kensuke Fukutani + * SPDX-License-Identifier: MIT + * + * @file + */ + +#ifndef FK_YAML_DETAIL_NODE_REF_STORAGE_HPP_ +#define FK_YAML_DETAIL_NODE_REF_STORAGE_HPP_ + +#include +#include +#include + +#include +#include +#include + +/** + * @namespace fkyaml + * @brief namespace for fkYAML library. + */ +FK_YAML_NAMESPACE_BEGIN + +/** + * @namespace detail + * @brief namespace for internal implementations of fkYAML library. + */ +namespace detail +{ + +/** + * @brief A temporal storage for basic_node class objects. + * @note This class makes it easier to handle lvalue basic_node objects in basic_node ctor with std::initializer_list. + * + * @tparam BasicNodeType A basic_node template instance type. + */ +template +class node_ref_storage +{ + static_assert(is_basic_node::value, "node_ref_storage only accepts basic_node<...>"); + + using node_type = BasicNodeType; + +public: + /** + * @brief Construct a new node ref storage object with an rvalue basic_node object. + * + * @param n An rvalue basic_node object. + */ + node_ref_storage(node_type&& n) + : owned_value(std::move(n)) + { + } + + /** + * @brief Construct a new node ref storage object with an lvalue basic_node object. + * + * @param n An lvalue basic_node object. + */ + node_ref_storage(const node_type& n) + : value_ref(&n) + { + } + + /** + * @brief Construct a new node ref storage object with a std::initializer_list object. + * + * @param init A std::initializer_list object. + */ + node_ref_storage(std::initializer_list init) + : owned_value(init) + { + } + + /** + * @brief Construct a new node ref storage object with variadic template arguments + * + * @tparam Args Types of arguments to construct a basic_node object. + * @param args Arguments to construct a basic_node object. + */ + template ::value, int> = 0> + node_ref_storage(Args&&... args) + : owned_value(std::forward(args)...) + { + } + + // allow only move construct/assignment + node_ref_storage(const node_ref_storage&) = delete; + node_ref_storage(node_ref_storage&&) = default; + node_ref_storage& operator=(const node_ref_storage&) = delete; + node_ref_storage& operator=(node_ref_storage&&) = default; + +public: + /** + * @brief An arrow operator for node_ref_storage objects. + * + * @return const node_type* A constant pointer to a basic_node object. + */ + const node_type* operator->() const + { + return value_ref ? value_ref : &owned_value; + } + + /** + * @brief Releases a basic_node object internally held. + * + * @return node_type A basic_node object internally held. + */ + node_type release() const + { + return value_ref ? *value_ref : std::move(owned_value); + } + +private: + /** A storage for a basic_node object given with rvalue reference. */ + mutable node_type owned_value = nullptr; + /** A pointer to a basic_node object given with lvalue reference. */ + const node_type* value_ref = nullptr; +}; + +} // namespace detail + +FK_YAML_NAMESPACE_END + +#endif /* FK_YAML_DETAIL_NODE_REF_STORAGE_HPP_ */ \ No newline at end of file diff --git a/include/fkYAML/node.hpp b/include/fkYAML/node.hpp index a20026f9..9ac5caeb 100644 --- a/include/fkYAML/node.hpp +++ b/include/fkYAML/node.hpp @@ -13,8 +13,10 @@ #ifndef FK_YAML_NODE_HPP_ #define FK_YAML_NODE_HPP_ +#include #include #include +#include #include #include #include @@ -28,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -99,6 +102,8 @@ class basic_node using deserializer_type = detail::basic_deserializer; /** A type for YAML docs serializers. */ using serializer_type = detail::basic_serializer; + /** An alias type for std::initializer_list. */ + using initializer_list_t = std::initializer_list>; /** * @union node_value @@ -395,20 +400,72 @@ class basic_node rhs.m_anchor_name = nullptr; } + /** + * @brief Construct a new basic_node object from a value of compatible types. + * + * @tparam CompatibleType A type of native data which is compatible with node values. + * @tparam U A type of compatible native data type without qualifiers. + * @param val The value of compatible native data type. + */ template < typename CompatibleType, typename U = detail::remove_cvref_t, detail::enable_if_t< detail::conjunction< detail::negation>, detail::disjunction< - std::is_same, detail::is_node_compatible_type>>::value, int> = 0> - explicit basic_node(CompatibleType&& val) noexcept( + basic_node(CompatibleType&& val) noexcept( noexcept(ConverterType::to_node(std::declval(), std::declval()))) { ConverterType::to_node(*this, std::forward(val)); } + /** + * @brief Construct a new basic node object with a node_ref_storage object. + * + * @tparam NodeRefStorageType A node_ref_storage template instance type. + * @param node_ref_storage A node_ref_storage object. + */ + template < + typename NodeRefStorageType, + detail::enable_if_t::value, int> = 0> + basic_node(const NodeRefStorageType& node_ref_storage) + : basic_node(node_ref_storage.release()) + { + } + + /** + * @brief Construct a new basic node object with std::initializer_list. + * + * @param init An initializer list object. + */ + basic_node(initializer_list_t init) + { + bool is_mapping = + std::all_of(init.begin(), init.end(), [](const detail::node_ref_storage& node_ref) { + return node_ref->is_sequence() && node_ref->size() == 2 && node_ref->operator[](0).is_string(); + }); + + if (is_mapping) + { + m_node_type = node_t::MAPPING; + m_node_value.p_mapping = create_object(); + + for (auto& elem_ref : init) + { + auto elem = elem_ref.release(); + m_node_value.p_mapping->emplace( + std::move(*((*(elem.m_node_value.p_sequence))[0].m_node_value.p_string)), + std::move((*(elem.m_node_value.p_sequence))[1])); + } + } + else + { + m_node_type = node_t::SEQUENCE; + m_node_value.p_sequence = create_object(init.begin(), init.end()); + } + } + /** * @brief Destroy the basic_node object and its value storage. */ diff --git a/test/unit_test/test_node_class.cpp b/test/unit_test/test_node_class.cpp index ae50c878..1db1d207 100644 --- a/test/unit_test/test_node_class.cpp +++ b/test/unit_test/test_node_class.cpp @@ -89,7 +89,7 @@ TEST_CASE("NodeClassTest_ThrowingSpecializationTypeCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_SequenceCtorTest", "[NodeClassTest]") { - fkyaml::node node(fkyaml::node_sequence_type {fkyaml::node {true}, fkyaml::node {false}}); + fkyaml::node node(fkyaml::node_sequence_type {fkyaml::node(true), fkyaml::node(false)}); REQUIRE(node.type() == fkyaml::node::node_t::SEQUENCE); REQUIRE(node.is_sequence()); REQUIRE(node.size() == 2); @@ -101,7 +101,7 @@ TEST_CASE("NodeClassTest_SequenceCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_MappingCtorTest", "[NodeClassTest]") { - fkyaml::node node(fkyaml::node_mapping_type {{"test", fkyaml::node {true}}}); + fkyaml::node node(fkyaml::node_mapping_type {{"test", fkyaml::node(true)}}); REQUIRE(node.type() == fkyaml::node::node_t::MAPPING); REQUIRE(node.is_mapping()); REQUIRE(node.size() == 1); @@ -338,6 +338,32 @@ TEST_CASE("NodeClassTest_AliasMoveCtorTest", "[NodeClassTest]") REQUIRE(alias.to_boolean() == true); } +TEST_CASE("NodeClassTest_InitializerListCtorTest", "[NodeClassTest]") +{ + fkyaml::node node = + { + { std::string("foo"), 3.14 }, + { std::string("bar"), 123 }, + { std::string("baz"), { true, false } }, + }; + + REQUIRE(node.contains("foo")); + REQUIRE(node["foo"].is_float_number()); + REQUIRE(node["foo"].to_float_number() == 3.14); + + REQUIRE(node.contains("bar")); + REQUIRE(node["bar"].is_integer()); + REQUIRE(node["bar"].to_integer() == 123); + + REQUIRE(node.contains("baz")); + REQUIRE(node["baz"].is_sequence()); + REQUIRE(node["baz"].size() == 2); + REQUIRE(node["baz"].to_sequence()[0].is_boolean()); + REQUIRE(node["baz"].to_sequence()[0].to_boolean() == true); + REQUIRE(node["baz"].to_sequence()[1].is_boolean()); + REQUIRE(node["baz"].to_sequence()[1].to_boolean() == false); +} + // // test cases for serialization/deserialization features // From 87b9efacb261553c156423b6551a7e2af35ebebc Mon Sep 17 00:00:00 2001 From: fktn Date: Sun, 22 Oct 2023 02:26:13 +0900 Subject: [PATCH 02/48] fixed issues when passing lvalue ref node to node_ref_storage ctor --- include/fkYAML/detail/meta/type_traits.hpp | 39 ++++++++++++++++++++++ include/fkYAML/detail/node_ref_storage.hpp | 4 ++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/include/fkYAML/detail/meta/type_traits.hpp b/include/fkYAML/detail/meta/type_traits.hpp index d7c25db3..c4562759 100644 --- a/include/fkYAML/detail/meta/type_traits.hpp +++ b/include/fkYAML/detail/meta/type_traits.hpp @@ -210,6 +210,45 @@ struct type_tag using type = T; }; +/** + * @brief A utility struct to retrieve the first type in variadic template arguments. + * + * @tparam Types Types of variadic template arguments. + */ +template +struct get_head_type; + +/** + * @brief A specialization of get_head_type if variadic template has no arguments. + * + * @tparam N/A + */ +template <> +struct get_head_type<> +{ + using type = void; +}; + +/** + * @brief A partial specialization of get_head_type if variadic template has one or more argument(s). + * + * @tparam First The first type in the arguments + * @tparam Rest The rest of the types in the arguments. + */ +template +struct get_head_type +{ + using type = First; +}; + +/** + * @brief An alias template to retrieve the first type in variadic template arguments. + * + * @tparam Types Types of variadic template arguments. + */ +template +using head_type = typename get_head_type::type; + } // namespace detail FK_YAML_NAMESPACE_END diff --git a/include/fkYAML/detail/node_ref_storage.hpp b/include/fkYAML/detail/node_ref_storage.hpp index 7c5282f5..3ef7dbc2 100644 --- a/include/fkYAML/detail/node_ref_storage.hpp +++ b/include/fkYAML/detail/node_ref_storage.hpp @@ -84,7 +84,9 @@ class node_ref_storage * @tparam Args Types of arguments to construct a basic_node object. * @param args Arguments to construct a basic_node object. */ - template ::value, int> = 0> + template >>, + std::is_constructible>::value, int> = 0> node_ref_storage(Args&&... args) : owned_value(std::forward(args)...) { From d9f308ffb96add985bc31a32f09b041909f2539e Mon Sep 17 00:00:00 2001 From: fktn Date: Sun, 22 Oct 2023 02:26:37 +0900 Subject: [PATCH 03/48] added unit test cases for node_ref_storage class --- test/unit_test/CMakeLists.txt | 1 + .../unit_test/test_node_ref_storage_class.cpp | 66 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 test/unit_test/test_node_ref_storage_class.cpp diff --git a/test/unit_test/CMakeLists.txt b/test/unit_test/CMakeLists.txt index 3d2ef6d7..52c8925f 100644 --- a/test/unit_test/CMakeLists.txt +++ b/test/unit_test/CMakeLists.txt @@ -145,6 +145,7 @@ add_executable( test_iterator_class.cpp test_lexical_analyzer_class.cpp test_node_class.cpp + test_node_ref_storage_class.cpp test_ordered_map_class.cpp test_serializer_class.cpp main.cpp) diff --git a/test/unit_test/test_node_ref_storage_class.cpp b/test/unit_test/test_node_ref_storage_class.cpp new file mode 100644 index 00000000..7a3388cc --- /dev/null +++ b/test/unit_test/test_node_ref_storage_class.cpp @@ -0,0 +1,66 @@ +// _______ __ __ __ _____ __ __ __ +// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) +// | __| _ < \_ _/| ___ | _ | |___ version 0.1.3 +// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML +// +// SPDX-FileCopyrightText: 2023 Kensuke Fukutani +// SPDX-License-Identifier: MIT + +#include + +#include + +#include +#include + +TEST_CASE("NodeRefStorageTest_CtorWithLvalueNodeTest", "[NodeRefStorageTest]") +{ + fkyaml::node node = true; + fkyaml::detail::node_ref_storage storage(node); + REQUIRE(node.is_boolean()); + + fkyaml::node retrieved_node = storage.release(); + REQUIRE(retrieved_node.is_boolean()); + REQUIRE(retrieved_node.to_boolean() == true); +} + +TEST_CASE("NodeRefStorageTest_CtorWithRvalueNodeTest", "[NodeRefStorageTest]") +{ + fkyaml::node node = 3.14; + fkyaml::detail::node_ref_storage storage(std::move(node)); + REQUIRE(node.is_null()); + + fkyaml::node retrieved_node = storage.release(); + REQUIRE(retrieved_node.is_float_number()); + REQUIRE(retrieved_node.to_float_number() == 3.14); +} + +TEST_CASE("NodeRefStorageTest_ArrowOperatorTest", "[NodeRefStorageTest]") +{ + fkyaml::node node = 123; + fkyaml::detail::node_ref_storage storage(node); + REQUIRE(storage.operator->() == &node); + REQUIRE(storage->is_integer()); + REQUIRE(storage->to_integer() == 123); + + fkyaml::node node2 = { true, false }; + fkyaml::detail::node_ref_storage storage2(std::move(node2)); + REQUIRE(storage2->is_sequence()); + REQUIRE(storage2->size() == 2); +} + +TEST_CASE("NodeRefStorageTest_ReleaseTest", "[NodeRefStorageTest]") +{ + fkyaml::node node = 123; + fkyaml::detail::node_ref_storage storage(node); + fkyaml::node released_node = storage.release(); + REQUIRE(&released_node != &node); + REQUIRE(released_node.is_integer()); + REQUIRE(released_node.to_integer() == 123); + + fkyaml::node node2 = { true, false }; + fkyaml::detail::node_ref_storage storage2(std::move(node2)); + fkyaml::node released_node2 = storage2.release(); + REQUIRE(released_node2.is_sequence()); + REQUIRE(released_node2.size() == 2); +} \ No newline at end of file From 075c1628151b0ed4003976814a3eaee3eaa47935 Mon Sep 17 00:00:00 2001 From: fktn Date: Sun, 22 Oct 2023 02:32:54 +0900 Subject: [PATCH 04/48] applied clang-format results --- include/fkYAML/detail/meta/type_traits.hpp | 8 +++---- include/fkYAML/detail/node_ref_storage.hpp | 21 +++++++++++-------- include/fkYAML/node.hpp | 10 ++++----- test/unit_test/test_node_class.cpp | 9 ++++---- .../unit_test/test_node_ref_storage_class.cpp | 4 ++-- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/include/fkYAML/detail/meta/type_traits.hpp b/include/fkYAML/detail/meta/type_traits.hpp index c4562759..93d57307 100644 --- a/include/fkYAML/detail/meta/type_traits.hpp +++ b/include/fkYAML/detail/meta/type_traits.hpp @@ -212,7 +212,7 @@ struct type_tag /** * @brief A utility struct to retrieve the first type in variadic template arguments. - * + * * @tparam Types Types of variadic template arguments. */ template @@ -220,7 +220,7 @@ struct get_head_type; /** * @brief A specialization of get_head_type if variadic template has no arguments. - * + * * @tparam N/A */ template <> @@ -231,7 +231,7 @@ struct get_head_type<> /** * @brief A partial specialization of get_head_type if variadic template has one or more argument(s). - * + * * @tparam First The first type in the arguments * @tparam Rest The rest of the types in the arguments. */ @@ -243,7 +243,7 @@ struct get_head_type /** * @brief An alias template to retrieve the first type in variadic template arguments. - * + * * @tparam Types Types of variadic template arguments. */ template diff --git a/include/fkYAML/detail/node_ref_storage.hpp b/include/fkYAML/detail/node_ref_storage.hpp index 3ef7dbc2..8c933be1 100644 --- a/include/fkYAML/detail/node_ref_storage.hpp +++ b/include/fkYAML/detail/node_ref_storage.hpp @@ -50,7 +50,7 @@ class node_ref_storage public: /** * @brief Construct a new node ref storage object with an rvalue basic_node object. - * + * * @param n An rvalue basic_node object. */ node_ref_storage(node_type&& n) @@ -60,7 +60,7 @@ class node_ref_storage /** * @brief Construct a new node ref storage object with an lvalue basic_node object. - * + * * @param n An lvalue basic_node object. */ node_ref_storage(const node_type& n) @@ -70,7 +70,7 @@ class node_ref_storage /** * @brief Construct a new node ref storage object with a std::initializer_list object. - * + * * @param init A std::initializer_list object. */ node_ref_storage(std::initializer_list init) @@ -80,13 +80,16 @@ class node_ref_storage /** * @brief Construct a new node ref storage object with variadic template arguments - * + * * @tparam Args Types of arguments to construct a basic_node object. * @param args Arguments to construct a basic_node object. */ - template >>, - std::is_constructible>::value, int> = 0> + template < + typename... Args, enable_if_t< + conjunction< + negation>>, + std::is_constructible>::value, + int> = 0> node_ref_storage(Args&&... args) : owned_value(std::forward(args)...) { @@ -101,7 +104,7 @@ class node_ref_storage public: /** * @brief An arrow operator for node_ref_storage objects. - * + * * @return const node_type* A constant pointer to a basic_node object. */ const node_type* operator->() const @@ -111,7 +114,7 @@ class node_ref_storage /** * @brief Releases a basic_node object internally held. - * + * * @return node_type A basic_node object internally held. */ node_type release() const diff --git a/include/fkYAML/node.hpp b/include/fkYAML/node.hpp index 9ac5caeb..fa95b1c8 100644 --- a/include/fkYAML/node.hpp +++ b/include/fkYAML/node.hpp @@ -402,7 +402,7 @@ class basic_node /** * @brief Construct a new basic_node object from a value of compatible types. - * + * * @tparam CompatibleType A type of native data which is compatible with node values. * @tparam U A type of compatible native data type without qualifiers. * @param val The value of compatible native data type. @@ -411,8 +411,8 @@ class basic_node typename CompatibleType, typename U = detail::remove_cvref_t, detail::enable_if_t< detail::conjunction< - detail::negation>, detail::disjunction< - detail::is_node_compatible_type>>::value, + detail::negation>, + detail::disjunction>>::value, int> = 0> basic_node(CompatibleType&& val) noexcept( noexcept(ConverterType::to_node(std::declval(), std::declval()))) @@ -422,7 +422,7 @@ class basic_node /** * @brief Construct a new basic node object with a node_ref_storage object. - * + * * @tparam NodeRefStorageType A node_ref_storage template instance type. * @param node_ref_storage A node_ref_storage object. */ @@ -436,7 +436,7 @@ class basic_node /** * @brief Construct a new basic node object with std::initializer_list. - * + * * @param init An initializer list object. */ basic_node(initializer_list_t init) diff --git a/test/unit_test/test_node_class.cpp b/test/unit_test/test_node_class.cpp index 1db1d207..9d8dbe14 100644 --- a/test/unit_test/test_node_class.cpp +++ b/test/unit_test/test_node_class.cpp @@ -340,11 +340,10 @@ TEST_CASE("NodeClassTest_AliasMoveCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_InitializerListCtorTest", "[NodeClassTest]") { - fkyaml::node node = - { - { std::string("foo"), 3.14 }, - { std::string("bar"), 123 }, - { std::string("baz"), { true, false } }, + fkyaml::node node = { + {std::string("foo"), 3.14}, + {std::string("bar"), 123}, + {std::string("baz"), {true, false}}, }; REQUIRE(node.contains("foo")); diff --git a/test/unit_test/test_node_ref_storage_class.cpp b/test/unit_test/test_node_ref_storage_class.cpp index 7a3388cc..34401b23 100644 --- a/test/unit_test/test_node_ref_storage_class.cpp +++ b/test/unit_test/test_node_ref_storage_class.cpp @@ -43,7 +43,7 @@ TEST_CASE("NodeRefStorageTest_ArrowOperatorTest", "[NodeRefStorageTest]") REQUIRE(storage->is_integer()); REQUIRE(storage->to_integer() == 123); - fkyaml::node node2 = { true, false }; + fkyaml::node node2 = {true, false}; fkyaml::detail::node_ref_storage storage2(std::move(node2)); REQUIRE(storage2->is_sequence()); REQUIRE(storage2->size() == 2); @@ -58,7 +58,7 @@ TEST_CASE("NodeRefStorageTest_ReleaseTest", "[NodeRefStorageTest]") REQUIRE(released_node.is_integer()); REQUIRE(released_node.to_integer() == 123); - fkyaml::node node2 = { true, false }; + fkyaml::node node2 = {true, false}; fkyaml::detail::node_ref_storage storage2(std::move(node2)); fkyaml::node released_node2 = storage2.release(); REQUIRE(released_node2.is_sequence()); From c7b61035cbfbdc284548868d52484c484a64845f Mon Sep 17 00:00:00 2001 From: fktn Date: Sun, 22 Oct 2023 02:44:00 +0900 Subject: [PATCH 05/48] fixed issues newly detected by codacy --- include/fkYAML/detail/node_ref_storage.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fkYAML/detail/node_ref_storage.hpp b/include/fkYAML/detail/node_ref_storage.hpp index 8c933be1..92f94c63 100644 --- a/include/fkYAML/detail/node_ref_storage.hpp +++ b/include/fkYAML/detail/node_ref_storage.hpp @@ -53,7 +53,7 @@ class node_ref_storage * * @param n An rvalue basic_node object. */ - node_ref_storage(node_type&& n) + explicit node_ref_storage(node_type&& n) : owned_value(std::move(n)) { } @@ -63,7 +63,7 @@ class node_ref_storage * * @param n An lvalue basic_node object. */ - node_ref_storage(const node_type& n) + explicit node_ref_storage(const node_type& n) : value_ref(&n) { } From b6dc46c98ec65856ce3bdb5805f12b25c7ecfcea Mon Sep 17 00:00:00 2001 From: fktn Date: Sun, 22 Oct 2023 14:10:43 +0900 Subject: [PATCH 06/48] use std::map as the default mapping node type --- include/fkYAML/node.hpp | 8 ++++++-- test/unit_test/test_serializer_class.cpp | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/fkYAML/node.hpp b/include/fkYAML/node.hpp index fa95b1c8..2d8cc7e9 100644 --- a/include/fkYAML/node.hpp +++ b/include/fkYAML/node.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -58,7 +59,7 @@ FK_YAML_NAMESPACE_BEGIN */ template < template class SequenceType = std::vector, - template class MappingType = ordered_map, typename BooleanType = bool, + template class MappingType = std::map, typename BooleanType = bool, typename IntegerType = std::int64_t, typename FloatNumberType = double, typename StringType = std::string, template class ConverterType = node_value_converter> class basic_node @@ -71,7 +72,10 @@ class basic_node /** A type for sequence basic_node values. */ using sequence_type = SequenceType>; - /** A type for mapping basic_node values. */ + /** + * @brief A type for mapping basic_node values. + * @note std::unordered_map is not supported since it does not allow incomplete types. + */ using mapping_type = MappingType; /** A type for boolean basic_node values. */ using boolean_type = BooleanType; diff --git a/test/unit_test/test_serializer_class.cpp b/test/unit_test/test_serializer_class.cpp index 305c799b..5da9bce3 100644 --- a/test/unit_test/test_serializer_class.cpp +++ b/test/unit_test/test_serializer_class.cpp @@ -23,7 +23,7 @@ TEST_CASE("SerializerClassTest_SerializeSequenceNode", "[SerializerClassTest]") NodeStrPair( fkyaml::node::sequence( {fkyaml::node::mapping({{"foo", fkyaml::node::integer_scalar(-1234)}, {"bar", fkyaml::node()}})}), - "-\n foo: -1234\n bar: null\n")); + "-\n bar: null\n foo: -1234\n")); fkyaml::detail::basic_serializer serializer; REQUIRE(serializer.serialize(node_str_pair.first) == node_str_pair.second); } @@ -34,7 +34,7 @@ TEST_CASE("SerializerClassTest_SerializeMappingNode", "[SerializerClassTest]") auto node_str_pair = GENERATE( NodeStrPair( fkyaml::node::mapping({{"foo", fkyaml::node::integer_scalar(-1234)}, {"bar", fkyaml::node()}}), - "foo: -1234\nbar: null\n"), + "bar: null\nfoo: -1234\n"), NodeStrPair( fkyaml::node::mapping( {{"foo", From c1fce5e434daf470d03459c0b91048fb0e729b39 Mon Sep 17 00:00:00 2001 From: fktn Date: Sun, 22 Oct 2023 14:15:41 +0900 Subject: [PATCH 07/48] added a test case for ordered_map class --- test/unit_test/test_ordered_map_class.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unit_test/test_ordered_map_class.cpp b/test/unit_test/test_ordered_map_class.cpp index 33216125..325671f7 100644 --- a/test/unit_test/test_ordered_map_class.cpp +++ b/test/unit_test/test_ordered_map_class.cpp @@ -63,7 +63,8 @@ TEST_CASE("OrderedMapClassTest_NonConstAtTest", "[OrderedMapClassTest]") map.emplace("foo", true); REQUIRE_NOTHROW(map.at("foo")); REQUIRE(map.at("foo") == true); - REQUIRE_THROWS_AS(map.at("bar"), fkyaml::exception); + std::string key("bar"); + REQUIRE_THROWS_AS(map.at(key), fkyaml::exception); } TEST_CASE("OrderedMapClassTest_ConstAtTest", "[OrderedMapClassTest]") From 0e6d7d44434616e5cc17ad433c27f8ff94a773c5 Mon Sep 17 00:00:00 2001 From: fktn Date: Sun, 22 Oct 2023 16:10:07 +0900 Subject: [PATCH 08/48] modified input_handler to hold the current position info --- include/fkYAML/detail/input/input_handler.hpp | 93 ++++++++++--- test/unit_test/test_input_handler.cpp | 124 ++++++++++++++++++ 2 files changed, 199 insertions(+), 18 deletions(-) diff --git a/include/fkYAML/detail/input/input_handler.hpp b/include/fkYAML/detail/input/input_handler.hpp index 7b6ff438..160091f7 100644 --- a/include/fkYAML/detail/input/input_handler.hpp +++ b/include/fkYAML/detail/input/input_handler.hpp @@ -52,6 +52,15 @@ class input_handler //!< The type of strings of the input buffer. using string_type = std::basic_string; +private: + struct position + { + std::size_t cur_pos {0}; + std::size_t cur_pos_in_line {0}; + std::size_t lines_read {0}; + }; + +public: /** * @brief Construct a new input_handler object. * @@ -61,7 +70,7 @@ class input_handler : m_input_adapter(std::move(input_adapter)) { get_next(); - m_cur_pos = 0; + m_position.cur_pos = m_position.cur_pos_in_line = m_position.lines_read = 0; } /** @@ -71,7 +80,7 @@ class input_handler */ int_type get_current() { - return m_cache[m_cur_pos]; + return m_cache[m_position.cur_pos]; } /** @@ -81,19 +90,32 @@ class input_handler */ int_type get_next() { + int_type ret = end_of_input; + // if already cached, return the cached value. - if (m_cur_pos + 1 < m_cache.size()) + if (m_position.cur_pos + 1 < m_cache.size()) { - return m_cache[++m_cur_pos]; + ret = m_cache[++m_position.cur_pos]; + ++m_position.cur_pos_in_line; + } + else + { + ret = m_input_adapter.get_character(); + if (ret != end_of_input || m_cache[m_position.cur_pos] != end_of_input) + { + // cache the return value for possible later use. + m_cache.push_back(ret); + ++m_position.cur_pos; + ++m_position.cur_pos_in_line; + } } - int_type ret = m_input_adapter.get_character(); - if (ret != end_of_input || m_cache[m_cur_pos] != end_of_input) + if (m_cache[m_position.cur_pos - 1] == '\n') { - // cache the return value for possible later use. - m_cache.push_back(ret); - ++m_cur_pos; + m_position.cur_pos_in_line = 0; + ++m_position.lines_read; } + return ret; } @@ -104,7 +126,7 @@ class input_handler * @param str A string which will contain the resulting characters. * @return int_type 0 (for success) or EOF (for error). */ - int_type get_range(size_t length, string_type& str) + int_type get_range(std::size_t length, string_type& str) { str.clear(); @@ -115,11 +137,15 @@ class input_handler str += char_traits_type::to_char_type(get_current()); - for (size_t i = 1; i < length; i++) + for (std::size_t i = 1; i < length; i++) { if (get_next() == end_of_input) { - m_cur_pos -= i; + // m_cur_pos -= i; + for (std::size_t j = i; j > 0; j--) + { + unget(); + } str.clear(); return end_of_input; } @@ -134,10 +160,28 @@ class input_handler */ void unget() { - if (m_cur_pos > 0) + if (m_position.cur_pos > 0) { // just move back the cursor. (no action for adapter) - --m_cur_pos; + --m_position.cur_pos; + --m_position.cur_pos_in_line; + if (m_cache[m_position.cur_pos] == '\n') + { + --m_position.lines_read; + m_position.cur_pos_in_line = 0; + if (m_position.cur_pos > 0) + { + for (std::size_t i = m_position.cur_pos - 1; m_cache[i] != '\n'; i--) + { + if (i == 0) + { + m_position.cur_pos_in_line = m_position.cur_pos; + break; + } + ++m_position.cur_pos_in_line; + } + } + } } } @@ -146,9 +190,12 @@ class input_handler * * @param length The length of moving backward. */ - void unget_range(size_t length) + void unget_range(std::size_t length) { - m_cur_pos = (m_cur_pos > length) ? m_cur_pos - length : 0; + for (std::size_t i = 0; i < length; i++) + { + unget(); + } } /** @@ -173,10 +220,20 @@ class input_handler } bool ret = char_traits_type::eq(char_traits_type::to_char_type(next), expected); - --m_cur_pos; + unget(); return ret; } + std::size_t get_cur_pos_in_line() const noexcept + { + return m_position.cur_pos_in_line; + } + + std::size_t get_lines_read() const noexcept + { + return m_position.lines_read; + } + private: //!< The value of EOF for the target character type. static constexpr int_type end_of_input = char_traits_type::eof(); @@ -186,7 +243,7 @@ class input_handler //!< Cached characters retrieved from an input adapter object. std::vector m_cache {}; //!< The current position in an input buffer. - size_t m_cur_pos {0}; + position m_position {}; }; } // namespace detail diff --git a/test/unit_test/test_input_handler.cpp b/test/unit_test/test_input_handler.cpp index 92064e18..132eb989 100644 --- a/test/unit_test/test_input_handler.cpp +++ b/test/unit_test/test_input_handler.cpp @@ -21,6 +21,8 @@ TEST_CASE("InputHandlerTest_InitialStateTest", "[InputHandlerTest]") pchar_input_handler handler(fkyaml::detail::input_adapter(input)); REQUIRE(handler.get_current() == 't'); + REQUIRE(handler.get_cur_pos_in_line() == 0); + REQUIRE(handler.get_lines_read() == 0); } TEST_CASE("InputHandlerTest_GetCurrentTest", "[InputHandlerTest]") @@ -29,16 +31,33 @@ TEST_CASE("InputHandlerTest_GetCurrentTest", "[InputHandlerTest]") pchar_input_handler handler(fkyaml::detail::input_adapter(input)); REQUIRE(handler.get_current() == 't'); + REQUIRE(handler.get_cur_pos_in_line() == 0); + REQUIRE(handler.get_lines_read() == 0); + REQUIRE(handler.get_next() == 'e'); REQUIRE(handler.get_current() == 'e'); + REQUIRE(handler.get_cur_pos_in_line() == 1); + REQUIRE(handler.get_lines_read() == 0); + REQUIRE(handler.get_next() == 's'); REQUIRE(handler.get_current() == 's'); + REQUIRE(handler.get_cur_pos_in_line() == 2); + REQUIRE(handler.get_lines_read() == 0); + REQUIRE(handler.get_next() == 't'); REQUIRE(handler.get_current() == 't'); + REQUIRE(handler.get_cur_pos_in_line() == 3); + REQUIRE(handler.get_lines_read() == 0); + REQUIRE(handler.get_next() == pchar_input_handler::char_traits_type::eof()); REQUIRE(handler.get_current() == pchar_input_handler::char_traits_type::eof()); + REQUIRE(handler.get_cur_pos_in_line() == 4); + REQUIRE(handler.get_lines_read() == 0); + REQUIRE(handler.get_next() == pchar_input_handler::char_traits_type::eof()); REQUIRE(handler.get_current() == pchar_input_handler::char_traits_type::eof()); + REQUIRE(handler.get_cur_pos_in_line() == 4); + REQUIRE(handler.get_lines_read() == 0); } TEST_CASE("InputHandlerTest_GetNextTest", "[InputHandlerTest]") @@ -47,10 +66,24 @@ TEST_CASE("InputHandlerTest_GetNextTest", "[InputHandlerTest]") pchar_input_handler handler(fkyaml::detail::input_adapter(input)); REQUIRE(handler.get_next() == 'e'); + REQUIRE(handler.get_cur_pos_in_line() == 1); + REQUIRE(handler.get_lines_read() == 0); + REQUIRE(handler.get_next() == 's'); + REQUIRE(handler.get_cur_pos_in_line() == 2); + REQUIRE(handler.get_lines_read() == 0); + REQUIRE(handler.get_next() == 't'); + REQUIRE(handler.get_cur_pos_in_line() == 3); + REQUIRE(handler.get_lines_read() == 0); + REQUIRE(handler.get_next() == pchar_input_handler::char_traits_type::eof()); + REQUIRE(handler.get_cur_pos_in_line() == 4); + REQUIRE(handler.get_lines_read() == 0); + REQUIRE(handler.get_next() == pchar_input_handler::char_traits_type::eof()); + REQUIRE(handler.get_cur_pos_in_line() == 4); + REQUIRE(handler.get_lines_read() == 0); } TEST_CASE("InputHandlerTest_GetRangeTest", "[InputHandlerTest]") @@ -62,13 +95,22 @@ TEST_CASE("InputHandlerTest_GetRangeTest", "[InputHandlerTest]") REQUIRE(handler.get_range(4, str) == 0); REQUIRE(str == "test"); REQUIRE(handler.get_current() == 't'); + REQUIRE(handler.get_cur_pos_in_line() == 3); + REQUIRE(handler.get_lines_read() == 0); REQUIRE(handler.get_range(2, str) == pchar_input_handler::char_traits_type::eof()); REQUIRE(handler.get_current() == 't'); + REQUIRE(handler.get_cur_pos_in_line() == 3); + REQUIRE(handler.get_lines_read() == 0); REQUIRE(handler.get_next() == pchar_input_handler::char_traits_type::eof()); + REQUIRE(handler.get_cur_pos_in_line() == 4); + REQUIRE(handler.get_lines_read() == 0); + REQUIRE(handler.get_range(0, str) == pchar_input_handler::char_traits_type::eof()); REQUIRE(handler.get_current() == pchar_input_handler::char_traits_type::eof()); + REQUIRE(handler.get_cur_pos_in_line() == 4); + REQUIRE(handler.get_lines_read() == 0); } TEST_CASE("InputHandlerTest_UngetTest", "[InputHandlerTest]") @@ -77,12 +119,19 @@ TEST_CASE("InputHandlerTest_UngetTest", "[InputHandlerTest]") pchar_input_handler handler(fkyaml::detail::input_adapter(input)); REQUIRE(handler.get_current() == 't'); + REQUIRE(handler.get_cur_pos_in_line() == 0); + REQUIRE(handler.get_lines_read() == 0); + handler.unget(); REQUIRE(handler.get_current() == 't'); + REQUIRE(handler.get_cur_pos_in_line() == 0); + REQUIRE(handler.get_lines_read() == 0); REQUIRE(handler.get_next() == 'e'); handler.unget(); REQUIRE(handler.get_current() == 't'); + REQUIRE(handler.get_cur_pos_in_line() == 0); + REQUIRE(handler.get_lines_read() == 0); REQUIRE(handler.get_next() == 'e'); REQUIRE(handler.get_next() == 's'); @@ -90,6 +139,8 @@ TEST_CASE("InputHandlerTest_UngetTest", "[InputHandlerTest]") REQUIRE(handler.get_next() == pchar_input_handler::char_traits_type::eof()); handler.unget(); REQUIRE(handler.get_current() == 't'); + REQUIRE(handler.get_cur_pos_in_line() == 3); + REQUIRE(handler.get_lines_read() == 0); } TEST_CASE("InputHandlerTest_UngetRangeTest", "[InputHandlerTest]") @@ -100,19 +151,28 @@ TEST_CASE("InputHandlerTest_UngetRangeTest", "[InputHandlerTest]") REQUIRE(handler.get_current() == 't'); handler.unget_range(4); REQUIRE(handler.get_current() == 't'); + REQUIRE(handler.get_cur_pos_in_line() == 0); + REQUIRE(handler.get_lines_read() == 0); REQUIRE(handler.get_next() == 'e'); REQUIRE(handler.get_next() == 's'); handler.unget_range(1); REQUIRE(handler.get_current() == 'e'); + REQUIRE(handler.get_cur_pos_in_line() == 1); + REQUIRE(handler.get_lines_read() == 0); + handler.unget_range(0); REQUIRE(handler.get_current() == 'e'); + REQUIRE(handler.get_cur_pos_in_line() == 1); + REQUIRE(handler.get_lines_read() == 0); REQUIRE(handler.get_next() == 's'); REQUIRE(handler.get_next() == 't'); REQUIRE(handler.get_next() == pchar_input_handler::char_traits_type::eof()); handler.unget_range(2); REQUIRE(handler.get_current() == 's'); + REQUIRE(handler.get_cur_pos_in_line() == 2); + REQUIRE(handler.get_lines_read() == 0); } TEST_CASE("InputHandlerTest_TestNextCharTest", "[InputHandlerTest]") @@ -121,18 +181,82 @@ TEST_CASE("InputHandlerTest_TestNextCharTest", "[InputHandlerTest]") pchar_input_handler handler(fkyaml::detail::input_adapter(input)); REQUIRE(handler.test_next_char('e') == true); + REQUIRE(handler.get_cur_pos_in_line() == 0); + REQUIRE(handler.get_lines_read() == 0); REQUIRE(handler.get_next() == 'e'); REQUIRE(handler.test_next_char('s') == true); REQUIRE(handler.test_next_char('t') == false); + REQUIRE(handler.get_cur_pos_in_line() == 1); + REQUIRE(handler.get_lines_read() == 0); REQUIRE(handler.get_next() == 's'); REQUIRE(handler.get_next() == 't'); REQUIRE(handler.get_next() == pchar_input_handler::char_traits_type::eof()); REQUIRE(handler.test_next_char('t') == false); + REQUIRE(handler.get_cur_pos_in_line() == 4); + REQUIRE(handler.get_lines_read() == 0); pchar_input_handler::char_type char_eof = pchar_input_handler::char_traits_type::to_char_type(pchar_input_handler::char_traits_type::eof()); REQUIRE(handler.test_next_char(char_eof) == false); REQUIRE(handler.get_current() == pchar_input_handler::char_traits_type::eof()); } + +TEST_CASE("InputHandlerTest_TestMultipleLinesTest", "[InputHandlerTest]") +{ + SECTION("first character is not a newline code.") + { + char input[] = "test\nfoo"; + pchar_input_handler::string_type str; + pchar_input_handler handler(fkyaml::detail::input_adapter(input)); + + REQUIRE(handler.get_range(4, str) == 0); + REQUIRE(handler.get_cur_pos_in_line() == 3); + REQUIRE(handler.get_lines_read() == 0); + + REQUIRE(handler.get_next() == '\n'); + REQUIRE(handler.get_cur_pos_in_line() == 4); + REQUIRE(handler.get_lines_read() == 0); + + REQUIRE(handler.get_next() == 'f'); + REQUIRE(handler.get_cur_pos_in_line() == 0); + REQUIRE(handler.get_lines_read() == 1); + + handler.unget(); + REQUIRE(handler.get_cur_pos_in_line() == 4); + REQUIRE(handler.get_lines_read() == 0); + } + + SECTION("first character is a newline code.") + { + char input[] = "\ntest\nfoo"; + pchar_input_handler::string_type str; + pchar_input_handler handler(fkyaml::detail::input_adapter(input)); + + REQUIRE(handler.get_next() == 't'); + REQUIRE(handler.get_cur_pos_in_line() == 0); + REQUIRE(handler.get_lines_read() == 1); + + handler.unget(); + REQUIRE(handler.get_cur_pos_in_line() == 0); + REQUIRE(handler.get_lines_read() == 0); + + REQUIRE(handler.get_range(5, str) == 0); + REQUIRE(handler.get_cur_pos_in_line() == 3); + REQUIRE(handler.get_lines_read() == 1); + + REQUIRE(handler.get_next() == '\n'); + REQUIRE(handler.get_cur_pos_in_line() == 4); + REQUIRE(handler.get_lines_read() == 1); + + REQUIRE(handler.get_next() == 'f'); + REQUIRE(handler.get_cur_pos_in_line() == 0); + REQUIRE(handler.get_lines_read() == 2); + + handler.unget(); + REQUIRE(handler.get_cur_pos_in_line() == 4); + REQUIRE(handler.get_lines_read() == 1); + } + +} From 3f6e91e225147a4d6fc1c4cf315a68b489d21d5f Mon Sep 17 00:00:00 2001 From: fktn Date: Sun, 22 Oct 2023 18:31:19 +0900 Subject: [PATCH 09/48] support detecting indentation in deserialization --- include/fkYAML/detail/input/deserializer.hpp | 41 +++++++++++-- .../fkYAML/detail/input/lexical_analyzer.hpp | 12 ++++ test/unit_test/test_deserializer_class.cpp | 60 +++++++++++++++++++ 3 files changed, 107 insertions(+), 6 deletions(-) diff --git a/include/fkYAML/detail/input/deserializer.hpp b/include/fkYAML/detail/input/deserializer.hpp index 805d03c8..1d50fc5c 100644 --- a/include/fkYAML/detail/input/deserializer.hpp +++ b/include/fkYAML/detail/input/deserializer.hpp @@ -13,6 +13,7 @@ #ifndef FK_YAML_DETAIL_INPUT_DESERIALIZER_HPP_ #define FK_YAML_DETAIL_INPUT_DESERIALIZER_HPP_ +#include #include #include @@ -84,6 +85,9 @@ class basic_deserializer m_current_node = &root; lexical_token_t type = lexer.get_next_token(); + std::size_t cur_indent = lexer.get_last_token_begin_pos(); + m_indent_stack.push_back(cur_indent); + while (type != lexical_token_t::END_OF_BUFFER) { switch (type) @@ -184,7 +188,7 @@ class basic_deserializer case lexical_token_t::NULL_VALUE: if (m_current_node->is_mapping()) { - add_new_key(lexer.get_string()); + add_new_key(lexer.get_string(), cur_indent); break; } @@ -195,7 +199,7 @@ class basic_deserializer case lexical_token_t::BOOLEAN_VALUE: if (m_current_node->is_mapping()) { - add_new_key(lexer.get_string()); + add_new_key(lexer.get_string(), cur_indent); break; } assign_node_value(BasicNodeType::boolean_scalar(lexer.get_boolean())); @@ -203,7 +207,7 @@ class basic_deserializer case lexical_token_t::INTEGER_VALUE: if (m_current_node->is_mapping()) { - add_new_key(lexer.get_string()); + add_new_key(lexer.get_string(), cur_indent); break; } assign_node_value(BasicNodeType::integer_scalar(lexer.get_integer())); @@ -211,7 +215,7 @@ class basic_deserializer case lexical_token_t::FLOAT_NUMBER_VALUE: if (m_current_node->is_mapping()) { - add_new_key(lexer.get_string()); + add_new_key(lexer.get_string(), cur_indent); break; } assign_node_value(BasicNodeType::float_number_scalar(lexer.get_float_number())); @@ -219,7 +223,7 @@ class basic_deserializer case lexical_token_t::STRING_VALUE: if (m_current_node->is_mapping()) { - add_new_key(lexer.get_string()); + add_new_key(lexer.get_string(), cur_indent); break; } assign_node_value(BasicNodeType::string_scalar(lexer.get_string())); @@ -229,6 +233,7 @@ class basic_deserializer } type = lexer.get_next_token(); + cur_indent = lexer.get_last_token_begin_pos(); } m_current_node = nullptr; @@ -245,8 +250,31 @@ class basic_deserializer * * @param key a key string to be added to the current YAML node. */ - void add_new_key(const string_type& key) noexcept + void add_new_key(const string_type& key, const std::size_t indent) { + if (indent < m_indent_stack.back()) + { + auto target_itr = std::find(m_indent_stack.begin(), m_indent_stack.end(), indent); + if (target_itr == m_indent_stack.end()) + { + throw fkyaml::exception("Detected invalid indentaion."); + } + + auto pop_num = std::distance(target_itr, m_indent_stack.end()) - 1; + for (auto i = 0; i < pop_num; i++) + { + m_indent_stack.pop_back(); + + // move back to the previous container node. + m_current_node = m_node_stack.back(); + m_node_stack.pop_back(); + } + } + else if (indent > m_indent_stack.back()) + { + m_indent_stack.push_back(indent); + } + m_current_node->to_mapping().emplace(key, BasicNodeType()); m_node_stack.push_back(m_current_node); m_current_node = &(m_current_node->to_mapping().at(key)); @@ -315,6 +343,7 @@ class basic_deserializer private: BasicNodeType* m_current_node {nullptr}; /** The currently focused YAML node. */ std::vector m_node_stack {}; /** The stack of YAML nodes. */ + std::vector m_indent_stack {}; yaml_version_t m_yaml_version {yaml_version_t::VER_1_2}; /** The YAML version specification type. */ bool m_needs_anchor_impl {false}; /** A flag to determine the need for YAML anchor node implementation */ string_type m_anchor_name {}; /** The last YAML anchor name. */ diff --git a/include/fkYAML/detail/input/lexical_analyzer.hpp b/include/fkYAML/detail/input/lexical_analyzer.hpp index 3be621dc..27e540d0 100644 --- a/include/fkYAML/detail/input/lexical_analyzer.hpp +++ b/include/fkYAML/detail/input/lexical_analyzer.hpp @@ -86,6 +86,7 @@ class lexical_analyzer skip_white_spaces(); char_int_type current = m_input_handler.get_current(); + m_last_token_begin_pos = m_input_handler.get_cur_pos_in_line(); if (0x00 <= current && current <= 0x7F && isdigit(current)) { @@ -298,6 +299,16 @@ class lexical_analyzer } } + /** + * @brief Get the beginning position of a last token. + * + * @return std::size_t The beginning position of a last token. + */ + std::size_t get_last_token_begin_pos() const noexcept + { + return m_last_token_begin_pos; + } + /** * @brief Convert from string to null and get the converted value. * @@ -1141,6 +1152,7 @@ class lexical_analyzer input_handler_type m_input_handler; //!< A temporal buffer to store a string to be parsed to an actual datum. input_string_type m_value_buffer {}; + std::size_t m_last_token_begin_pos {0}; //!< The last found token type. lexical_token_t m_last_token_type {lexical_token_t::END_OF_BUFFER}; //!< A temporal bool holder. diff --git a/test/unit_test/test_deserializer_class.cpp b/test/unit_test/test_deserializer_class.cpp index 22127843..665820f7 100644 --- a/test/unit_test/test_deserializer_class.cpp +++ b/test/unit_test/test_deserializer_class.cpp @@ -82,6 +82,14 @@ TEST_CASE("DeserializerClassTest_DeserializeNumericKey", "[DeserializerClassTest REQUIRE(root[str_val_pair.second].to_string() == "foo"); } +TEST_CASE("DeserializerClassTest_DeserializeInvalidIndentation", "[DeserializerClassTest]") +{ + fkyaml::detail::basic_deserializer deserializer; + fkyaml::node root; + + REQUIRE_THROWS_AS(root = deserializer.deserialize(fkyaml::detail::input_adapter("foo:\n bar: baz\n qux: true")), fkyaml::exception); +} + TEST_CASE("DeserializerClassTest_DeserializeBlockSequenceTest", "[DeserializerClassTest]") { fkyaml::detail::basic_deserializer deserializer; @@ -507,6 +515,58 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockMappingTest", "[DeserializerCla REQUIRE_NOTHROW(bar_node.to_string()); REQUIRE(bar_node.to_string() == foo_node.to_string()); } + + SECTION("Input source No.8.") + { + REQUIRE_NOTHROW( + root = deserializer.deserialize(fkyaml::detail::input_adapter("foo:\n bar: baz\nqux: 123\nquux:\n corge: grault"))); + + REQUIRE(root.is_mapping()); + REQUIRE(root.size() == 3); + + REQUIRE(root.contains("foo")); + REQUIRE(root["foo"].is_mapping()); + REQUIRE(root["foo"].size() == 1); + REQUIRE(root["foo"].contains("bar")); + REQUIRE(root["foo"]["bar"].is_string()); + REQUIRE(root["foo"]["bar"].to_string() == "baz"); + + REQUIRE(root.contains("qux")); + REQUIRE(root["qux"].is_integer()); + REQUIRE(root["qux"].to_integer() == 123); + + REQUIRE(root.contains("quux")); + REQUIRE(root["quux"].is_mapping()); + REQUIRE(root["quux"].size() == 1); + REQUIRE(root["quux"].contains("corge")); + REQUIRE(root["quux"]["corge"].is_string()); + REQUIRE(root["quux"]["corge"].to_string() == "grault"); + } + + SECTION("Input source No.9.") + { + REQUIRE_NOTHROW( + root = deserializer.deserialize(fkyaml::detail::input_adapter("foo:\n bar:\n baz: 123\nqux: true"))); + + REQUIRE(root.is_mapping()); + REQUIRE(root.size() == 2); + + REQUIRE(root.contains("foo")); + REQUIRE(root["foo"].is_mapping()); + REQUIRE(root["foo"].size() == 1); + + REQUIRE(root["foo"].contains("bar")); + REQUIRE(root["foo"]["bar"].is_mapping()); + REQUIRE(root["foo"]["bar"].size() == 1); + + REQUIRE(root["foo"]["bar"].contains("baz")); + REQUIRE(root["foo"]["bar"]["baz"].is_integer()); + REQUIRE(root["foo"]["bar"]["baz"].to_integer() == 123); + + REQUIRE(root.contains("qux")); + REQUIRE(root["qux"].is_boolean()); + REQUIRE(root["qux"].to_boolean() == true); + } } TEST_CASE("DeserializerClassTest_DeserializeFlowSequenceTest", "[DeserializerClassTest]") From 173127d19fb9c72f3b5b950e5cd20175c96f8ff5 Mon Sep 17 00:00:00 2001 From: fktn Date: Sun, 22 Oct 2023 18:41:40 +0900 Subject: [PATCH 10/48] fixed errors from clang-format --- include/fkYAML/detail/input/deserializer.hpp | 4 ++-- test/unit_test/test_deserializer_class.cpp | 7 +++++-- test/unit_test/test_input_handler.cpp | 1 - 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/fkYAML/detail/input/deserializer.hpp b/include/fkYAML/detail/input/deserializer.hpp index 1d50fc5c..4a7ed3f6 100644 --- a/include/fkYAML/detail/input/deserializer.hpp +++ b/include/fkYAML/detail/input/deserializer.hpp @@ -341,8 +341,8 @@ class basic_deserializer } private: - BasicNodeType* m_current_node {nullptr}; /** The currently focused YAML node. */ - std::vector m_node_stack {}; /** The stack of YAML nodes. */ + BasicNodeType* m_current_node {nullptr}; /** The currently focused YAML node. */ + std::vector m_node_stack {}; /** The stack of YAML nodes. */ std::vector m_indent_stack {}; yaml_version_t m_yaml_version {yaml_version_t::VER_1_2}; /** The YAML version specification type. */ bool m_needs_anchor_impl {false}; /** A flag to determine the need for YAML anchor node implementation */ diff --git a/test/unit_test/test_deserializer_class.cpp b/test/unit_test/test_deserializer_class.cpp index 665820f7..561d9211 100644 --- a/test/unit_test/test_deserializer_class.cpp +++ b/test/unit_test/test_deserializer_class.cpp @@ -87,7 +87,9 @@ TEST_CASE("DeserializerClassTest_DeserializeInvalidIndentation", "[DeserializerC fkyaml::detail::basic_deserializer deserializer; fkyaml::node root; - REQUIRE_THROWS_AS(root = deserializer.deserialize(fkyaml::detail::input_adapter("foo:\n bar: baz\n qux: true")), fkyaml::exception); + REQUIRE_THROWS_AS( + root = deserializer.deserialize(fkyaml::detail::input_adapter("foo:\n bar: baz\n qux: true")), + fkyaml::exception); } TEST_CASE("DeserializerClassTest_DeserializeBlockSequenceTest", "[DeserializerClassTest]") @@ -519,7 +521,8 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockMappingTest", "[DeserializerCla SECTION("Input source No.8.") { REQUIRE_NOTHROW( - root = deserializer.deserialize(fkyaml::detail::input_adapter("foo:\n bar: baz\nqux: 123\nquux:\n corge: grault"))); + root = deserializer.deserialize( + fkyaml::detail::input_adapter("foo:\n bar: baz\nqux: 123\nquux:\n corge: grault"))); REQUIRE(root.is_mapping()); REQUIRE(root.size() == 3); diff --git a/test/unit_test/test_input_handler.cpp b/test/unit_test/test_input_handler.cpp index 132eb989..f20d8a15 100644 --- a/test/unit_test/test_input_handler.cpp +++ b/test/unit_test/test_input_handler.cpp @@ -258,5 +258,4 @@ TEST_CASE("InputHandlerTest_TestMultipleLinesTest", "[InputHandlerTest]") REQUIRE(handler.get_cur_pos_in_line() == 4); REQUIRE(handler.get_lines_read() == 1); } - } From 804c0454f99ed7f2da35bd8a414cab824c38ccdc Mon Sep 17 00:00:00 2001 From: fktn Date: Sun, 22 Oct 2023 19:05:32 +0900 Subject: [PATCH 11/48] added missing doxygen comments --- include/fkYAML/detail/input/input_handler.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/fkYAML/detail/input/input_handler.hpp b/include/fkYAML/detail/input/input_handler.hpp index 160091f7..1ce89142 100644 --- a/include/fkYAML/detail/input/input_handler.hpp +++ b/include/fkYAML/detail/input/input_handler.hpp @@ -53,10 +53,16 @@ class input_handler using string_type = std::basic_string; private: + /** + * @brief A set of information on the current position in an input buffer. + */ struct position { + //!< The current position from the beginning of an input buffer. std::size_t cur_pos {0}; + //!< The current position in the current line. std::size_t cur_pos_in_line {0}; + //!< The number of lines which have already been read. std::size_t lines_read {0}; }; @@ -224,11 +230,21 @@ class input_handler return ret; } + /** + * @brief Get the current position in the current line. + * + * @return std::size_t The current position in the current line. + */ std::size_t get_cur_pos_in_line() const noexcept { return m_position.cur_pos_in_line; } + /** + * @brief Get the number of lines which have already been read. + * + * @return std::size_t The number of lines which have already been read. + */ std::size_t get_lines_read() const noexcept { return m_position.lines_read; From e68b7adfd285579890075beb4b0535e6af50123b Mon Sep 17 00:00:00 2001 From: fktn Date: Mon, 23 Oct 2023 00:34:48 +0900 Subject: [PATCH 12/48] refactored input adapters by deleting unused members --- include/fkYAML/detail/input/input_adapter.hpp | 113 +++++++----------- .../detail/meta/input_adapter_traits.hpp | 36 +----- include/fkYAML/node.hpp | 6 + 3 files changed, 51 insertions(+), 104 deletions(-) diff --git a/include/fkYAML/detail/input/input_adapter.hpp b/include/fkYAML/detail/input/input_adapter.hpp index 37f33dd8..a67c6a38 100644 --- a/include/fkYAML/detail/input/input_adapter.hpp +++ b/include/fkYAML/detail/input/input_adapter.hpp @@ -21,6 +21,7 @@ #include #include +#include /** * @namespace fkyaml @@ -66,11 +67,17 @@ class iterator_input_adapter */ iterator_input_adapter(IterType begin, IterType end) : m_current(begin), - m_begin(begin), m_end(end) { } + // allow only move construct/assignment like other input adapters. + iterator_input_adapter(const iterator_input_adapter&) = delete; + iterator_input_adapter(iterator_input_adapter&& rhs) = default; + iterator_input_adapter& operator=(const iterator_input_adapter&) = delete; + iterator_input_adapter& operator=(iterator_input_adapter&&) = default; + ~iterator_input_adapter() = default; + /** * @brief Get a character at the current position and move forward. * @@ -88,20 +95,8 @@ class iterator_input_adapter return std::char_traits::eof(); } - /** - * @brief Move backward if the current position is not at the beginning. - */ - void unget_character() - { - if (m_current != m_begin) - { - --m_current; - } - } - private: IterType m_current {}; - IterType m_begin {}; IterType m_end {}; }; @@ -121,7 +116,10 @@ class file_input_adapter file_input_adapter() = default; /** - * @brief Construct a new file_input_adapter object + * @brief Construct a new file_input_adapter object. + * @note + * This class doesn't call fopen() nor fclose(). + * It's user's responsibility to call those functions. * * @param file A file handle for this adapter. (A non-null pointer is assumed.) */ @@ -144,15 +142,12 @@ class file_input_adapter */ typename std::char_traits::int_type get_character() { - return std::fgetc(m_file); - } - - /** - * @brief Move backward if the current position is not at the beginning. - */ - void unget_character() - { - (void)std::fseek(m_file, -1, SEEK_CUR); + int ret = std::fgetc(m_file); + if (ret != EOF) + { + return ret; + } + return std::char_traits::eof(); } private: @@ -187,41 +182,8 @@ class stream_input_adapter // allow only move construct/assignment stream_input_adapter(const stream_input_adapter&) = delete; stream_input_adapter& operator=(const stream_input_adapter&) = delete; - - /** - * @brief Construct a new stream_input_adapter object. - * - * @param rhs An adapter whose values are to be moved to this object. - */ - stream_input_adapter(stream_input_adapter&& rhs) noexcept - : m_istream(rhs.m_istream) - { - rhs.m_istream = nullptr; - } - - /** - * @brief A move assignment operator for stream_input_adapter. - * - * @param rhs An adapter whose values are to be moved to this object. - * @return stream_input_adapter& Reference to this object. - */ - stream_input_adapter& operator=(stream_input_adapter&& rhs) noexcept - { - if (&rhs == this) - { - return *this; - } - - m_istream = rhs.m_istream; - - rhs.m_istream = nullptr; - - return *this; - } - - /** - * @brief Destroy the stream_input_adapter object. - */ + stream_input_adapter(stream_input_adapter&&) = default; + stream_input_adapter& operator=(stream_input_adapter&&) = default; ~stream_input_adapter() = default; /** @@ -234,14 +196,6 @@ class stream_input_adapter return m_istream->get(); } - /** - * @brief Move backward if the current position is not at the beginning. - */ - void unget_character() - { - m_istream->unget(); - } - private: std::istream* m_istream {nullptr}; }; @@ -277,11 +231,17 @@ template < conjunction< std::is_pointer, negation>, std::is_integral>, - bool_constant) == 1>>::value, + bool_constant) == sizeof(char)>>::value, int> = 0> -inline auto input_adapter(CharPtrType ptr) -> decltype(input_adapter(ptr, ptr + std::strlen(ptr))) +inline auto input_adapter(CharPtrType ptr, std::size_t size) -> decltype(input_adapter(ptr, ptr + size)) { - return input_adapter(ptr, ptr + std::strlen(ptr)); + // get the actual buffer size. + std::size_t i = 0; + for (; i < size && *(ptr + i) != '\0'; i++) + { + } + size = (i < size) ? i : size; + return input_adapter(ptr, ptr + size); } /** @@ -294,7 +254,14 @@ inline auto input_adapter(CharPtrType ptr) -> decltype(input_adapter(ptr, ptr + template inline auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N)) { - return input_adapter(array, array + (N - 1)); + // get the actual buffer size. + std::size_t i = 0; + const T null_char(0); + for (; i < N && array[i] != null_char; i++) + { + } + std::size_t size = (i < N - 1) ? i : N - 1; + return input_adapter(array, array + size); } /** @@ -366,6 +333,10 @@ input_adapter(ContainerType&& container) */ inline file_input_adapter input_adapter(std::FILE* file) { + if (!file) + { + throw fkyaml::exception("Invalid FILE object pointer."); + } return file_input_adapter(file); } @@ -375,7 +346,7 @@ inline file_input_adapter input_adapter(std::FILE* file) * @param stream * @return stream_input_adapter */ -inline stream_input_adapter input_adapter(std::istream& stream) +inline stream_input_adapter input_adapter(std::istream& stream) noexcept { return stream_input_adapter(stream); } diff --git a/include/fkYAML/detail/meta/input_adapter_traits.hpp b/include/fkYAML/detail/meta/input_adapter_traits.hpp index 81494cca..59ad810e 100644 --- a/include/fkYAML/detail/meta/input_adapter_traits.hpp +++ b/include/fkYAML/detail/meta/input_adapter_traits.hpp @@ -52,14 +52,6 @@ using detect_char_type_helper_t = typename T::char_type; template using get_character_fn_t = decltype(std::declval().get_character()); -/** - * @brief A type which respresents unget_character function. - * - * @tparam T A target type. - */ -template -using unget_character_fn_t = decltype(std::declval().unget_character()); - /** * @brief Type traits to check if T has char_type as its member. * @@ -107,28 +99,6 @@ struct has_get_character -struct has_unget_character : std::false_type -{ -}; - -/** - * @brief A partial specialization of has_unget_character if InputAdapterType has unget_character member function. - * - * @tparam InputAdapterType - */ -template -struct has_unget_character::value>> - : std::true_type -{ -}; - //////////////////////////////// // is_input_adapter traits //////////////////////////////// @@ -151,9 +121,9 @@ struct is_input_adapter : std::false_type */ template struct is_input_adapter< - InputAdapterType, enable_if_t, has_get_character, - has_unget_character>::value>> : std::true_type + InputAdapterType, + enable_if_t, has_get_character>::value>> + : std::true_type { }; diff --git a/include/fkYAML/node.hpp b/include/fkYAML/node.hpp index 2d8cc7e9..c0ff2021 100644 --- a/include/fkYAML/node.hpp +++ b/include/fkYAML/node.hpp @@ -510,6 +510,12 @@ class basic_node detail::input_adapter(std::forward(begin), std::forward(end))); } + template ::value, int> = 0> + static basic_node deserialize(PtrType&& ptr, std::size_t size) + { + return deserializer_type().deserialize(detail::input_adapter(std::forward(ptr), size)); + } + /** * @brief Serialize a basic_node object into a string. * From 3b187a71d6500154ed270543b6444d4d7c887016 Mon Sep 17 00:00:00 2001 From: fktn Date: Mon, 23 Oct 2023 00:35:10 +0900 Subject: [PATCH 13/48] added test cases for input adapters --- test/unit_test/CMakeLists.txt | 6 + .../test_data/input_adapter_test_data.txt | 1 + test/unit_test/test_input_adapter.cpp | 145 ++++++++++++++++++ test/unit_test/test_node_class.cpp | 3 +- 4 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 test/unit_test/test_data/input_adapter_test_data.txt create mode 100644 test/unit_test/test_input_adapter.cpp diff --git a/test/unit_test/CMakeLists.txt b/test/unit_test/CMakeLists.txt index 52c8925f..30d260f3 100644 --- a/test/unit_test/CMakeLists.txt +++ b/test/unit_test/CMakeLists.txt @@ -141,6 +141,7 @@ add_executable( test_deserializer_class.cpp test_exception_class.cpp test_from_string.cpp + test_input_adapter.cpp test_input_handler.cpp test_iterator_class.cpp test_lexical_analyzer_class.cpp @@ -157,6 +158,11 @@ catch_discover_tests(${TEST_TARGET}) add_dependencies(${TEST_TARGET} ${FK_YAML_TARGET_NAME}) +add_custom_command( + TARGET ${TEST_TARGET} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/test_data $/test_data +) + ############################################ # Configure custom target for coverage # ############################################ diff --git a/test/unit_test/test_data/input_adapter_test_data.txt b/test/unit_test/test_data/input_adapter_test_data.txt new file mode 100644 index 00000000..c188e5d1 --- /dev/null +++ b/test/unit_test/test_data/input_adapter_test_data.txt @@ -0,0 +1 @@ +test source. \ No newline at end of file diff --git a/test/unit_test/test_input_adapter.cpp b/test/unit_test/test_input_adapter.cpp new file mode 100644 index 00000000..b58d8ecc --- /dev/null +++ b/test/unit_test/test_input_adapter.cpp @@ -0,0 +1,145 @@ +// _______ __ __ __ _____ __ __ __ +// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library (supporting code) +// | __| _ < \_ _/| ___ | _ | |___ version 0.1.3 +// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML +// +// SPDX-FileCopyrightText: 2023 Kensuke Fukutani +// SPDX-License-Identifier: MIT + +#include +#include +#include + +#include + +#include + +static constexpr char input_file_path[] = "test_data/input_adapter_test_data.txt"; + +TEST_CASE("InputAdapterTest_IteratorInputAdapterProviderTest", "[InputAdapterTest]") +{ + char input[] = "test"; + + SECTION("c-style char array") + { + auto input_adapter = fkyaml::detail::input_adapter(input); + REQUIRE(std::is_same>::value); + } + + SECTION("char pointer and size") + { + auto input_adapter = fkyaml::detail::input_adapter(&input[0], sizeof(input)); + REQUIRE(std::is_same>::value); + } + + SECTION("char pointers for beginning/end") + { + auto input_adapter = fkyaml::detail::input_adapter(&input[0], &input[sizeof(input) - 1]); + REQUIRE(std::is_same>::value); + } + + SECTION("std::string") + { + std::string input_str(input); + auto input_adapter = fkyaml::detail::input_adapter(input_str); + REQUIRE( + std::is_same>::value); + } +} + +TEST_CASE("InputAdapterTest_FileInputAdapterProviderTest", "[InputAdapterTest]") +{ + SECTION("invalid FILE object pointer") + { + FILE* p_file = nullptr; + REQUIRE_THROWS_AS(fkyaml::detail::input_adapter(p_file), fkyaml::exception); + } + + SECTION("valie FILE object pointer") + { + FILE* p_file = std::fopen(input_file_path, "r"); + REQUIRE(p_file != nullptr); + auto input_adapter = fkyaml::detail::input_adapter(p_file); + REQUIRE(std::is_same::value); + } +} + +TEST_CASE("InputAdapterTest_StreamInputAdapterProviderTest", "[InputAdapterTest]") +{ + std::ifstream ifs(input_file_path); + REQUIRE(ifs); + auto input_adapter = fkyaml::detail::input_adapter(ifs); + REQUIRE(std::is_same::value); +} + +TEST_CASE("InputAdapterTest_GetCharacterTest", "[InputAdapterTest]") +{ + SECTION("iterator_input_adapter") + { + char input[] = "test source."; + auto input_adapter = fkyaml::detail::input_adapter(input); + REQUIRE(std::is_same>::value); + + using char_traits_type = std::char_traits; + + REQUIRE(input_adapter.get_character() == 't'); + REQUIRE(input_adapter.get_character() == 'e'); + REQUIRE(input_adapter.get_character() == 's'); + REQUIRE(input_adapter.get_character() == 't'); + REQUIRE(input_adapter.get_character() == ' '); + REQUIRE(input_adapter.get_character() == 's'); + REQUIRE(input_adapter.get_character() == 'o'); + REQUIRE(input_adapter.get_character() == 'u'); + REQUIRE(input_adapter.get_character() == 'r'); + REQUIRE(input_adapter.get_character() == 'c'); + REQUIRE(input_adapter.get_character() == 'e'); + REQUIRE(input_adapter.get_character() == '.'); + REQUIRE(input_adapter.get_character() == char_traits_type::eof()); + } + + SECTION("file_input_adapter") + { + FILE* p_file = std::fopen(input_file_path, "r"); + auto input_adapter = fkyaml::detail::input_adapter(p_file); + REQUIRE(std::is_same::value); + + using char_traits_type = std::char_traits; + + REQUIRE(input_adapter.get_character() == 't'); + REQUIRE(input_adapter.get_character() == 'e'); + REQUIRE(input_adapter.get_character() == 's'); + REQUIRE(input_adapter.get_character() == 't'); + REQUIRE(input_adapter.get_character() == ' '); + REQUIRE(input_adapter.get_character() == 's'); + REQUIRE(input_adapter.get_character() == 'o'); + REQUIRE(input_adapter.get_character() == 'u'); + REQUIRE(input_adapter.get_character() == 'r'); + REQUIRE(input_adapter.get_character() == 'c'); + REQUIRE(input_adapter.get_character() == 'e'); + REQUIRE(input_adapter.get_character() == '.'); + REQUIRE(input_adapter.get_character() == char_traits_type::eof()); + } + + SECTION("stream_input_adapter") + { + std::ifstream ifs(input_file_path); + auto input_adapter = fkyaml::detail::input_adapter(ifs); + REQUIRE(std::is_same::value); + + using char_traits_type = std::char_traits; + + REQUIRE(input_adapter.get_character() == 't'); + REQUIRE(input_adapter.get_character() == 'e'); + REQUIRE(input_adapter.get_character() == 's'); + REQUIRE(input_adapter.get_character() == 't'); + REQUIRE(input_adapter.get_character() == ' '); + REQUIRE(input_adapter.get_character() == 's'); + REQUIRE(input_adapter.get_character() == 'o'); + REQUIRE(input_adapter.get_character() == 'u'); + REQUIRE(input_adapter.get_character() == 'r'); + REQUIRE(input_adapter.get_character() == 'c'); + REQUIRE(input_adapter.get_character() == 'e'); + REQUIRE(input_adapter.get_character() == '.'); + REQUIRE(input_adapter.get_character() == char_traits_type::eof()); + } +} \ No newline at end of file diff --git a/test/unit_test/test_node_class.cpp b/test/unit_test/test_node_class.cpp index 9d8dbe14..d16ea8bb 100644 --- a/test/unit_test/test_node_class.cpp +++ b/test/unit_test/test_node_class.cpp @@ -375,7 +375,8 @@ TEST_CASE("NodeClassTest_DeserializeTest", "[NodeClassTest]") fkyaml::node node = GENERATE_REF( fkyaml::node::deserialize("foo: bar"), - fkyaml::node::deserialize(&source[0]), + fkyaml::node::deserialize(source), + fkyaml::node::deserialize(&source[0], sizeof(source)), fkyaml::node::deserialize(&source[0], &source[8]), fkyaml::node::deserialize(std::string(source)), fkyaml::node::deserialize(ss)); From eed038b62d2fe9f893b173f8fb8e975f0c776a24 Mon Sep 17 00:00:00 2001 From: fktn Date: Mon, 23 Oct 2023 01:04:24 +0900 Subject: [PATCH 14/48] fixed clang-format errors --- test/unit_test/test_input_adapter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit_test/test_input_adapter.cpp b/test/unit_test/test_input_adapter.cpp index b58d8ecc..94fe2f0e 100644 --- a/test/unit_test/test_input_adapter.cpp +++ b/test/unit_test/test_input_adapter.cpp @@ -42,8 +42,8 @@ TEST_CASE("InputAdapterTest_IteratorInputAdapterProviderTest", "[InputAdapterTes { std::string input_str(input); auto input_adapter = fkyaml::detail::input_adapter(input_str); - REQUIRE( - std::is_same>::value); + using iterator_type = typename std::string::iterator; + REQUIRE(std::is_same>::value); } } From 6469b0641cccea3162895d4af5f938949029e375 Mon Sep 17 00:00:00 2001 From: fktn Date: Mon, 23 Oct 2023 03:10:41 +0900 Subject: [PATCH 15/48] made a workaround to read a test data file on windows --- test/unit_test/CMakeLists.txt | 12 ++++++++++++ test/unit_test/test_input_adapter.cpp | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/test/unit_test/CMakeLists.txt b/test/unit_test/CMakeLists.txt index 30d260f3..6f1c2180 100644 --- a/test/unit_test/CMakeLists.txt +++ b/test/unit_test/CMakeLists.txt @@ -50,11 +50,23 @@ if(NOT compiler_supports_cxx_${FK_YAML_TEST_TARGET_CXX_STANDARD}) return() endif() +###################################### +# Prepare to use test data files # +###################################### + +# While executing CTest on Windows, just specifying a relative path seems not working. +# This is a workaround to resolve the issue. (Delete it when a better solution is found.) +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/include/test_data.hpp "#ifndef FK_YAML_TEST_TEST_DATA_HPP_\n") +file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/include/test_data.hpp "#define FK_YAML_TEST_TEST_DATA_HPP_\n\n") +file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/include/test_data.hpp "#define FK_YAML_TEST_DATA_DIR \"${CMAKE_CURRENT_SOURCE_DIR}/test_data\"\n\n") +file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/include/test_data.hpp "#endif /* FK_YAML_TEST_TEST_DATA_HPP_ */\n") + ################################# # Configure compile options # ################################# add_library(unit_test_config INTERFACE) +target_include_directories(unit_test_config INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/include) target_link_libraries(unit_test_config INTERFACE Catch2::Catch2 ${FK_YAML_TARGET_NAME}) target_compile_features(unit_test_config INTERFACE cxx_std_${FK_YAML_TEST_TARGET_CXX_STANDARD}) set_target_properties(unit_test_config PROPERTIES CXX_EXTENTIONS OFF) diff --git a/test/unit_test/test_input_adapter.cpp b/test/unit_test/test_input_adapter.cpp index 94fe2f0e..4f97de15 100644 --- a/test/unit_test/test_input_adapter.cpp +++ b/test/unit_test/test_input_adapter.cpp @@ -14,7 +14,10 @@ #include -static constexpr char input_file_path[] = "test_data/input_adapter_test_data.txt"; +// generated in test/unit_test/CMakeLists.txt +#include + +static constexpr char input_file_path[] = FK_YAML_TEST_DATA_DIR "/input_adapter_test_data.txt"; TEST_CASE("InputAdapterTest_IteratorInputAdapterProviderTest", "[InputAdapterTest]") { From 6810f51ec75bb49ae57c04262f5835d0c089196f Mon Sep 17 00:00:00 2001 From: fktn Date: Mon, 23 Oct 2023 03:33:23 +0900 Subject: [PATCH 16/48] suppress warnings against calling fopen() in input adapters' test cases --- test/unit_test/test_input_adapter.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/unit_test/test_input_adapter.cpp b/test/unit_test/test_input_adapter.cpp index 4f97de15..9c32b328 100644 --- a/test/unit_test/test_input_adapter.cpp +++ b/test/unit_test/test_input_adapter.cpp @@ -6,6 +6,7 @@ // SPDX-FileCopyrightText: 2023 Kensuke Fukutani // SPDX-License-Identifier: MIT + #include #include #include @@ -17,6 +18,15 @@ // generated in test/unit_test/CMakeLists.txt #include +#ifdef _MSC_VER + #define DISABLE_C4996 __pragma(warning(push)) __pragma(warning(disable:4996)) + #define ENABLE_C4996 __pragma(warning(pop)) +#else + #define DISABLE_C4996 + #define ENABLE_C4996 +#endif + + static constexpr char input_file_path[] = FK_YAML_TEST_DATA_DIR "/input_adapter_test_data.txt"; TEST_CASE("InputAdapterTest_IteratorInputAdapterProviderTest", "[InputAdapterTest]") @@ -60,7 +70,10 @@ TEST_CASE("InputAdapterTest_FileInputAdapterProviderTest", "[InputAdapterTest]") SECTION("valie FILE object pointer") { +DISABLE_C4996 FILE* p_file = std::fopen(input_file_path, "r"); +ENABLE_C4996 + REQUIRE(p_file != nullptr); auto input_adapter = fkyaml::detail::input_adapter(p_file); REQUIRE(std::is_same::value); @@ -102,7 +115,10 @@ TEST_CASE("InputAdapterTest_GetCharacterTest", "[InputAdapterTest]") SECTION("file_input_adapter") { +DISABLE_C4996 FILE* p_file = std::fopen(input_file_path, "r"); +ENABLE_C4996 + auto input_adapter = fkyaml::detail::input_adapter(p_file); REQUIRE(std::is_same::value); From 0c78d4fbf3f2608a1bc58f8d7fa40e9461fbc158 Mon Sep 17 00:00:00 2001 From: fktn Date: Mon, 23 Oct 2023 03:46:09 +0900 Subject: [PATCH 17/48] fixed clang-format errors again --- test/unit_test/test_input_adapter.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/test/unit_test/test_input_adapter.cpp b/test/unit_test/test_input_adapter.cpp index 9c32b328..8f9b8eb1 100644 --- a/test/unit_test/test_input_adapter.cpp +++ b/test/unit_test/test_input_adapter.cpp @@ -6,7 +6,6 @@ // SPDX-FileCopyrightText: 2023 Kensuke Fukutani // SPDX-License-Identifier: MIT - #include #include #include @@ -19,14 +18,13 @@ #include #ifdef _MSC_VER - #define DISABLE_C4996 __pragma(warning(push)) __pragma(warning(disable:4996)) - #define ENABLE_C4996 __pragma(warning(pop)) + #define DISABLE_C4996 __pragma(warning(push)) __pragma(warning(disable : 4996)) + #define ENABLE_C4996 __pragma(warning(pop)) #else #define DISABLE_C4996 #define ENABLE_C4996 #endif - static constexpr char input_file_path[] = FK_YAML_TEST_DATA_DIR "/input_adapter_test_data.txt"; TEST_CASE("InputAdapterTest_IteratorInputAdapterProviderTest", "[InputAdapterTest]") @@ -70,9 +68,9 @@ TEST_CASE("InputAdapterTest_FileInputAdapterProviderTest", "[InputAdapterTest]") SECTION("valie FILE object pointer") { -DISABLE_C4996 + DISABLE_C4996 FILE* p_file = std::fopen(input_file_path, "r"); -ENABLE_C4996 + ENABLE_C4996 REQUIRE(p_file != nullptr); auto input_adapter = fkyaml::detail::input_adapter(p_file); @@ -115,9 +113,9 @@ TEST_CASE("InputAdapterTest_GetCharacterTest", "[InputAdapterTest]") SECTION("file_input_adapter") { -DISABLE_C4996 + DISABLE_C4996 FILE* p_file = std::fopen(input_file_path, "r"); -ENABLE_C4996 + ENABLE_C4996 auto input_adapter = fkyaml::detail::input_adapter(p_file); REQUIRE(std::is_same::value); From eb0405e9ede4d97a9ff253cb647acdb30bc468f3 Mon Sep 17 00:00:00 2001 From: fktn Date: Thu, 26 Oct 2023 08:29:06 +0900 Subject: [PATCH 18/48] migrating to MkDocs --- .gitignore | 5 +- docs/mkdocs/docs/api/basic_node/begin.md | 47 ++ .../docs/api/basic_node/boolean_type.md | 41 ++ .../docs/api/basic_node/const_iterator.md | 0 .../mkdocs/docs/api/basic_node/constructor.md | 275 +++++++++++ docs/mkdocs/docs/api/basic_node/contains.md | 0 .../mkdocs/docs/api/basic_node/deserialize.md | 0 docs/mkdocs/docs/api/basic_node/destructor.md | 9 + docs/mkdocs/docs/api/basic_node/empty.md | 0 docs/mkdocs/docs/api/basic_node/end.md | 49 ++ .../api/basic_node/float_number_scalar.md | 0 .../docs/api/basic_node/float_number_type.md | 41 ++ .../docs/api/basic_node/get_yaml_version.md | 0 docs/mkdocs/docs/api/basic_node/index.md | 102 ++++ .../docs/api/basic_node/initializer_list_t.md | 0 .../docs/api/basic_node/integer_scalar.md | 0 .../docs/api/basic_node/integer_type.md | 38 ++ docs/mkdocs/docs/api/basic_node/is_boolean.md | 0 .../docs/api/basic_node/is_float_number.md | 0 docs/mkdocs/docs/api/basic_node/is_integer.md | 0 docs/mkdocs/docs/api/basic_node/is_mapping.md | 0 docs/mkdocs/docs/api/basic_node/is_null.md | 0 docs/mkdocs/docs/api/basic_node/is_scalar.md | 0 .../mkdocs/docs/api/basic_node/is_sequence.md | 0 docs/mkdocs/docs/api/basic_node/is_string.md | 0 docs/mkdocs/docs/api/basic_node/iterator.md | 0 docs/mkdocs/docs/api/basic_node/mapping.md | 0 .../docs/api/basic_node/mapping_type.md | 62 +++ docs/mkdocs/docs/api/basic_node/node.md | 54 +++ docs/mkdocs/docs/api/basic_node/node_t.md | 82 ++++ docs/mkdocs/docs/api/basic_node/operator=.md | 0 docs/mkdocs/docs/api/basic_node/operator[].md | 0 docs/mkdocs/docs/api/basic_node/sequence.md | 0 .../docs/api/basic_node/sequence_type.md | 0 docs/mkdocs/docs/api/basic_node/serialize.md | 0 .../docs/api/basic_node/set_yaml_version.md | 0 docs/mkdocs/docs/api/basic_node/size.md | 0 .../docs/api/basic_node/string_scalar.md | 0 .../mkdocs/docs/api/basic_node/string_type.md | 0 docs/mkdocs/docs/api/basic_node/type.md | 0 .../api/basic_node/value_converter_type.md | 0 .../docs/api/basic_node/yaml_version_t.md | 57 +++ docs/mkdocs/docs/api/exception/constructor.md | 74 +++ docs/mkdocs/docs/api/exception/destructor.md | 9 + docs/mkdocs/docs/api/exception/index.md | 24 + docs/mkdocs/docs/api/exception/what.md | 13 + docs/mkdocs/docs/api/macros/index.md | 0 .../api/node_value_converter/from_node.md | 0 .../docs/api/node_value_converter/index.md | 25 + .../docs/api/node_value_converter/to_node.md | 0 .../docs/api/ordered_map/constructor.md | 0 .../mkdocs/docs/api/ordered_map/destructor.md | 0 docs/mkdocs/docs/api/ordered_map/index.md | 37 ++ docs/mkdocs/docs/home/CHANGELOG.md | 115 +++++ docs/mkdocs/docs/home/license.md | 21 + docs/mkdocs/docs/img/range-begin-end.svg | 435 ++++++++++++++++++ .../img/range-begin-end.svg:Zone.Identifier | 0 docs/mkdocs/docs/index.md | 27 ++ docs/mkdocs/docs/javascripts/config.js | 1 + docs/mkdocs/docs/tutorials.md | 1 + docs/mkdocs/mkdocs.yml | 151 ++++++ include/fkYAML/exception.hpp | 32 +- include/fkYAML/node.hpp | 137 ++---- 63 files changed, 1854 insertions(+), 110 deletions(-) create mode 100644 docs/mkdocs/docs/api/basic_node/begin.md create mode 100644 docs/mkdocs/docs/api/basic_node/boolean_type.md create mode 100644 docs/mkdocs/docs/api/basic_node/const_iterator.md create mode 100644 docs/mkdocs/docs/api/basic_node/constructor.md create mode 100644 docs/mkdocs/docs/api/basic_node/contains.md create mode 100644 docs/mkdocs/docs/api/basic_node/deserialize.md create mode 100644 docs/mkdocs/docs/api/basic_node/destructor.md create mode 100644 docs/mkdocs/docs/api/basic_node/empty.md create mode 100644 docs/mkdocs/docs/api/basic_node/end.md create mode 100644 docs/mkdocs/docs/api/basic_node/float_number_scalar.md create mode 100644 docs/mkdocs/docs/api/basic_node/float_number_type.md create mode 100644 docs/mkdocs/docs/api/basic_node/get_yaml_version.md create mode 100644 docs/mkdocs/docs/api/basic_node/index.md create mode 100644 docs/mkdocs/docs/api/basic_node/initializer_list_t.md create mode 100644 docs/mkdocs/docs/api/basic_node/integer_scalar.md create mode 100644 docs/mkdocs/docs/api/basic_node/integer_type.md create mode 100644 docs/mkdocs/docs/api/basic_node/is_boolean.md create mode 100644 docs/mkdocs/docs/api/basic_node/is_float_number.md create mode 100644 docs/mkdocs/docs/api/basic_node/is_integer.md create mode 100644 docs/mkdocs/docs/api/basic_node/is_mapping.md create mode 100644 docs/mkdocs/docs/api/basic_node/is_null.md create mode 100644 docs/mkdocs/docs/api/basic_node/is_scalar.md create mode 100644 docs/mkdocs/docs/api/basic_node/is_sequence.md create mode 100644 docs/mkdocs/docs/api/basic_node/is_string.md create mode 100644 docs/mkdocs/docs/api/basic_node/iterator.md create mode 100644 docs/mkdocs/docs/api/basic_node/mapping.md create mode 100644 docs/mkdocs/docs/api/basic_node/mapping_type.md create mode 100644 docs/mkdocs/docs/api/basic_node/node.md create mode 100644 docs/mkdocs/docs/api/basic_node/node_t.md create mode 100644 docs/mkdocs/docs/api/basic_node/operator=.md create mode 100644 docs/mkdocs/docs/api/basic_node/operator[].md create mode 100644 docs/mkdocs/docs/api/basic_node/sequence.md create mode 100644 docs/mkdocs/docs/api/basic_node/sequence_type.md create mode 100644 docs/mkdocs/docs/api/basic_node/serialize.md create mode 100644 docs/mkdocs/docs/api/basic_node/set_yaml_version.md create mode 100644 docs/mkdocs/docs/api/basic_node/size.md create mode 100644 docs/mkdocs/docs/api/basic_node/string_scalar.md create mode 100644 docs/mkdocs/docs/api/basic_node/string_type.md create mode 100644 docs/mkdocs/docs/api/basic_node/type.md create mode 100644 docs/mkdocs/docs/api/basic_node/value_converter_type.md create mode 100644 docs/mkdocs/docs/api/basic_node/yaml_version_t.md create mode 100644 docs/mkdocs/docs/api/exception/constructor.md create mode 100644 docs/mkdocs/docs/api/exception/destructor.md create mode 100644 docs/mkdocs/docs/api/exception/index.md create mode 100644 docs/mkdocs/docs/api/exception/what.md create mode 100644 docs/mkdocs/docs/api/macros/index.md create mode 100644 docs/mkdocs/docs/api/node_value_converter/from_node.md create mode 100644 docs/mkdocs/docs/api/node_value_converter/index.md create mode 100644 docs/mkdocs/docs/api/node_value_converter/to_node.md create mode 100644 docs/mkdocs/docs/api/ordered_map/constructor.md create mode 100644 docs/mkdocs/docs/api/ordered_map/destructor.md create mode 100644 docs/mkdocs/docs/api/ordered_map/index.md create mode 100644 docs/mkdocs/docs/home/CHANGELOG.md create mode 100644 docs/mkdocs/docs/home/license.md create mode 100644 docs/mkdocs/docs/img/range-begin-end.svg create mode 100644 docs/mkdocs/docs/img/range-begin-end.svg:Zone.Identifier create mode 100644 docs/mkdocs/docs/index.md create mode 100644 docs/mkdocs/docs/javascripts/config.js create mode 100644 docs/mkdocs/docs/tutorials.md create mode 100644 docs/mkdocs/mkdocs.yml diff --git a/.gitignore b/.gitignore index 72c875dc..4c726ce9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ build* .vscode/ -.vs/ \ No newline at end of file +.vs/ + +# documentation +/docs/mkdocs/site/ \ No newline at end of file diff --git a/docs/mkdocs/docs/api/basic_node/begin.md b/docs/mkdocs/docs/api/basic_node/begin.md new file mode 100644 index 00000000..dcedad5e --- /dev/null +++ b/docs/mkdocs/docs/api/basic_node/begin.md @@ -0,0 +1,47 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::begin + +```cpp +iterator begin(); +const_iterator begin() const; +``` + +Returns an iterator to the first element of a container node value. +Throws a [`fkyaml::exception`](../exception/index.md) if a basic_node does not have a sequence nor mapping value. + +![Image from https://en.cppreference.com/w/cpp/iterator/begin](../../img/range-begin-end.svg) + +### **Return Value** + +An iterator to the first element of a container node value (either sequence or mapping). + +??? Example + + ```cpp + #include + #include + + int main() + { + // create a sequence node. + fkyaml::node n = {std::string("foo"), std::string("bar")}; + // get an iterator to the first element. + fkyaml::node::iterator it = n.begin(); + std::cout << fkyaml::node::serialize(*it) << std::endl; + return 0; + } + ``` + + output: + ```yaml + foo + ``` + +### **See Also** + +* [basic_node](index.md) +* [node](node.md) +* [iterator](iterator.md) +* [const_iterator](const_iterator.md) +* [end](end.md) diff --git a/docs/mkdocs/docs/api/basic_node/boolean_type.md b/docs/mkdocs/docs/api/basic_node/boolean_type.md new file mode 100644 index 00000000..6fe213f2 --- /dev/null +++ b/docs/mkdocs/docs/api/basic_node/boolean_type.md @@ -0,0 +1,41 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::boolean_type + +```cpp +using boolean_type = BooleanType; +``` + +The type used to store boolean node values. +The YAML specification describes a boolean as a type which differentiates the following literals: + +* true, True, TRUE -> `true` +* false, False, FALSE -> `false` + +To store boolean objects in [`basic_node`](index.md) class, the type is defined by the template parameter `BooleanType` which chooses the type to use for boolean objects. +If not explicitly specified, the default type `bool` will be chosen. +With the decided type, boolean objects are stored directly inside a [`basic_node`](index.md). + +??? Example + + ```cpp + #include + #include + #include + #include + + int main() + { + std::cout << std::boolalpha << std::is_same::value << std::endl; + return 0; + } + ``` + + output: + ```bash + true + ``` + +### **See Also** + +* [basic_node](index.md) \ No newline at end of file diff --git a/docs/mkdocs/docs/api/basic_node/const_iterator.md b/docs/mkdocs/docs/api/basic_node/const_iterator.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/constructor.md b/docs/mkdocs/docs/api/basic_node/constructor.md new file mode 100644 index 00000000..eb4f1831 --- /dev/null +++ b/docs/mkdocs/docs/api/basic_node/constructor.md @@ -0,0 +1,275 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::(constructor) + +Constructs new basic_node from a variety of data sources. +Available overloads + +## Overloads + +```cpp +basic_node() = default; +``` +Default constructor. Constructs a basic_node with a null value. +The resulting basic_node has the [`node_t::NULL_OBJECT`](node_t.md) type. + +??? example + + ```cpp + #include + #include + + int main() + { + fkyaml::node n; + std::cout << fkyaml::node::serialize(n) << std::endl; + return 0; + } + ``` + output: + + ```yaml + null + ``` +--- + +```cpp +explicit basic_node(const node_t type); +``` +Constructs a basic_node with the given type. +The resulting basic_node has a default value for the given type. + +### **Parameters** + +***`type`*** [in] +: A YAML node value. + +??? example + + ```cpp + #include + #include + + int main() + { + fkyaml::node n(fkyaml::node::node_t::INTEGER); + std::cout << fkyaml::node::serialize(n) << std::endl; + return 0; + } + ``` + output: + + ```yaml + 0 + ``` +--- + +```cpp +basic_node(const basic_node& rhs); +``` +Copy constructor. Copies the internal data of `rhs` into the resulting basic_node. +The resulting basic_node has the same type and value as `rhs`. + +### **Parameters** + +***`rhs`*** [in] +: A basic node to be copied with. + +??? example + + ```cpp + #include + #include + + int main() + { + fkyaml::node n(fkyaml::node::node_t::BOOLEAN); + fkyaml::node n2(n); + std::cout << fkyaml::node::serialize(n) << std::endl; + return 0; + } + ``` + output: + + ```yaml + false + ``` +--- + +```cpp +basic_node(basic_node&& rhs) noexcept; +``` +Move constructor. Move the internal data of `rhs` into the resulting basic_node. +The resulting basic_node has the same type and value as `rhs`. +The value of the argument `rhs` after calling this move constructor, will be the same as a default-constructed basic_node. + +### **Parameters** + +***`rhs`*** [in] +: A basic node to be moved from. + +??? example + + ```cpp + #include + #include + + int main() + { + fkyaml::node n(fkyaml::node::node_t::BOOLEAN); + fkyaml::node n2(n); + std::cout << fkyaml::node::serialize(n) << std::endl; + return 0; + } + ``` + output: + + ```yaml + false + ``` +--- + +```cpp +template < + typename CompatibleType, typename U = detail::remove_cv_ref_t, + detail::enable_if_t< + detail::conjunction< + detail::negation>, + detail::disjunction>>::value, + int> = 0> +basic_node(CompatibleType&& val); +``` +Constructs a basic_node with a value of a compatible type. +The resulting basic_node has the value of `val` and the type which is associated with `CompatibleType`. + +### **Template Parameters** + +***`CompatibleType`*** +: Type of native data which is compatible with node values. + +***`U`*** +: Type of compatible native data without cv-qualifiers and reference. + +### **Parameters** + +***`val`*** [in] +: The value of a compatible type. + +??? example + + ```cpp + #include + #include + + int main() + { + double pi = 3.141592; + fkyaml::node n(pi); + std::cout << fkyaml::node::serialize(n) << std::endl; + return 0; + } + ``` + output: + + ```yaml + 3.141592 + ``` +--- + +```cpp +template < + typename NodeRefStorageType, + detail::enable_if_t::value, int> = 0> +basic_node(const NodeRefStorageType& node_ref_storage); +``` +Constructs a basic_node with a node_ref_storage. +The resulting basic_node has the value of the referenced basic_node by `node_ref_storage`. + +!!! Warning + + This constructor is mainly for the one with std::initializer_list, and the argument type is too detailed to be used from outside the fkYAML library. + So, this overload might become unavailable in the future major version. + Please refrain from intentionally using this overload, and use the overload with std::initializer_list instead. + +### **Template Parameters** + +***`NodeRefStorageType`*** +: Type of basic_node with reference. + +### **Parameters** + +***`node_ref_storage`*** [in] +: A node_ref_storage template class object. + +??? example + + ```cpp + #include + #include + + int main() + { + fkyaml::node n({true, false}); + std::cout << fkyaml::node::serialize(n) << std::endl; + return 0; + } + ``` + output: + + ```yaml + - true + - false + ``` +--- + +```cpp +basic_node(initializer_list_t init); +``` +Constructs a basic_node with a initializer_list_t object. +The resulting basic_node has the value of a container (sequence or mapping) which has the contents of `init`. +Basically, the basic_node objects in `init` are considered as a sequence node. +If `init` contains a sequence of basic_node objects in which the number of basic_node objects is 2 and the first has the type of `node_t::STRING`, however, such a sequence is reinterpreted as a mapping node. + +!!! Note + + To avoid ambiguity between a sequence of `char` and a `std::string`, c-style char arrays are intentionally unsupported in this constructor. + To contain a string in a `initializer_list_t` object, you must explicitly pass a `std::string` object as follows: + ```cpp + // this is not supported. + fkyaml::node n = {"foo", "bar"}; + + // you must do this instead. + fkyaml::node n2 = {std::string("foo"), std::string("bar")}; + ``` + +### **Parameters** + +***`init`*** [in] +: A initializer list of basic_node objects. + +??? example + + ```cpp + #include + #include + + int main() + { + fkyaml::node n = {true, false}; + std::cout << fkyaml::node::serialize(n) << std::endl; + + fkyaml::node n2 = {std::string("foo"), 1024}; + std::cout << fkyaml::node::serialize(n2) << std::endl; + return 0; + } + ``` + output: + + ```yaml + - true + - false + ``` + ```yaml + foo: 1024 + ``` +--- \ No newline at end of file diff --git a/docs/mkdocs/docs/api/basic_node/contains.md b/docs/mkdocs/docs/api/basic_node/contains.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/deserialize.md b/docs/mkdocs/docs/api/basic_node/deserialize.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/destructor.md b/docs/mkdocs/docs/api/basic_node/destructor.md new file mode 100644 index 00000000..4be1041e --- /dev/null +++ b/docs/mkdocs/docs/api/basic_node/destructor.md @@ -0,0 +1,9 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::(destructor) + +```cpp +~basic_node() noexcept; +``` + +Destroys the YAML node value and frees all allocated memory. diff --git a/docs/mkdocs/docs/api/basic_node/empty.md b/docs/mkdocs/docs/api/basic_node/empty.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/end.md b/docs/mkdocs/docs/api/basic_node/end.md new file mode 100644 index 00000000..17ccc657 --- /dev/null +++ b/docs/mkdocs/docs/api/basic_node/end.md @@ -0,0 +1,49 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::end + +```cpp +iterator end(); +const_iterator end() const; +``` + +Returns an iterator to the past-the-last element of a container node value. +Throws a [`fkyaml::exception`](../exception/index.md) if a basic_node does not have a sequence nor mapping value. + +![Image from https://en.cppreference.com/w/cpp/iterator/end](../../img/range-begin-end.svg) + +### **Return Value** + +An iterator to the past-the-last element of a container node value (either sequence or mapping). + +??? Example + + ```cpp + #include + #include + + int main() + { + // create a sequence node. + fkyaml::node n = {std::string("foo"), std::string("bar")}; + // get an iterator to the past-the-last element. + fkyaml::node::iterator it = n.end(); + // decrement the iterator to point to the last element. + --it; + std::cout << fkyaml::node::serialize(*it) << std::endl; + return 0; + } + ``` + + output: + ```yaml + bar + ``` + +### **See Also** + +* [basic_node](index.md) +* [node](node.md) +* [iterator](iterator.md) +* [const_iterator](const_iterator.md) +* [begin](begin.md) \ No newline at end of file diff --git a/docs/mkdocs/docs/api/basic_node/float_number_scalar.md b/docs/mkdocs/docs/api/basic_node/float_number_scalar.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/float_number_type.md b/docs/mkdocs/docs/api/basic_node/float_number_type.md new file mode 100644 index 00000000..ae6fc917 --- /dev/null +++ b/docs/mkdocs/docs/api/basic_node/float_number_type.md @@ -0,0 +1,41 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::float_number_type + +```cpp +using float_number_type = FloatNumberType; +``` + +The type used to store boolean node values. +The YAML specification describes a floating point number as a type which differentiates the following literals: + +* .inf, .Inf, .INF -> an infinite number +* .nan, .NaN, .NAN -> Not a Number + +To store floating point number objects in [`basic_node`](index.md) class, the type is defined by the template parameter `FloatNumberType` which chooses the type to use for floating point number objects. +If not explicitly specified, the default type `double` will be chosen. +With the decided type, floating point number objects are stored directly inside a [`basic_node`](index.md). + +??? Example + + ```cpp + #include + #include + #include + #include + + int main() + { + std::cout << std::boolalpha << std::is_same::value << std::endl; + return 0; + } + ``` + + output: + ```bash + true + ``` + +### **See Also** + +* [basic_node](index.md) \ No newline at end of file diff --git a/docs/mkdocs/docs/api/basic_node/get_yaml_version.md b/docs/mkdocs/docs/api/basic_node/get_yaml_version.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/index.md b/docs/mkdocs/docs/api/basic_node/index.md new file mode 100644 index 00000000..453fe579 --- /dev/null +++ b/docs/mkdocs/docs/api/basic_node/index.md @@ -0,0 +1,102 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node + +```cpp +template< + template class SequenceType = std::vector, + template class MappingType = std::map, + typename BooleanType = bool, + typename IntegerType = std::int64_t, + typename FloatNumberType = double, + typename StringType = std::string, + template class ConverterType = node_value_converter> +class basic_node; +``` + +This class provides features to handle YAML nodes. + +## Template Paramters + +| Template parameter | Description | Default | Derived type | +|--------------------|--------------------------------------------------------------|----------------------------------------------------------------------|---------------------------------------------------| +| `SequenceType` | type for sequence node value containers | [std::vector](https://en.cppreference.com/w/cpp/container/vector) | [`sequence_type`](sequence_type.md) | +| `MappingType` | type for mapping node value containers | [std::map](https://en.cppreference.com/w/cpp/container/map) | [`mapping_type`](mapping_type.md) | +| `BooleanType` | type for boolean node values | [bool](https://en.cppreference.com/w/cpp/keyword/bool) | [`boolean_type`](boolean_type.md) | +| `IntegerType` | type for integer node values | [std::int64_t](https://en.cppreference.com/w/cpp/types/integer) | [`integer_type`](integer_type.md) | +| `FloatNumberType` | type for float number node values | [double](https://en.cppreference.com/w/cpp/keyword/double) | [`float_number_type`](float_number_type.md) | +| `StringType` | type for string node values | [std::string](https://en.cppreference.com/w/cpp/string/basic_string) | [`string_type`](string_type.md) | +| `ConverterType` | type for converters between
nodes and native data types | [node_value_converter](../node_value_converter/index.md) | [`value_converter_type`](value_converter_type.md) | + +## Specializations + +* [node](node.md) - default specialization + +## Member Types + +| Name | Description | +|-------------------------------------------------|------------------------------------------------------------| +| [boolean_type](boolean_type.md) | The type used to store boolean node values. | +| [const_iterator](const_iterator.md) | The type for constant iterators. | +| [float_number_type](float_number_type.md) | The type used to store float number node values. | +| [initializer_list_t](initializer_list_t.md) | The type alias for constructor with std::initializer_list. | +| [integer_type](integer_type.md) | The type used to store integer node values. | +| [iterator](iterator.md) | The type for non-constant iterators. | +| [mapping_type](mapping_type.md) | The type used to store mapping node value containers. | +| [node_t](node_t.md) | The type used to store the internal value type. | +| [sequence_type](sequence_type.md) | The type used to store sequence node value containers. | +| [string_type](string_type.md) | The type used to store string node values. | +| [value_converter_type](value_converter_type.md) | The type used to convert between node and native data. | +| [yaml_version_t](yaml_version_t.md) | The type used to store the enable version of YAML. | + +## Member Functions + +### Construction/Destruction +| Name | | Description | +|----------------------------------------------|----------|---------------------------------------------------------------| +| [(constructor)](constructor.md) | | constructs a basic_node. | +| [(destructor)](destructor.md) | | destroys a basic_node, deallocating internal storage if used. | +| [operator=](operator=.md) | | assigns values to the basic_node. | +| [float_number_scalar](float_number_scalar.md)| (static) | constructs a basic_node with a float number value. | +| [integer_scalar](integer_scalar.md) | (static) | constructs a basic_node with an integer value. | +| [mapping](mapping.md) | (static) | constructs a basic_node with a mapping container. | +| [sequence](sequence.md) | (static) | constructs a basic_node with a sequence container. | +| [string_scalar](string_scalar.md) | (static) | constructs a basic_node with a string value. | + +### Inspection for Node Value Types +| Name | Description | +|---------------------------------------|-------------------------------------------------------| +| [type](type.md) | returns the type of a node value in a basic_node. | +| [is_sequence](is_sequence.md) | checks if a basic_node has a sequence node value. | +| [is_mapping](is_mapping.md) | checks if a basic_node has a mapping node value. | +| [is_null](is_null.md) | checks if a basic_node has a null node value. | +| [is_scalar](is_scalar.md) | checks if a basic_node has a scalar node value. | +| [is_boolean](is_boolean.md) | checks if a basic_node has a boolean node value. | +| [is_integer](is_integer.md) | checks if a basic_node has an integer node value. | +| [is_float_number](is_float_number.md) | checks if a basic_node has a float number node value. | +| [is_string](is_string.md) | checks if a basic_node has a string node value. | + +### Conversions +| Name | Description | +| ----------------------------- | ------------------------------------------------------- | +| [deserialize](deserialize.md) | deserializes a YAML formatted string into a basic_node. | +| [serialize](serialize.md) | serializes a basic_node into a YAML formatted string. | +| | | + +### Iterators +| Name | Description | +|-------------------|----------------------------------------------------------| +| [begin](begin.md) | returns an iterator to the beginning of mapping/sequence | +| [end](end.md) | returns an iterator to the end of mapping/sequence | + +### Inspection for Container Node Values +| Name | Description | +|-------------------------|--------------------------------------------------------| +| [contains](contains.md) | checks if a basic_node has the given key. | +| [empty](empty.md) | checks if a basic_node has an empty container. | +| [size](size.md) | returns the size of a container value of a basic_node. | + +### Access Elements in Containers +| Name | Description | +|-----------------------------|---------------------------------------------| +| [operator[]](operator[].md) | accesses an item specified by the key/index | \ No newline at end of file diff --git a/docs/mkdocs/docs/api/basic_node/initializer_list_t.md b/docs/mkdocs/docs/api/basic_node/initializer_list_t.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/integer_scalar.md b/docs/mkdocs/docs/api/basic_node/integer_scalar.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/integer_type.md b/docs/mkdocs/docs/api/basic_node/integer_type.md new file mode 100644 index 00000000..4a397052 --- /dev/null +++ b/docs/mkdocs/docs/api/basic_node/integer_type.md @@ -0,0 +1,38 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::integer_type + +```cpp +using integer_type = IntegerType; +``` + +The type used to store boolean node values. + +To store integer objects in [`basic_node`](index.md) class, the type is defined by the template parameter `IntegerType` which chooses the type to use for integer objects. +If not explicitly specified, the default type `std::int64_t` will be chosen. +With the decided type, integer objects are stored directly inside a [`basic_node`](index.md). + +??? Example + + ```cpp + #include + #include + #include + #include + #include + + int main() + { + std::cout << std::boolalpha << std::is_same::value << std::endl; + return 0; + } + ``` + + output: + ```bash + true + ``` + +### **See Also** + +* [basic_node](index.md) \ No newline at end of file diff --git a/docs/mkdocs/docs/api/basic_node/is_boolean.md b/docs/mkdocs/docs/api/basic_node/is_boolean.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/is_float_number.md b/docs/mkdocs/docs/api/basic_node/is_float_number.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/is_integer.md b/docs/mkdocs/docs/api/basic_node/is_integer.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/is_mapping.md b/docs/mkdocs/docs/api/basic_node/is_mapping.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/is_null.md b/docs/mkdocs/docs/api/basic_node/is_null.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/is_scalar.md b/docs/mkdocs/docs/api/basic_node/is_scalar.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/is_sequence.md b/docs/mkdocs/docs/api/basic_node/is_sequence.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/is_string.md b/docs/mkdocs/docs/api/basic_node/is_string.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/iterator.md b/docs/mkdocs/docs/api/basic_node/iterator.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/mapping.md b/docs/mkdocs/docs/api/basic_node/mapping.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/mapping_type.md b/docs/mkdocs/docs/api/basic_node/mapping_type.md new file mode 100644 index 00000000..60ed80ef --- /dev/null +++ b/docs/mkdocs/docs/api/basic_node/mapping_type.md @@ -0,0 +1,62 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::mapping_type + +```cpp +using mapping_type = MappingType; +``` + +The type used to store mapping node values. + +To store mapping objects in [`basic_node`](index.md) class, the container type is defined by the template parameter `MappingType` which chooses the type to use for integer objects. +If not explicitly specified, the default type `std::map` will be chosen. +With the decided container type, the type of mapping objects will then be decided in the form of `MappingType` with which mapping objects are stored inside a [`basic_node`](index.md). +Note that mapping objects are stored as pointers in a [`basic_node`](index.md) so that the internal storage size will at most be 8 bytes. + +!!! Note "Preserve the insertion order of key-value pairs" + + The YAML specification describes as a mapping node as "an unordered association of unique keys to values". + Which means that **the insertion order of key-value pairs are not guranteed by the YAML specification**. + To follow the specification, the fkYAML library uses `std::map` as the mapping container type by default with the intention of better integration with other C++ programs. + If your YAML documents really needs to be dependent on the insertion order (the YAML specification discourages that though), you can force preserving the insertion order by specifying [`fkyaml::ordered_map`](../ordered_map/index.md) as the MappingType template parameter as follows: + + ```cpp + #include + using ordered_node = basic_node; + ``` + +### **Template Paramters** + +`MappingType` +: The container to store key-value pairs. Defaults to `std::map`. + +`StringType` +: The type of keys and string scalar values. Defaults to `std::string`. + +??? Example + + ```cpp + #include + #include + #include + #include + #include + + int main() + { + std::cout << std::boolalpha + << std::is_same, fkyaml::node::mapping_type>::value + << std::endl; + return 0; + } + ``` + + output: + ```bash + true + ``` + +### **See Also** + +* [basic_node](index.md) +* [ordered_map](../ordered_map/index.md) diff --git a/docs/mkdocs/docs/api/basic_node/node.md b/docs/mkdocs/docs/api/basic_node/node.md new file mode 100644 index 00000000..50bea0b9 --- /dev/null +++ b/docs/mkdocs/docs/api/basic_node/node.md @@ -0,0 +1,54 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::node + +```cpp +using node = basic_node<>; +``` + +This type is the default specialization of the [basic_node](index.md) class which uses the standard template types. + +??? Example + + ```cpp + #include + #include + + int main() + { + // create a YAML node. + fkyaml::node n = + { + {std::string("foo"), 3.14}, + {std::string("bar"), true}, + {std::string("baz"), nullptr}, + {std::string("qux"), { + {std::string("corge"), {1, 2, 3}} + }} + }; + + // add a new value. + n["qux"]["key"] = {std::string("another"), std::string("value")}; + + // output a YAML formatted string. + std::cout << fkyaml::node::serialize(n) << std::endl; + }; + ``` + + output: + ```yaml + bar: true + baz: null + foo: 3.14 + qux: + corge: + - 1 + - 2 + - 3 + key: + another: value + ``` + +### **See Also** + +* [basic_node](index.md) \ No newline at end of file diff --git a/docs/mkdocs/docs/api/basic_node/node_t.md b/docs/mkdocs/docs/api/basic_node/node_t.md new file mode 100644 index 00000000..f271b9d3 --- /dev/null +++ b/docs/mkdocs/docs/api/basic_node/node_t.md @@ -0,0 +1,82 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::node_t + +```cpp +enum class node_t +{ + SEQUENCE, + MAPPING, + NULL_OBJECT, + BOOLEAN, + INTEGER, + FLOAT_NUMBER, + STRING, +}; +``` + +This enumeration collects the different YAML value types. They are internally used to distinguish the stored values, and the functions [`is_sequence`](is_sequence.md), [`is_mapping`](is_mapping.md) and [`is_scalar`](is_scalar.md) (with [`is_null`](is_null.md), [`is_boolean`](is_boolean.md), [`is_integer`](is_integer.md), [`is_float_number`](is_float_number.md), [`is_string`](is_string.md)) rely on it. + +!!! Note "Types of scalars" + + There are five enumerators for scalars (`NULL_OBJECT`, `BOOLEAN`, `INTEGER`, `FLOAT_NUMBER`, `STRING`) to distinguish between different types of scalars: + + * [`boolean_type`](boolean_type.md) for boolean scalar values + * [`integer_type`](integer_type.md) for integer scalar values + * [`float_number_type`](float_number_type.md) for float number scalar values + * [`string_type`](string_type.md) for string scalar values + +??? Example + + ```cpp + #include + #include + #include + + int main() + { + // create YAML nodes. + fkyaml::node sequence_node = {1, 2, 3}; + fkyaml::node mapping_node = {{std::string("foo"), true}, {std::string("bar"), false}}; + fkyaml::node null_node; + fkyaml::node boolean_node = true; + fkyaml::node integer_node = 256; + fkyaml::node float_node = 3.14; + fkyaml::node string_node = std::string("Hello, world!"); + + // call type() + std::cout << std::boolalpha; + std::cout << (sequence_node.type() == fkyaml::node::node_t::SEQUENCE) << std::endl; + std::cout << (mapping_node.type() == fkyaml::node::node_t::MAPPING) << std::endl; + std::cout << (null_node.type() == fkyaml::node::node_t::NULL_OBJECT) << std::endl; + std::cout << (boolean_node.type() == fkyaml::node::node_t::BOOLEAN) << std::endl; + std::cout << (integer_node.type() == fkyaml::node::node_t::INTEGER) << std::endl; + std::cout << (float_node.type() == fkyaml::node::node_t::FLOAT_NUMBER) << std::endl; + std::cout << (string_node.type() == fkyaml::node::node_t::STRING) << std::endl; + + return 0; + }; + ``` + + output: + ```bash + true + true + true + true + true + true + true + ``` + +### **See Also** + +* [type](type.md) +* [is_sequence](is_sequence.md) +* [is_mapping](is_mapping.md) +* [is_scalar](is_scalar.md) +* [is_null](is_null.md) +* [is_boolean](is_boolean.md) +* [is_integer](is_integer.md) +* [is_float_number](is_float_number.md) +* [is_string](is_string.md) \ No newline at end of file diff --git a/docs/mkdocs/docs/api/basic_node/operator=.md b/docs/mkdocs/docs/api/basic_node/operator=.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/operator[].md b/docs/mkdocs/docs/api/basic_node/operator[].md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/sequence.md b/docs/mkdocs/docs/api/basic_node/sequence.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/sequence_type.md b/docs/mkdocs/docs/api/basic_node/sequence_type.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/serialize.md b/docs/mkdocs/docs/api/basic_node/serialize.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/set_yaml_version.md b/docs/mkdocs/docs/api/basic_node/set_yaml_version.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/size.md b/docs/mkdocs/docs/api/basic_node/size.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/string_scalar.md b/docs/mkdocs/docs/api/basic_node/string_scalar.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/string_type.md b/docs/mkdocs/docs/api/basic_node/string_type.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/type.md b/docs/mkdocs/docs/api/basic_node/type.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/value_converter_type.md b/docs/mkdocs/docs/api/basic_node/value_converter_type.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/yaml_version_t.md b/docs/mkdocs/docs/api/basic_node/yaml_version_t.md new file mode 100644 index 00000000..9448a66e --- /dev/null +++ b/docs/mkdocs/docs/api/basic_node/yaml_version_t.md @@ -0,0 +1,57 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::yaml_version_t + +```cpp +enum class yaml_version_t +{ + VER_1_1, + VER_1_2, +}; +``` + +This enumeration collects the used versions of YAML specification. It is used as meta data of a basic_node and the functions [`get_yaml_version`](get_yaml_version.md) and [`set_yaml_version`](set_yaml_version.md) rely on it. + +??? Example + + ```cpp + #include + #include + #include + + int main() + { + char input[] = + "%YAML 1.2\n" + "---\n" + "foo: bar\n"; + + // deserialize a YAML formatted string. + fkyaml::node n = fkyaml::node::deserialize(input); + + // call get_yaml_version(). + fkyaml::node::yaml_version_t yaml_ver = n.get_yaml_version(); + std::cout << std::boolalpha; + std::cout << (n.get_yaml_version() == fkyaml::node::yaml_version_t::VER_1_2) << std::endl; + + // overwrite the YAML version to 1.1. + n.set_yaml_version(fkyaml::node::yaml_version_t::VER_1_1); + + // call get_yaml_version() again. + std::cout << (n.get_yaml_version() == fkyaml::node::yaml_version_t::VER_1_1) << std::endl; + + return 0; + } + ``` + + output: + ```bash + true + true + ``` + +### **See Also** + +* [deserialize](deserialize.md) +* [get_yaml_version](get_yaml_version.md) +* [set_yaml_version](set_yaml_version.md) \ No newline at end of file diff --git a/docs/mkdocs/docs/api/exception/constructor.md b/docs/mkdocs/docs/api/exception/constructor.md new file mode 100644 index 00000000..cb2aa7dc --- /dev/null +++ b/docs/mkdocs/docs/api/exception/constructor.md @@ -0,0 +1,74 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/exception.hpp) + +# fkyaml::exception::(constructor) + +```cpp +exception() = default; +``` + +Constructs an exception without an error message. +You can specify an error message on constructing an exception with an overloaded constructor. + +??? example + + ```cpp + #include + #include + + int main() + { + try + { + throw fkyaml::exception(); + } + catch (const fkyaml::exception& e) + { + std::cout << e.what() << std::endl; + } + return 0; + } + ``` + + output: + ```bash + + ``` + +## Overloads + +```cpp +explicit exception(const char* msg); +``` + +Constructs an exception with a given error message. +The given error message can be retrieved by calling [`exception::what()`](what.md) function. + +### **Parameters** + +***`msg`*** [in] +: An error message for the exception. If `nullptr` is given, the resulting error message will be empty. + +??? example + + ```cpp + #include + #include + + int main() + { + try + { + throw fkyaml::exception("An error message."); + } + catch (const fkyaml::exception& e) + { + std::cout << e.what() << std::endl; + } + return 0; + } + ``` + + output: + ```bash + An error message. + ``` \ No newline at end of file diff --git a/docs/mkdocs/docs/api/exception/destructor.md b/docs/mkdocs/docs/api/exception/destructor.md new file mode 100644 index 00000000..2d5f0bde --- /dev/null +++ b/docs/mkdocs/docs/api/exception/destructor.md @@ -0,0 +1,9 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/exception.hpp) + +# fkyaml::exception::(destructor) + +```cpp +~exception() noexcept; +``` + +Destroy an exception. diff --git a/docs/mkdocs/docs/api/exception/index.md b/docs/mkdocs/docs/api/exception/index.md new file mode 100644 index 00000000..34e02bd1 --- /dev/null +++ b/docs/mkdocs/docs/api/exception/index.md @@ -0,0 +1,24 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/exception.hpp) + +# fkyaml::exception + +```cpp +class exception : public std::exception; +``` + +A basic exception class used in the fkYAML library. + +## Member Functions + +### Construction/Destruction + +| Type | Description | +|---------------------------------|--------------------------| +| [(constructor)](constructor.md) | constructs an exception. | +| [(destructor)](destructor.md) | destroys an exception. | + +### Operation + +| Type | Description | +|-----------------|--------------------------------------------| +| [what](what.md) | provides an error message for a exception. | diff --git a/docs/mkdocs/docs/api/exception/what.md b/docs/mkdocs/docs/api/exception/what.md new file mode 100644 index 00000000..6b4cae08 --- /dev/null +++ b/docs/mkdocs/docs/api/exception/what.md @@ -0,0 +1,13 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/exception.hpp) + +# fkyaml::exception::what + +```cpp +const char* what(); +``` + +Returns an error message for an exception. If nothing, a non-null, empty string will be returned. + +### **See Also** + +* [(constructor)](constructor.md) \ No newline at end of file diff --git a/docs/mkdocs/docs/api/macros/index.md b/docs/mkdocs/docs/api/macros/index.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/node_value_converter/from_node.md b/docs/mkdocs/docs/api/node_value_converter/from_node.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/node_value_converter/index.md b/docs/mkdocs/docs/api/node_value_converter/index.md new file mode 100644 index 00000000..b5d4445b --- /dev/null +++ b/docs/mkdocs/docs/api/node_value_converter/index.md @@ -0,0 +1,25 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node_value_converter.hpp) + +# fkyaml::node_value_converter + +```cpp +template +class node_value_converter; +``` + +An ADL friendly converter between [basic_node](../basic_node/index.md) objects and native data objects. + +## Template Paramters + +| Template parameter | Description | +|--------------------|--------------------------------------| +| `ValueType` | The default target native data type. | + +## Member Functions + +### Conversions + +| Name | Description | +|---------------------------|-------------------------------------------| +| [from_node](from_node.md) | converts a native data into a basic_node. | +| [to_node](to_node.md) | converts a basic_node into a native data. | diff --git a/docs/mkdocs/docs/api/node_value_converter/to_node.md b/docs/mkdocs/docs/api/node_value_converter/to_node.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/ordered_map/constructor.md b/docs/mkdocs/docs/api/ordered_map/constructor.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/ordered_map/destructor.md b/docs/mkdocs/docs/api/ordered_map/destructor.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/ordered_map/index.md b/docs/mkdocs/docs/api/ordered_map/index.md new file mode 100644 index 00000000..a11a01b1 --- /dev/null +++ b/docs/mkdocs/docs/api/ordered_map/index.md @@ -0,0 +1,37 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/ordered_map.hpp) + +# fkyaml::ordered_map + +```cpp +template< + typename Key, typename Value, typename IgnoredCompare = std::less, + typename Allocator = std::allocator>> +class ordered_map; +``` + +A minimal map-like container which preserves insertion order. + +## Template Parameters + +| Template parameter | Description | Derived type | +|--------------------|---------------------------------------------------------|--------------| +| `Key` | type for sequence node value containers | key_type | +| `Value` | type for mapping node value containers | mapped_type | +| `IgnoredCompare` | type for boolean node values | - | +| `Allocator` | type for integer node values | - | + + +## Member Types + +| Name | Description | +|----------------|-------------------------------------------------| +| key_type | The type for keys. | +| mapped_type | The type for values. | +| Container | The type for internal key-value containers. | +| value_type | The type for key-value pairs. | +| iterator | The type for non-constant iterators. | +| const_iterator | The type for constant iterators. | +| size_type | The type for size parameters used in the class. | +| key_compare | The type for comparison between keys. | + +## Member Functions \ No newline at end of file diff --git a/docs/mkdocs/docs/home/CHANGELOG.md b/docs/mkdocs/docs/home/CHANGELOG.md new file mode 100644 index 00000000..969c5d3a --- /dev/null +++ b/docs/mkdocs/docs/home/CHANGELOG.md @@ -0,0 +1,115 @@ +# Changelog + +## [v0.1.3](https://github.com/fktn-k/fkYAML/releases/tag/v0.1.3) (2023-10-21) + +[Full Changelog](https://github.com/fktn-k/fkYAML/compare/v0.1.2...v0.1.3) + +- \#166 Organize CMake scripts for testing [\#171](https://github.com/fktn-k/fkYAML/pull/171) ([fktn-k](https://github.com/fktn-k)) +- \#158 Added to\_string\(\) for serialization of YAML nodes. [\#170](https://github.com/fktn-k/fkYAML/pull/170) ([fktn-k](https://github.com/fktn-k)) +- \#164 Use default initial values for class member variables [\#168](https://github.com/fktn-k/fkYAML/pull/168) ([fktn-k](https://github.com/fktn-k)) +- \#18 Resolve warnings while building library/tests [\#165](https://github.com/fktn-k/fkYAML/pull/165) ([fktn-k](https://github.com/fktn-k)) +- \#145 Expand swap\(\) support for basic node [\#163](https://github.com/fktn-k/fkYAML/pull/163) ([fktn-k](https://github.com/fktn-k)) + +- \#160 Added the Codacy badge to README.md [\#162](https://github.com/fktn-k/fkYAML/pull/162) ([fktn-k](https://github.com/fktn-k)) + +## [v0.1.2](https://github.com/fktn-k/fkYAML/releases/tag/v0.1.2) (2023-10-18) + +[Full Changelog](https://github.com/fktn-k/fkYAML/compare/v0.1.1...v0.1.2) + +- \#150 Added tests for basic\_deserializer class [\#155](https://github.com/fktn-k/fkYAML/pull/155) ([fktn-k](https://github.com/fktn-k)) +- \#150 added/modified unit tests for lexical\_analyzer test [\#154](https://github.com/fktn-k/fkYAML/pull/154) ([fktn-k](https://github.com/fktn-k)) +- \#150 Covered a missing branch in ordered\_map class [\#153](https://github.com/fktn-k/fkYAML/pull/153) ([fktn-k](https://github.com/fktn-k)) +- \#150 Excluded unreachable lines in serializer class test from coverage data [\#152](https://github.com/fktn-k/fkYAML/pull/152) ([fktn-k](https://github.com/fktn-k)) +- \#150 Add unit tests for input\_handler class [\#151](https://github.com/fktn-k/fkYAML/pull/151) ([fktn-k](https://github.com/fktn-k)) +- \#133 refactor lexer [\#146](https://github.com/fktn-k/fkYAML/pull/146) ([fktn-k](https://github.com/fktn-k)) + +- Fix version\_macros.hpp file path in Makefile [\#147](https://github.com/fktn-k/fkYAML/pull/147) ([fktn-k](https://github.com/fktn-k)) + +- Updated documents [\#156](https://github.com/fktn-k/fkYAML/pull/156) ([fktn-k](https://github.com/fktn-k)) + +## [v0.1.1](https://github.com/fktn-k/fkYAML/releases/tag/v0.1.1) (2023-10-15) + +[Full Changelog](https://github.com/fktn-k/fkYAML/compare/v0.1.0...v0.1.1) + +## [v0.1.0](https://github.com/fktn-k/fkYAML/releases/tag/v0.1.0) (2023-10-15) + +[Full Changelog](https://github.com/fktn-k/fkYAML/compare/v0.0.1...v0.1.0) + +- \#136 Auto-generate a helper source file for the clang-tidy tool [\#139](https://github.com/fktn-k/fkYAML/pull/139) ([fktn-k](https://github.com/fktn-k)) +- \#135 optimize build scripts [\#138](https://github.com/fktn-k/fkYAML/pull/138) ([fktn-k](https://github.com/fktn-k)) +- \#132 Classify source files in detail directory [\#137](https://github.com/fktn-k/fkYAML/pull/137) ([fktn-k](https://github.com/fktn-k)) +- \#126 Generalize serialization/deserialization features [\#134](https://github.com/fktn-k/fkYAML/pull/134) ([fktn-k](https://github.com/fktn-k)) +- \#127 Generalize conversions between nodes and native data [\#129](https://github.com/fktn-k/fkYAML/pull/129) ([fktn-k](https://github.com/fktn-k)) + +- \#128 fixed filtering source files to generate full-spec coverage [\#140](https://github.com/fktn-k/fkYAML/pull/140) ([fktn-k](https://github.com/fktn-k)) + +- \#127 Update examples in readme [\#141](https://github.com/fktn-k/fkYAML/pull/141) ([fktn-k](https://github.com/fktn-k)) +- \#128 moved internal impl to detail dir/namespace [\#131](https://github.com/fktn-k/fkYAML/pull/131) ([fktn-k](https://github.com/fktn-k)) +- \#123 Changed file naming convention [\#125](https://github.com/fktn-k/fkYAML/pull/125) ([fktn-k](https://github.com/fktn-k)) +- \#123 Change naming conventions to lower\_snake\_case [\#124](https://github.com/fktn-k/fkYAML/pull/124) ([fktn-k](https://github.com/fktn-k)) + +## [v0.0.1](https://github.com/fktn-k/fkYAML/releases/tag/v0.0.1) (2023-10-06) + +[Full Changelog](https://github.com/fktn-k/fkYAML/compare/v0.0.0...v0.0.1) + +- \#118 introduce cmake-format [\#119](https://github.com/fktn-k/fkYAML/pull/119) ([fktn-k](https://github.com/fktn-k)) +- Expand usable key types [\#115](https://github.com/fktn-k/fkYAML/pull/115) ([fktn-k](https://github.com/fktn-k)) +- \#113 Generate API documentation only for public members [\#114](https://github.com/fktn-k/fkYAML/pull/114) ([fktn-k](https://github.com/fktn-k)) +- \#111 Use docker images for Clang compilers during CI jobs [\#112](https://github.com/fktn-k/fkYAML/pull/112) ([fktn-k](https://github.com/fktn-k)) +- \#109 Use official docker image for GCC during CI jobs [\#110](https://github.com/fktn-k/fkYAML/pull/110) ([fktn-k](https://github.com/fktn-k)) + +- \#120 added target to use github-changelog-generator tool [\#121](https://github.com/fktn-k/fkYAML/pull/121) ([fktn-k](https://github.com/fktn-k)) +- \#116 use reuse software for file headers [\#117](https://github.com/fktn-k/fkYAML/pull/117) ([fktn-k](https://github.com/fktn-k)) +- \#101 added memory leak check with Valgrind [\#108](https://github.com/fktn-k/fkYAML/pull/108) ([fktn-k](https://github.com/fktn-k)) +- \#21 Update issue templates [\#100](https://github.com/fktn-k/fkYAML/pull/100) ([fktn-k](https://github.com/fktn-k)) +- \#34 add unit tests for deserializer [\#97](https://github.com/fktn-k/fkYAML/pull/97) ([fktn-k](https://github.com/fktn-k)) + +## [v0.0.0](https://github.com/fktn-k/fkYAML/releases/tag/v0.0.0) (2023-09-23) + +[Full Changelog](https://github.com/fktn-k/fkYAML/compare/95b9ee09cc0fe0a609198f2754512c359c31dd6e...v0.0.0) + +- \#88 add more documents [\#89](https://github.com/fktn-k/fkYAML/pull/89) ([fktn-k](https://github.com/fktn-k)) +- \#83 Add compiler support on Windows & macOS [\#87](https://github.com/fktn-k/fkYAML/pull/87) ([fktn-k](https://github.com/fktn-k)) +- \#85 change integer scalar data type to int64\_t only [\#86](https://github.com/fktn-k/fkYAML/pull/86) ([fktn-k](https://github.com/fktn-k)) +- \#81 Disable clang-format & clang-tidy by default [\#84](https://github.com/fktn-k/fkYAML/pull/84) ([fktn-k](https://github.com/fktn-k)) +- \#17 add descriptions in readme [\#82](https://github.com/fktn-k/fkYAML/pull/82) ([fktn-k](https://github.com/fktn-k)) +- \#79 support include-what-you-use [\#80](https://github.com/fktn-k/fkYAML/pull/80) ([fktn-k](https://github.com/fktn-k)) +- \#77 Run sanitizer only on self-hosted runners [\#78](https://github.com/fktn-k/fkYAML/pull/78) ([fktn-k](https://github.com/fktn-k)) +- \#74 Fixed keeping insertion orders of mapping node items [\#76](https://github.com/fktn-k/fkYAML/pull/76) ([fktn-k](https://github.com/fktn-k)) +- \#5 implemented yaml node serializer [\#75](https://github.com/fktn-k/fkYAML/pull/75) ([fktn-k](https://github.com/fktn-k)) +- \#72 Added inline namespace for library versioning [\#73](https://github.com/fktn-k/fkYAML/pull/73) ([fktn-k](https://github.com/fktn-k)) +- \#70 Fixed Git tag for FetchContent test [\#71](https://github.com/fktn-k/fkYAML/pull/71) ([fktn-k](https://github.com/fktn-k)) +- \#62 Added build integration tests [\#69](https://github.com/fktn-k/fkYAML/pull/69) ([fktn-k](https://github.com/fktn-k)) +- \#66 Added tests for various C++ versions [\#68](https://github.com/fktn-k/fkYAML/pull/68) ([fktn-k](https://github.com/fktn-k)) +- \#64 add self-hosted runner for GitHub Actions [\#65](https://github.com/fktn-k/fkYAML/pull/65) ([fktn-k](https://github.com/fktn-k)) +- \#61 Support YAML version directives [\#63](https://github.com/fktn-k/fkYAML/pull/63) ([fktn-k](https://github.com/fktn-k)) +- \#14 Support clang-tidy on CI [\#60](https://github.com/fktn-k/fkYAML/pull/60) ([fktn-k](https://github.com/fktn-k)) +- \#33 Added unit test cases for LexicalAnalyzer class [\#59](https://github.com/fktn-k/fkYAML/pull/59) ([fktn-k](https://github.com/fktn-k)) +- \#57 Added static/runtime assertion checks [\#58](https://github.com/fktn-k/fkYAML/pull/58) ([fktn-k](https://github.com/fktn-k)) +- \#35 Add feature of deserializing anchors & aliases [\#56](https://github.com/fktn-k/fkYAML/pull/56) ([fktn-k](https://github.com/fktn-k)) +- \#54 add unit tests for Exception class [\#55](https://github.com/fktn-k/fkYAML/pull/55) ([fktn-k](https://github.com/fktn-k)) +- Feature/42 add key check api to basicnode [\#53](https://github.com/fktn-k/fkYAML/pull/53) ([fktn-k](https://github.com/fktn-k)) +- \#20 add unit test for iterator [\#52](https://github.com/fktn-k/fkYAML/pull/52) ([fktn-k](https://github.com/fktn-k)) +- \#50 add lacked test cases for Node class [\#51](https://github.com/fktn-k/fkYAML/pull/51) ([fktn-k](https://github.com/fktn-k)) +- \#45 add code coverage job [\#49](https://github.com/fktn-k/fkYAML/pull/49) ([fktn-k](https://github.com/fktn-k)) +- \#17 add badges to readme [\#47](https://github.com/fktn-k/fkYAML/pull/47) ([fktn-k](https://github.com/fktn-k)) +- add CodeQL analysis to CI [\#46](https://github.com/fktn-k/fkYAML/pull/46) ([fktn-k](https://github.com/fktn-k)) +- \#41 introduce catch2 v2 lib to unit test app [\#44](https://github.com/fktn-k/fkYAML/pull/44) ([fktn-k](https://github.com/fktn-k)) +- \#35 support anchors & aliases in Node class [\#43](https://github.com/fktn-k/fkYAML/pull/43) ([fktn-k](https://github.com/fktn-k)) +- \#39 changed newline code from CRLF to LF [\#40](https://github.com/fktn-k/fkYAML/pull/40) ([fktn-k](https://github.com/fktn-k)) +- \#28 add sanitizers to unit test app [\#38](https://github.com/fktn-k/fkYAML/pull/38) ([fktn-k](https://github.com/fktn-k)) +- \#36 support custom node value data types [\#37](https://github.com/fktn-k/fkYAML/pull/37) ([fktn-k](https://github.com/fktn-k)) +- \#4 add block mapping deserialization [\#31](https://github.com/fktn-k/fkYAML/pull/31) ([fktn-k](https://github.com/fktn-k)) +- \#19 add unit test cases for node [\#30](https://github.com/fktn-k/fkYAML/pull/30) ([fktn-k](https://github.com/fktn-k)) +- \#4 supported block sequence deserialization [\#29](https://github.com/fktn-k/fkYAML/pull/29) ([fktn-k](https://github.com/fktn-k)) +- regulated package workflow trigger events & deleted unnecessary comments [\#27](https://github.com/fktn-k/fkYAML/pull/27) ([fktn-k](https://github.com/fktn-k)) +- \#4 implement yaml deserialization [\#26](https://github.com/fktn-k/fkYAML/pull/26) ([fktn-k](https://github.com/fktn-k)) +- \#10 support doxygen [\#12](https://github.com/fktn-k/fkYAML/pull/12) ([fktn-k](https://github.com/fktn-k)) +- \#8 support clang format & clang tidy [\#11](https://github.com/fktn-k/fkYAML/pull/11) ([fktn-k](https://github.com/fktn-k)) +- \#3 implement yaml node [\#9](https://github.com/fktn-k/fkYAML/pull/9) ([fktn-k](https://github.com/fktn-k)) +- \#2 configure CI/CD [\#7](https://github.com/fktn-k/fkYAML/pull/7) ([fktn-k](https://github.com/fktn-k)) +- \#1 create blank project [\#6](https://github.com/fktn-k/fkYAML/pull/6) ([fktn-k](https://github.com/fktn-k)) + + + +\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* diff --git a/docs/mkdocs/docs/home/license.md b/docs/mkdocs/docs/home/license.md new file mode 100644 index 00000000..c3c26b80 --- /dev/null +++ b/docs/mkdocs/docs/home/license.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 fktn + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/docs/mkdocs/docs/img/range-begin-end.svg b/docs/mkdocs/docs/img/range-begin-end.svg new file mode 100644 index 00000000..8e2b2fb6 --- /dev/null +++ b/docs/mkdocs/docs/img/range-begin-end.svg @@ -0,0 +1,435 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + Past-the-last element + + + + begin + + + + end + + + + + diff --git a/docs/mkdocs/docs/img/range-begin-end.svg:Zone.Identifier b/docs/mkdocs/docs/img/range-begin-end.svg:Zone.Identifier new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/index.md b/docs/mkdocs/docs/index.md new file mode 100644 index 00000000..b6391ddd --- /dev/null +++ b/docs/mkdocs/docs/index.md @@ -0,0 +1,27 @@ +# fkYAML +fkYAML is a C++ header-only YAML library. +If you want portability & development speed-up, fkYAML is the way to go. +No need to build a library only for a third party project. +You can add YAML support into your projects by just including header files where it's needed. + +## Design Goals +There are a lot of YAML library out there, and each may have its reason to exist. +The fkYAML library has 3 design goals: + +#### :briefcase: **Portable** +: The whole code depends only on C++ standards, and is designed to work on any kind of platforms so that it can be imported into any C++ projects written in C++11 or later. + No external dependencies, no sub-project, or no additional compiler flags are required. + Besides that, the project supports [CMake](https://cmake.org/), which is widely used among various kinds of C++ projects as the de-facto standard software build system. + We believe those features will surely be useful for a lot of C++ developers. + +#### :hammer: **Quickly Integrated** +: By just copy-and-paste or use from CMake the fkYAML libary to your own C++ projects, everything should work fine with no other extra requirements than a compiler which supports C++. + Just follow the [How to integrate with existing C++ projects](#how-to-integrate-with-existing-c-projects) section, and you will be able to add YAML support to your own project. + If there should arise any issue, it might be our fault. Please let us know by creating an issue or a PR to fix it up. + +#### :memo: **Heavily Tested** +: The fkYAML library has been [unit-tested](https://github.com/fktn-k/fkYAML/tree/develop/test/unit_test) and covers 100% of lines and conditions of the codebase. (You can see the actual coverage [here](https://coveralls.io/github/fktn-k/fkYAML?branch=develop).) + We check with [Valgrind](https://valgrind.org) and the [Clang Sanitizers](https://clang.llvm.org/docs/index.html) that there are no runtime issues such as memory leak. + Furthermore, the quality of our codebase has been checked with [Clang-Tidy](https://clang.llvm.org/extra/clang-tidy/) and [CodeQL](https://codeql.github.com/docs/). + [GitHub Actions](https://docs.github.com/en/actions) workflows run against every commit pushed on the main & develop branches to ensure that the fkYAML library can be successfully built/tested with a variety of compilers and C++ standards. + See the [supported compilers](#supported-compilers) section for more details. \ No newline at end of file diff --git a/docs/mkdocs/docs/javascripts/config.js b/docs/mkdocs/docs/javascripts/config.js new file mode 100644 index 00000000..223ad87a --- /dev/null +++ b/docs/mkdocs/docs/javascripts/config.js @@ -0,0 +1 @@ +hljs.initHighlighting() diff --git a/docs/mkdocs/docs/tutorials.md b/docs/mkdocs/docs/tutorials.md new file mode 100644 index 00000000..944558be --- /dev/null +++ b/docs/mkdocs/docs/tutorials.md @@ -0,0 +1 @@ +This is the top page for tutorials for the fkYAML library. \ No newline at end of file diff --git a/docs/mkdocs/mkdocs.yml b/docs/mkdocs/mkdocs.yml new file mode 100644 index 00000000..7bbeea41 --- /dev/null +++ b/docs/mkdocs/mkdocs.yml @@ -0,0 +1,151 @@ +site_name: "fkYAML : A C++ header-only YAML library" +site_author: Kensuke Fukutani +site_url: https://fktn-k.github.io/fkYAML/ + +repo_name: fktn-k/fkYAML +repo_url: https://github.com/fktn-k/fkYAML + +copyright: Copyright © 2023 Kensuke Fukutani + +theme: + name: material + language: en + palette: + - media: '(prefers-color-scheme: light)' + scheme: default + primary: teal + accent: green + toggle: + icon: material/brightness-7 + name: Switch to dark mode + - media: '(prefers-color-scheme: dark)' + scheme: slate + primary: blue grey + accent: blue + toggle: + icon: material/brightness-4 + name: Switch to light mode + font: + text: Roboto + code: JetBrains Mono + icon: + repo: fontawesome/brands/github + features: + - navigation.instant + - navigation.tracking + - navigation.tabs + - navigation.indexes + - navigation.top + - content.tabs.link + - content.code.copy + - search.suggest + +markdown_extensions: + - abbr + - admonition + - attr_list + - def_list + - pymdownx.details + - pymdownx.emoji: + emoji_index: !!python/name:material.extensions.emoji.twemoji + emoji_generator: !!python/name:material.extensions.emoji.to_svg + - pymdownx.highlight: + anchor_linenums: true + line_spans: __span + pygments_lang_class: true + - pymdownx.inlinehilite + - pymdownx.magiclink + - pymdownx.superfences: + # custom_fences: + # - name: mermaid + # class: mermaid + # format: !!python/name:pymdownx.superfences.fence_code_format + - pymdownx.tabbed: + alternate_style: true + - pymdownx.tilde + - toc: + permalink: true + +extra: + social: + - icon: fontawesome/brands/github + link: https://github.com/fktn-k + generator: false + +extra_javascript: + - https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/hightlight.min.js + - javascripts/config.js + +extra_css: + - https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/default.min.css + +plugins: + - search: + lang: en + # - plantuml: + # puml_url: https://www.plantuml.com/plantuml/ + +nav: + - Home: + - Overview: index.md + - License: home/license.md + - Changelog: home/CHANGELOG.md + - "API Documentation": + - basic_node: + - basic_node: api/basic_node/index.md + - (constructor): api/basic_node/constructor.md + - (destructor): api/basic_node/destructor.md + - begin: api/basic_node/begin.md + - boolean_type: api/basic_node/boolean_type.md + - const_iterator: api/basic_node/const_iterator.md + - contains: api/basic_node/contains.md + - deserialize: api/basic_node/deserialize.md + - empty: api/basic_node/empty.md + - end: api/basic_node/end.md + - float_number_scalar: api/basic_node/float_number_scalar.md + - float_number_type: api/basic_node/float_number_type.md + - get_yaml_version: api/basic_node/get_yaml_version.md + - initializer_list_t: api/basic_node/initializer_list_t.md + - integer_scalar: api/basic_node/integer_scalar.md + - integer_type: api/basic_node/integer_type.md + - is_boolean: api/basic_node/is_boolean.md + - is_float_number: api/basic_node/is_float_number.md + - is_integer: api/basic_node/is_integer.md + - is_mapping: api/basic_node/is_mapping.md + - is_null: api/basic_node/is_null.md + - is_scalar: api/basic_node/is_scalar.md + - is_sequence: api/basic_node/is_sequence.md + - is_string: api/basic_node/is_string.md + - iterator: api/basic_node/iterator.md + - mapping_type: api/basic_node/mapping_type.md + - mapping: api/basic_node/mapping.md + - node_t: api/basic_node/node_t.md + - node: api/basic_node/node.md + - sequence_type: api/basic_node/sequence_type.md + - sequence: api/basic_node/sequence.md + - serialize: api/basic_node/serialize.md + - set_yaml_version: api/basic_node/set_yaml_version.md + - size: api/basic_node/size.md + - string_scalar: api/basic_node/string_scalar.md + - string_type: api/basic_node/string_type.md + - type: api/basic_node/type.md + - value_converter_type: api/basic_node/value_converter_type.md + - yaml_version_t: api/basic_node/yaml_version_t.md + - operator=: api/basic_node/operator=.md + - operator[]: api/basic_node/operator[].md + - exception: + - exception: api/exception/index.md + - (constructor): api/exception/constructor.md + - (destructor): api/exception/destructor.md + - what: api/exception/what.md + - macros: + - macros: api/macros/index.md + - node_value_converter: + - node_value_converter: api/node_value_converter/index.md + - from_node: api/node_value_converter/from_node.md + - to_node: api/node_value_converter/to_node.md + - ordered_map: + - ordered_map: api/ordered_map/index.md + - (constructor): api/ordered_map/constructor.md + - (destructor): api/ordered_map/destructor.md + - Tutorials: tutorials.md diff --git a/include/fkYAML/exception.hpp b/include/fkYAML/exception.hpp index 8237d292..a7961e29 100644 --- a/include/fkYAML/exception.hpp +++ b/include/fkYAML/exception.hpp @@ -18,29 +18,20 @@ #include -/** - * @namespace fkyaml - * @brief namespace for fkYAML library. - */ +/// @brief namespace for fkYAML library. FK_YAML_NAMESPACE_BEGIN -/** - * @class exception - * @brief A base exception class used in fkYAML library. - */ +/// @brief A base exception class used in fkYAML library. +/// @sa https://fktn-k.github.io/fkYAML/api/exception/ class exception : public std::exception { public: - /** - * @brief Construct a new exception object without any error messages. - */ + /// @brief Construct a new exception object without any error messages. + /// @sa https://fktn-k.github.io/fkYAML/api/exception/constructor/ exception() = default; - /** - * @brief Construct a new exception object with an error message. - * - * @param msg An error description message. - */ + /// @brief Construct a new exception object with an error message. + /// @sa https://fktn-k.github.io/fkYAML/api/exception/constructor/ explicit exception(const char* msg) { if (msg) @@ -50,18 +41,15 @@ class exception : public std::exception } public: - /** - * @brief Returns an error message internally held. If nothing, a non-null, empty string will be returned. - * - * @return const char* A pointer to error messages - */ + /// @brief Returns an error message internally held. If nothing, a non-null, empty string will be returned. + /// @sa https://fktn-k.github.io/fkYAML/api/exception/what/ const char* what() const noexcept override { return m_error_msg.c_str(); } private: - /** An error message holder. */ + /// An error message holder. std::string m_error_msg {}; }; diff --git a/include/fkYAML/node.hpp b/include/fkYAML/node.hpp index c0ff2021..ceaf68c4 100644 --- a/include/fkYAML/node.hpp +++ b/include/fkYAML/node.hpp @@ -39,24 +39,11 @@ #include #include -/** - * @namespace fkyaml - * @brief namespace for fkYAML library. - */ +/// @brief namespace for fkYAML library. FK_YAML_NAMESPACE_BEGIN -/** - * @class basic_node - * @brief A class to store value of YAML nodes. - * - * @tparam SequenceType A type for sequence node value containers. - * @tparam MappingType A type for mapping node value containers. - * @tparam BooleanType A type for boolean node values. - * @tparam IntegerType A type for integer node values. - * @tparam FloatNumberType A type for float number node values. - * @tparam StringType A type for string node values. - * @tparam Converter A type for node value converter. - */ +/// @brief A class to store value of YAML nodes. +/// @sa https://fktn-k.github.io/fkYAML/api/basic_node/ template < template class SequenceType = std::vector, template class MappingType = std::map, typename BooleanType = bool, @@ -72,17 +59,24 @@ class basic_node /** A type for sequence basic_node values. */ using sequence_type = SequenceType>; - /** - * @brief A type for mapping basic_node values. - * @note std::unordered_map is not supported since it does not allow incomplete types. - */ + + /// @brief A type for mapping basic_node values. + /// @note std::unordered_map is not supported since it does not allow incomplete types. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/mapping_type/ using mapping_type = MappingType; - /** A type for boolean basic_node values. */ + + /// @brief A type for boolean basic_node values. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/boolean_type/ using boolean_type = BooleanType; - /** A type for integer basic_node values. */ + + /// @brief A type for integer basic_node values. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/integer_type/ using integer_type = IntegerType; - /** A type for float number basic_node values. */ + + /// @brief A type for float number basic_node values. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/float_number_type/ using float_number_type = FloatNumberType; + /** A type for string basic_node values. */ using string_type = StringType; @@ -95,7 +89,12 @@ class basic_node template using value_converter_type = ConverterType; + /// @brief Definition of node value types. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/node_t/ using node_t = detail::node_t; + + /// @brief Definition of YAML version types. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/yaml_version_t/ using yaml_version_t = detail::yaml_version_t; private: @@ -289,28 +288,20 @@ class basic_node } public: - /** - * @brief Construct a new basic_node object of null type. - */ + /// @brief Construct a new basic_node object of null type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor basic_node() = default; - /** - * @brief Construct a new basic_node object with a specified type. - * @note If you construct an alias node, call basic_node::AliasOf() instead. - * - * @param[in] type A YAML node value type. - */ + /// @brief Construct a new basic_node object with a specified type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor explicit basic_node(const node_t type) : m_node_type(type), m_node_value(type) { } - /** - * @brief Copy constructor of the basic_node class. - * - * @param[in] rhs A basic_node object to be copied with. - */ + /// @brief Copy constructor of the basic_node class. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor basic_node(const basic_node& rhs) : m_node_type(rhs.m_node_type), m_yaml_version_type(rhs.m_yaml_version_type) @@ -353,11 +344,8 @@ class basic_node } } - /** - * @brief Move constructor of the basic_node class. - * - * @param[in] rhs A basic_node object to be moved from. - */ + /// @brief Move constructor of the basic_node class. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor basic_node(basic_node&& rhs) noexcept : m_node_type(rhs.m_node_type), m_yaml_version_type(rhs.m_yaml_version_type), @@ -404,13 +392,8 @@ class basic_node rhs.m_anchor_name = nullptr; } - /** - * @brief Construct a new basic_node object from a value of compatible types. - * - * @tparam CompatibleType A type of native data which is compatible with node values. - * @tparam U A type of compatible native data type without qualifiers. - * @param val The value of compatible native data type. - */ + /// @brief Construct a new basic_node object from a value of compatible types. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor template < typename CompatibleType, typename U = detail::remove_cvref_t, detail::enable_if_t< @@ -424,12 +407,8 @@ class basic_node ConverterType::to_node(*this, std::forward(val)); } - /** - * @brief Construct a new basic node object with a node_ref_storage object. - * - * @tparam NodeRefStorageType A node_ref_storage template instance type. - * @param node_ref_storage A node_ref_storage object. - */ + /// @brief Construct a new basic node object with a node_ref_storage object. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor template < typename NodeRefStorageType, detail::enable_if_t::value, int> = 0> @@ -438,11 +417,8 @@ class basic_node { } - /** - * @brief Construct a new basic node object with std::initializer_list. - * - * @param init An initializer list object. - */ + /// @brief Construct a new basic node object with std::initializer_list. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor basic_node(initializer_list_t init) { bool is_mapping = @@ -470,9 +446,8 @@ class basic_node } } - /** - * @brief Destroy the basic_node object and its value storage. - */ + /// @brief Destroy the basic_node object and its value storage. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/destructor ~basic_node() noexcept // NOLINT(bugprone-exception-escape) { destroy_object(m_anchor_name); @@ -1327,12 +1302,9 @@ class basic_node swap(m_anchor_name, rhs.m_anchor_name); } - /** - * @brief Returns the first iterator of basic_node values of container types (sequence or mapping) from a non-const - * basic_node object. Throws exception if the basic_node value is not of container types. - * - * @return iterator The first iterator of basic_node values of container types. - */ + /// @brief Returns the first iterator of basic_node values of container types (sequence or mapping) from a non-const + /// basic_node object. Throws exception if the basic_node value is not of container types. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/begin/ iterator begin() { switch (m_node_type) @@ -1348,12 +1320,9 @@ class basic_node } } - /** - * @brief Returns the first iterator of basic_node values of container types (sequence or mapping) from a const - * basic_node object. Throws exception if the basic_node value is not of container types. - * - * @return const_iterator The first iterator of basic_node values of container types. - */ + /// @brief Returns the first iterator of basic_node values of container types (sequence or mapping) from a const + /// basic_node object. Throws exception if the basic_node value is not of container types. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/begin/ const_iterator begin() const { switch (m_node_type) @@ -1369,12 +1338,9 @@ class basic_node } } - /** - * @brief Returns the last iterator of basic_node values of container types (sequence or mapping) from a non-const - * basic_node object. Throws exception if the basic_node value is not of container types. - * - * @return iterator The last iterator of basic_node values of container types. - */ + /// @brief Returns the last iterator of basic_node values of container types (sequence or mapping) from a non-const + /// basic_node object. Throws exception if the basic_node value is not of container types. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/end/ iterator end() { switch (m_node_type) @@ -1390,12 +1356,9 @@ class basic_node } } - /** - * @brief Returns the last iterator of basic_node values of container types (sequence or mapping) from a const - * basic_node object. Throws exception if the basic_node value is not of container types. - * - * @return const_iterator The last iterator of basic_node values of container types. - */ + /// @brief Returns the last iterator of basic_node values of container types (sequence or mapping) from a const + /// basic_node object. Throws exception if the basic_node value is not of container types. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/end/ const_iterator end() const { switch (m_node_type) From b464309f1b3c82e71e4e03aa63c4ba0e5917cfaa Mon Sep 17 00:00:00 2001 From: fktn Date: Thu, 26 Oct 2023 22:03:41 +0900 Subject: [PATCH 19/48] prepare Python virtual environment to use MkDocs --- .gitignore | 3 ++- docs/mkdocs/Makefile | 16 ++++++++++++++++ docs/mkdocs/requirements.txt | 28 ++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 docs/mkdocs/Makefile create mode 100644 docs/mkdocs/requirements.txt diff --git a/.gitignore b/.gitignore index 4c726ce9..927cff2b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ build* .vs/ # documentation -/docs/mkdocs/site/ \ No newline at end of file +/docs/mkdocs/site/ +/docs/mkdocs/venv/ \ No newline at end of file diff --git a/docs/mkdocs/Makefile b/docs/mkdocs/Makefile new file mode 100644 index 00000000..b81bc222 --- /dev/null +++ b/docs/mkdocs/Makefile @@ -0,0 +1,16 @@ +# build the site +build: install-venv + venv/bin/mkdocs build + +# serve the site locally +serve: build + venv/bin/mkdocs serve + +# install a Python virtual environment +install-venv: requirements.txt + python3 -m venv venv + venv/bin/pip install --upgrade pip + venv/bin/pip install -r requirements.txt + +uninstall-venv: + rm -rf venv \ No newline at end of file diff --git a/docs/mkdocs/requirements.txt b/docs/mkdocs/requirements.txt new file mode 100644 index 00000000..e249234d --- /dev/null +++ b/docs/mkdocs/requirements.txt @@ -0,0 +1,28 @@ +Babel==2.13.1 +certifi==2023.7.22 +charset-normalizer==3.3.1 +click==8.1.7 +colorama==0.4.6 +ghp-import==2.1.0 +idna==3.4 +Jinja2==3.1.2 +Markdown==3.5 +MarkupSafe==2.1.3 +mergedeep==1.3.4 +mkdocs==1.5.3 +mkdocs-material==9.4.6 +mkdocs-material-extensions==1.3 +packaging==23.2 +paginate==0.5.6 +pathspec==0.11.2 +platformdirs==3.11.0 +Pygments==2.16.1 +pymdown-extensions==10.3.1 +python-dateutil==2.8.2 +PyYAML==6.0.1 +pyyaml_env_tag==0.1 +regex==2023.10.3 +requests==2.31.0 +six==1.16.0 +urllib3==2.0.7 +watchdog==3.0.0 From 58f8aa1ec45cbc69a2a2456a990f6699d5c4e581 Mon Sep 17 00:00:00 2001 From: fktn Date: Fri, 27 Oct 2023 00:56:43 +0900 Subject: [PATCH 20/48] rewrote more basic_node API docs with MkDocs --- .../docs/api/basic_node/const_iterator.md | 39 ++++++ docs/mkdocs/docs/api/basic_node/empty.md | 67 ++++++++++ .../docs/api/basic_node/float_number_type.md | 6 +- docs/mkdocs/docs/api/basic_node/get_value.md | 0 docs/mkdocs/docs/api/basic_node/index.md | 2 +- .../docs/api/basic_node/integer_type.md | 6 +- docs/mkdocs/docs/api/basic_node/is_boolean.md | 37 ++++++ .../docs/api/basic_node/is_float_number.md | 37 ++++++ docs/mkdocs/docs/api/basic_node/is_integer.md | 37 ++++++ docs/mkdocs/docs/api/basic_node/is_mapping.md | 37 ++++++ docs/mkdocs/docs/api/basic_node/is_null.md | 37 ++++++ docs/mkdocs/docs/api/basic_node/is_scalar.md | 59 +++++++++ .../mkdocs/docs/api/basic_node/is_sequence.md | 37 ++++++ docs/mkdocs/docs/api/basic_node/is_string.md | 37 ++++++ docs/mkdocs/docs/api/basic_node/iterator.md | 39 ++++++ .../docs/api/basic_node/sequence_type.md | 40 ++++++ docs/mkdocs/docs/api/basic_node/size.md | 67 ++++++++++ .../mkdocs/docs/api/basic_node/string_type.md | 40 ++++++ docs/mkdocs/docs/api/basic_node/type.md | 70 +++++++++++ .../api/basic_node/value_converter_type.md | 53 ++++++++ docs/mkdocs/mkdocs.yml | 1 + include/fkYAML/node.hpp | 117 +++++------------- 22 files changed, 775 insertions(+), 90 deletions(-) create mode 100644 docs/mkdocs/docs/api/basic_node/get_value.md diff --git a/docs/mkdocs/docs/api/basic_node/const_iterator.md b/docs/mkdocs/docs/api/basic_node/const_iterator.md index e69de29b..b028201e 100644 --- a/docs/mkdocs/docs/api/basic_node/const_iterator.md +++ b/docs/mkdocs/docs/api/basic_node/const_iterator.md @@ -0,0 +1,39 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::const_iterator + +```cpp +using const_iterator = detail::iterator; +``` + +The type for constant iterators of [`basic_node`](index.md) containers. +This iterator type is commonly used for sequence and mapping container values. + +??? Example + + ```cpp + #include + #include + #include + + int main() + { + // create YAML nodes. + const fkyaml::node sequence_node = {1, 2, 3}; + // get an iterator to the first sequence element. + fkyaml::node::const_iterator it = sequence_node.begin(); + std::cout << fkyaml::node::serialize(*it) << std::endl; + return 0; + }; + ``` + + output: + ```bash + 1 + ``` + +### **See Also** + +* [basic_node](index.md) +* [begin](begin.md) +* [iterator](iterator.md) diff --git a/docs/mkdocs/docs/api/basic_node/empty.md b/docs/mkdocs/docs/api/basic_node/empty.md index e69de29b..488abfbd 100644 --- a/docs/mkdocs/docs/api/basic_node/empty.md +++ b/docs/mkdocs/docs/api/basic_node/empty.md @@ -0,0 +1,67 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::empty + +```cpp +boolean empty() const; +``` + +Tests whether the node value is empty. +Throws a [`fkyaml::exception`](../exception/index.md) if a basic_node does not have a conatiner nor string value. + +### **Return Value** + +Returns `true` if the node value is empty, `false` otherwise. + +??? Example + + ```cpp + #include + #include + #include + + int main() + { + // create YAML nodes. + std::vector nodes = + { + {1, 2, 3}, + {{std::string("foo"), true}, {std::string("bar"), false}}, + fkyaml::node(), + true, + 256, + 3.14, + std::string("Hello, world!") + }; + + for (const auto& n : nodes) + { + try + { + // call empty() + std::cout << std::boolalpha << n.empty() << std::endl; + } + catch (const fkyaml::exception& e) + { + std::cout << "The node does not have a container nor string value." << std::endl; + } + } + + return 0; + } + ``` + + output: + ```yaml + true + true + The node does not have a container nor string value. + The node does not have a container nor string value. + The node does not have a container nor string value. + The node does not have a container nor string value. + true + ``` + +### **See Also** + +* [basic_node](index.md) diff --git a/docs/mkdocs/docs/api/basic_node/float_number_type.md b/docs/mkdocs/docs/api/basic_node/float_number_type.md index ae6fc917..aa1c4b7c 100644 --- a/docs/mkdocs/docs/api/basic_node/float_number_type.md +++ b/docs/mkdocs/docs/api/basic_node/float_number_type.md @@ -26,7 +26,9 @@ With the decided type, floating point number objects are stored directly inside int main() { - std::cout << std::boolalpha << std::is_same::value << std::endl; + std::cout << std::boolalpha + << std::is_same::value + << std::endl; return 0; } ``` @@ -38,4 +40,4 @@ With the decided type, floating point number objects are stored directly inside ### **See Also** -* [basic_node](index.md) \ No newline at end of file +* [basic_node](index.md) diff --git a/docs/mkdocs/docs/api/basic_node/get_value.md b/docs/mkdocs/docs/api/basic_node/get_value.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/index.md b/docs/mkdocs/docs/api/basic_node/index.md index 453fe579..7e7a824e 100644 --- a/docs/mkdocs/docs/api/basic_node/index.md +++ b/docs/mkdocs/docs/api/basic_node/index.md @@ -81,7 +81,7 @@ This class provides features to handle YAML nodes. | ----------------------------- | ------------------------------------------------------- | | [deserialize](deserialize.md) | deserializes a YAML formatted string into a basic_node. | | [serialize](serialize.md) | serializes a basic_node into a YAML formatted string. | -| | | +| [get_value](get_value.md) | converts a basic_node into a target native data type. | ### Iterators | Name | Description | diff --git a/docs/mkdocs/docs/api/basic_node/integer_type.md b/docs/mkdocs/docs/api/basic_node/integer_type.md index 4a397052..890486d2 100644 --- a/docs/mkdocs/docs/api/basic_node/integer_type.md +++ b/docs/mkdocs/docs/api/basic_node/integer_type.md @@ -23,7 +23,9 @@ With the decided type, integer objects are stored directly inside a [`basic_node int main() { - std::cout << std::boolalpha << std::is_same::value << std::endl; + std::cout << std::boolalpha + << std::is_same::value + << std::endl; return 0; } ``` @@ -35,4 +37,4 @@ With the decided type, integer objects are stored directly inside a [`basic_node ### **See Also** -* [basic_node](index.md) \ No newline at end of file +* [basic_node](index.md) diff --git a/docs/mkdocs/docs/api/basic_node/is_boolean.md b/docs/mkdocs/docs/api/basic_node/is_boolean.md index e69de29b..1dca1007 100644 --- a/docs/mkdocs/docs/api/basic_node/is_boolean.md +++ b/docs/mkdocs/docs/api/basic_node/is_boolean.md @@ -0,0 +1,37 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::is_boolean + +```cpp +bool is_boolean() const noexcept; +``` + +Tests whether the node value type is [`node_t::BOOLEAN`](node_t.md). + +### **Return Value** + +`true` if the type is [`node_t::BOOLEAN`](node_t.md), `false` otherwise. + +??? Example + + ```cpp + #include + #include + #include + + int main() + { + fkyaml::node n = true; + std::cout << std::boolalpha << n.is_boolean() << std::endl; + return 0; + } + ``` + + output: + ```bash + true + ``` + +### **See Also** + +* [node_t](node_t.md) diff --git a/docs/mkdocs/docs/api/basic_node/is_float_number.md b/docs/mkdocs/docs/api/basic_node/is_float_number.md index e69de29b..e67f95b2 100644 --- a/docs/mkdocs/docs/api/basic_node/is_float_number.md +++ b/docs/mkdocs/docs/api/basic_node/is_float_number.md @@ -0,0 +1,37 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::is_float_number + +```cpp +bool is_float_number() const noexcept; +``` + +Tests whether the node value type is [`node_t::FLOAT_NUMBER`](node_t.md). + +### **Return Value** + +`true` if the type is [`node_t::FLOAT_NUMBER`](node_t.md), `false` otherwise. + +??? Example + + ```cpp + #include + #include + #include + + int main() + { + fkyaml::node n = 3.14; + std::cout << std::boolalpha << n.is_float_number() << std::endl; + return 0; + } + ``` + + output: + ```bash + true + ``` + +### **See Also** + +* [node_t](node_t.md) diff --git a/docs/mkdocs/docs/api/basic_node/is_integer.md b/docs/mkdocs/docs/api/basic_node/is_integer.md index e69de29b..7e95764b 100644 --- a/docs/mkdocs/docs/api/basic_node/is_integer.md +++ b/docs/mkdocs/docs/api/basic_node/is_integer.md @@ -0,0 +1,37 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::is_integer + +```cpp +bool is_integer() const noexcept; +``` + +Tests whether the node value type is [`node_t::INTEGER`](node_t.md). + +### **Return Value** + +`true` if the type is [`node_t::INTEGER`](node_t.md), `false` otherwise. + +??? Example + + ```cpp + #include + #include + #include + + int main() + { + fkyaml::node n = 123; + std::cout << std::boolalpha << n.is_integer() << std::endl; + return 0; + } + ``` + + output: + ```bash + true + ``` + +### **See Also** + +* [node_t](node_t.md) diff --git a/docs/mkdocs/docs/api/basic_node/is_mapping.md b/docs/mkdocs/docs/api/basic_node/is_mapping.md index e69de29b..181424f4 100644 --- a/docs/mkdocs/docs/api/basic_node/is_mapping.md +++ b/docs/mkdocs/docs/api/basic_node/is_mapping.md @@ -0,0 +1,37 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::is_mapping + +```cpp +bool is_mapping() const noexcept; +``` + +Tests whether the node value type is [`node_t::MAPPING`](node_t.md). + +### **Return Value** + +`true` if the type is [`node_t::MAPPING`](node_t.md), `false` otherwise. + +??? Example + + ```cpp + #include + #include + #include + + int main() + { + fkyaml::node n = {{std::string("foo"), true}}; + std::cout << std::boolalpha << n.is_mapping() << std::endl; + return 0; + } + ``` + + output: + ```bash + true + ``` + +### **See Also** + +* [node_t](node_t.md) diff --git a/docs/mkdocs/docs/api/basic_node/is_null.md b/docs/mkdocs/docs/api/basic_node/is_null.md index e69de29b..c561cca4 100644 --- a/docs/mkdocs/docs/api/basic_node/is_null.md +++ b/docs/mkdocs/docs/api/basic_node/is_null.md @@ -0,0 +1,37 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::is_null + +```cpp +bool is_null() const noexcept; +``` + +Tests whether the node value type is [`node_t::NULL_OBJECT`](node_t.md). + +### **Return Value** + +`true` if the type is [`node_t::NULL_OBJECT`](node_t.md), `false` otherwise. + +??? Example + + ```cpp + #include + #include + #include + + int main() + { + fkyaml::node n; + std::cout << std::boolalpha << n.is_null() << std::endl; + return 0; + } + ``` + + output: + ```bash + true + ``` + +### **See Also** + +* [node_t](node_t.md) diff --git a/docs/mkdocs/docs/api/basic_node/is_scalar.md b/docs/mkdocs/docs/api/basic_node/is_scalar.md index e69de29b..b7e2d12c 100644 --- a/docs/mkdocs/docs/api/basic_node/is_scalar.md +++ b/docs/mkdocs/docs/api/basic_node/is_scalar.md @@ -0,0 +1,59 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::is_scalar + +```cpp +bool is_scalar() const noexcept; +``` + +Tests whether the node value type is one of the followings: +* [`node_t::NULL_OBJECT`](node_t.md) +* [`node_t::BOOLEAN`](node_t.md) +* [`node_t::INTEGER`](node_t.md) +* [`node_t::FLOAT_NUMBER`](node_t.md) +* [`node_t::STRING`](node_t.md) + +### **Return Value** + +`true` if the type is a scalar type, `false` otherwise. + +??? Example + + ```cpp + #include + #include + #include + + int main() + { + // create YAML nodes. + fkyaml::node null_node; + fkyaml::node boolean_node = true; + fkyaml::node integer_node = 256; + fkyaml::node float_node = 3.14; + fkyaml::node string_node = std::string("Hello, world!"); + + // call type() + std::cout << std::boolalpha; + std::cout << (null_node.type() == fkyaml::node::node_t::NULL_OBJECT) << std::endl; + std::cout << (boolean_node.type() == fkyaml::node::node_t::BOOLEAN) << std::endl; + std::cout << (integer_node.type() == fkyaml::node::node_t::INTEGER) << std::endl; + std::cout << (float_node.type() == fkyaml::node::node_t::FLOAT_NUMBER) << std::endl; + std::cout << (string_node.type() == fkyaml::node::node_t::STRING) << std::endl; + + return 0; + }; + ``` + + output: + ```bash + true + true + true + true + true + ``` + +### **See Also** + +* [node_t](node_t.md) diff --git a/docs/mkdocs/docs/api/basic_node/is_sequence.md b/docs/mkdocs/docs/api/basic_node/is_sequence.md index e69de29b..034eeab4 100644 --- a/docs/mkdocs/docs/api/basic_node/is_sequence.md +++ b/docs/mkdocs/docs/api/basic_node/is_sequence.md @@ -0,0 +1,37 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::is_sequence + +```cpp +bool is_sequence() const noexcept; +``` + +Tests whether the node value type is [`node_t::SEQUENCE`](node_t.md). + +### **Return Value** + +`true` if the type is [`node_t::SEQUENCE`](node_t.md), `false` otherwise. + +??? Example + + ```cpp + #include + #include + #include + + int main() + { + fkyaml::node n = {1, 2, 3}; + std::cout << std::boolalpha << n.is_sequence() << std::endl; + return 0; + } + ``` + + output: + ```bash + true + ``` + +### **See Also** + +* [node_t](node_t.md) diff --git a/docs/mkdocs/docs/api/basic_node/is_string.md b/docs/mkdocs/docs/api/basic_node/is_string.md index e69de29b..55f2a678 100644 --- a/docs/mkdocs/docs/api/basic_node/is_string.md +++ b/docs/mkdocs/docs/api/basic_node/is_string.md @@ -0,0 +1,37 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::is_string + +```cpp +bool is_string() const noexcept; +``` + +Tests whether the node value type is [`node_t::STRING`](node_t.md). + +### **Return Value** + +`true` if the type is [`node_t::STRING`](node_t.md), `false` otherwise. + +??? Example + + ```cpp + #include + #include + #include + + int main() + { + fkyaml::node n = std::string("foo"); + std::cout << std::boolalpha << n.is_string() << std::endl; + return 0; + } + ``` + + output: + ```bash + true + ``` + +### **See Also** + +* [node_t](node_t.md) diff --git a/docs/mkdocs/docs/api/basic_node/iterator.md b/docs/mkdocs/docs/api/basic_node/iterator.md index e69de29b..c08910cf 100644 --- a/docs/mkdocs/docs/api/basic_node/iterator.md +++ b/docs/mkdocs/docs/api/basic_node/iterator.md @@ -0,0 +1,39 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::iterator + +```cpp +using iterator = detail::iterator; +``` + +The type for iterators of [`basic_node`](index.md) containers. +This iterator type is commonly used for sequence and mapping container values. + +??? Example + + ```cpp + #include + #include + #include + + int main() + { + // create YAML nodes. + fkyaml::node sequence_node = {1, 2, 3}; + // get an iterator to the first sequence element. + fkyaml::node::iterator it = sequence_node.begin(); + std::cout << fkyaml::node::serialize(*it) << std::endl; + return 0; + }; + ``` + + output: + ```bash + 1 + ``` + +### **See Also** + +* [basic_node](index.md) +* [begin](begin.md) +* [const_iterator](const_iterator.md) diff --git a/docs/mkdocs/docs/api/basic_node/sequence_type.md b/docs/mkdocs/docs/api/basic_node/sequence_type.md index e69de29b..dc9a6171 100644 --- a/docs/mkdocs/docs/api/basic_node/sequence_type.md +++ b/docs/mkdocs/docs/api/basic_node/sequence_type.md @@ -0,0 +1,40 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::sequence_type + +```cpp +using sequence_type = SequenceType; +``` + +The type used to store sequence node values. + +To store sequence objects in [`basic_node`](index.md) class, the type is defined by the template parameter `SequenceType` which chooses the type to use for sequence objects. +If not explicitly specified, the default type `std::vector` will be chosen. +Note that sequence objects are stored as pointers to the decided type in a [`basic_node`](index.md) so that the internal storage size will at most be 8 bytes. + +??? Example + + ```cpp + #include + #include + #include + #include + #include + + int main() + { + std::cout << std::boolalpha + << std::is_same, fkyaml::node::sequence_type>::value + << std::endl; + return 0; + } + ``` + + output: + ```bash + true + ``` + +### **See Also** + +* [basic_node](index.md) diff --git a/docs/mkdocs/docs/api/basic_node/size.md b/docs/mkdocs/docs/api/basic_node/size.md index e69de29b..1ba48a2a 100644 --- a/docs/mkdocs/docs/api/basic_node/size.md +++ b/docs/mkdocs/docs/api/basic_node/size.md @@ -0,0 +1,67 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::size + +```cpp +std::size_t size() const; +``` + +Gets the size of a node value. +Throws a [`fkyaml::exception`](../exception/index.md) if a basic_node does not have a conatiner nor string value. + +### **Return Value** + +Returns the size of a node value. + +??? Example + + ```cpp + #include + #include + #include + + int main() + { + // create YAML nodes. + std::vector nodes = + { + {1, 2, 3}, + {{std::string("foo"), true}, {std::string("bar"), false}. {std::string("baz"), true}}, + fkyaml::node(), + true, + 256, + 3.14, + std::string("foo") + }; + + for (const auto& n : nodes) + { + try + { + // call size() + std::cout << n.size() << std::endl; + } + catch (const fkyaml::exception& e) + { + std::cout << "The node does not have a container nor string value." << std::endl; + } + } + + return 0; + } + ``` + + output: + ```yaml + 3 + 3 + The node does not have a container nor string value. + The node does not have a container nor string value. + The node does not have a container nor string value. + The node does not have a container nor string value. + 3 + ``` + +### **See Also** + +* [basic_node](index.md) diff --git a/docs/mkdocs/docs/api/basic_node/string_type.md b/docs/mkdocs/docs/api/basic_node/string_type.md index e69de29b..19f68df3 100644 --- a/docs/mkdocs/docs/api/basic_node/string_type.md +++ b/docs/mkdocs/docs/api/basic_node/string_type.md @@ -0,0 +1,40 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::string_type + +```cpp +using string_type = StringType; +``` + +The type used to store integer node values and keys for mapping nodes. + +To store string objects in [`basic_node`](index.md) class, the type is defined by the template parameter `StringType` which chooses the type to use for string objects. +If not explicitly specified, the default type `std::string` will be chosen. +Note that string objects are stored as pointers to the decided type in a [`basic_node`](index.md) so that the internal storage size will at most be 8 bytes. + +??? Example + + ```cpp + #include + #include + #include + #include + #include + + int main() + { + std::cout << std::boolalpha + << std::is_same::value + << std::endl; + return 0; + } + ``` + + output: + ```bash + true + ``` + +### **See Also** + +* [basic_node](index.md) diff --git a/docs/mkdocs/docs/api/basic_node/type.md b/docs/mkdocs/docs/api/basic_node/type.md index e69de29b..60684f4d 100644 --- a/docs/mkdocs/docs/api/basic_node/type.md +++ b/docs/mkdocs/docs/api/basic_node/type.md @@ -0,0 +1,70 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::type + +```cpp +node_t type() const noexcept; +``` + +Returns the type of the YAML node value as a value from the [`node_t`](node_t.md) enumeration. + +### **Return Value** + +The type of the YAML node value. + +| Value Type | Return Value | +| --------------------- | -------------------- | +| sequence | node_t::SEQUENCE | +| mapping | node_t::MAPPING | +| null | node_t::NULL_OBJECT | +| boolean | node_t::BOOLEAN | +| integer | node_t::INTEGER | +| floating point number | node_t::FLOAT_NUMBER | +| string | node_t::STRING | + +??? Example + + ```cpp + #include + #include + #include + + int main() + { + // create YAML nodes. + fkyaml::node sequence_node = {1, 2, 3}; + fkyaml::node mapping_node = {{std::string("foo"), true}, {std::string("bar"), false}}; + fkyaml::node null_node; + fkyaml::node boolean_node = true; + fkyaml::node integer_node = 256; + fkyaml::node float_node = 3.14; + fkyaml::node string_node = std::string("Hello, world!"); + + // call type() + std::cout << std::boolalpha; + std::cout << (sequence_node.type() == fkyaml::node::node_t::SEQUENCE) << std::endl; + std::cout << (mapping_node.type() == fkyaml::node::node_t::MAPPING) << std::endl; + std::cout << (null_node.type() == fkyaml::node::node_t::NULL_OBJECT) << std::endl; + std::cout << (boolean_node.type() == fkyaml::node::node_t::BOOLEAN) << std::endl; + std::cout << (integer_node.type() == fkyaml::node::node_t::INTEGER) << std::endl; + std::cout << (float_node.type() == fkyaml::node::node_t::FLOAT_NUMBER) << std::endl; + std::cout << (string_node.type() == fkyaml::node::node_t::STRING) << std::endl; + + return 0; + }; + ``` + + output: + ```bash + true + true + true + true + true + true + true + ``` + +### **See Also** + +* [node_t](node_t.md) \ No newline at end of file diff --git a/docs/mkdocs/docs/api/basic_node/value_converter_type.md b/docs/mkdocs/docs/api/basic_node/value_converter_type.md index e69de29b..480fa548 100644 --- a/docs/mkdocs/docs/api/basic_node/value_converter_type.md +++ b/docs/mkdocs/docs/api/basic_node/value_converter_type.md @@ -0,0 +1,53 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::value_converter_type + +```cpp +template +using value_converter_type = ValueConverterType; +``` + +A helper type alias to determine converter type for the given target native data type `T`. +The default type of the template parameter `ValueConverterType` is [`node_value_converter`](../node_value_converter/index.md). +This type alias is used to determine the target type `T` is convertible from/to [`basic_node`](index.md). +The function [`get_value`](get_value.md) relies on it internally. +If you want to convert some type from/to `basic_node`, however, it is recommended to use [`basic_node::get_value`](get_value.md) instead, in order both to make your program more understandable and to avoid too much dependency on the fkYAML library implementation. + +### **Template Parameters** + +***T*** +: The target native data type. + +***SFINAE*** +: Type to add compile type checks via SFINAE. Usually `void` is given. + +??? Example + + ```cpp + #include + #include + #include + + int main() + { + std::cout << std::boolalpha + << std::is_same< + fkyaml::node_value_converter, + fkyaml::node::value_converter_type>::value + << std::endl; + + fkyaml::node n = 3.14; + double d = 0.0; + // This leads to the same result as `d = n.get_value()`. + fkyaml::value_converter_type::from_node(n, d); + std::cout << std::setprecision(3) << d << std::endl; + + return 0; + } + ``` + + output: + ```bash + true + 3.14 + ``` diff --git a/docs/mkdocs/mkdocs.yml b/docs/mkdocs/mkdocs.yml index 7bbeea41..23db523b 100644 --- a/docs/mkdocs/mkdocs.yml +++ b/docs/mkdocs/mkdocs.yml @@ -104,6 +104,7 @@ nav: - end: api/basic_node/end.md - float_number_scalar: api/basic_node/float_number_scalar.md - float_number_type: api/basic_node/float_number_type.md + - get_value: api/basic_node/get_value.md - get_yaml_version: api/basic_node/get_yaml_version.md - initializer_list_t: api/basic_node/initializer_list_t.md - integer_scalar: api/basic_node/integer_scalar.md diff --git a/include/fkYAML/node.hpp b/include/fkYAML/node.hpp index ceaf68c4..ab0c8c1c 100644 --- a/include/fkYAML/node.hpp +++ b/include/fkYAML/node.hpp @@ -52,12 +52,16 @@ template < class basic_node { public: - /** A type for constant iterators of basic_node containers. */ - using const_iterator = fkyaml::detail::iterator; - /** A type for iterators of basic_node containers. */ + /// @brief A type for iterators of basic_node containers. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/iterator/ using iterator = fkyaml::detail::iterator; - /** A type for sequence basic_node values. */ + /// @brief A type for constant iterators of basic_node containers. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/const_iterator/ + using const_iterator = fkyaml::detail::iterator; + + /// @brief A type for sequence basic_node values. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/sequence_type/ using sequence_type = SequenceType>; /// @brief A type for mapping basic_node values. @@ -77,7 +81,8 @@ class basic_node /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/float_number_type/ using float_number_type = FloatNumberType; - /** A type for string basic_node values. */ + /// @brief A type for string basic_node values. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/string_type/ using string_type = StringType; /** @@ -802,126 +807,71 @@ class basic_node } public: - /** - * @brief Returns the type of the current basic_node value. - * - * @return node_t The type of the current basic_node value. - * @retval node_t::SEQUENCE sequence type. - * @retval node_t::MAPPINT mapping type. - * @retval node_t::NULL_OBJECT null type. - * @retval node_t::BOOLEAN boolean type. - * @retval node_t::INTEGER integer type. - * @retval node_t::FLOAT_NUMBER float number type. - * @retval node_t::STRING string type. - */ + /// @brief Returns the type of the current basic_node value. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/type/ node_t type() const noexcept { return m_node_type; } - /** - * @brief Tests whether the current basic_node value is of sequence type. - * - * @return bool A result of testing whetehre the current basic_node value is of sequence type. - * @retval true The current basic_node value is of sequence type. - * @return false The current basic_node value is not of sequence type. - */ + /// @brief Tests whether the current basic_node value is of sequence type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/is_sequence/ bool is_sequence() const noexcept { return m_node_type == node_t::SEQUENCE; } - /** - * @brief Tests whether the current basic_node value is of mapping type. - * - * @return bool A result of testing whetehre the current basic_node value is of mapping type. - * @retval true The current basic_node value is of mapping type. - * @return false The current basic_node value is not of mapping type. - */ + /// @brief Tests whether the current basic_node value is of mapping type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/is_mapping/ bool is_mapping() const noexcept { return m_node_type == node_t::MAPPING; } - /** - * @brief Tests whether the current basic_node value is of null type. - * - * @return bool A result of testing whetehre the current basic_node value is of null type. - * @retval true The current basic_node value is of null type. - * @return false The current basic_node value is not of null type. - */ + /// @brief Tests whether the current basic_node value is of null type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/is_null/ bool is_null() const noexcept { return m_node_type == node_t::NULL_OBJECT; } - /** - * @brief Tests whether the current basic_node value is of boolean type. - * - * @return bool A result of testing whetehre the current basic_node value is of boolean type. - * @retval true The current basic_node value is of boolean type. - * @return false The current basic_node value is not of boolean type. - */ + /// @brief Tests whether the current basic_node value is of boolean type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/is_boolean/ bool is_boolean() const noexcept { return m_node_type == node_t::BOOLEAN; } - /** - * @brief Tests whether the current basic_node value is of integer type. - * - * @return bool A result of testing whetehre the current basic_node value is of integer type. - * @retval true The current basic_node value is of integer type. - * @return false The current basic_node value is not of integer type. - */ + /// @brief Tests whether the current basic_node value is of integer type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/is_integer/ bool is_integer() const noexcept { return m_node_type == node_t::INTEGER; } - /** - * @brief Tests whether the current basic_node value is of float number type. - * - * @return bool A result of testing whetehre the current basic_node value is of float number type. - * @retval true The current basic_node value is of float number type. - * @return false The current basic_node value is not of float number type. - */ + /// @brief Tests whether the current basic_node value is of float number type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/is_float_number/ bool is_float_number() const noexcept { return m_node_type == node_t::FLOAT_NUMBER; } - /** - * @brief Tests whether the current basic_node value is of string type. - * - * @return bool A result of testing whetehre the current basic_node value is of string type. - * @retval true The current basic_node value is of string type. - * @return false The current basic_node value is not of string type. - */ + /// @brief Tests whether the current basic_node value is of string type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/is_string/ bool is_string() const noexcept { return m_node_type == node_t::STRING; } - /** - * @brief Tests whether the current basic_node value is of scalar types. - * - * @return bool A result of testing whetehre the current basic_node value is of scalar types. - * @retval true The current basic_node value is of scalar types. - * @return false The current basic_node value is not of scalar types. - */ + /// @brief Tests whether the current basic_node value is of scalar types. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/is_scalar/ bool is_scalar() const noexcept { return !is_sequence() && !is_mapping(); } - /** - * @brief Tests whether the current basic_node value (sequence, mapping, string) is empty. - * - * @return bool A result of testing whetehre the current basic_node value is empty. - * @retval true The current basic_node value is empty. - * @return false The current basic_node value is not empty. - */ + /// @brief Tests whether the current basic_node value (sequence, mapping, string) is empty. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/empty/ bool empty() const { switch (m_node_type) @@ -940,11 +890,8 @@ class basic_node } } - /** - * @brief Returns the size of the current basic_node value (sequence, mapping, string). - * - * @return std::size_t The size of the current basic_node value. - */ + /// @brief Returns the size of the current basic_node value (sequence, mapping, string). + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/size/ std::size_t size() const { switch (m_node_type) From 39b04f69285bef305068fb69aaddaf985b279f55 Mon Sep 17 00:00:00 2001 From: fktn Date: Sat, 28 Oct 2023 14:10:40 +0900 Subject: [PATCH 21/48] migrated more docs with MkDocs --- .../mkdocs/docs/api/basic_node/constructor.md | 8 +- docs/mkdocs/docs/api/basic_node/index.md | 22 +++--- docs/mkdocs/docs/api/basic_node/mapping.md | 43 +++++++++++ docs/mkdocs/docs/api/basic_node/sequence.md | 40 ++++++++++ .../{float_number_scalar.md => to_boolean.md} | 0 ...itializer_list_t.md => to_float_number.md} | 0 .../{integer_scalar.md => to_integer.md} | 0 .../{string_scalar.md => to_mapping.md} | 0 .../basic_node/to_sequence.md} | 0 docs/mkdocs/docs/api/basic_node/to_string.md | 0 docs/mkdocs/mkdocs.yml | 18 ++--- docs/mkdocs/requirements.txt | 5 ++ include/fkYAML/node.hpp | 76 ++++++------------- 13 files changed, 140 insertions(+), 72 deletions(-) rename docs/mkdocs/docs/api/basic_node/{float_number_scalar.md => to_boolean.md} (100%) rename docs/mkdocs/docs/api/basic_node/{initializer_list_t.md => to_float_number.md} (100%) rename docs/mkdocs/docs/api/basic_node/{integer_scalar.md => to_integer.md} (100%) rename docs/mkdocs/docs/api/basic_node/{string_scalar.md => to_mapping.md} (100%) rename docs/mkdocs/docs/{img/range-begin-end.svg:Zone.Identifier => api/basic_node/to_sequence.md} (100%) create mode 100644 docs/mkdocs/docs/api/basic_node/to_string.md diff --git a/docs/mkdocs/docs/api/basic_node/constructor.md b/docs/mkdocs/docs/api/basic_node/constructor.md index eb4f1831..2b89080a 100644 --- a/docs/mkdocs/docs/api/basic_node/constructor.md +++ b/docs/mkdocs/docs/api/basic_node/constructor.md @@ -3,7 +3,7 @@ # fkyaml::basic_node::(constructor) Constructs new basic_node from a variety of data sources. -Available overloads +Available overloads are described down below. ## Overloads @@ -272,4 +272,8 @@ If `init` contains a sequence of basic_node objects in which the number of basic ```yaml foo: 1024 ``` ---- \ No newline at end of file +--- + +## **See Also** + +* [basic_node](index.md) diff --git a/docs/mkdocs/docs/api/basic_node/index.md b/docs/mkdocs/docs/api/basic_node/index.md index 7e7a824e..0af4684b 100644 --- a/docs/mkdocs/docs/api/basic_node/index.md +++ b/docs/mkdocs/docs/api/basic_node/index.md @@ -39,7 +39,6 @@ This class provides features to handle YAML nodes. | [boolean_type](boolean_type.md) | The type used to store boolean node values. | | [const_iterator](const_iterator.md) | The type for constant iterators. | | [float_number_type](float_number_type.md) | The type used to store float number node values. | -| [initializer_list_t](initializer_list_t.md) | The type alias for constructor with std::initializer_list. | | [integer_type](integer_type.md) | The type used to store integer node values. | | [iterator](iterator.md) | The type for non-constant iterators. | | [mapping_type](mapping_type.md) | The type used to store mapping node value containers. | @@ -57,11 +56,8 @@ This class provides features to handle YAML nodes. | [(constructor)](constructor.md) | | constructs a basic_node. | | [(destructor)](destructor.md) | | destroys a basic_node, deallocating internal storage if used. | | [operator=](operator=.md) | | assigns values to the basic_node. | -| [float_number_scalar](float_number_scalar.md)| (static) | constructs a basic_node with a float number value. | -| [integer_scalar](integer_scalar.md) | (static) | constructs a basic_node with an integer value. | | [mapping](mapping.md) | (static) | constructs a basic_node with a mapping container. | | [sequence](sequence.md) | (static) | constructs a basic_node with a sequence container. | -| [string_scalar](string_scalar.md) | (static) | constructs a basic_node with a string value. | ### Inspection for Node Value Types | Name | Description | @@ -77,11 +73,17 @@ This class provides features to handle YAML nodes. | [is_string](is_string.md) | checks if a basic_node has a string node value. | ### Conversions -| Name | Description | -| ----------------------------- | ------------------------------------------------------- | -| [deserialize](deserialize.md) | deserializes a YAML formatted string into a basic_node. | -| [serialize](serialize.md) | serializes a basic_node into a YAML formatted string. | -| [get_value](get_value.md) | converts a basic_node into a target native data type. | +| Name | Description | +| ------------------------------------- | ------------------------------------------------------- | +| [deserialize](deserialize.md) | deserializes a YAML formatted string into a basic_node. | +| [serialize](serialize.md) | serializes a basic_node into a YAML formatted string. | +| [get_value](get_value.md) | converts a basic_node into a target native data type. | +| [to_sequence](to_sequence.md) | gets reference to the sequence node value. | +| [to_mapping](to_mapping.md) | gets reference to the mapping node value. | +| [to_boolean](to_boolean.md) | gets reference to the boolean node value. | +| [to_integer](to_integer.md) | gets reference to the integer node value. | +| [to_float_number](to_float_number.md) | gets reference to the floating point number node value. | +| [to_string](to_string.md) | gets reference to the string node value. | ### Iterators | Name | Description | @@ -99,4 +101,4 @@ This class provides features to handle YAML nodes. ### Access Elements in Containers | Name | Description | |-----------------------------|---------------------------------------------| -| [operator[]](operator[].md) | accesses an item specified by the key/index | \ No newline at end of file +| [operator[]](operator[].md) | accesses an item specified by the key/index | diff --git a/docs/mkdocs/docs/api/basic_node/mapping.md b/docs/mkdocs/docs/api/basic_node/mapping.md index e69de29b..d85e269c 100644 --- a/docs/mkdocs/docs/api/basic_node/mapping.md +++ b/docs/mkdocs/docs/api/basic_node/mapping.md @@ -0,0 +1,43 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::mapping + +```cpp +static basic_node mapping(); +static basic_node mapping(const mapping_type& seq); +static basic_node mapping(mapping_type&& seq); +``` + +The factory method which constructs a basic_node with the [`node_t::MAPPING`](node_t.md) type from a mapping node value. +Calling this API with no arguments will constructs a basic_node with an empty mapping node value. +The resulting basic_node has the [`node_t::MAPPING`](node_t.md) type. + +??? example + + ```cpp + #include + #include + + int main() + { + fkyaml::node::mapping_type m = { + {fkyaml::node(std::string("foo")), fkyaml::node(false)}, + {fkyaml::node(std::string("bar")), fkyaml::node(3.14)} + }; + fkyaml::node n = fkyaml::node::mapping(m); + std::cout << fkyaml::node::serialize(n) << std::endl; + return 0; + } + ``` + output: + + ```yaml + foo: false + bar: 3.14 + ``` + + +### **See Also** + +* [basic_node](index.md) +* [node_t](node_t.md) diff --git a/docs/mkdocs/docs/api/basic_node/sequence.md b/docs/mkdocs/docs/api/basic_node/sequence.md index e69de29b..8a0a2928 100644 --- a/docs/mkdocs/docs/api/basic_node/sequence.md +++ b/docs/mkdocs/docs/api/basic_node/sequence.md @@ -0,0 +1,40 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::sequence + +```cpp +static basic_node sequence(); +static basic_node sequence(const sequence_type& seq); +static basic_node sequence(sequence_type&& seq); +``` + +The factory method which constructs a basic_node with the [`node_t::SEQUENCE`](node_t.md) type from a sequence node value. +Calling this API with no arguments will constructs a basic_node with an empty sequence node value. +The resulting basic_node has the [`node_t::SEQUENCE`](node_t.md) type. + +??? example + + ```cpp + #include + #include + + int main() + { + fkyaml::node::sequence_type s = {fkyaml::node(true), fkyaml::node(false)}; + fkyaml::node n = fkyaml::node::sequence(s); + std::cout << fkyaml::node::serialize(n) << std::endl; + return 0; + } + ``` + output: + + ```yaml + - true + - false + ``` + + +### **See Also** + +* [basic_node](index.md) +* [node_t](node_t.md) diff --git a/docs/mkdocs/docs/api/basic_node/float_number_scalar.md b/docs/mkdocs/docs/api/basic_node/to_boolean.md similarity index 100% rename from docs/mkdocs/docs/api/basic_node/float_number_scalar.md rename to docs/mkdocs/docs/api/basic_node/to_boolean.md diff --git a/docs/mkdocs/docs/api/basic_node/initializer_list_t.md b/docs/mkdocs/docs/api/basic_node/to_float_number.md similarity index 100% rename from docs/mkdocs/docs/api/basic_node/initializer_list_t.md rename to docs/mkdocs/docs/api/basic_node/to_float_number.md diff --git a/docs/mkdocs/docs/api/basic_node/integer_scalar.md b/docs/mkdocs/docs/api/basic_node/to_integer.md similarity index 100% rename from docs/mkdocs/docs/api/basic_node/integer_scalar.md rename to docs/mkdocs/docs/api/basic_node/to_integer.md diff --git a/docs/mkdocs/docs/api/basic_node/string_scalar.md b/docs/mkdocs/docs/api/basic_node/to_mapping.md similarity index 100% rename from docs/mkdocs/docs/api/basic_node/string_scalar.md rename to docs/mkdocs/docs/api/basic_node/to_mapping.md diff --git a/docs/mkdocs/docs/img/range-begin-end.svg:Zone.Identifier b/docs/mkdocs/docs/api/basic_node/to_sequence.md similarity index 100% rename from docs/mkdocs/docs/img/range-begin-end.svg:Zone.Identifier rename to docs/mkdocs/docs/api/basic_node/to_sequence.md diff --git a/docs/mkdocs/docs/api/basic_node/to_string.md b/docs/mkdocs/docs/api/basic_node/to_string.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/mkdocs.yml b/docs/mkdocs/mkdocs.yml index 23db523b..f34bff50 100644 --- a/docs/mkdocs/mkdocs.yml +++ b/docs/mkdocs/mkdocs.yml @@ -80,10 +80,8 @@ extra_css: - https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/default.min.css plugins: - - search: - lang: en - # - plantuml: - # puml_url: https://www.plantuml.com/plantuml/ + - search + - git-revision-date-localized nav: - Home: @@ -95,6 +93,7 @@ nav: - basic_node: api/basic_node/index.md - (constructor): api/basic_node/constructor.md - (destructor): api/basic_node/destructor.md + - operator=: api/basic_node/operator=.md - begin: api/basic_node/begin.md - boolean_type: api/basic_node/boolean_type.md - const_iterator: api/basic_node/const_iterator.md @@ -102,12 +101,9 @@ nav: - deserialize: api/basic_node/deserialize.md - empty: api/basic_node/empty.md - end: api/basic_node/end.md - - float_number_scalar: api/basic_node/float_number_scalar.md - float_number_type: api/basic_node/float_number_type.md - get_value: api/basic_node/get_value.md - get_yaml_version: api/basic_node/get_yaml_version.md - - initializer_list_t: api/basic_node/initializer_list_t.md - - integer_scalar: api/basic_node/integer_scalar.md - integer_type: api/basic_node/integer_type.md - is_boolean: api/basic_node/is_boolean.md - is_float_number: api/basic_node/is_float_number.md @@ -127,12 +123,16 @@ nav: - serialize: api/basic_node/serialize.md - set_yaml_version: api/basic_node/set_yaml_version.md - size: api/basic_node/size.md - - string_scalar: api/basic_node/string_scalar.md - string_type: api/basic_node/string_type.md + - to_boolean: api/basic_node/to_boolean.md + - to_float_number: api/basic_node/to_float_number.md + - to_integer: api/basic_node/to_integer.md + - to_mapping: api/basic_node/to_mapping.md + - to_sequence: api/basic_node/to_sequence.md + - to_string: api/basic_node/to_string.md - type: api/basic_node/type.md - value_converter_type: api/basic_node/value_converter_type.md - yaml_version_t: api/basic_node/yaml_version_t.md - - operator=: api/basic_node/operator=.md - operator[]: api/basic_node/operator[].md - exception: - exception: api/exception/index.md diff --git a/docs/mkdocs/requirements.txt b/docs/mkdocs/requirements.txt index e249234d..0613eb4b 100644 --- a/docs/mkdocs/requirements.txt +++ b/docs/mkdocs/requirements.txt @@ -4,12 +4,15 @@ charset-normalizer==3.3.1 click==8.1.7 colorama==0.4.6 ghp-import==2.1.0 +gitdb==4.0.11 +GitPython==3.1.40 idna==3.4 Jinja2==3.1.2 Markdown==3.5 MarkupSafe==2.1.3 mergedeep==1.3.4 mkdocs==1.5.3 +mkdocs-git-revision-date-localized-plugin==1.2.1 mkdocs-material==9.4.6 mkdocs-material-extensions==1.3 packaging==23.2 @@ -19,10 +22,12 @@ platformdirs==3.11.0 Pygments==2.16.1 pymdown-extensions==10.3.1 python-dateutil==2.8.2 +pytz==2023.3.post1 PyYAML==6.0.1 pyyaml_env_tag==0.1 regex==2023.10.3 requests==2.31.0 six==1.16.0 +smmap==5.0.1 urllib3==2.0.7 watchdog==3.0.0 diff --git a/include/fkYAML/node.hpp b/include/fkYAML/node.hpp index ab0c8c1c..b96afa39 100644 --- a/include/fkYAML/node.hpp +++ b/include/fkYAML/node.hpp @@ -85,12 +85,8 @@ class basic_node /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/string_type/ using string_type = StringType; - /** - * @brief A helper alias to determine converter type for the given target native data type. - * - * @tparam T A target native data type. - * @tparam SFINAE A type placeholder for SFINAE - */ + /// @brief A helper alias to determine converter type for the given target native data type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/value_converter_type/ template using value_converter_type = ConverterType; @@ -106,11 +102,11 @@ class basic_node template friend struct fkyaml::detail::external_node_constructor; - /** A type for YAML docs deserializers. */ + /// @brief A type for YAML docs deserializers. using deserializer_type = detail::basic_deserializer; - /** A type for YAML docs serializers. */ + /// @brief A type for YAML docs serializers. using serializer_type = detail::basic_serializer; - /** An alias type for std::initializer_list. */ + /// @brief A helper type alias for std::initializer_list. using initializer_list_t = std::initializer_list>; /** @@ -294,11 +290,11 @@ class basic_node public: /// @brief Construct a new basic_node object of null type. - /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor/ basic_node() = default; /// @brief Construct a new basic_node object with a specified type. - /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor/ explicit basic_node(const node_t type) : m_node_type(type), m_node_value(type) @@ -306,7 +302,7 @@ class basic_node } /// @brief Copy constructor of the basic_node class. - /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor/ basic_node(const basic_node& rhs) : m_node_type(rhs.m_node_type), m_yaml_version_type(rhs.m_yaml_version_type) @@ -350,7 +346,7 @@ class basic_node } /// @brief Move constructor of the basic_node class. - /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor/ basic_node(basic_node&& rhs) noexcept : m_node_type(rhs.m_node_type), m_yaml_version_type(rhs.m_yaml_version_type), @@ -398,7 +394,7 @@ class basic_node } /// @brief Construct a new basic_node object from a value of compatible types. - /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor/ template < typename CompatibleType, typename U = detail::remove_cvref_t, detail::enable_if_t< @@ -413,7 +409,7 @@ class basic_node } /// @brief Construct a new basic node object with a node_ref_storage object. - /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor/ template < typename NodeRefStorageType, detail::enable_if_t::value, int> = 0> @@ -423,7 +419,7 @@ class basic_node } /// @brief Construct a new basic node object with std::initializer_list. - /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor/ basic_node(initializer_list_t init) { bool is_mapping = @@ -452,7 +448,7 @@ class basic_node } /// @brief Destroy the basic_node object and its value storage. - /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/destructor + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/destructor/ ~basic_node() noexcept // NOLINT(bugprone-exception-escape) { destroy_object(m_anchor_name); @@ -507,11 +503,8 @@ class basic_node return serializer_type().serialize(node); } - /** - * @brief A factory method for sequence basic_node objects without sequence_type objects. - * - * @return basic_node A constructed basic_node object of sequence type. - */ + /// @brief A factory method for sequence basic_node objects without sequence_type objects. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/sequence/ static basic_node sequence() { basic_node node; @@ -521,12 +514,8 @@ class basic_node return node; } // LCOV_EXCL_LINE - /** - * @brief A factory method for sequence basic_node objects with lvalue sequence_type objects. - * - * @param[in] seq A lvalue source of sequence type. - * @return basic_node A constructed basic_node object of sequence type. - */ + /// @brief A factory method for sequence basic_node objects with lvalue sequence_type objects. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/sequence/ static basic_node sequence(const sequence_type& seq) { basic_node node; @@ -536,12 +525,8 @@ class basic_node return node; } // LCOV_EXCL_LINE - /** - * @brief A factory method for sequence basic_node objects with rvalue sequence_type objects. - * - * @param[in] seq A rvalue source of sequence type. - * @return basic_node A constructed basic_node object of sequence type. - */ + /// @brief A factory method for sequence basic_node objects with rvalue sequence_type objects. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/sequence/ static basic_node sequence(sequence_type&& seq) { basic_node node; @@ -551,11 +536,8 @@ class basic_node return node; } // LCOV_EXCL_LINE - /** - * @brief A factory method for mapping basic_node objects without mapping_type objects. - * - * @return basic_node A constructed basic_node object of mapping type. - */ + /// @brief A factory method for mapping basic_node objects without mapping_type objects. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/mapping/ static basic_node mapping() { basic_node node; @@ -565,12 +547,8 @@ class basic_node return node; } // LCOV_EXCL_LINE - /** - * @brief A factory method for mapping basic_node objects with lvalue mapping_type objects. - * - * @param[in] map A lvalue source of mapping type. - * @return basic_node A constructed basic_node object of mapping type. - */ + /// @brief A factory method for mapping basic_node objects with lvalue mapping_type objects. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/mapping/ static basic_node mapping(const mapping_type& map) { basic_node node; @@ -580,12 +558,8 @@ class basic_node return node; } // LCOV_EXCL_LINE - /** - * @brief A factory method for mapping basic_node objects with rvalue mapping_type objects. - * - * @param[in] map A rvalue source of mapping type. - * @return basic_node A constructed basic_node object of mapping type. - */ + /// @brief A factory method for mapping basic_node objects with rvalue mapping_type objects. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/mapping/ static basic_node mapping(mapping_type&& map) { basic_node node; From d601b040f19b3de2f280cb5d0fffd4cfd9a5fa60 Mon Sep 17 00:00:00 2001 From: fktn Date: Mon, 30 Oct 2023 01:21:53 +0900 Subject: [PATCH 22/48] migrated more documents for basic_node class with MkDocs --- .../docs/api/basic_node/add_anchor_name.md | 0 docs/mkdocs/docs/api/basic_node/alias_of.md | 7 + .../mkdocs/docs/api/basic_node/constructor.md | 48 ++- docs/mkdocs/docs/api/basic_node/contains.md | 12 + .../mkdocs/docs/api/basic_node/deserialize.md | 219 ++++++++++ docs/mkdocs/docs/api/basic_node/get_value.md | 14 + .../docs/api/basic_node/get_yaml_version.md | 37 ++ .../docs/api/basic_node/has_anchor_name.md | 0 docs/mkdocs/docs/api/basic_node/index.md | 21 +- docs/mkdocs/docs/api/basic_node/operator=.md | 52 +++ docs/mkdocs/docs/api/basic_node/operator[].md | 23 + docs/mkdocs/docs/api/basic_node/serialize.md | 62 +++ .../docs/api/basic_node/set_yaml_version.md | 55 +++ docs/mkdocs/docs/api/basic_node/to_boolean.md | 9 + .../docs/api/basic_node/to_float_number.md | 9 + docs/mkdocs/docs/api/basic_node/to_integer.md | 9 + docs/mkdocs/docs/api/basic_node/to_mapping.md | 9 + .../mkdocs/docs/api/basic_node/to_sequence.md | 9 + docs/mkdocs/docs/api/basic_node/to_string.md | 9 + .../api/node_value_converter/from_node.md | 10 + .../docs/api/node_value_converter/to_node.md | 10 + docs/mkdocs/mkdocs.yml | 3 + include/fkYAML/node.hpp | 404 ++++++------------ 23 files changed, 739 insertions(+), 292 deletions(-) create mode 100644 docs/mkdocs/docs/api/basic_node/add_anchor_name.md create mode 100644 docs/mkdocs/docs/api/basic_node/alias_of.md create mode 100644 docs/mkdocs/docs/api/basic_node/has_anchor_name.md diff --git a/docs/mkdocs/docs/api/basic_node/add_anchor_name.md b/docs/mkdocs/docs/api/basic_node/add_anchor_name.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/alias_of.md b/docs/mkdocs/docs/api/basic_node/alias_of.md new file mode 100644 index 00000000..cef5402f --- /dev/null +++ b/docs/mkdocs/docs/api/basic_node/alias_of.md @@ -0,0 +1,7 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::alias_of + +```cpp +yaml_version_t alias_of(const basic_node& anchor) const noexcept; +``` diff --git a/docs/mkdocs/docs/api/basic_node/constructor.md b/docs/mkdocs/docs/api/basic_node/constructor.md index 2b89080a..b57faa57 100644 --- a/docs/mkdocs/docs/api/basic_node/constructor.md +++ b/docs/mkdocs/docs/api/basic_node/constructor.md @@ -2,10 +2,36 @@ # fkyaml::basic_node::(constructor) -Constructs new basic_node from a variety of data sources. +```cpp +basic_node() = default; // (1) + +explicit basic_node(const node_t type); // (2) + +basic_node(const basic_node& rhs); // (3) + +basic_node(basic_node&& rhs) noexcept; // (4) + +template < + typename CompatibleType, typename U = detail::remove_cv_ref_t, + detail::enable_if_t< + detail::conjunction< + detail::negation>, + detail::disjunction>>::value, + int> = 0> +basic_node(CompatibleType&& val); // (5) + +template < + typename NodeRefStorageType, + detail::enable_if_t::value, int> = 0> +basic_node(const NodeRefStorageType& node_ref_storage); // (6) + +basic_node(initializer_list_t init); // (7) +``` + +Constructs a new basic_node from a variety of data sources. Available overloads are described down below. -## Overloads +## Overload (1) ```cpp basic_node() = default; @@ -31,7 +57,8 @@ The resulting basic_node has the [`node_t::NULL_OBJECT`](node_t.md) type. ```yaml null ``` ---- + +## Overload (2) ```cpp explicit basic_node(const node_t type); @@ -62,7 +89,8 @@ The resulting basic_node has a default value for the given type. ```yaml 0 ``` ---- + +## Overload (3) ```cpp basic_node(const basic_node& rhs); @@ -94,7 +122,8 @@ The resulting basic_node has the same type and value as `rhs`. ```yaml false ``` ---- + +## Overload (4) ```cpp basic_node(basic_node&& rhs) noexcept; @@ -127,7 +156,8 @@ The value of the argument `rhs` after calling this move constructor, will be the ```yaml false ``` ---- + +## Overload (5) ```cpp template < @@ -174,7 +204,8 @@ The resulting basic_node has the value of `val` and the type which is associated ```yaml 3.141592 ``` ---- + +## Overload (6) ```cpp template < @@ -220,7 +251,8 @@ The resulting basic_node has the value of the referenced basic_node by `node_ref - true - false ``` ---- + +## Overload (7) ```cpp basic_node(initializer_list_t init); diff --git a/docs/mkdocs/docs/api/basic_node/contains.md b/docs/mkdocs/docs/api/basic_node/contains.md index e69de29b..967214e4 100644 --- a/docs/mkdocs/docs/api/basic_node/contains.md +++ b/docs/mkdocs/docs/api/basic_node/contains.md @@ -0,0 +1,12 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::contains + +```cpp +template < + typename KeyType, detail::enable_if_t< + detail::is_usable_as_key_type< + typename mapping_type::key_compare, typename mapping_type::key_type, KeyType>::value, + int> = 0> +bool contains(KeyType&& key) const; +``` diff --git a/docs/mkdocs/docs/api/basic_node/deserialize.md b/docs/mkdocs/docs/api/basic_node/deserialize.md index e69de29b..b91cb613 100644 --- a/docs/mkdocs/docs/api/basic_node/deserialize.md +++ b/docs/mkdocs/docs/api/basic_node/deserialize.md @@ -0,0 +1,219 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::deserialize + +```cpp +template +static basic_node deserialize(InputType&& input); // (1) + +template +static basic_node deserialize(ItrType&& begin, ItrType&& end); // (2) + +template ::value, int> = 0> +static basic_node deserialize(PtrType&& ptr, std::size_t size); // (3) +``` + +Deserializes from compatible input sources. +Throws a [`fkyaml::exception`](../exception/index.md) if the deserialization process detects an error from the input sources. + +## Overload (1) + +```cpp +template +static basic_node deserialize(InputType&& input); +``` + +### **Template Parameters** + +***`InputType`*** +: Type of a compatible input, for instance: + + * an `std::istream` object + * a `FILE` pointer (must not be `nullptr`) + * a C-style array of characters + * a pointer to a null-terminated string of single byte characters. + * a container `obj` for which `begin(obj)` and `end(obj)` produces a valid pair of iterators + * std::string, std::array, and the likes. + +### **Parameters** + +***`input`*** [in] +: An input source in the YAML format. + +### **Return Values** + +The resulting `basic_node` object deserialized from the input source. + +## Overload (2) + +```cpp +template +static basic_node deserialize(ItrType&& begin, ItrType&& end); +``` + +### **Template Parameters** + +***`ItrType`*** +: Type of a compatible iterator, for instance: + + * a pair of `std::string::iterator` + * a pair of pointers such as `ptr` and `ptr + len` + +### **Parameters** + +***`begin`*** [in] +: An iterator to the first element of an input sequence + +***`end`*** [in] +: An iterator to the past-the-last element of an input sequence + +### **Return Values** + +The resulting `basic_node` object deserialized from the pair of iterators. + +## Examples + +??? Example "Example (a character array)" + + ```cpp + #include + #include + #include + #include + + int main() + { + // deserialize a YAML string. + char input[] = R"( + foo: true + bar: 123 + baz: 3.14 + )"; + fkyaml::node n = fkyaml::node::deserialize(input); + + // check the deserialization result. + std::cout << n["foo"].get_value() << std::endl; + std::cout << n["bar"].get_value() << std::endl; + std::cout << std::setprecision(3) << n["baz"].get_value() << std::endl; + + return 0; + } + ``` + + ```bash + true + 123 + 3.14 + ``` + +??? Example "Example (a std::string object)" + + ```cpp + #include + #include + #include + #include + #include + + int main() + { + // deserialize a YAML string. + std::string s = R"( + foo: true + bar: 123 + baz: 3.14 + )"; + fkyaml::node n = fkyaml::node::deserialize(s); + + // check the deserialization result. + std::cout << n["foo"].get_value() << std::endl; + std::cout << n["bar"].get_value() << std::endl; + std::cout << std::setprecision(3) << n["baz"].get_value() << std::endl; + + return 0; + } + ``` + + ```bash + true + 123 + 3.14 + ``` + +??? Example "Example (a FILE pointer)" + + ```yaml title="input.yaml" + foo: true + bar: 123 + baz: 3.14 + ``` + + ```cpp + #include + #include + #include + #include + #include + + int main() + { + // deserialize a YAML string. + FILE* p_file = std::fopen("input.yaml", "r"); + if (!p_file) + { + // You must not pass a null FILE pointer. + return -1; + } + fkyaml::node n = fkyaml::node::deserialize(p_file); + + // check the deserialization result. + std::cout << n["foo"].get_value() << std::endl; + std::cout << n["bar"].get_value() << std::endl; + std::cout << std::setprecision(3) << n["baz"].get_value() << std::endl; + + return 0; + } + ``` + + ```bash + true + 123 + 3.14 + ``` + +??? Example "Example (a pair of iterators)" + + ```cpp + #include + #include + #include + #include + #include + + int main() + { + // deserialize a YAML string. + std::array input = { + 'f', 'o', 'o', ':', ' ', 't', 'r', 'u', 'e', 'd', 'u', 'm', 'm', 'y' + }; + fkyaml::node n = fkyaml::node::deserialize(input.begin(), input.begin() + 9); + + // check the deserialization result. + std::cout << n["foo"].get_value() << std::endl; + std::cout << n["bar"].get_value() << std::endl; + std::cout << std::setprecision(3) << n["baz"].get_value() << std::endl; + + return 0; + } + ``` + + ```bash + true + 123 + 3.14 + ``` + +### **See Also** + +* [basic_node](index.md) +* [get_value](get_value.md) diff --git a/docs/mkdocs/docs/api/basic_node/get_value.md b/docs/mkdocs/docs/api/basic_node/get_value.md index e69de29b..3a850af4 100644 --- a/docs/mkdocs/docs/api/basic_node/get_value.md +++ b/docs/mkdocs/docs/api/basic_node/get_value.md @@ -0,0 +1,14 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::get_value + +```cpp +template < + typename T, typename ValueType = detail::remove_cvref_t, + detail::enable_if_t< + detail::conjunction< + std::is_default_constructible, detail::has_from_node>::value, + int> = 0> +T get_value() const noexcept( + noexcept(ConverterType::from_node(std::declval(), std::declval()))); +``` diff --git a/docs/mkdocs/docs/api/basic_node/get_yaml_version.md b/docs/mkdocs/docs/api/basic_node/get_yaml_version.md index e69de29b..4a68d2a6 100644 --- a/docs/mkdocs/docs/api/basic_node/get_yaml_version.md +++ b/docs/mkdocs/docs/api/basic_node/get_yaml_version.md @@ -0,0 +1,37 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::get_yaml_version + +```cpp +yaml_version_t get_yaml_version() const noexcept; +``` + +Returns the version of the YAML format applied for the `basic_node` object. + +### **Return Values** + +| YAML version | Return Value | +| ------------ | ----------------------- | +| 1.1 | yaml_version_t::VER_1_1 | +| 1.2 | yaml_version_t::VER_1_2 | + +??? Example + + ```cpp + #include + #include + #include + + int main() + { + + + return 0; + } + ``` + +## **See Also** + +* [basic_node](index.md) +* [yaml_verion_t](yaml_version_t.md) +* [set_yaml_version](set_yaml_version.md) \ No newline at end of file diff --git a/docs/mkdocs/docs/api/basic_node/has_anchor_name.md b/docs/mkdocs/docs/api/basic_node/has_anchor_name.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/mkdocs/docs/api/basic_node/index.md b/docs/mkdocs/docs/api/basic_node/index.md index 0af4684b..ee66262e 100644 --- a/docs/mkdocs/docs/api/basic_node/index.md +++ b/docs/mkdocs/docs/api/basic_node/index.md @@ -51,13 +51,14 @@ This class provides features to handle YAML nodes. ## Member Functions ### Construction/Destruction -| Name | | Description | -|----------------------------------------------|----------|---------------------------------------------------------------| -| [(constructor)](constructor.md) | | constructs a basic_node. | -| [(destructor)](destructor.md) | | destroys a basic_node, deallocating internal storage if used. | -| [operator=](operator=.md) | | assigns values to the basic_node. | -| [mapping](mapping.md) | (static) | constructs a basic_node with a mapping container. | -| [sequence](sequence.md) | (static) | constructs a basic_node with a sequence container. | +| Name | | Description | +| ------------------------------- | -------- | ------------------------------------------------------------- | +| [(constructor)](constructor.md) | | constructs a basic_node. | +| [(destructor)](destructor.md) | | destroys a basic_node, deallocating internal storage if used. | +| [operator=](operator=.md) | | assigns values to the basic_node. | +| [mapping](mapping.md) | (static) | constructs a basic_node with a mapping container. | +| [sequence](sequence.md) | (static) | constructs a basic_node with a sequence container. | +| [alias_of](alias_of.md) | (static) | constructs a basic_node with an anchor node. | ### Inspection for Node Value Types | Name | Description | @@ -102,3 +103,9 @@ This class provides features to handle YAML nodes. | Name | Description | |-----------------------------|---------------------------------------------| | [operator[]](operator[].md) | accesses an item specified by the key/index | + +### Aliasing Nodes +| Name | Description | +| ------------------------------------- | ------------------------------------------------ | +| [add_anchor_name](add_anchor_name.md) | registers an anchor name to a basic_node object. | +| [has_anchor_name](has_anchor_name.md) | checks if a basic_node has any anchor name. | diff --git a/docs/mkdocs/docs/api/basic_node/operator=.md b/docs/mkdocs/docs/api/basic_node/operator=.md index e69de29b..52db2a3a 100644 --- a/docs/mkdocs/docs/api/basic_node/operator=.md +++ b/docs/mkdocs/docs/api/basic_node/operator=.md @@ -0,0 +1,52 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::operator= + +```cpp +basic_node& operator=(const basic_node& rhs) noexcept; // (1) + +basic_node& operator=(basic_node&& rhs) noexcept; // (2) +``` + +Assignment operator. +The `basic_node` class supports both copy and move assignments. + +## Overload (1) + +```cpp +basic_node& operator=(const basic_node& rhs) noexcept; +``` + +Copy assignment operator. +Copies a YAML node value via the "copy and swap" strategy to enhance exception safety. + +??? Example + + ```cpp + #include + #include + + int main() + { + fkyaml::node n = true; + fkyaml::node n2 = 123; + n = n2; + + std::cout << std::boolalpha << n.is_integer() << std::endl; + std::cout << n.get_value() << std::endl; + + return 0; + } + ``` + + output: + ```bash + true + 123 + ``` + +## **See Also** + +* [basic_node](index.md) +* [is_integer](is_integer.md) +* [get_value](get_value.md) diff --git a/docs/mkdocs/docs/api/basic_node/operator[].md b/docs/mkdocs/docs/api/basic_node/operator[].md index e69de29b..8f34536a 100644 --- a/docs/mkdocs/docs/api/basic_node/operator[].md +++ b/docs/mkdocs/docs/api/basic_node/operator[].md @@ -0,0 +1,23 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::operator[] + +```cpp +basic_node& operator[](std::size_t index); + +const basic_node& operator[](std::size_t index) const; + +template < + typename KeyType, detail::enable_if_t< + detail::is_usable_as_key_type< + typename mapping_type::key_compare, typename mapping_type::key_type, KeyType>::value, + int> = 0> +basic_node& operator[](KeyType&& key); + +template < + typename KeyType, detail::enable_if_t< + detail::is_usable_as_key_type< + typename mapping_type::key_compare, typename mapping_type::key_type, KeyType>::value, + int> = 0> +const basic_node& operator[](KeyType&& key) const; +``` diff --git a/docs/mkdocs/docs/api/basic_node/serialize.md b/docs/mkdocs/docs/api/basic_node/serialize.md index e69de29b..8aa00186 100644 --- a/docs/mkdocs/docs/api/basic_node/serialize.md +++ b/docs/mkdocs/docs/api/basic_node/serialize.md @@ -0,0 +1,62 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::serialize + +```cpp +static std::string serialize(const basic_node& node); +``` + +Serializes YAML node values recursively. +Currently, the serialization result only supports block styles. +That means that, even if a deserialized source input is written in flow styles, the serialization result forces to convert it in block styles. + +### **Parameters** + +***node*** [in] +: A `basic_node` object to be serialized. + +### **Return Values** + +The resulting string object from the serialization of the `node` object. + +??? Example + + ```cpp + #include + #include + + int main() + { + // create a basic_node object. + fkyaml::node n = { + {std::string("foo"), true}, + {std::string("bar"), {1, 2, 3}}, + {std::string("baz"), { + {std::string("qux"), 3.14}, + {std::string("corge"), nullptr} + }} + }; + + // serialize the basic_node object. + std::cout << fkyaml::node::serialize(n) << std::endl; + + return 0; + } + ``` + + output: + ```yaml + foo: true + bar: + - 1 + - 2 + - 3 + baz: + qux: 3.14 + corge: null + ``` + +### **See Also** + +* [basic_node](index.md) +* [deserialize](deserialize.md) diff --git a/docs/mkdocs/docs/api/basic_node/set_yaml_version.md b/docs/mkdocs/docs/api/basic_node/set_yaml_version.md index e69de29b..b1f2408a 100644 --- a/docs/mkdocs/docs/api/basic_node/set_yaml_version.md +++ b/docs/mkdocs/docs/api/basic_node/set_yaml_version.md @@ -0,0 +1,55 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::set_yaml_version + +```cpp +void set_yaml_version(const yaml_version_t version) noexcept; +``` + +Sets the version of the YAML format to the `basic_node` object. + +### **Parameters** + +***version*** [in] +: A version of the YAML format. + +### **Return Values** + +| YAML version | Return Value | +| ------------ | ----------------------- | +| 1.1 | yaml_version_t::VER_1_1 | +| 1.2 | yaml_version_t::VER_1_2 | + +??? Example + + ```cpp + #include + #include + #include + + int main() + { + fkyaml::node n; + n.set_yaml_version(fkyaml::node::yaml_version_t::VER_1_1); + fkyaml::node n2; + n2.set_yaml_version(fkyaml::node::yaml_version_t::VER_1_2); + + std::cout << std::boolalpha; + std::cout << n.get_yaml_version() == fkyaml::node::yaml_version_t::VER_1_1 << std::endl; + std::cout << n2.get_yaml_version() == fkyaml::node::yaml_version_t::VER_1_2 << std::endl; + + return 0; + } + ``` + + output: + ```bash + true + true + ``` + +## **See Also** + +* [basic_node](index.md) +* [yaml_verion_t](yaml_version_t.md) +* [set_yaml_version](set_yaml_version.md) \ No newline at end of file diff --git a/docs/mkdocs/docs/api/basic_node/to_boolean.md b/docs/mkdocs/docs/api/basic_node/to_boolean.md index e69de29b..a186936c 100644 --- a/docs/mkdocs/docs/api/basic_node/to_boolean.md +++ b/docs/mkdocs/docs/api/basic_node/to_boolean.md @@ -0,0 +1,9 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::to_boolean + +```cpp +boolean_type& to_boolean(); + +const boolean_type& to_boolean() const; +``` diff --git a/docs/mkdocs/docs/api/basic_node/to_float_number.md b/docs/mkdocs/docs/api/basic_node/to_float_number.md index e69de29b..666ea335 100644 --- a/docs/mkdocs/docs/api/basic_node/to_float_number.md +++ b/docs/mkdocs/docs/api/basic_node/to_float_number.md @@ -0,0 +1,9 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::to_float_number + +```cpp +float_number_type& to_float_number(); + +const float_number_type& to_float_number() const; +``` diff --git a/docs/mkdocs/docs/api/basic_node/to_integer.md b/docs/mkdocs/docs/api/basic_node/to_integer.md index e69de29b..52d6799c 100644 --- a/docs/mkdocs/docs/api/basic_node/to_integer.md +++ b/docs/mkdocs/docs/api/basic_node/to_integer.md @@ -0,0 +1,9 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::to_integer + +```cpp +integer_type& to_integer(); + +const integer_type& to_integer() const; +``` diff --git a/docs/mkdocs/docs/api/basic_node/to_mapping.md b/docs/mkdocs/docs/api/basic_node/to_mapping.md index e69de29b..4022b983 100644 --- a/docs/mkdocs/docs/api/basic_node/to_mapping.md +++ b/docs/mkdocs/docs/api/basic_node/to_mapping.md @@ -0,0 +1,9 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::to_mapping + +```cpp +mapping_type& to_mapping(); + +const mapping_type& to_mapping() const; +``` diff --git a/docs/mkdocs/docs/api/basic_node/to_sequence.md b/docs/mkdocs/docs/api/basic_node/to_sequence.md index e69de29b..808e98fc 100644 --- a/docs/mkdocs/docs/api/basic_node/to_sequence.md +++ b/docs/mkdocs/docs/api/basic_node/to_sequence.md @@ -0,0 +1,9 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::to_sequence + +```cpp +sequence_type& to_sequence(); + +const sequence_type& to_sequence() const; +``` diff --git a/docs/mkdocs/docs/api/basic_node/to_string.md b/docs/mkdocs/docs/api/basic_node/to_string.md index e69de29b..e1bca62f 100644 --- a/docs/mkdocs/docs/api/basic_node/to_string.md +++ b/docs/mkdocs/docs/api/basic_node/to_string.md @@ -0,0 +1,9 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::to_string + +```cpp +string_type& to_string(); + +const string_type& to_string() const; +``` diff --git a/docs/mkdocs/docs/api/node_value_converter/from_node.md b/docs/mkdocs/docs/api/node_value_converter/from_node.md index e69de29b..3d5fe21c 100644 --- a/docs/mkdocs/docs/api/node_value_converter/from_node.md +++ b/docs/mkdocs/docs/api/node_value_converter/from_node.md @@ -0,0 +1,10 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node_value_converter.hpp) + +# fkyaml::basic_node::from_node + +```cpp +template +static auto from_node(BasicNodeType&& n, TargetType& val) noexcept( + noexcept(::fkyaml::from_node(std::forward(n), val))) + -> decltype(::fkyaml::from_node(std::forward(n), val), void()) +``` diff --git a/docs/mkdocs/docs/api/node_value_converter/to_node.md b/docs/mkdocs/docs/api/node_value_converter/to_node.md index e69de29b..b4c626aa 100644 --- a/docs/mkdocs/docs/api/node_value_converter/to_node.md +++ b/docs/mkdocs/docs/api/node_value_converter/to_node.md @@ -0,0 +1,10 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node_value_converter.hpp) + +# fkyaml::basic_node::from_node + +```cpp +template +static auto to_node(BasicNodeType& n, TargetType&& val) noexcept( + noexcept(::fkyaml::to_node(n, std::forward(val)))) + -> decltype(::fkyaml::to_node(n, std::forward(val))) +``` diff --git a/docs/mkdocs/mkdocs.yml b/docs/mkdocs/mkdocs.yml index f34bff50..4350c455 100644 --- a/docs/mkdocs/mkdocs.yml +++ b/docs/mkdocs/mkdocs.yml @@ -94,6 +94,8 @@ nav: - (constructor): api/basic_node/constructor.md - (destructor): api/basic_node/destructor.md - operator=: api/basic_node/operator=.md + - add_anchor_name: api/basic_node/add_anchor_name.md + - alias_of: api/basic_node/alias_of.md - begin: api/basic_node/begin.md - boolean_type: api/basic_node/boolean_type.md - const_iterator: api/basic_node/const_iterator.md @@ -104,6 +106,7 @@ nav: - float_number_type: api/basic_node/float_number_type.md - get_value: api/basic_node/get_value.md - get_yaml_version: api/basic_node/get_yaml_version.md + - has_anchor_name: api/basic_node/has_anchor_name.md - integer_type: api/basic_node/integer_type.md - is_boolean: api/basic_node/is_boolean.md - is_float_number: api/basic_node/is_float_number.md diff --git a/include/fkYAML/node.hpp b/include/fkYAML/node.hpp index b96afa39..546eab71 100644 --- a/include/fkYAML/node.hpp +++ b/include/fkYAML/node.hpp @@ -109,25 +109,18 @@ class basic_node /// @brief A helper type alias for std::initializer_list. using initializer_list_t = std::initializer_list>; - /** - * @union node_value - * @brief The actual storage for a YAML node value of the @ref basic_node class. - * @details This union combines the different sotrage types for the YAML value types defined in @ref node_t. - * @note Container types are stored as pointers so that the size of this union should not exceed 64 bits by default. - */ + /// @brief The actual storage for a YAML node value of the @ref basic_node class. + /// @details This union combines the different sotrage types for the YAML value types defined in @ref node_t. + /// @note Container types are stored as pointers so that the size of this union should not exceed 64 bits by + /// default. union node_value { - /** - * @brief Construct a new basic_node Value object for null types. - */ + /// @brief Construct a new basic_node Value object for null types. node_value() = default; - /** - * @brief Construct a new basic_node Value object with basic_node types. The default value for the specified - * type will be assigned. - * - * @param[in] type A Node type. - */ + /// @brief Construct a new basic_node Value object with basic_node types. The default value for the specified + /// type will be assigned. + /// @param[in] type A Node type. explicit node_value(node_t type) { switch (type) @@ -158,12 +151,9 @@ class basic_node } } - /** - * @brief Destroy the existing Node value. This process is recursive if the specified node type is fpr - * containers. - * - * @param[in] type A Node type to determine which Node value is destroyed. - */ + /// @brief Destroy the existing Node value. This process is recursive if the specified node type is fpr + /// containers. + /// @param[in] type A Node type to determine which Node value is destroyed. void destroy(node_t type) { if (type == node_t::SEQUENCE || type == node_t::MAPPING) @@ -242,14 +232,11 @@ class basic_node }; private: - /** - * @brief Allocates and constructs an object with specified type and arguments. - * - * @tparam ObjType The target object type. - * @tparam ArgTypes The packed argument types for constructor arguments. - * @param[in] args A parameter pack for constructor arguments of the target object type. - * @return ObjType* An address of allocated memory on the heap. - */ + /// @brief Allocates and constructs an object with specified type and arguments. + /// @tparam ObjType The target object type. + /// @tparam ArgTypes The packed argument types for constructor arguments. + /// @param[in] args A parameter pack for constructor arguments of the target object type. + /// @return ObjType* An address of allocated memory on the heap. template static ObjType* create_object(ArgTypes&&... args) { @@ -269,12 +256,9 @@ class basic_node return object.release(); } - /** - * @brief Destroys and deallocates an object with specified type. - * - * @tparam ObjType The target object type. - * @param[in] obj A pointer to the target object to be destroyed. - */ + /// @brief Destroys and deallocates an object with specified type. + /// @tparam ObjType The target object type. + /// @param[in] obj A pointer to the target object to be destroyed. template static void destroy_object(ObjType* obj) { @@ -458,27 +442,16 @@ class basic_node } public: - /** - * @brief Deserialize an input source into a basic_node object. - * - * @tparam InputType A type of an input source. - * @param input An input source in YAML format. - * @return basic_node The result of deserialization. - */ + /// @brief Deserialize an input source into a basic_node object. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/deserialize/ template static basic_node deserialize(InputType&& input) { return deserializer_type().deserialize(detail::input_adapter(std::forward(input))); } - /** - * @brief Deserialize input iterators into a basic_node object. - * - * @tparam ItrType A type of input iterators. - * @param begin The beginning of input iterators. - * @param end The end of input iterators. - * @return basic_node The result of deserialization. - */ + /// @brief Deserialize input iterators into a basic_node object. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/deserialize/ template static basic_node deserialize(ItrType&& begin, ItrType&& end) { @@ -486,18 +459,16 @@ class basic_node detail::input_adapter(std::forward(begin), std::forward(end))); } + /// @brief Deserialize an input string specified with a pointer and a size. + /// @todo Delete this API b/c this can be achieved with iterators and possibly yield undefined behavior. template ::value, int> = 0> static basic_node deserialize(PtrType&& ptr, std::size_t size) { return deserializer_type().deserialize(detail::input_adapter(std::forward(ptr), size)); } - /** - * @brief Serialize a basic_node object into a string. - * - * @param node A basic_node object. - * @return std::string The result of serialization. - */ + /// @brief Serialize a basic_node object into a string. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/serialize/ static std::string serialize(const basic_node& node) { return serializer_type().serialize(node); @@ -569,12 +540,8 @@ class basic_node return node; } // LCOV_EXCL_LINE - /** - * @brief A factory method for boolean scalar basic_node objects. - * - * @param[in] boolean A source of boolean type. - * @return basic_node A constructed basic_node object of boolean type. - */ + /// @brief A factory method for boolean scalar basic_node objects. + /// @todo delete this API b/c this can be achieved with constructor with std::initializer_list. static basic_node boolean_scalar(const boolean_type boolean) noexcept { basic_node node; @@ -583,12 +550,8 @@ class basic_node return node; } - /** - * @brief A factory method for integer scalar basic_node objects. - * - * @param[in] integer A source of integer type. - * @return basic_node A constructed basic_node object of integer type. - */ + /// @brief A factory method for integer scalar basic_node objects. + /// @todo delete this API b/c this can be achieved with constructor with std::initializer_list. static basic_node integer_scalar(const integer_type integer) noexcept { basic_node node; @@ -597,12 +560,8 @@ class basic_node return node; } - /** - * @brief A factory method for float number scalar basic_node objects. - * - * @param[in] float_val A source of unsigned integer type. - * @return basic_node A constructed basic_node object of float number type. - */ + /// @brief A factory method for float number scalar basic_node objects. + /// @todo delete this API b/c this can be achieved with constructor with std::initializer_list. static basic_node float_number_scalar(const float_number_type float_val) noexcept { basic_node node; @@ -611,11 +570,8 @@ class basic_node return node; } - /** - * @brief A factory method for string basic_node objects without string_type objects. - * - * @return basic_node A constructed basic_node object of string type. - */ + /// @brief A factory method for string basic_node objects without string_type objects. + /// @todo delete this API b/c this can be achieved with constructor with std::initializer_list. static basic_node string_scalar() { basic_node node; @@ -625,12 +581,8 @@ class basic_node return node; } // LCOV_EXCL_LINE - /** - * @brief A factory method for string basic_node objects with lvalue string_type objects. - * - * @param[in] str A lvalue source of string type. - * @return basic_node A constructed basic_node object of string type. - */ + /// @brief A factory method for string basic_node objects with lvalue string_type objects. + /// @todo delete this API b/c this can be achieved with constructor with std::initializer_list. static basic_node string_scalar(const string_type& str) { basic_node node; @@ -640,12 +592,8 @@ class basic_node return node; } // LCOV_EXCL_LINE - /** - * @brief A factory method for string basic_node objects with rvalue string_type objects. - * - * @param[in] str A rvalue source of string type. - * @return basic_node A constructed basic_node object of string type. - */ + /// @brief A factory method for string basic_node objects with rvalue string_type objects. + /// @todo delete this API b/c this can be achieved with constructor with std::initializer_list. static basic_node string_scalar(string_type&& str) { basic_node node; @@ -655,13 +603,9 @@ class basic_node return node; } // LCOV_EXCL_LINE - /** - * @brief A factory method for alias basic_node objects referencing the given anchor basic_node object. - * @note The given anchor basic_node must have a non-empty anchor name. - * - * @param anchor_node An anchor node to be referenced by the newly constructed basic_node object. - * @return basic_node A constructed basic_node object of alias type. - */ + /// @brief A factory method for alias basic_node objects referencing the given anchor basic_node object. + /// @note The given anchor basic_node must have a non-empty anchor name. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/alias_of/ static basic_node alias_of(const basic_node& anchor_node) { if (!anchor_node.m_anchor_name || anchor_node.m_anchor_name->empty()) @@ -674,36 +618,24 @@ class basic_node } public: - /** - * @brief A copy assignment operator of the basic_node class. - * - * @param[in] rhs A lvalue basic_node object to be copied with. - * @return basic_node& Reference to this basic_node object. - */ + /// @brief A copy assignment operator of the basic_node class. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/operator=/ basic_node& operator=(const basic_node& rhs) noexcept { basic_node(rhs).swap(*this); return *this; } - /** - * @brief A move assignment operator of the basic_node class. - * - * @param[in] rhs A rvalue basic_node object to be moved from. - * @return basic_node& Reference to this basic_node object. - */ + /// @brief A move assignment operator of the basic_node class. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/operator=/ basic_node& operator=(basic_node&& rhs) noexcept { basic_node(std::move(rhs)).swap(*this); return *this; } - /** - * @brief A subscript operator for non-const basic_node objects. - * - * @param[in] index An index of sequence basic_node values. - * @return basic_node& Reference to a basic_node object located at the specified index. - */ + /// @brief A subscript operator for non-const basic_node objects. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/operator[]/ basic_node& operator[](std::size_t index) // NOLINT(readability-make-member-function-const) { if (!is_sequence()) @@ -716,12 +648,8 @@ class basic_node return m_node_value.p_sequence->operator[](index); } - /** - * @brief A subscript operator for const basic_node objects. - * - * @param[in] index An index of sequence basic_node values. - * @return const basic_node& Constant reference to a basic_node object located at the specified index. - */ + /// @brief A subscript operator for const basic_node objects. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/operator[]/ const basic_node& operator[](std::size_t index) const { if (!is_sequence()) @@ -734,13 +662,8 @@ class basic_node return m_node_value.p_sequence->operator[](index); } - /** - * @brief A subscript operator for non-const basic_node objects. - * - * @tparam KeyType A type for the input key. - * @param[in] key A key to the target basic_node object.. - * @return basic_node& Reference to a basic_node object associated with the given key. - */ + /// @brief A subscript operator for non-const basic_node objects. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/operator[]/ template < typename KeyType, detail::enable_if_t< detail::is_usable_as_key_type< @@ -757,13 +680,8 @@ class basic_node return m_node_value.p_mapping->operator[](std::forward(key)); } - /** - * @brief A subscript operator for const basic_node objects. - * - * @tparam KeyType A type for the input key. - * @param[in] key A key to the basic_node object. - * @return const basic_node& Constant reference to a basic_node object associated with the given key. - */ + /// @brief A subscript operator for const basic_node objects. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/operator[]/ template < typename KeyType, detail::enable_if_t< detail::is_usable_as_key_type< @@ -884,14 +802,8 @@ class basic_node } } - /** - * @brief Check whether or not this basic_node object has a given key in its inner mapping Node value. - * - * @tparam KeyType A type for the input key. - * @param[in] key A key to the target basic_node object. - * @return true If this basic_node object has a given key. - * @return false If this basic_node object does not have a given key. - */ + /// @brief Check whether or not this basic_node object has a given key in its inner mapping Node value. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/contains/ template < typename KeyType, detail::enable_if_t< detail::is_usable_as_key_type< @@ -911,44 +823,31 @@ class basic_node } } - /** - * @brief Get the YAML version specification for this basic_node object. - * - * @return yaml_version_t The YAML version specification. - */ + /// @brief Get the YAML version specification for this basic_node object. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/get_yaml_version/ yaml_version_t get_yaml_version() const noexcept { return m_yaml_version_type; } - /** - * @brief Set the YAML version specification for this basic_node object. - * - * @param version The YAML version specification. - */ + /// @brief Set the YAML version specification for this basic_node object. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/set_yaml_version/ void set_yaml_version(const yaml_version_t version) noexcept { m_yaml_version_type = version; } - /** - * @brief Check whether or not this basic_node object has already had any anchor name. - * - * @return true If this basic_node object has already had any anchor name. - * @return false If this basic_node object has not had any anchor name yet. - */ + /// @brief Check whether or not this basic_node object has already had any anchor name. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/has_anchor_name/ bool has_anchor_name() const noexcept { return m_anchor_name != nullptr; } - /** - * @brief Get the anchor name associated to this basic_node object. - * @note Some anchor name must be set before calling this method. Call basic_node::HasAnchorName() to see if this - * basic_node object has any anchor name. - * - * @return const std::string& Const reference to the anchor name. - */ + /// @brief Get the anchor name associated to this basic_node object. + /// @note Some anchor name must be set before calling this method. Call basic_node::HasAnchorName() to see if this + /// basic_node object has any anchor name. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/get_anchor_name/ const std::string& get_anchor_name() const { if (!m_anchor_name) @@ -958,12 +857,9 @@ class basic_node return *m_anchor_name; } - /** - * @brief Add an anchor name to this basic_node object. - * @note If this basic_node object has already had any anchor name, the new anchor name will overwrite the old one. - * - * @param anchor_name An anchor name associated to this basic_node object. - */ + /// @brief Add an anchor name to this basic_node object. + /// @note If this basic_node object has already had any anchor name, the new anchor name will overwrite the old one. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/add_anchor_name/ void add_anchor_name(const std::string& anchor_name) { destroy_object(m_anchor_name); @@ -971,12 +867,9 @@ class basic_node FK_YAML_ASSERT(m_anchor_name != nullptr); } - /** - * @brief Add an anchor name to this basic_node object. - * @note If this basic_node object has already had any anchor name, the new anchor name will overwrite the old one. - * - * @param anchor_name An anchor name associated to this basic_node object. - */ + /// @brief Add an anchor name to this basic_node object. + /// @note If this basic_node object has already had any anchor name, the new anchor name will overwrite the old one. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/add_anchor_name/ void add_anchor_name(std::string&& anchor_name) { destroy_object(m_anchor_name); @@ -984,14 +877,9 @@ class basic_node FK_YAML_ASSERT(m_anchor_name != nullptr); } - /** - * @brief Get the node value object converted into a given type. - * @note This function requires T objects to be default constructible. - * - * @tparam T A native data type for conversion. - * @tparam ValueType T without cv qualifiers and reference. - * @return T A native data converted from the node value. - */ + /// @brief Get the node value object converted into a given type. + /// @note This function requires T objects to be default constructible. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/get_value/ template < typename T, typename ValueType = detail::remove_cvref_t, detail::enable_if_t< @@ -1006,12 +894,9 @@ class basic_node return ret; } - /** - * @brief Returns reference to sequence basic_node value from a non-const basic_node object. Throws exception if the - * basic_node value is not of sequence type. - * - * @return sequence_type& Reference to sequence basic_node value. - */ + /// @brief Returns reference to sequence basic_node value from a non-const basic_node object. Throws exception if + /// the basic_node value is not of sequence type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_sequence/ sequence_type& to_sequence() // NOLINT(readability-make-member-function-const) { if (!is_sequence()) @@ -1023,12 +908,9 @@ class basic_node return *(m_node_value.p_sequence); } - /** - * @brief Returns reference to sequence basic_node value from a const basic_node object. Throws exception if the - * basic_node value is not of sequence type. - * - * @return const sequence_type& Constant reference to sequence basic_node value. - */ + /// @brief Returns reference to sequence basic_node value from a const basic_node object. Throws exception if the + /// basic_node value is not of sequence type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_sequence/ const sequence_type& to_sequence() const { if (!is_sequence()) @@ -1040,12 +922,9 @@ class basic_node return *(m_node_value.p_sequence); } - /** - * @brief Returns reference to mapping basic_node value from a non-const basic_node object. Throws exception if the - * basic_node value is not of mapping type. - * - * @return mapping_type& Reference to mapping basic_node value. - */ + /// @brief Returns reference to mapping basic_node value from a non-const basic_node object. Throws exception if the + /// basic_node value is not of mapping type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_mapping/ mapping_type& to_mapping() // NOLINT(readability-make-member-function-const) { if (!is_mapping()) @@ -1057,12 +936,9 @@ class basic_node return *(m_node_value.p_mapping); } - /** - * @brief Returns reference to mapping basic_node value from a const basic_node object. Throws exception if the - * basic_node value is not of mapping type. - * - * @return const mapping_type& Constant reference to mapping basic_node value. - */ + /// @brief Returns reference to mapping basic_node value from a const basic_node object. Throws exception if the + /// basic_node value is not of mapping type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_mapping/ const mapping_type& to_mapping() const { if (!is_mapping()) @@ -1074,12 +950,9 @@ class basic_node return *(m_node_value.p_mapping); } - /** - * @brief Returns reference to boolean basic_node value from a non-const basic_node object. Throws exception if the - * basic_node value is not of boolean type. - * - * @return boolean_type& Reference to boolean basic_node value. - */ + /// @brief Returns reference to boolean basic_node value from a non-const basic_node object. Throws exception if the + /// basic_node value is not of boolean type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_boolean/ boolean_type& to_boolean() { if (!is_boolean()) @@ -1090,12 +963,9 @@ class basic_node return m_node_value.boolean; } - /** - * @brief Returns reference to boolean basic_node value from a const basic_node object. Throws exception if the - * basic_node value is not of boolean type. - * - * @return const boolean_type& Constant reference to boolean basic_node value. - */ + /// @brief Returns reference to boolean basic_node value from a const basic_node object. Throws exception if the + /// basic_node value is not of boolean type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_boolean const boolean_type& to_boolean() const { if (!is_boolean()) @@ -1106,12 +976,9 @@ class basic_node return m_node_value.boolean; } - /** - * @brief Returns reference to integer basic_node value from a non-const basic_node object. Throws exception if - * the basic_node value is not of integer type. - * - * @return integer_type& Reference to integer basic_node value. - */ + /// @brief Returns reference to integer basic_node value from a non-const basic_node object. Throws exception if + /// the basic_node value is not of integer type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_integer/ integer_type& to_integer() { if (!is_integer()) @@ -1122,12 +989,9 @@ class basic_node return m_node_value.integer; } - /** - * @brief Returns reference to integer basic_node value from a const basic_node object. Throws exception if the - * basic_node value is not of integer type. - * - * @return const integer_type& Constant reference to integer basic_node value. - */ + /// @brief Returns reference to integer basic_node value from a const basic_node object. Throws exception if the + /// basic_node value is not of integer type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_integer/ const integer_type& to_integer() const { if (!is_integer()) @@ -1138,12 +1002,9 @@ class basic_node return m_node_value.integer; } - /** - * @brief Returns reference to float number basic_node value from a non-const basic_node object. Throws exception if - * the basic_node value is not of float number type. - * - * @return float_number_type& Reference to float number basic_node value. - */ + /// @brief Returns reference to float number basic_node value from a non-const basic_node object. Throws exception + /// if the basic_node value is not of float number type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_float_number/ float_number_type& to_float_number() { if (!is_float_number()) @@ -1154,12 +1015,9 @@ class basic_node return m_node_value.float_val; } - /** - * @brief Returns reference to float number basic_node value from a const basic_node object. Throws exception if the - * basic_node value is not of float number type. - * - * @return const float_number_type& Constant reference to float number basic_node value. - */ + /// @brief Returns reference to float number basic_node value from a const basic_node object. Throws exception if + /// the basic_node value is not of float number type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_float_number/ const float_number_type& to_float_number() const { if (!is_float_number()) @@ -1170,12 +1028,9 @@ class basic_node return m_node_value.float_val; } - /** - * @brief Returns reference to string basic_node value from a non-const basic_node object. Throws exception if the - * basic_node value is not of string type. - * - * @return string_type& Reference to string basic_node value. - */ + /// @brief Returns reference to string basic_node value from a non-const basic_node object. Throws exception if the + /// basic_node value is not of string type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_string/ string_type& to_string() // NOLINT(readability-make-member-function-const) { if (!is_string()) @@ -1187,12 +1042,9 @@ class basic_node return *(m_node_value.p_string); } - /** - * @brief Returns reference to string basic_node value from a const basic_node object. Throws exception if the - * basic_node value is not of string type. - * - * @return const string_type& Constant reference to string basic_node value. - */ + /// @brief Returns reference to string basic_node value from a const basic_node object. Throws exception if the + /// basic_node value is not of string type. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_string/ const string_type& to_string() const { if (!is_string()) @@ -1204,11 +1056,8 @@ class basic_node return *(m_node_value.p_string); } - /** - * @brief Swaps data with the specified basic_node object. - * - * @param[in] rhs A basic_node object to be swapped with. - */ + /// @brief Swaps data with the specified basic_node object. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/swap/ void swap(basic_node& rhs) noexcept { using std::swap; @@ -1296,16 +1145,18 @@ class basic_node } private: - /** The current node value type. */ + /// The current node value type. node_t m_node_type {node_t::NULL_OBJECT}; - /** The YAML version specification. */ + /// The YAML version specification. yaml_version_t m_yaml_version_type {yaml_version_t::VER_1_2}; - /** The current node value. */ + /// The current node value. node_value m_node_value {}; - /** The anchor name for this node. */ + /// The anchor name for this node. std::string* m_anchor_name {nullptr}; }; +/// @brief Swap function for basic_node objects. +/// @sa https://fktn-k.github.io/fkYAML/api/swap/ template < template class SequenceType, template class MappingType, typename BooleanType, typename IntegerType, typename FloatNumberType, typename StringType, @@ -1318,27 +1169,26 @@ inline void swap( lhs.swap(rhs); } -/** - * @brief default YAML node value container. - */ +/// @brief default YAML node value container. +/// @sa https://fktn-k.github.io/fkYAML/api/basic_node/node/ using node = basic_node<>; -/** A default type for sequence node values. */ +/// @brief A default type for sequence node values. using node_sequence_type = typename node::sequence_type; -/** A default type for mapping node values. */ +/// @brief A default type for mapping node values. using node_mapping_type = typename node::mapping_type; -/** A default type for boolean node values. */ +/// @brief A default type for boolean node values. using node_boolean_type = typename node::boolean_type; -/** A default type for integer node values. */ +/// @brief A default type for integer node values. using node_integer_type = typename node::integer_type; -/** A default type for float number node values. */ +/// @brief A default type for float number node values. using node_float_number_type = typename node::float_number_type; -/** A default type for string node values. */ +/// @brief A default type for string node values. using node_string_type = typename node::string_type; FK_YAML_NAMESPACE_END From bf92a7a0ad42ad414126d8262758bfea14c2405b Mon Sep 17 00:00:00 2001 From: fktn Date: Mon, 30 Oct 2023 02:57:23 +0900 Subject: [PATCH 23/48] deleted factory methods for scalar nodes --- include/fkYAML/detail/input/deserializer.hpp | 8 +- include/fkYAML/node.hpp | 65 +---- test/unit_test/test_iterator_class.cpp | 158 ++++-------- test/unit_test/test_node_class.cpp | 248 +++++++++---------- test/unit_test/test_serializer_class.cpp | 37 ++- 5 files changed, 199 insertions(+), 317 deletions(-) diff --git a/include/fkYAML/detail/input/deserializer.hpp b/include/fkYAML/detail/input/deserializer.hpp index 4a7ed3f6..11556936 100644 --- a/include/fkYAML/detail/input/deserializer.hpp +++ b/include/fkYAML/detail/input/deserializer.hpp @@ -202,7 +202,7 @@ class basic_deserializer add_new_key(lexer.get_string(), cur_indent); break; } - assign_node_value(BasicNodeType::boolean_scalar(lexer.get_boolean())); + assign_node_value(BasicNodeType(lexer.get_boolean())); break; case lexical_token_t::INTEGER_VALUE: if (m_current_node->is_mapping()) @@ -210,7 +210,7 @@ class basic_deserializer add_new_key(lexer.get_string(), cur_indent); break; } - assign_node_value(BasicNodeType::integer_scalar(lexer.get_integer())); + assign_node_value(BasicNodeType(lexer.get_integer())); break; case lexical_token_t::FLOAT_NUMBER_VALUE: if (m_current_node->is_mapping()) @@ -218,7 +218,7 @@ class basic_deserializer add_new_key(lexer.get_string(), cur_indent); break; } - assign_node_value(BasicNodeType::float_number_scalar(lexer.get_float_number())); + assign_node_value(BasicNodeType(lexer.get_float_number())); break; case lexical_token_t::STRING_VALUE: if (m_current_node->is_mapping()) @@ -226,7 +226,7 @@ class basic_deserializer add_new_key(lexer.get_string(), cur_indent); break; } - assign_node_value(BasicNodeType::string_scalar(lexer.get_string())); + assign_node_value(BasicNodeType(lexer.get_string())); break; default: // LCOV_EXCL_LINE throw fkyaml::exception("Unsupported lexical token found."); // LCOV_EXCL_LINE diff --git a/include/fkYAML/node.hpp b/include/fkYAML/node.hpp index 546eab71..abfbe704 100644 --- a/include/fkYAML/node.hpp +++ b/include/fkYAML/node.hpp @@ -144,7 +144,7 @@ class basic_node float_val = static_cast(0.0); break; case node_t::STRING: - p_string = create_object(""); + p_string = create_object(); break; default: // LCOV_EXCL_LINE throw fkyaml::exception("Unsupported node value type."); // LCOV_EXCL_LINE @@ -540,69 +540,6 @@ class basic_node return node; } // LCOV_EXCL_LINE - /// @brief A factory method for boolean scalar basic_node objects. - /// @todo delete this API b/c this can be achieved with constructor with std::initializer_list. - static basic_node boolean_scalar(const boolean_type boolean) noexcept - { - basic_node node; - node.m_node_type = node_t::BOOLEAN; - node.m_node_value.boolean = boolean; - return node; - } - - /// @brief A factory method for integer scalar basic_node objects. - /// @todo delete this API b/c this can be achieved with constructor with std::initializer_list. - static basic_node integer_scalar(const integer_type integer) noexcept - { - basic_node node; - node.m_node_type = node_t::INTEGER; - node.m_node_value.integer = integer; - return node; - } - - /// @brief A factory method for float number scalar basic_node objects. - /// @todo delete this API b/c this can be achieved with constructor with std::initializer_list. - static basic_node float_number_scalar(const float_number_type float_val) noexcept - { - basic_node node; - node.m_node_type = node_t::FLOAT_NUMBER; - node.m_node_value.float_val = float_val; - return node; - } - - /// @brief A factory method for string basic_node objects without string_type objects. - /// @todo delete this API b/c this can be achieved with constructor with std::initializer_list. - static basic_node string_scalar() - { - basic_node node; - node.m_node_type = node_t::STRING; - node.m_node_value.p_string = create_object(); - FK_YAML_ASSERT(node.m_node_value.p_string != nullptr); - return node; - } // LCOV_EXCL_LINE - - /// @brief A factory method for string basic_node objects with lvalue string_type objects. - /// @todo delete this API b/c this can be achieved with constructor with std::initializer_list. - static basic_node string_scalar(const string_type& str) - { - basic_node node; - node.m_node_type = node_t::STRING; - node.m_node_value.p_string = create_object(str); - FK_YAML_ASSERT(node.m_node_value.p_string != nullptr); - return node; - } // LCOV_EXCL_LINE - - /// @brief A factory method for string basic_node objects with rvalue string_type objects. - /// @todo delete this API b/c this can be achieved with constructor with std::initializer_list. - static basic_node string_scalar(string_type&& str) - { - basic_node node; - node.m_node_type = node_t::STRING; - node.m_node_value.p_string = create_object(std::move(str)); - FK_YAML_ASSERT(node.m_node_value.p_string != nullptr); - return node; - } // LCOV_EXCL_LINE - /// @brief A factory method for alias basic_node objects referencing the given anchor basic_node object. /// @note The given anchor basic_node must have a non-empty anchor name. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/alias_of/ diff --git a/test/unit_test/test_iterator_class.cpp b/test/unit_test/test_iterator_class.cpp index cc03c1fb..b557f2cf 100644 --- a/test/unit_test/test_iterator_class.cpp +++ b/test/unit_test/test_iterator_class.cpp @@ -50,7 +50,7 @@ TEST_CASE("IteratorClassTest_MappingCopyCtorTest", "[IteratorClassTest]") TEST_CASE("IteratorClassTest_SequenceMoveCtorTest", "[IteratorClassTest]") { - fkyaml::node sequence = fkyaml::node::sequence({fkyaml::node::string_scalar("test")}); + fkyaml::node sequence = {std::string("test")}; fkyaml::detail::iterator moved( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); fkyaml::detail::iterator iterator(std::move(moved)); @@ -94,10 +94,10 @@ TEST_CASE("IteratorClassTest_AssignmentOperatorTest", "[IteratorClassTest]") SECTION("Test sequence iterators.") { - fkyaml::node copied_seq = fkyaml::node::sequence({fkyaml::node::string_scalar("test")}); + fkyaml::node copied_seq = {std::string("test")}; fkyaml::detail::iterator copied_itr( fkyaml::detail::sequence_iterator_tag {}, copied_seq.to_sequence().begin()); - fkyaml::node sequence = fkyaml::node::sequence({fkyaml::node::boolean_scalar(false)}); + fkyaml::node sequence = {false}; fkyaml::detail::iterator iterator( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); @@ -120,10 +120,10 @@ TEST_CASE("IteratorClassTest_AssignmentOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterators.") { - fkyaml::node copied_map = fkyaml::node::mapping({{"key", fkyaml::node::string_scalar("test")}}); + fkyaml::node copied_map = {{std::string("key"), std::string("test")}}; fkyaml::detail::iterator copied_itr( fkyaml::detail::mapping_iterator_tag {}, copied_map.to_mapping().begin()); - fkyaml::node map = fkyaml::node::mapping({{"foo", fkyaml::node::boolean_scalar(false)}}); + fkyaml::node map = {{std::string("foo"), false}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, map.to_mapping().begin()); @@ -151,7 +151,7 @@ TEST_CASE("IteratorClassTest_ArrowOperatorTest", "[IteratorClassTest]") { SECTION("Test sequence iterator.") { - fkyaml::node seq = fkyaml::node::sequence({fkyaml::node::string_scalar("test")}); + fkyaml::node seq = {std::string("test")}; fkyaml::detail::iterator iterator( fkyaml::detail::sequence_iterator_tag {}, seq.to_sequence().begin()); REQUIRE(iterator.operator->() == &(seq.to_sequence().operator[](0))); @@ -159,7 +159,7 @@ TEST_CASE("IteratorClassTest_ArrowOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node map = fkyaml::node::mapping({{"key", fkyaml::node::string_scalar("test")}}); + fkyaml::node map = {{std::string("key"), std::string("test")}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, map.to_mapping().begin()); REQUIRE(iterator.operator->() == &(map.to_mapping().operator[]("key"))); @@ -170,7 +170,7 @@ TEST_CASE("IteratorClassTest_DereferenceOperatorTest", "[IteratorClassTest]") { SECTION("Test sequence iterator.") { - fkyaml::node seq = fkyaml::node::sequence({fkyaml::node::string_scalar("test")}); + fkyaml::node seq = {std::string("test")}; fkyaml::detail::iterator iterator( fkyaml::detail::sequence_iterator_tag {}, seq.to_sequence().begin()); REQUIRE(&(iterator.operator*()) == &(seq.to_sequence().operator[](0))); @@ -178,7 +178,7 @@ TEST_CASE("IteratorClassTest_DereferenceOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node map = fkyaml::node::mapping({{"key", fkyaml::node::string_scalar("test")}}); + fkyaml::node map = fkyaml::node::mapping({{"key", std::string("test")}}); fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, map.to_mapping().begin()); REQUIRE(&(iterator.operator*()) == &(map.to_mapping().operator[]("key"))); @@ -189,8 +189,7 @@ TEST_CASE("IteratorClassTest_CompoundAssignmentOperatorBySumTest", "[IteratorCla { SECTION("Test sequence iterator.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); iterator += 1; @@ -200,8 +199,7 @@ TEST_CASE("IteratorClassTest_CompoundAssignmentOperatorBySumTest", "[IteratorCla SECTION("Test mapping iterator.") { - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); iterator += 1; @@ -215,8 +213,7 @@ TEST_CASE("IteratorClassTest_PlusOperatorTest", "[IteratorClassTest]") { SECTION("Test sequence iterator.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); fkyaml::detail::iterator after_plus_itr = iterator + 1; @@ -226,8 +223,7 @@ TEST_CASE("IteratorClassTest_PlusOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); fkyaml::detail::iterator after_plus_itr = iterator + 1; @@ -241,8 +237,7 @@ TEST_CASE("IteratorClassTest_PreIncrementOperatorTest", "[IteratorClassTest]") { SECTION("Test sequence iterator.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); ++iterator; @@ -252,8 +247,7 @@ TEST_CASE("IteratorClassTest_PreIncrementOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); ++iterator; @@ -267,8 +261,7 @@ TEST_CASE("IteratorClassTest_PostIncrementOperatorTest", "[IteratorClassTest]") { SECTION("Test sequence iterator.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); iterator++; @@ -278,8 +271,7 @@ TEST_CASE("IteratorClassTest_PostIncrementOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); iterator++; @@ -289,14 +281,11 @@ TEST_CASE("IteratorClassTest_PostIncrementOperatorTest", "[IteratorClassTest]") } } -// FIXME - TEST_CASE("IteratorClassTest_CompoundAssignmentOperatorByDifferenceTest", "[IteratorClassTest]") { SECTION("Test sequence iterator.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().end()); iterator -= 1; @@ -306,8 +295,7 @@ TEST_CASE("IteratorClassTest_CompoundAssignmentOperatorByDifferenceTest", "[Iter SECTION("Test mapping iterator.") { - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().end()); iterator -= 1; @@ -321,8 +309,7 @@ TEST_CASE("IteratorClassTest_MinusOperatorTest", "[IteratorClassTest]") { SECTION("Test sequence iterator.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().end()); fkyaml::detail::iterator after_minus_itr = iterator - 1; @@ -332,8 +319,7 @@ TEST_CASE("IteratorClassTest_MinusOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().end()); fkyaml::detail::iterator after_minus_itr = iterator - 1; @@ -347,8 +333,7 @@ TEST_CASE("IteratorClassTest_PreDecrementOperatorTest", "[IteratorClassTest]") { SECTION("Test sequence iterator.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().end()); --iterator; @@ -358,8 +343,7 @@ TEST_CASE("IteratorClassTest_PreDecrementOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().end()); --iterator; @@ -373,8 +357,7 @@ TEST_CASE("IteratorClassTest_PostDecrementOperatorTest", "[IteratorClassTest]") { SECTION("Test sequence iterator.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().end()); iterator--; @@ -384,8 +367,7 @@ TEST_CASE("IteratorClassTest_PostDecrementOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().end()); iterator--; @@ -399,8 +381,7 @@ TEST_CASE("IteratorClassTest_EqualToOperatorTest", "[IteratorClassTest]") { SECTION("Test sequence iterator.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); fkyaml::detail::iterator rhs( @@ -410,8 +391,7 @@ TEST_CASE("IteratorClassTest_EqualToOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator lhs( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); fkyaml::detail::iterator rhs( @@ -421,12 +401,10 @@ TEST_CASE("IteratorClassTest_EqualToOperatorTest", "[IteratorClassTest]") SECTION("Test equality check between different type iterators.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator rhs( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); REQUIRE_THROWS_AS(lhs == rhs, fkyaml::exception); @@ -437,8 +415,7 @@ TEST_CASE("IteratorClassTest_NotEqualToOperatorTest", "[IteratorClassTest]") { SECTION("Test sequence iterator.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); fkyaml::detail::iterator rhs( @@ -449,8 +426,7 @@ TEST_CASE("IteratorClassTest_NotEqualToOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator lhs( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); fkyaml::detail::iterator rhs( @@ -461,12 +437,10 @@ TEST_CASE("IteratorClassTest_NotEqualToOperatorTest", "[IteratorClassTest]") SECTION("Test equality check between different type iterators.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator rhs( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); REQUIRE_THROWS_AS(lhs == rhs, fkyaml::exception); @@ -477,8 +451,7 @@ TEST_CASE("IteratorClassTest_LessThanOperatorTest", "[IteratorClassTest]") { SECTION("Test sequence iterator.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); fkyaml::detail::iterator rhs( @@ -490,8 +463,7 @@ TEST_CASE("IteratorClassTest_LessThanOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator lhs( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); fkyaml::detail::iterator rhs( @@ -501,12 +473,10 @@ TEST_CASE("IteratorClassTest_LessThanOperatorTest", "[IteratorClassTest]") SECTION("Test less-than check between different type iterators.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator rhs( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); REQUIRE_THROWS_AS(lhs < rhs, fkyaml::exception); @@ -517,8 +487,7 @@ TEST_CASE("IteratorClassTest_LessThanOrEqualToOperatorTest", "[IteratorClassTest { SECTION("Test sequence iterator.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); fkyaml::detail::iterator rhs( @@ -533,8 +502,7 @@ TEST_CASE("IteratorClassTest_LessThanOrEqualToOperatorTest", "[IteratorClassTest SECTION("Test mapping iterator.") { - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator lhs( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); fkyaml::detail::iterator rhs( @@ -544,12 +512,10 @@ TEST_CASE("IteratorClassTest_LessThanOrEqualToOperatorTest", "[IteratorClassTest SECTION("Test less-than-or-equal-to check between different type iterators.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator rhs( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); REQUIRE_THROWS_AS(lhs <= rhs, fkyaml::exception); @@ -560,8 +526,7 @@ TEST_CASE("IteratorClassTest_GreaterThanOperatorTest", "[IteratorClassTest]") { SECTION("Test sequence iterator.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); fkyaml::detail::iterator rhs( @@ -573,8 +538,7 @@ TEST_CASE("IteratorClassTest_GreaterThanOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator lhs( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); fkyaml::detail::iterator rhs( @@ -584,12 +548,10 @@ TEST_CASE("IteratorClassTest_GreaterThanOperatorTest", "[IteratorClassTest]") SECTION("Test greater-than check between different type iterators.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator rhs( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); REQUIRE_THROWS_AS(lhs > rhs, fkyaml::exception); @@ -600,8 +562,7 @@ TEST_CASE("IteratorClassTest_GreaterThanOrEqualToOperatorTest", "[IteratorClassT { SECTION("Test sequence iterator.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); fkyaml::detail::iterator rhs( @@ -616,8 +577,7 @@ TEST_CASE("IteratorClassTest_GreaterThanOrEqualToOperatorTest", "[IteratorClassT SECTION("Test mapping iterator.") { - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator lhs( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); fkyaml::detail::iterator rhs( @@ -627,12 +587,10 @@ TEST_CASE("IteratorClassTest_GreaterThanOrEqualToOperatorTest", "[IteratorClassT SECTION("Test greater-than-or-equal-to check between different type iterators.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator rhs( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); REQUIRE_THROWS_AS(lhs >= rhs, fkyaml::exception); @@ -643,8 +601,7 @@ TEST_CASE("IteratorClassTest_TypeGetterTest", "[IteratorClassTest]") { SECTION("Test sequence iterator.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); REQUIRE(iterator.type() == fkyaml::detail::iterator_t::SEQUENCE); @@ -652,8 +609,7 @@ TEST_CASE("IteratorClassTest_TypeGetterTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); REQUIRE(iterator.type() == fkyaml::detail::iterator_t::MAPPING); @@ -664,8 +620,7 @@ TEST_CASE("IteratorClassTest_KeyGetterTest", "[IteratorClassTest]") { SECTION("Test sequence iterator.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); REQUIRE_THROWS_AS(iterator.key(), fkyaml::exception); @@ -673,8 +628,7 @@ TEST_CASE("IteratorClassTest_KeyGetterTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); REQUIRE_NOTHROW(iterator.key()); @@ -686,8 +640,7 @@ TEST_CASE("IteratorClassTest_ValueGetterTest", "[IteratorClassTest]") { SECTION("Test sequence iterator.") { - fkyaml::node sequence = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(false), fkyaml::node::boolean_scalar(true)}); + fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); REQUIRE(iterator.value().is_boolean()); @@ -696,8 +649,7 @@ TEST_CASE("IteratorClassTest_ValueGetterTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = fkyaml::node::mapping( - {{"test0", fkyaml::node::boolean_scalar(false)}, {"test1", fkyaml::node::boolean_scalar(true)}}); + fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); REQUIRE(iterator.value().is_boolean()); diff --git a/test/unit_test/test_node_class.cpp b/test/unit_test/test_node_class.cpp index d16ea8bb..a2eec2ff 100644 --- a/test/unit_test/test_node_class.cpp +++ b/test/unit_test/test_node_class.cpp @@ -84,7 +84,7 @@ TEST_CASE("NodeClassTest_ThrowingSpecializationTypeCtorTest", "[NodeClassTest]") }; using NodeType = fkyaml::basic_node; - REQUIRE_THROWS_AS(NodeType::string_scalar(), fkyaml::exception); + REQUIRE_THROWS_AS(NodeType(NodeType::node_t::STRING), fkyaml::exception); } TEST_CASE("NodeClassTest_SequenceCtorTest", "[NodeClassTest]") @@ -152,8 +152,7 @@ TEST_CASE("NodeClassTest_StringCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_SequenceCopyCtorTest", "[NodeClassTest]") { - fkyaml::node copied = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(true), fkyaml::node::string_scalar("test")}); + fkyaml::node copied = {true, std::string("test")}; fkyaml::node node(copied); REQUIRE(node.is_sequence()); REQUIRE_NOTHROW(node.size()); @@ -172,8 +171,7 @@ TEST_CASE("NodeClassTest_SequenceCopyCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_MappingCopyCtorTest", "[NodeClassTest]") { - fkyaml::node copied = fkyaml::node::mapping( - {{"test0", fkyaml::node::integer_scalar(123)}, {"test1", fkyaml::node::float_number_scalar(3.14)}}); + fkyaml::node copied = {{std::string("test0"), 123}, {std::string("test1"), 3.14}}; fkyaml::node node(copied); REQUIRE(node.is_mapping()); REQUIRE_NOTHROW(node.size()); @@ -197,7 +195,7 @@ TEST_CASE("NodeClassTest_NullCopyCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_BooleanCopyCtorTest", "[NodeClassTest]") { - fkyaml::node copied = fkyaml::node::boolean_scalar(true); + fkyaml::node copied = true; fkyaml::node node(copied); REQUIRE(node.is_boolean()); REQUIRE_NOTHROW(node.to_boolean()); @@ -206,7 +204,7 @@ TEST_CASE("NodeClassTest_BooleanCopyCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_IntegerCopyCtorTest", "[NodeClassTest]") { - fkyaml::node copied = fkyaml::node::integer_scalar(123); + fkyaml::node copied = 123; fkyaml::node node(copied); REQUIRE(node.is_integer()); REQUIRE_NOTHROW(node.to_integer()); @@ -215,7 +213,7 @@ TEST_CASE("NodeClassTest_IntegerCopyCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_FloatNumberCopyCtorTest", "[NodeClassTest]") { - fkyaml::node copied = fkyaml::node::float_number_scalar(3.14); + fkyaml::node copied = 3.14; fkyaml::node node(copied); REQUIRE(node.is_float_number()); REQUIRE_NOTHROW(node.to_float_number()); @@ -224,7 +222,7 @@ TEST_CASE("NodeClassTest_FloatNumberCopyCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_StringCopyCtorTest", "[NodeClassTest]") { - fkyaml::node copied = fkyaml::node::string_scalar("test"); + fkyaml::node copied = std::string("test"); fkyaml::node node(copied); REQUIRE(node.is_string()); REQUIRE_NOTHROW(node.size()); @@ -235,7 +233,7 @@ TEST_CASE("NodeClassTest_StringCopyCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_AliasCopyCtorTest", "[NodeClassTest]") { - fkyaml::node tmp = fkyaml::node::boolean_scalar(true); + fkyaml::node tmp = true; tmp.add_anchor_name("anchor_name"); fkyaml::node tmp_alias = fkyaml::node::alias_of(tmp); fkyaml::node alias(tmp_alias); @@ -246,8 +244,7 @@ TEST_CASE("NodeClassTest_AliasCopyCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_SequenceMoveCtorTest", "[NodeClassTest]") { - fkyaml::node moved = - fkyaml::node::sequence({fkyaml::node::boolean_scalar(true), fkyaml::node::string_scalar("test")}); + fkyaml::node moved = {true, std::string("test")}; fkyaml::node node(std::move(moved)); REQUIRE(node.is_sequence()); REQUIRE_NOTHROW(node.size()); @@ -266,8 +263,7 @@ TEST_CASE("NodeClassTest_SequenceMoveCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_MappingMoveCtorTest", "[NodeClassTest]") { - fkyaml::node moved = fkyaml::node::mapping( - {{"test0", fkyaml::node::integer_scalar(123)}, {"test1", fkyaml::node::float_number_scalar(3.14)}}); + fkyaml::node moved = {{std::string("test0"), 123}, {std::string("test1"), 3.14}}; fkyaml::node node(std::move(moved)); REQUIRE(node.is_mapping()); REQUIRE_NOTHROW(node.size()); @@ -291,7 +287,7 @@ TEST_CASE("NodeClassTest_NullMoveCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_BooleanMoveCtorTest", "[NodeClassTest]") { - fkyaml::node moved = fkyaml::node::boolean_scalar(true); + fkyaml::node moved = true; fkyaml::node node(std::move(moved)); REQUIRE(node.is_boolean()); REQUIRE_NOTHROW(node.to_boolean()); @@ -300,7 +296,7 @@ TEST_CASE("NodeClassTest_BooleanMoveCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_IntegerMoveCtorTest", "[NodeClassTest]") { - fkyaml::node moved = fkyaml::node::integer_scalar(123); + fkyaml::node moved = 123; fkyaml::node node(std::move(moved)); REQUIRE(node.is_integer()); REQUIRE_NOTHROW(node.to_integer()); @@ -309,7 +305,7 @@ TEST_CASE("NodeClassTest_IntegerMoveCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_FloatNumberMoveCtorTest", "[NodeClassTest]") { - fkyaml::node moved = fkyaml::node::float_number_scalar(3.14); + fkyaml::node moved = 3.14; fkyaml::node node(std::move(moved)); REQUIRE(node.is_float_number()); REQUIRE_NOTHROW(node.to_float_number()); @@ -318,7 +314,7 @@ TEST_CASE("NodeClassTest_FloatNumberMoveCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_StringMoveCtorTest", "[NodeClassTest]") { - fkyaml::node moved = fkyaml::node::string_scalar("test"); + fkyaml::node moved = std::string("test"); fkyaml::node node(std::move(moved)); REQUIRE(node.is_string()); REQUIRE_NOTHROW(node.size()); @@ -329,7 +325,7 @@ TEST_CASE("NodeClassTest_StringMoveCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_AliasMoveCtorTest", "[NodeClassTest]") { - fkyaml::node tmp = fkyaml::node::boolean_scalar(true); + fkyaml::node tmp = true; tmp.add_anchor_name("anchor_name"); fkyaml::node tmp_alias = fkyaml::node::alias_of(tmp); fkyaml::node alias(std::move(tmp_alias)); @@ -344,6 +340,7 @@ TEST_CASE("NodeClassTest_InitializerListCtorTest", "[NodeClassTest]") {std::string("foo"), 3.14}, {std::string("bar"), 123}, {std::string("baz"), {true, false}}, + {std::string("qux"), nullptr}, }; REQUIRE(node.contains("foo")); @@ -361,6 +358,9 @@ TEST_CASE("NodeClassTest_InitializerListCtorTest", "[NodeClassTest]") REQUIRE(node["baz"].to_sequence()[0].to_boolean() == true); REQUIRE(node["baz"].to_sequence()[1].is_boolean()); REQUIRE(node["baz"].to_sequence()[1].to_boolean() == false); + + REQUIRE(node.contains("qux")); + REQUIRE(node["qux"].is_null()); } // @@ -446,7 +446,7 @@ TEST_CASE("NodeClassTest_MappingNodeFactoryTest", "[NodeClassTest]") SECTION("Test non-empty mapping node factory methods.") { - fkyaml::node_mapping_type map {{std::string("test"), fkyaml::node::boolean_scalar(true)}}; + fkyaml::node_mapping_type map {{std::string("test"), true}}; SECTION("Test lvalue mapping node factory method.") { @@ -471,7 +471,7 @@ TEST_CASE("NodeClassTest_MappingNodeFactoryTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_BooleanNodeFactoryTest", "[NodeClassTest]") { auto boolean = GENERATE(true, false); - fkyaml::node node = fkyaml::node::boolean_scalar(boolean); + fkyaml::node node = boolean; REQUIRE(node.is_boolean()); REQUIRE(node.to_boolean() == boolean); } @@ -482,7 +482,7 @@ TEST_CASE("NodeClassTest_IntegerNodeFactoryTest", "[NodeClassTest]") std::numeric_limits::min(), 0, std::numeric_limits::max()); - fkyaml::node node = fkyaml::node::integer_scalar(integer); + fkyaml::node node = integer; REQUIRE(node.is_integer()); REQUIRE(node.to_integer() == integer); } @@ -493,7 +493,7 @@ TEST_CASE("NodeClassTest_FloatNumberNodeFactoryTest", "[NodeClassTest]") std::numeric_limits::min(), 3.141592, std::numeric_limits::max()); - fkyaml::node node = fkyaml::node::float_number_scalar(float_val); + fkyaml::node node = float_val; REQUIRE(node.is_float_number()); REQUIRE(node.to_float_number() == float_val); } @@ -502,7 +502,7 @@ TEST_CASE("NodeClassTest_StringNodeFactoryTest", "[NodeClassTest]") { SECTION("Test empty string node factory method.") { - fkyaml::node node = fkyaml::node::string_scalar(); + fkyaml::node node = std::string(); REQUIRE(node.is_string()); REQUIRE(node.size() == 0); } @@ -510,7 +510,7 @@ TEST_CASE("NodeClassTest_StringNodeFactoryTest", "[NodeClassTest]") SECTION("Test lvalue string node factory method.") { fkyaml::node_string_type str("test"); - fkyaml::node node = fkyaml::node::string_scalar(str); + fkyaml::node node = std::string(str); REQUIRE(node.is_string()); REQUIRE(node.size() == str.size()); REQUIRE(node.to_string() == str); @@ -518,7 +518,7 @@ TEST_CASE("NodeClassTest_StringNodeFactoryTest", "[NodeClassTest]") SECTION("Test rvalue string node factory method.") { - fkyaml::node node = fkyaml::node::string_scalar("test"); + fkyaml::node node = std::string("test"); REQUIRE(node.is_string()); REQUIRE(node.size() == 4); REQUIRE(node.to_string().compare("test") == 0); @@ -527,7 +527,7 @@ TEST_CASE("NodeClassTest_StringNodeFactoryTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_AliasNodeFactoryTest", "[NodeClassTest]") { - fkyaml::node anchor = fkyaml::node::string_scalar("alias_test"); + fkyaml::node anchor = std::string("alias_test"); SECTION("Make sure BasicNode::alias_of() throws an exception without anchor name.") { @@ -620,10 +620,10 @@ TEST_CASE("NodeClassTest_StringSubscriptOperatorTest", "[NodeClassTest]") auto node = GENERATE( fkyaml::node::sequence(), fkyaml::node(), - fkyaml::node::boolean_scalar(false), - fkyaml::node::integer_scalar(0), - fkyaml::node::float_number_scalar(0.0), - fkyaml::node::string_scalar()); + fkyaml::node(false), + fkyaml::node(0), + fkyaml::node(0.0), + fkyaml::node(std::string())); SECTION("Test non-const lvalue throwing invocation.") { @@ -689,10 +689,10 @@ TEST_CASE("NodeClassTest_IntegerSubscriptOperatorTest", "[NodeClassTest]") auto node = GENERATE( fkyaml::node::mapping(), fkyaml::node(), - fkyaml::node::boolean_scalar(false), - fkyaml::node::integer_scalar(0), - fkyaml::node::float_number_scalar(0.0), - fkyaml::node::string_scalar()); + fkyaml::node(false), + fkyaml::node(0), + fkyaml::node(0.0), + fkyaml::node(std::string())); SECTION("Test non-const non-sequence nodes.") { @@ -718,10 +718,10 @@ TEST_CASE("NodeClassTest_TypeGetterTest", "[NodeClassTest]") NodeTypePair(fkyaml::node::sequence(), fkyaml::node::node_t::SEQUENCE), NodeTypePair(fkyaml::node::mapping(), fkyaml::node::node_t::MAPPING), NodeTypePair(fkyaml::node(), fkyaml::node::node_t::NULL_OBJECT), - NodeTypePair(fkyaml::node::boolean_scalar(false), fkyaml::node::node_t::BOOLEAN), - NodeTypePair(fkyaml::node::integer_scalar(0), fkyaml::node::node_t::INTEGER), - NodeTypePair(fkyaml::node::float_number_scalar(0.0), fkyaml::node::node_t::FLOAT_NUMBER), - NodeTypePair(fkyaml::node::string_scalar(), fkyaml::node::node_t::STRING)); + NodeTypePair(fkyaml::node(false), fkyaml::node::node_t::BOOLEAN), + NodeTypePair(fkyaml::node(0), fkyaml::node::node_t::INTEGER), + NodeTypePair(fkyaml::node(0.0), fkyaml::node::node_t::FLOAT_NUMBER), + NodeTypePair(fkyaml::node(std::string()), fkyaml::node::node_t::STRING)); SECTION("Test non-alias node types.") { @@ -760,10 +760,10 @@ TEST_CASE("NodeClassTest_is_sequenceTest", "[NodeClassTest]") auto node = GENERATE( fkyaml::node::mapping(), fkyaml::node(), - fkyaml::node::boolean_scalar(false), - fkyaml::node::integer_scalar(0), - fkyaml::node::float_number_scalar(0.0), - fkyaml::node::string_scalar()); + fkyaml::node(false), + fkyaml::node(0), + fkyaml::node(0.0), + fkyaml::node(std::string())); SECTION("Test non-alias non-sequence node types") { @@ -803,10 +803,10 @@ TEST_CASE("NodeClassTest_is_mappingTest", "[NodeClassTest]") auto node = GENERATE( fkyaml::node::sequence(), fkyaml::node(), - fkyaml::node::boolean_scalar(false), - fkyaml::node::integer_scalar(0), - fkyaml::node::float_number_scalar(0.0), - fkyaml::node::string_scalar()); + fkyaml::node(false), + fkyaml::node(0), + fkyaml::node(0.0), + fkyaml::node(std::string())); SECTION("Test non-alias non-mapping node types") { @@ -846,10 +846,10 @@ TEST_CASE("NodeClassTest_is_nullTest", "[NodeClassTest]") auto node = GENERATE( fkyaml::node::sequence(), fkyaml::node::mapping(), - fkyaml::node::boolean_scalar(false), - fkyaml::node::integer_scalar(0), - fkyaml::node::float_number_scalar(0.0), - fkyaml::node::string_scalar()); + fkyaml::node(false), + fkyaml::node(0), + fkyaml::node(0.0), + fkyaml::node(std::string())); SECTION("Test non-alias non-null node types") { @@ -869,7 +869,7 @@ TEST_CASE("NodeClassTest_is_booleanTest", "[NodeClassTest]") { SECTION("Test boolean node type.") { - fkyaml::node node = fkyaml::node::boolean_scalar(false); + fkyaml::node node = false; SECTION("Test non-alias boolean node type.") { @@ -890,9 +890,9 @@ TEST_CASE("NodeClassTest_is_booleanTest", "[NodeClassTest]") fkyaml::node::sequence(), fkyaml::node::mapping(), fkyaml::node(), - fkyaml::node::integer_scalar(0), - fkyaml::node::float_number_scalar(0.0), - fkyaml::node::string_scalar()); + fkyaml::node(0), + fkyaml::node(0.0), + fkyaml::node(std::string())); SECTION("Test non-alias non-boolean node types") { @@ -912,7 +912,7 @@ TEST_CASE("NodeClassTest_is_integerTest", "[NodeClassTest]") { SECTION("Test integer node type.") { - fkyaml::node node = fkyaml::node::integer_scalar(0); + fkyaml::node node = 0; SECTION("Test non-alias integer node type.") { @@ -933,9 +933,9 @@ TEST_CASE("NodeClassTest_is_integerTest", "[NodeClassTest]") fkyaml::node::sequence(), fkyaml::node::mapping(), fkyaml::node(), - fkyaml::node::boolean_scalar(false), - fkyaml::node::float_number_scalar(0.0), - fkyaml::node::string_scalar()); + fkyaml::node(false), + fkyaml::node(0.0), + fkyaml::node(std::string())); SECTION("Test non-alias non-integer node types") { @@ -955,7 +955,7 @@ TEST_CASE("NodeClassTest_IsFloatNumberTest", "[NodeClassTest]") { SECTION("Test float number node type.") { - fkyaml::node node = fkyaml::node::float_number_scalar(0.0); + fkyaml::node node = 0.0; SECTION("Test non-alias float number node type.") { @@ -976,9 +976,9 @@ TEST_CASE("NodeClassTest_IsFloatNumberTest", "[NodeClassTest]") fkyaml::node::sequence(), fkyaml::node::mapping(), fkyaml::node(), - fkyaml::node::boolean_scalar(false), - fkyaml::node::integer_scalar(0), - fkyaml::node::string_scalar()); + fkyaml::node(false), + fkyaml::node(0), + fkyaml::node(std::string())); SECTION("Test non-alias non-float-number node types") { @@ -998,7 +998,7 @@ TEST_CASE("NodeClassTest_IsStringTest", "[NodeClassTest]") { SECTION("Test string node type.") { - fkyaml::node node = fkyaml::node::string_scalar(); + fkyaml::node node = std::string(); SECTION("Test non-alias string node type.") { @@ -1019,9 +1019,9 @@ TEST_CASE("NodeClassTest_IsStringTest", "[NodeClassTest]") fkyaml::node::sequence(), fkyaml::node::mapping(), fkyaml::node(), - fkyaml::node::boolean_scalar(false), - fkyaml::node::integer_scalar(0), - fkyaml::node::float_number_scalar(0.0)); + fkyaml::node(false), + fkyaml::node(0), + fkyaml::node(0.0)); SECTION("Test non-alias non-string node types") { @@ -1043,10 +1043,10 @@ TEST_CASE("NodeClassTest_is_scalarTest", "[NodeClassTest]") { auto node = GENERATE( fkyaml::node(), - fkyaml::node::boolean_scalar(false), - fkyaml::node::integer_scalar(0), - fkyaml::node::float_number_scalar(0.0), - fkyaml::node::string_scalar()); + fkyaml::node(false), + fkyaml::node(0), + fkyaml::node(0.0), + fkyaml::node(std::string())); SECTION("Test non-alias scalar node types.") { @@ -1085,10 +1085,10 @@ TEST_CASE("NodeClassTest_IsAliasTest", "[NodeClassTest]") fkyaml::node::sequence(), fkyaml::node::mapping(), fkyaml::node(), - fkyaml::node::boolean_scalar(false), - fkyaml::node::integer_scalar(0), - fkyaml::node::float_number_scalar(0.0), - fkyaml::node::string_scalar()); + fkyaml::node(false), + fkyaml::node(0), + fkyaml::node(0.0), + fkyaml::node(std::string())); SECTION("Test alias node types.") { @@ -1107,7 +1107,7 @@ TEST_CASE("NodeClassTest_emptyTest", "[NodeClassTest]") { SECTION("Test empty container node emptiness.") { - auto node = GENERATE(fkyaml::node::sequence(), fkyaml::node::mapping(), fkyaml::node::string_scalar()); + auto node = GENERATE(fkyaml::node::sequence(), fkyaml::node::mapping(), fkyaml::node(std::string())); SECTION("Test empty non-alias container node emptiness.") { @@ -1129,7 +1129,7 @@ TEST_CASE("NodeClassTest_emptyTest", "[NodeClassTest]") auto node = GENERATE( fkyaml::node::sequence(fkyaml::node_sequence_type(3)), fkyaml::node::mapping(fkyaml::node_mapping_type {{"test", fkyaml::node()}}), - fkyaml::node::string_scalar("test")); + fkyaml::node(std::string("test"))); SECTION("Test non-empty non-alias container node emptiness.") { @@ -1151,9 +1151,9 @@ TEST_CASE("NodeClassTest_emptyTest", "[NodeClassTest]") { auto node = GENERATE( fkyaml::node(), - fkyaml::node::boolean_scalar(false), - fkyaml::node::integer_scalar(0), - fkyaml::node::float_number_scalar(0.0)); + fkyaml::node(false), + fkyaml::node(0), + fkyaml::node(0.0)); SECTION("Test non-const non-alias non-container node emptiness.") { @@ -1223,10 +1223,10 @@ TEST_CASE("NodeClassTest_ContainsTest", "[NodeClassTest]") auto node = GENERATE( fkyaml::node::sequence(), fkyaml::node(), - fkyaml::node::boolean_scalar(false), - fkyaml::node::integer_scalar(0), - fkyaml::node::float_number_scalar(0.0), - fkyaml::node::string_scalar()); + fkyaml::node(false), + fkyaml::node(0), + fkyaml::node(0.0), + fkyaml::node(std::string())); std::string key = "test"; SECTION("Test non-alias non-mapping node with lvalue key.") @@ -1266,7 +1266,7 @@ TEST_CASE("NodeClassTest_sizeGetterTest", "[NodeClassTest]") auto node = GENERATE( fkyaml::node::sequence({fkyaml::node(), fkyaml::node(), fkyaml::node()}), fkyaml::node::mapping({{"test0", fkyaml::node()}, {"test1", fkyaml::node()}, {"test2", fkyaml::node()}}), - fkyaml::node::string_scalar("tmp")); + fkyaml::node(std::string("tmp"))); SECTION("Test container node size.") { @@ -1302,9 +1302,9 @@ TEST_CASE("NodeClassTest_sizeGetterTest", "[NodeClassTest]") { auto node = GENERATE( fkyaml::node(), - fkyaml::node::boolean_scalar(false), - fkyaml::node::integer_scalar(0), - fkyaml::node::float_number_scalar(0.0)); + fkyaml::node(false), + fkyaml::node(0), + fkyaml::node(0.0)); SECTION("Test non-const non-alias non-container node size.") { @@ -1692,10 +1692,10 @@ TEST_CASE("NodeClassTest_ToSequenceTest", "[NodeClassTest]") auto node = GENERATE( fkyaml::node::mapping(), fkyaml::node(), - fkyaml::node::boolean_scalar(false), - fkyaml::node::integer_scalar(0), - fkyaml::node::float_number_scalar(0.0), - fkyaml::node::string_scalar()); + fkyaml::node(false), + fkyaml::node(0), + fkyaml::node(0.0), + fkyaml::node(std::string())); SECTION("Test non-alias non-sequence nodes.") { @@ -1777,10 +1777,10 @@ TEST_CASE("NodeClassTest_ToMappingTest", "[NodeClassTest]") auto node = GENERATE( fkyaml::node::sequence(), fkyaml::node(), - fkyaml::node::boolean_scalar(false), - fkyaml::node::integer_scalar(0), - fkyaml::node::float_number_scalar(0.0), - fkyaml::node::string_scalar()); + fkyaml::node(false), + fkyaml::node(0), + fkyaml::node(0.0), + fkyaml::node(std::string())); SECTION("Test non-alias non-mapping nodes.") { @@ -1813,7 +1813,7 @@ TEST_CASE("NodeClassTest_ToBooleanTest", "[NodeClassTest]") { SECTION("Test nothrow expected nodes.") { - fkyaml::node node = fkyaml::node::boolean_scalar(true); + fkyaml::node node = true; SECTION("Test non-alias boolean node.") { @@ -1851,9 +1851,9 @@ TEST_CASE("NodeClassTest_ToBooleanTest", "[NodeClassTest]") fkyaml::node::sequence(), fkyaml::node::mapping(), fkyaml::node(), - fkyaml::node::integer_scalar(0), - fkyaml::node::float_number_scalar(0.0), - fkyaml::node::string_scalar()); + fkyaml::node(0), + fkyaml::node(0.0), + fkyaml::node(std::string())); SECTION("Test non-alias non-boolean nodes.") { @@ -1887,7 +1887,7 @@ TEST_CASE("NodeClassTest_ToIntegerTest", "[NodeClassTest]") SECTION("Test nothrow expected nodes.") { fkyaml::node_integer_type integer = -123; - fkyaml::node node = fkyaml::node::integer_scalar(integer); + fkyaml::node node = integer; SECTION("Test non-alias integer node.") { @@ -1925,9 +1925,9 @@ TEST_CASE("NodeClassTest_ToIntegerTest", "[NodeClassTest]") fkyaml::node::sequence(), fkyaml::node::mapping(), fkyaml::node(), - fkyaml::node::boolean_scalar(false), - fkyaml::node::float_number_scalar(0.0), - fkyaml::node::string_scalar()); + fkyaml::node(false), + fkyaml::node(0.0), + fkyaml::node(std::string())); SECTION("Test non-alias non-integer nodes.") { @@ -1961,7 +1961,7 @@ TEST_CASE("NodeClassTest_ToFloatNumberTest", "[NodeClassTest]") SECTION("Test nothrow expected nodes.") { fkyaml::node_float_number_type float_val = 123.45; - fkyaml::node node = fkyaml::node::float_number_scalar(float_val); + fkyaml::node node = float_val; SECTION("Test non-alias float number node.") { @@ -1999,9 +1999,9 @@ TEST_CASE("NodeClassTest_ToFloatNumberTest", "[NodeClassTest]") fkyaml::node::sequence(), fkyaml::node::mapping(), fkyaml::node(), - fkyaml::node::boolean_scalar(false), - fkyaml::node::integer_scalar(0), - fkyaml::node::string_scalar()); + fkyaml::node(false), + fkyaml::node(0), + fkyaml::node(std::string())); SECTION("Test non-alias non-float-number nodes.") { @@ -2035,7 +2035,7 @@ TEST_CASE("NodeClassTest_ToStringTest", "[NodeClassTest]") SECTION("Test nothrow expected nodes.") { fkyaml::node_string_type str = "test"; - fkyaml::node node = fkyaml::node::string_scalar(str); + fkyaml::node node = str; SECTION("Test non-alias string node.") { @@ -2073,9 +2073,9 @@ TEST_CASE("NodeClassTest_ToStringTest", "[NodeClassTest]") fkyaml::node::sequence(), fkyaml::node::mapping(), fkyaml::node(), - fkyaml::node::boolean_scalar(false), - fkyaml::node::integer_scalar(0), - fkyaml::node::float_number_scalar(0.0)); + fkyaml::node(false), + fkyaml::node(0), + fkyaml::node(0.0)); SECTION("Test non-alias non-string nodes.") { @@ -2155,10 +2155,10 @@ TEST_CASE("NodeClassTest_BeginTest", "[NodeClassTest]") { auto node = GENERATE( fkyaml::node(), - fkyaml::node::boolean_scalar(false), - fkyaml::node::integer_scalar(0), - fkyaml::node::float_number_scalar(0.0), - fkyaml::node::string_scalar()); + fkyaml::node(false), + fkyaml::node(0), + fkyaml::node(0.0), + fkyaml::node(std::string())); SECTION("Test non-const throwing node.") { @@ -2220,10 +2220,10 @@ TEST_CASE("NodeClassTest_EndTest", "[NodeClassTest]") { auto node = GENERATE( fkyaml::node(), - fkyaml::node::boolean_scalar(false), - fkyaml::node::integer_scalar(0), - fkyaml::node::float_number_scalar(0.0), - fkyaml::node::string_scalar()); + fkyaml::node(false), + fkyaml::node(0), + fkyaml::node(0.0), + fkyaml::node(std::string())); SECTION("Test non-const throwing node.") { @@ -2244,8 +2244,8 @@ TEST_CASE("NodeClassTest_EndTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_SwapTest", "[NodeClassTest]") { - fkyaml::node lhs_node = fkyaml::node::boolean_scalar(true); - fkyaml::node rhs_node = fkyaml::node::integer_scalar(123); + fkyaml::node lhs_node = true; + fkyaml::node rhs_node = 123; lhs_node.swap(rhs_node); REQUIRE(lhs_node.is_integer()); REQUIRE(lhs_node.to_integer() == 123); @@ -2255,8 +2255,8 @@ TEST_CASE("NodeClassTest_SwapTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_ADLSwapTest", "[NodeClassTest]") { - fkyaml::node lhs_node = fkyaml::node::boolean_scalar(true); - fkyaml::node rhs_node = fkyaml::node::integer_scalar(123); + fkyaml::node lhs_node = true; + fkyaml::node rhs_node = 123; using std::swap; swap(lhs_node, rhs_node); diff --git a/test/unit_test/test_serializer_class.cpp b/test/unit_test/test_serializer_class.cpp index 5da9bce3..7a02a21e 100644 --- a/test/unit_test/test_serializer_class.cpp +++ b/test/unit_test/test_serializer_class.cpp @@ -17,12 +17,9 @@ TEST_CASE("SerializerClassTest_SerializeSequenceNode", "[SerializerClassTest]") { using NodeStrPair = std::pair; auto node_str_pair = GENERATE( + NodeStrPair({true, false}, "- true\n- false\n"), NodeStrPair( - fkyaml::node::sequence({fkyaml::node::boolean_scalar(true), fkyaml::node::boolean_scalar(false)}), - "- true\n- false\n"), - NodeStrPair( - fkyaml::node::sequence( - {fkyaml::node::mapping({{"foo", fkyaml::node::integer_scalar(-1234)}, {"bar", fkyaml::node()}})}), + {{{std::string("foo"), -1234}, {std::string("bar"), nullptr}}}, "-\n bar: null\n foo: -1234\n")); fkyaml::detail::basic_serializer serializer; REQUIRE(serializer.serialize(node_str_pair.first) == node_str_pair.second); @@ -33,13 +30,9 @@ TEST_CASE("SerializerClassTest_SerializeMappingNode", "[SerializerClassTest]") using NodeStrPair = std::pair; auto node_str_pair = GENERATE( NodeStrPair( - fkyaml::node::mapping({{"foo", fkyaml::node::integer_scalar(-1234)}, {"bar", fkyaml::node()}}), + {{std::string("foo"), -1234}, {std::string("bar"), nullptr}}, "bar: null\nfoo: -1234\n"), - NodeStrPair( - fkyaml::node::mapping( - {{"foo", - fkyaml::node::sequence({fkyaml::node::boolean_scalar(true), fkyaml::node::boolean_scalar(false)})}}), - "foo:\n - true\n - false\n")); + NodeStrPair({{std::string("foo"), {true, false}}}, "foo:\n - true\n - false\n")); fkyaml::detail::basic_serializer serializer; REQUIRE(serializer.serialize(node_str_pair.first) == node_str_pair.second); } @@ -55,8 +48,8 @@ TEST_CASE("SerializerClassTest_SerializeBooleanNode", "[SerializerClassTest]") { using NodeStrPair = std::pair; auto node_str_pair = GENERATE( - NodeStrPair(fkyaml::node::boolean_scalar(false), "false"), - NodeStrPair(fkyaml::node::boolean_scalar(true), "true")); + NodeStrPair(fkyaml::node(false), "false"), + NodeStrPair(fkyaml::node(true), "true")); fkyaml::detail::basic_serializer serializer; REQUIRE(serializer.serialize(node_str_pair.first) == node_str_pair.second); } @@ -65,8 +58,8 @@ TEST_CASE("SerializerClassTest_SerializeIntegerNode", "[SerializerClassTest]") { using NodeStrPair = std::pair; auto node_str_pair = GENERATE( - NodeStrPair(fkyaml::node::integer_scalar(-1234), "-1234"), - NodeStrPair(fkyaml::node::integer_scalar(5678), "5678")); + NodeStrPair(fkyaml::node(-1234), "-1234"), + NodeStrPair(fkyaml::node(5678), "5678")); fkyaml::detail::basic_serializer serializer; REQUIRE(serializer.serialize(node_str_pair.first) == node_str_pair.second); } @@ -75,14 +68,14 @@ TEST_CASE("SerializeClassTest_SerializeFloatNumberNode", "[SerializeClassTest]") { using NodeStrPair = std::pair; auto node_str_pair = GENERATE( - NodeStrPair(fkyaml::node::float_number_scalar(3.14), "3.14"), - NodeStrPair(fkyaml::node::float_number_scalar(-53.97), "-53.97"), + NodeStrPair(fkyaml::node(3.14), "3.14"), + NodeStrPair(fkyaml::node(-53.97), "-53.97"), NodeStrPair( - fkyaml::node::float_number_scalar(std::numeric_limits::infinity()), ".inf"), + fkyaml::node(std::numeric_limits::infinity()), ".inf"), NodeStrPair( - fkyaml::node::float_number_scalar(-1 * std::numeric_limits::infinity()), + fkyaml::node(-1 * std::numeric_limits::infinity()), "-.inf"), - NodeStrPair(fkyaml::node::float_number_scalar(std::nan("")), ".nan")); + NodeStrPair(fkyaml::node(std::nan("")), ".nan")); fkyaml::detail::basic_serializer serializer; REQUIRE(serializer.serialize(node_str_pair.first) == node_str_pair.second); } @@ -91,8 +84,8 @@ TEST_CASE("SerializerClassTest_SerializeStringNode", "[SerializerClassTest]") { using node_str_pair_t = std::pair; auto node_str_pair = GENERATE( - node_str_pair_t(fkyaml::node::string_scalar("test"), "test"), - node_str_pair_t(fkyaml::node::string_scalar("foo bar"), "foo bar")); + node_str_pair_t(fkyaml::node(std::string("test")), "test"), + node_str_pair_t(fkyaml::node(std::string("foo bar")), "foo bar")); fkyaml::detail::basic_serializer serializer; REQUIRE(serializer.serialize(node_str_pair.first) == node_str_pair.second); From 33e058e20050b0251ac7fa6999c28ea7750fe789 Mon Sep 17 00:00:00 2001 From: fktn Date: Mon, 30 Oct 2023 02:57:45 +0900 Subject: [PATCH 24/48] updated examples in README.md --- README.md | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 3aedf21e..95363497 100644 --- a/README.md +++ b/README.md @@ -201,14 +201,11 @@ The `Serializer` class provides an API for serializing YAML node values into a s // ... -fkyaml::node root = fkyaml::node::Mapping({ - { "foo", fkyaml::node::string_scalar("test") }, - { "bar", fkyaml::node::sequence({ - fkyaml::node(3.14), - fkyaml::node(std::nan("")) - }) }, - { "baz", fkyaml::node(true) } -}); +fkyaml::node root = { + { std::string("foo"), std::string("test") }, + { std::string("bar"), { 3.14, std::nan("") } }, + { std::string("baz"), true } +}; std::string str = fkyaml::node::serialize(root); // foo: test @@ -236,33 +233,27 @@ The `node` class provides APIs for building YAML nodes programatically. fkyaml::node root = fkyaml::node::mapping(); // Add a string scalar node. -root["foo"] = fkyaml::node(std::string("test")); +root["foo"] = std::string("test"); // Add a sequence node containing floating number scalar nodes. -root["bar"] = fkyaml::node::sequence({ - fkyaml::node(3.14), - fkyaml::node(std::nan("")) -}); +root["bar"] = { 3.14, std::nan("") }; // Add a boolean node. -root["baz"] = fkyaml::node(true); +root["baz"] = true; // Instead, you can build YAML nodes all at once. -fkyaml::node another_root = fkyaml::node::mapping({ - { "foo", fkyaml::node(std::string("test")) }, - { "bar", fkyaml::node::sequence({ - fkyaml::node(3.14), - fkyaml::node(std::nan("")) - }) }, - { "baz", fkyaml::node(true) } -}); +fkyaml::node another_root = { + { std::string("foo"), std::string("test") }, + { std::string("bar"), { 3.14, std::nan("") } }, + { std::string("baz"), true } +}; ``` ### Customize serialization/deserialization -To make your own custom types convertible from/to ``fkyaml::node`` type, you can implement your own `to_node()` & `from_node()` **outside** of the fkyaml namespace. +To make your own custom types convertible from/to `fkyaml::node` type, you can implement your own `to_node()` & `from_node()` **outside** of the fkyaml namespace. (Those functions will be called when you use `fkyaml::node::get_value\` to get a CustomType object out of a `fkyaml::node` object.)
From e352a1654b659908d34cbca3dd52a9d1e2843c2b Mon Sep 17 00:00:00 2001 From: fktn Date: Mon, 30 Oct 2023 03:01:50 +0900 Subject: [PATCH 25/48] deleted deserialize API overload which possibly behave in undefined ways --- include/fkYAML/detail/input/input_adapter.hpp | 26 ------------------- include/fkYAML/node.hpp | 8 ------ test/unit_test/test_input_adapter.cpp | 6 ----- test/unit_test/test_node_class.cpp | 1 - 4 files changed, 41 deletions(-) diff --git a/include/fkYAML/detail/input/input_adapter.hpp b/include/fkYAML/detail/input/input_adapter.hpp index a67c6a38..fa261164 100644 --- a/include/fkYAML/detail/input/input_adapter.hpp +++ b/include/fkYAML/detail/input/input_adapter.hpp @@ -218,32 +218,6 @@ inline iterator_input_adapter input_adapter(ItrType begin, ItrType end) return iterator_input_adapter(begin, end); } -/** - * @brief A factory method for iterator_input_adapter objects with char* objects. - * @note This function assumes a null-terminated string as an argument. - * - * @tparam CharPtrType A pointer type for char. - * @param ptr A pointer to the beginning of a target null-terminated string. - * @return decltype(input_adapter(ptr, ptr + std::strlen(ptr))) - */ -template < - typename CharPtrType, enable_if_t< - conjunction< - std::is_pointer, negation>, - std::is_integral>, - bool_constant) == sizeof(char)>>::value, - int> = 0> -inline auto input_adapter(CharPtrType ptr, std::size_t size) -> decltype(input_adapter(ptr, ptr + size)) -{ - // get the actual buffer size. - std::size_t i = 0; - for (; i < size && *(ptr + i) != '\0'; i++) - { - } - size = (i < size) ? i : size; - return input_adapter(ptr, ptr + size); -} - /** * @brief A factory method for iterator_input_adapter objects with C-style arrays. * diff --git a/include/fkYAML/node.hpp b/include/fkYAML/node.hpp index abfbe704..7a1b6455 100644 --- a/include/fkYAML/node.hpp +++ b/include/fkYAML/node.hpp @@ -459,14 +459,6 @@ class basic_node detail::input_adapter(std::forward(begin), std::forward(end))); } - /// @brief Deserialize an input string specified with a pointer and a size. - /// @todo Delete this API b/c this can be achieved with iterators and possibly yield undefined behavior. - template ::value, int> = 0> - static basic_node deserialize(PtrType&& ptr, std::size_t size) - { - return deserializer_type().deserialize(detail::input_adapter(std::forward(ptr), size)); - } - /// @brief Serialize a basic_node object into a string. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/serialize/ static std::string serialize(const basic_node& node) diff --git a/test/unit_test/test_input_adapter.cpp b/test/unit_test/test_input_adapter.cpp index 8f9b8eb1..96e60d95 100644 --- a/test/unit_test/test_input_adapter.cpp +++ b/test/unit_test/test_input_adapter.cpp @@ -37,12 +37,6 @@ TEST_CASE("InputAdapterTest_IteratorInputAdapterProviderTest", "[InputAdapterTes REQUIRE(std::is_same>::value); } - SECTION("char pointer and size") - { - auto input_adapter = fkyaml::detail::input_adapter(&input[0], sizeof(input)); - REQUIRE(std::is_same>::value); - } - SECTION("char pointers for beginning/end") { auto input_adapter = fkyaml::detail::input_adapter(&input[0], &input[sizeof(input) - 1]); diff --git a/test/unit_test/test_node_class.cpp b/test/unit_test/test_node_class.cpp index a2eec2ff..9973d7a9 100644 --- a/test/unit_test/test_node_class.cpp +++ b/test/unit_test/test_node_class.cpp @@ -376,7 +376,6 @@ TEST_CASE("NodeClassTest_DeserializeTest", "[NodeClassTest]") fkyaml::node node = GENERATE_REF( fkyaml::node::deserialize("foo: bar"), fkyaml::node::deserialize(source), - fkyaml::node::deserialize(&source[0], sizeof(source)), fkyaml::node::deserialize(&source[0], &source[8]), fkyaml::node::deserialize(std::string(source)), fkyaml::node::deserialize(ss)); From aff3715098e2a43fcbdcb857c017b4d0c2c0d143 Mon Sep 17 00:00:00 2001 From: fktn Date: Mon, 30 Oct 2023 03:02:32 +0900 Subject: [PATCH 26/48] applied clang-format result --- test/unit_test/test_node_class.cpp | 30 ++++-------------------- test/unit_test/test_serializer_class.cpp | 23 +++++------------- 2 files changed, 11 insertions(+), 42 deletions(-) diff --git a/test/unit_test/test_node_class.cpp b/test/unit_test/test_node_class.cpp index 9973d7a9..cb3a6d3f 100644 --- a/test/unit_test/test_node_class.cpp +++ b/test/unit_test/test_node_class.cpp @@ -1041,11 +1041,7 @@ TEST_CASE("NodeClassTest_is_scalarTest", "[NodeClassTest]") SECTION("Test scalar node types.") { auto node = GENERATE( - fkyaml::node(), - fkyaml::node(false), - fkyaml::node(0), - fkyaml::node(0.0), - fkyaml::node(std::string())); + fkyaml::node(), fkyaml::node(false), fkyaml::node(0), fkyaml::node(0.0), fkyaml::node(std::string())); SECTION("Test non-alias scalar node types.") { @@ -1148,11 +1144,7 @@ TEST_CASE("NodeClassTest_emptyTest", "[NodeClassTest]") SECTION("Test nothrow unexpected node emptiness.") { - auto node = GENERATE( - fkyaml::node(), - fkyaml::node(false), - fkyaml::node(0), - fkyaml::node(0.0)); + auto node = GENERATE(fkyaml::node(), fkyaml::node(false), fkyaml::node(0), fkyaml::node(0.0)); SECTION("Test non-const non-alias non-container node emptiness.") { @@ -1299,11 +1291,7 @@ TEST_CASE("NodeClassTest_sizeGetterTest", "[NodeClassTest]") SECTION("Test nothrow unexpected node size.") { - auto node = GENERATE( - fkyaml::node(), - fkyaml::node(false), - fkyaml::node(0), - fkyaml::node(0.0)); + auto node = GENERATE(fkyaml::node(), fkyaml::node(false), fkyaml::node(0), fkyaml::node(0.0)); SECTION("Test non-const non-alias non-container node size.") { @@ -2153,11 +2141,7 @@ TEST_CASE("NodeClassTest_BeginTest", "[NodeClassTest]") SECTION("Test nothrow unexpected nodes.") { auto node = GENERATE( - fkyaml::node(), - fkyaml::node(false), - fkyaml::node(0), - fkyaml::node(0.0), - fkyaml::node(std::string())); + fkyaml::node(), fkyaml::node(false), fkyaml::node(0), fkyaml::node(0.0), fkyaml::node(std::string())); SECTION("Test non-const throwing node.") { @@ -2218,11 +2202,7 @@ TEST_CASE("NodeClassTest_EndTest", "[NodeClassTest]") SECTION("Test nothrow unexpected nodes.") { auto node = GENERATE( - fkyaml::node(), - fkyaml::node(false), - fkyaml::node(0), - fkyaml::node(0.0), - fkyaml::node(std::string())); + fkyaml::node(), fkyaml::node(false), fkyaml::node(0), fkyaml::node(0.0), fkyaml::node(std::string())); SECTION("Test non-const throwing node.") { diff --git a/test/unit_test/test_serializer_class.cpp b/test/unit_test/test_serializer_class.cpp index 7a02a21e..22ef0d5c 100644 --- a/test/unit_test/test_serializer_class.cpp +++ b/test/unit_test/test_serializer_class.cpp @@ -18,9 +18,7 @@ TEST_CASE("SerializerClassTest_SerializeSequenceNode", "[SerializerClassTest]") using NodeStrPair = std::pair; auto node_str_pair = GENERATE( NodeStrPair({true, false}, "- true\n- false\n"), - NodeStrPair( - {{{std::string("foo"), -1234}, {std::string("bar"), nullptr}}}, - "-\n bar: null\n foo: -1234\n")); + NodeStrPair({{{std::string("foo"), -1234}, {std::string("bar"), nullptr}}}, "-\n bar: null\n foo: -1234\n")); fkyaml::detail::basic_serializer serializer; REQUIRE(serializer.serialize(node_str_pair.first) == node_str_pair.second); } @@ -29,9 +27,7 @@ TEST_CASE("SerializerClassTest_SerializeMappingNode", "[SerializerClassTest]") { using NodeStrPair = std::pair; auto node_str_pair = GENERATE( - NodeStrPair( - {{std::string("foo"), -1234}, {std::string("bar"), nullptr}}, - "bar: null\nfoo: -1234\n"), + NodeStrPair({{std::string("foo"), -1234}, {std::string("bar"), nullptr}}, "bar: null\nfoo: -1234\n"), NodeStrPair({{std::string("foo"), {true, false}}}, "foo:\n - true\n - false\n")); fkyaml::detail::basic_serializer serializer; REQUIRE(serializer.serialize(node_str_pair.first) == node_str_pair.second); @@ -47,9 +43,7 @@ TEST_CASE("SerializerClassTest_SerializeNullNode", "[SerializerClassTest]") TEST_CASE("SerializerClassTest_SerializeBooleanNode", "[SerializerClassTest]") { using NodeStrPair = std::pair; - auto node_str_pair = GENERATE( - NodeStrPair(fkyaml::node(false), "false"), - NodeStrPair(fkyaml::node(true), "true")); + auto node_str_pair = GENERATE(NodeStrPair(fkyaml::node(false), "false"), NodeStrPair(fkyaml::node(true), "true")); fkyaml::detail::basic_serializer serializer; REQUIRE(serializer.serialize(node_str_pair.first) == node_str_pair.second); } @@ -57,9 +51,7 @@ TEST_CASE("SerializerClassTest_SerializeBooleanNode", "[SerializerClassTest]") TEST_CASE("SerializerClassTest_SerializeIntegerNode", "[SerializerClassTest]") { using NodeStrPair = std::pair; - auto node_str_pair = GENERATE( - NodeStrPair(fkyaml::node(-1234), "-1234"), - NodeStrPair(fkyaml::node(5678), "5678")); + auto node_str_pair = GENERATE(NodeStrPair(fkyaml::node(-1234), "-1234"), NodeStrPair(fkyaml::node(5678), "5678")); fkyaml::detail::basic_serializer serializer; REQUIRE(serializer.serialize(node_str_pair.first) == node_str_pair.second); } @@ -70,11 +62,8 @@ TEST_CASE("SerializeClassTest_SerializeFloatNumberNode", "[SerializeClassTest]") auto node_str_pair = GENERATE( NodeStrPair(fkyaml::node(3.14), "3.14"), NodeStrPair(fkyaml::node(-53.97), "-53.97"), - NodeStrPair( - fkyaml::node(std::numeric_limits::infinity()), ".inf"), - NodeStrPair( - fkyaml::node(-1 * std::numeric_limits::infinity()), - "-.inf"), + NodeStrPair(fkyaml::node(std::numeric_limits::infinity()), ".inf"), + NodeStrPair(fkyaml::node(-1 * std::numeric_limits::infinity()), "-.inf"), NodeStrPair(fkyaml::node(std::nan("")), ".nan")); fkyaml::detail::basic_serializer serializer; REQUIRE(serializer.serialize(node_str_pair.first) == node_str_pair.second); From 1c0b59863b0c5800434fe65c43b3ec4586868822 Mon Sep 17 00:00:00 2001 From: fktn Date: Tue, 31 Oct 2023 01:08:25 +0900 Subject: [PATCH 27/48] generalized get reference APIs with get_value_ref API --- README.md | 8 +- .../fkYAML/detail/conversions/from_node.hpp | 21 +- include/fkYAML/detail/input/deserializer.hpp | 20 +- include/fkYAML/detail/meta/stl_supplement.hpp | 22 ++ include/fkYAML/detail/output/serializer.hpp | 11 +- include/fkYAML/node.hpp | 311 +++++++++--------- test/unit_test/test_deserializer_class.cpp | 180 +++++----- test/unit_test/test_iterator_class.cpp | 200 +++++------ test/unit_test/test_node_class.cpp | 297 ++++++++--------- .../unit_test/test_node_ref_storage_class.cpp | 8 +- 10 files changed, 550 insertions(+), 528 deletions(-) diff --git a/README.md b/README.md index 95363497..09fd1700 100644 --- a/README.md +++ b/README.md @@ -176,9 +176,9 @@ assert(root["bar"].is_float_number()); assert(root["baz"].is_boolean()); // You can get references to YAML node values like the followings: -assert(root["foo"].to_string() == "test"); -assert(root["bar"].to_float_number() == 3.14); -assert(root["baz"].to_boolean() == true); +assert(root["foo"].get_value_ref() == "test"); +assert(root["bar"].get_value_ref() == 3.14); +assert(root["baz"].get_value_ref() == true); // You can get values of YAML node like the followings: assert(root["foo"].get_value() == "test"); @@ -285,7 +285,7 @@ void to_node(fkyaml::node& n, const CustomType& c) // overload from_node() with the CustomType type. void from_node(const fkyaml::node& n, CustomType& c) { - c.foo = n.get_value(); + c.foo = n.get_value_ref(); c.bar = n.get_value(); c.baz = n.get_value(); } diff --git a/include/fkYAML/detail/conversions/from_node.hpp b/include/fkYAML/detail/conversions/from_node.hpp index 9b2e4f87..a53e240c 100644 --- a/include/fkYAML/detail/conversions/from_node.hpp +++ b/include/fkYAML/detail/conversions/from_node.hpp @@ -57,7 +57,7 @@ inline void from_node(const BasicNodeType& n, typename BasicNodeType::sequence_t { throw exception("The target node value type is not sequence type."); } - s = n.to_sequence(); + s = n.template get_value_ref(); } /** @@ -75,7 +75,7 @@ inline void from_node(const BasicNodeType& n, typename BasicNodeType::mapping_ty throw exception("The target node value type is not mapping type."); } - for (auto pair : n.to_mapping()) + for (auto pair : n.template get_value_ref()) { m.emplace(pair.first, pair.second); } @@ -113,7 +113,7 @@ inline void from_node(const BasicNodeType& n, typename BasicNodeType::boolean_ty { throw exception("The target node value type is not boolean type."); } - b = n.to_boolean(); + b = n.template get_value_ref(); } /** @@ -130,7 +130,7 @@ inline void from_node(const BasicNodeType& n, typename BasicNodeType::integer_ty { throw exception("The target node value type is not integer type."); } - i = n.to_integer(); + i = n.template get_value_ref(); } /** @@ -156,12 +156,13 @@ inline void from_node(const BasicNodeType& n, IntegerType& i) } // under/overflow check. - typename BasicNodeType::integer_type tmp_int = n.to_integer(); - if (tmp_int < static_cast(std::numeric_limits::min())) + using node_int_type = typename BasicNodeType::integer_type; + node_int_type tmp_int = n.template get_value_ref(); + if (tmp_int < static_cast(std::numeric_limits::min())) { throw exception("Integer value underflow detected."); } - if (static_cast(std::numeric_limits::max()) < tmp_int) + if (static_cast(std::numeric_limits::max()) < tmp_int) { throw exception("Integer value overflow detected."); } @@ -183,7 +184,7 @@ inline void from_node(const BasicNodeType& n, typename BasicNodeType::float_numb { throw exception("The target node value type is not float number type."); } - f = n.to_float_number(); + f = n.template get_value_ref(); } /** @@ -208,7 +209,7 @@ inline void from_node(const BasicNodeType& n, FloatType& f) throw exception("The target node value type is not float number type."); } - typename BasicNodeType::float_number_type tmp_float = n.to_float_number(); + auto tmp_float = n.template get_value_ref(); if (tmp_float < std::numeric_limits::min()) { throw exception("Floating point value underflow detected."); @@ -235,7 +236,7 @@ inline void from_node(const BasicNodeType& n, typename BasicNodeType::string_typ { throw exception("The target node value type is not string type."); } - s = n.to_string(); + s = n.template get_value_ref(); } /** diff --git a/include/fkYAML/detail/input/deserializer.hpp b/include/fkYAML/detail/input/deserializer.hpp index 11556936..32917d8b 100644 --- a/include/fkYAML/detail/input/deserializer.hpp +++ b/include/fkYAML/detail/input/deserializer.hpp @@ -102,12 +102,12 @@ class basic_deserializer { // make sequence node to mapping node. // TODO: This is just a workaround. Need to be refactored to fix this way. - string_type tmp_str = m_current_node->operator[](0).to_string(); + string_type tmp_str = m_current_node->operator[](0).template get_value(); m_current_node->operator[](0) = BasicNodeType::mapping(); m_node_stack.emplace_back(m_current_node); m_current_node = &(m_current_node->operator[](0)); set_yaml_version(*m_current_node); - m_current_node->to_mapping().emplace(tmp_str, BasicNodeType()); + m_current_node->template get_value_ref().emplace(tmp_str, BasicNodeType()); m_node_stack.emplace_back(m_current_node); m_current_node = &(m_current_node->operator[](tmp_str)); set_yaml_version(*m_current_node); @@ -155,8 +155,8 @@ class basic_deserializer } // for the second or later mapping items in a sequence node. - m_node_stack.back()->to_sequence().emplace_back(BasicNodeType::mapping()); - m_current_node = &(m_node_stack.back()->to_sequence().back()); + m_node_stack.back()->template get_value_ref().emplace_back(BasicNodeType::mapping()); + m_current_node = &(m_node_stack.back()->template get_value_ref().back()); set_yaml_version(*m_current_node); break; } @@ -275,9 +275,9 @@ class basic_deserializer m_indent_stack.push_back(indent); } - m_current_node->to_mapping().emplace(key, BasicNodeType()); + m_current_node->template get_value_ref().emplace(key, BasicNodeType()); m_node_stack.push_back(m_current_node); - m_current_node = &(m_current_node->to_mapping().at(key)); + m_current_node = &(m_current_node->template get_value_ref().at(key)); } /** @@ -289,12 +289,12 @@ class basic_deserializer { if (m_current_node->is_sequence()) { - m_current_node->to_sequence().emplace_back(std::move(node_value)); - set_yaml_version(m_current_node->to_sequence().back()); + m_current_node->template get_value_ref().emplace_back(std::move(node_value)); + set_yaml_version(m_current_node->template get_value_ref().back()); if (m_needs_anchor_impl) { - m_current_node->to_sequence().back().add_anchor_name(m_anchor_name); - m_anchor_table[m_anchor_name] = m_current_node->to_sequence().back(); + m_current_node->template get_value_ref().back().add_anchor_name(m_anchor_name); + m_anchor_table[m_anchor_name] = m_current_node->template get_value_ref().back(); m_needs_anchor_impl = false; m_anchor_name.clear(); } diff --git a/include/fkYAML/detail/meta/stl_supplement.hpp b/include/fkYAML/detail/meta/stl_supplement.hpp index 2aa072cd..09304c8d 100644 --- a/include/fkYAML/detail/meta/stl_supplement.hpp +++ b/include/fkYAML/detail/meta/stl_supplement.hpp @@ -41,6 +41,16 @@ namespace detail #ifndef FK_YAML_HAS_CXX_14 +/** + * @brief An alias template for std::add_pointer::type with C++11. + * @note std::add_pointer_t is available since C++14. + * @sa https://en.cppreference.com/w/cpp/types/add_pointer + * + * @tparam T A type to be added a pointer. + */ +template +using add_pointer_t = typename std::add_pointer::type; + /** * @brief An alias template for std::enable_if::type with C++11. * @note std::enable_if_t is available since C++14. @@ -72,11 +82,23 @@ using remove_cv_t = typename std::remove_cv::type; template using remove_pointer_t = typename std::remove_pointer::type; +/** + * @brief An alias template for std::remove_reference::type with C++11. + * @note std::remove_reference_t is available since C++14. + * @sa https://en.cppreference.com/w/cpp/types/remove_reference + * + * @tparam T A type from which a reference is removed. + */ +template +using remove_reference_t = typename std::remove_reference::type; + #else +using std::add_pointer_t; using std::enable_if_t; using std::remove_cv_t; using std::remove_pointer_t; +using std::remove_reference_t; #endif diff --git a/include/fkYAML/detail/output/serializer.hpp b/include/fkYAML/detail/output/serializer.hpp index 83eb1e26..ac4e3a39 100644 --- a/include/fkYAML/detail/output/serializer.hpp +++ b/include/fkYAML/detail/output/serializer.hpp @@ -116,20 +116,19 @@ class basic_serializer str += m_tmp_str_buff; break; case node_t::BOOLEAN: - to_string(m_tmp_str_buff, node.to_boolean()); + to_string(m_tmp_str_buff, node.template get_value()); str += m_tmp_str_buff; break; case node_t::INTEGER: - to_string(m_tmp_str_buff, node.to_integer()); + to_string(m_tmp_str_buff, node.template get_value()); str += m_tmp_str_buff; break; - case node_t::FLOAT_NUMBER: { - to_string(m_tmp_str_buff, node.to_float_number()); + case node_t::FLOAT_NUMBER: + to_string(m_tmp_str_buff, node.template get_value()); str += m_tmp_str_buff; break; - } case node_t::STRING: - str += node.to_string(); + str += node.template get_value_ref(); break; default: // LCOV_EXCL_LINE throw fkyaml::exception("Unsupported node type found."); // LCOV_EXCL_LINE diff --git a/include/fkYAML/node.hpp b/include/fkYAML/node.hpp index 7a1b6455..4d04342b 100644 --- a/include/fkYAML/node.hpp +++ b/include/fkYAML/node.hpp @@ -823,166 +823,21 @@ class basic_node return ret; } - /// @brief Returns reference to sequence basic_node value from a non-const basic_node object. Throws exception if - /// the basic_node value is not of sequence type. - /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_sequence/ - sequence_type& to_sequence() // NOLINT(readability-make-member-function-const) + template ::value, int> = 0> + ReferenceType get_value_ref() { - if (!is_sequence()) - { - throw fkyaml::exception("The target node is not of a sequence type."); - } - - FK_YAML_ASSERT(m_node_value.p_sequence != nullptr); - return *(m_node_value.p_sequence); - } - - /// @brief Returns reference to sequence basic_node value from a const basic_node object. Throws exception if the - /// basic_node value is not of sequence type. - /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_sequence/ - const sequence_type& to_sequence() const - { - if (!is_sequence()) - { - throw fkyaml::exception("The target node is not of a sequence type."); - } - - FK_YAML_ASSERT(m_node_value.p_sequence != nullptr); - return *(m_node_value.p_sequence); - } - - /// @brief Returns reference to mapping basic_node value from a non-const basic_node object. Throws exception if the - /// basic_node value is not of mapping type. - /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_mapping/ - mapping_type& to_mapping() // NOLINT(readability-make-member-function-const) - { - if (!is_mapping()) - { - throw fkyaml::exception("The target node is not of a mapping type."); - } - - FK_YAML_ASSERT(m_node_value.p_mapping != nullptr); - return *(m_node_value.p_mapping); - } - - /// @brief Returns reference to mapping basic_node value from a const basic_node object. Throws exception if the - /// basic_node value is not of mapping type. - /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_mapping/ - const mapping_type& to_mapping() const - { - if (!is_mapping()) - { - throw fkyaml::exception("The target node is not of a mapping type."); - } - - FK_YAML_ASSERT(m_node_value.p_mapping != nullptr); - return *(m_node_value.p_mapping); - } - - /// @brief Returns reference to boolean basic_node value from a non-const basic_node object. Throws exception if the - /// basic_node value is not of boolean type. - /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_boolean/ - boolean_type& to_boolean() - { - if (!is_boolean()) - { - throw fkyaml::exception("The target node is not of a boolean type."); - } - - return m_node_value.boolean; - } - - /// @brief Returns reference to boolean basic_node value from a const basic_node object. Throws exception if the - /// basic_node value is not of boolean type. - /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_boolean - const boolean_type& to_boolean() const - { - if (!is_boolean()) - { - throw fkyaml::exception("The target node is not of a boolean type."); - } - - return m_node_value.boolean; - } - - /// @brief Returns reference to integer basic_node value from a non-const basic_node object. Throws exception if - /// the basic_node value is not of integer type. - /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_integer/ - integer_type& to_integer() - { - if (!is_integer()) - { - throw fkyaml::exception("The target node is not of integer type."); - } - - return m_node_value.integer; - } - - /// @brief Returns reference to integer basic_node value from a const basic_node object. Throws exception if the - /// basic_node value is not of integer type. - /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_integer/ - const integer_type& to_integer() const - { - if (!is_integer()) - { - throw fkyaml::exception("The target node is not of integer type."); - } - - return m_node_value.integer; - } - - /// @brief Returns reference to float number basic_node value from a non-const basic_node object. Throws exception - /// if the basic_node value is not of float number type. - /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_float_number/ - float_number_type& to_float_number() - { - if (!is_float_number()) - { - throw fkyaml::exception("The target node is not of a float number type."); - } - - return m_node_value.float_val; - } - - /// @brief Returns reference to float number basic_node value from a const basic_node object. Throws exception if - /// the basic_node value is not of float number type. - /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_float_number/ - const float_number_type& to_float_number() const - { - if (!is_float_number()) - { - throw fkyaml::exception("The target node is not of a float number type."); - } - - return m_node_value.float_val; - } - - /// @brief Returns reference to string basic_node value from a non-const basic_node object. Throws exception if the - /// basic_node value is not of string type. - /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_string/ - string_type& to_string() // NOLINT(readability-make-member-function-const) - { - if (!is_string()) - { - throw fkyaml::exception("The target node is not of a string type."); - } - - FK_YAML_ASSERT(m_node_value.p_string != nullptr); - return *(m_node_value.p_string); + return get_value_ref_impl(static_cast>(nullptr)); } - /// @brief Returns reference to string basic_node value from a const basic_node object. Throws exception if the - /// basic_node value is not of string type. - /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/to_string/ - const string_type& to_string() const + template < + typename ReferenceType, + detail::enable_if_t< + detail::conjunction< + std::is_reference, std::is_const>>::value, + int> = 0> + ReferenceType get_value_ref() const { - if (!is_string()) - { - throw fkyaml::exception("The target node is not of a string type."); - } - - FK_YAML_ASSERT(m_node_value.p_string != nullptr); - return *(m_node_value.p_string); + return get_value_ref_impl(static_cast>(nullptr)); } /// @brief Swaps data with the specified basic_node object. @@ -1074,6 +929,150 @@ class basic_node } private: + /// @brief Returns reference to the sequence node value. + /// @throw fkyaml::exception The node value is not a sequence. + /// @return Reference to the sequence node value. + sequence_type& get_value_ref_impl(sequence_type* /*unused*/) + { + if (!is_sequence()) + { + throw fkyaml::exception("The node value is not a sequence."); + } + return *(m_node_value.p_sequence); + } + + /// @brief Returns constant reference to the sequence node value. + /// @throw fkyaml::exception The node value is not a sequence. + /// @return Constant reference to the sequence node value. + constexpr const sequence_type& get_value_ref_impl(const sequence_type* /*unused*/) const + { + if (!is_sequence()) + { + throw fkyaml::exception("The node value is not a sequence."); + } + return *(m_node_value.p_sequence); + } + + /// @brief Returns reference to the mapping node value. + /// @throw fkyaml::exception The node value is not a mapping. + /// @return Reference to the mapping node value. + mapping_type& get_value_ref_impl(mapping_type* /*unused*/) + { + if (!is_mapping()) + { + throw fkyaml::exception("The node value is not a mapping."); + } + return *(m_node_value.p_mapping); + } + + /// @brief Returns constant reference to the mapping node value. + /// @throw fkyaml::exception The node value is not a mapping. + /// @return Constant reference to the mapping node value. + constexpr const mapping_type& get_value_ref_impl(const mapping_type* /*unused*/) const + { + if (!is_mapping()) + { + throw fkyaml::exception("The node value is not a mapping."); + } + return *(m_node_value.p_mapping); + } + + /// @brief Returns reference to the boolean node value. + /// @throw fkyaml::exception The node value is not a boolean. + /// @return Reference to the boolean node value. + boolean_type& get_value_ref_impl(boolean_type* /*unused*/) + { + if (!is_boolean()) + { + throw fkyaml::exception("The node value is not a boolean."); + } + return m_node_value.boolean; + } + + /// @brief Returns reference to the boolean node value. + /// @throw fkyaml::exception The node value is not a boolean. + /// @return Reference to the boolean node value. + constexpr const boolean_type& get_value_ref_impl(const boolean_type* /*unused*/) const + { + if (!is_boolean()) + { + throw fkyaml::exception("The node value is not a boolean."); + } + return m_node_value.boolean; + } + + /// @brief Returns reference to the integer node value. + /// @throw fkyaml::exception The node value is not an integer. + /// @return Reference to the integer node value. + integer_type& get_value_ref_impl(integer_type* /*unused*/) + { + if (!is_integer()) + { + throw fkyaml::exception("The node value is not an integer."); + } + return m_node_value.integer; + } + + /// @brief Returns reference to the integer node value. + /// @throw fkyaml::exception The node value is not an integer. + /// @return Reference to the integer node value. + constexpr const integer_type& get_value_ref_impl(const integer_type* /*unused*/) const + { + if (!is_integer()) + { + throw fkyaml::exception("The node value is not an integer."); + } + return m_node_value.integer; + } + + /// @brief Returns reference to the floating point number node value. + /// @throw fkyaml::exception The node value is not a floating point number. + /// @return Reference to the floating point number node value. + float_number_type& get_value_ref_impl(float_number_type* /*unused*/) + { + if (!is_float_number()) + { + throw fkyaml::exception("The node value is not a floating point number."); + } + return m_node_value.float_val; + } + + /// @brief Returns reference to the floating point number node value. + /// @throw fkyaml::exception The node value is not a floating point number. + /// @return Reference to the floating point number node value. + constexpr const float_number_type& get_value_ref_impl(const float_number_type* /*unused*/) const + { + if (!is_float_number()) + { + throw fkyaml::exception("The node value is not a floating point number."); + } + return m_node_value.float_val; + } + + /// @brief Returns reference to the string node value. + /// @throw fkyaml::exception The node value is not a string. + /// @return Reference to the string node value. + string_type& get_value_ref_impl(string_type* /*unused*/) + { + if (!is_string()) + { + throw fkyaml::exception("The node value is not a string."); + } + return *(m_node_value.p_string); + } + + /// @brief Returns reference to the string node value. + /// @throw fkyaml::exception The node value is not a string. + /// @return Reference to the string node value. + constexpr const string_type& get_value_ref_impl(const string_type* /*unused*/) const + { + if (!is_string()) + { + throw fkyaml::exception("The node value is not a string."); + } + return *(m_node_value.p_string); + } + /// The current node value type. node_t m_node_type {node_t::NULL_OBJECT}; /// The YAML version specification. diff --git a/test/unit_test/test_deserializer_class.cpp b/test/unit_test/test_deserializer_class.cpp index 561d9211..d573637d 100644 --- a/test/unit_test/test_deserializer_class.cpp +++ b/test/unit_test/test_deserializer_class.cpp @@ -79,7 +79,7 @@ TEST_CASE("DeserializerClassTest_DeserializeNumericKey", "[DeserializerClassTest REQUIRE(root.is_mapping()); REQUIRE(root.size() == 1); REQUIRE(root.contains(str_val_pair.second)); - REQUIRE(root[str_val_pair.second].to_string() == "foo"); + REQUIRE(root[str_val_pair.second].get_value_ref() == "foo"); } TEST_CASE("DeserializerClassTest_DeserializeInvalidIndentation", "[DeserializerClassTest]") @@ -116,16 +116,16 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockSequenceTest", "[DeserializerCl REQUIRE(test_0_node.is_string()); REQUIRE_NOTHROW(test_0_node.size()); REQUIRE(test_0_node.size() == 3); - REQUIRE_NOTHROW(test_0_node.to_string()); - REQUIRE(test_0_node.to_string().compare("foo") == 0); + REQUIRE_NOTHROW(test_0_node.get_value_ref()); + REQUIRE(test_0_node.get_value_ref().compare("foo") == 0); REQUIRE_NOTHROW(test_node[1]); fkyaml::node& test_1_node = test_node[1]; REQUIRE(test_1_node.is_string()); REQUIRE_NOTHROW(test_1_node.size()); REQUIRE(test_1_node.size() == 3); - REQUIRE_NOTHROW(test_1_node.to_string()); - REQUIRE(test_1_node.to_string().compare("bar") == 0); + REQUIRE_NOTHROW(test_1_node.get_value_ref()); + REQUIRE(test_1_node.get_value_ref().compare("bar") == 0); } SECTION("Input source No.2.") @@ -153,14 +153,14 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockSequenceTest", "[DeserializerCl REQUIRE_NOTHROW(test_0_node["foo"]); fkyaml::node& test_0_foo_node = test_0_node["foo"]; REQUIRE(test_0_foo_node.is_boolean()); - REQUIRE_NOTHROW(test_0_foo_node.to_boolean()); - REQUIRE(test_0_foo_node.to_boolean() == true); + REQUIRE_NOTHROW(test_0_foo_node.get_value()); + REQUIRE(test_0_foo_node.get_value() == true); REQUIRE_NOTHROW(test_0_node["bar"]); fkyaml::node& test_0_bar_node = test_0_node["bar"]; REQUIRE(test_0_bar_node.is_string()); - REQUIRE_NOTHROW(test_0_bar_node.to_string()); - REQUIRE(test_0_bar_node.to_string().compare("one") == 0); + REQUIRE_NOTHROW(test_0_bar_node.get_value_ref()); + REQUIRE(test_0_bar_node.get_value_ref().compare("one") == 0); REQUIRE_NOTHROW(test_node[1]); fkyaml::node& test_1_node = test_node[1]; @@ -171,14 +171,14 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockSequenceTest", "[DeserializerCl REQUIRE_NOTHROW(test_1_node["foo"]); fkyaml::node& test_1_foo_node = test_1_node["foo"]; REQUIRE(test_1_foo_node.is_boolean()); - REQUIRE_NOTHROW(test_1_foo_node.to_boolean()); - REQUIRE(test_1_foo_node.to_boolean() == false); + REQUIRE_NOTHROW(test_1_foo_node.get_value()); + REQUIRE(test_1_foo_node.get_value() == false); REQUIRE_NOTHROW(test_1_node["bar"]); fkyaml::node& test_1_bar_node = test_1_node["bar"]; REQUIRE(test_1_bar_node.is_string()); - REQUIRE_NOTHROW(test_1_bar_node.to_string()); - REQUIRE(test_1_bar_node.to_string().compare("two") == 0); + REQUIRE_NOTHROW(test_1_bar_node.get_value_ref()); + REQUIRE(test_1_bar_node.get_value_ref().compare("two") == 0); } SECTION("Input source No.3.") @@ -201,14 +201,14 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockSequenceTest", "[DeserializerCl REQUIRE(test_0_node.has_anchor_name()); REQUIRE(test_0_node.get_anchor_name().compare("anchor") == 0); REQUIRE(test_0_node.is_boolean()); - REQUIRE_NOTHROW(test_0_node.to_boolean()); - REQUIRE(test_0_node.to_boolean() == true); + REQUIRE_NOTHROW(test_0_node.get_value()); + REQUIRE(test_0_node.get_value() == true); REQUIRE_NOTHROW(test_node[1]); fkyaml::node& test_1_node = test_node[1]; REQUIRE(test_1_node.is_boolean()); - REQUIRE_NOTHROW(test_1_node.to_boolean()); - REQUIRE(test_1_node.to_boolean() == test_0_node.to_boolean()); + REQUIRE_NOTHROW(test_1_node.get_value()); + REQUIRE(test_1_node.get_value() == test_0_node.get_value()); } SECTION("Input source No.4.") @@ -231,14 +231,14 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockSequenceTest", "[DeserializerCl REQUIRE(test_0_node.has_anchor_name()); REQUIRE(test_0_node.get_anchor_name().compare("anchor") == 0); REQUIRE(test_0_node.is_integer()); - REQUIRE_NOTHROW(test_0_node.to_integer()); - REQUIRE(test_0_node.to_integer() == -123); + REQUIRE_NOTHROW(test_0_node.get_value()); + REQUIRE(test_0_node.get_value() == -123); REQUIRE_NOTHROW(test_node[1]); fkyaml::node& test_1_node = test_node[1]; REQUIRE(test_1_node.is_integer()); - REQUIRE_NOTHROW(test_1_node.to_integer()); - REQUIRE(test_1_node.to_integer() == test_0_node.to_integer()); + REQUIRE_NOTHROW(test_1_node.get_value()); + REQUIRE(test_1_node.get_value() == test_0_node.get_value()); } SECTION("Input source No.5.") @@ -261,14 +261,14 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockSequenceTest", "[DeserializerCl REQUIRE(test_0_node.has_anchor_name()); REQUIRE(test_0_node.get_anchor_name().compare("anchor") == 0); REQUIRE(test_0_node.is_integer()); - REQUIRE_NOTHROW(test_0_node.to_integer()); - REQUIRE(test_0_node.to_integer() == 567); + REQUIRE_NOTHROW(test_0_node.get_value()); + REQUIRE(test_0_node.get_value() == 567); REQUIRE_NOTHROW(test_node[1]); fkyaml::node& test_1_node = test_node[1]; REQUIRE(test_1_node.is_integer()); - REQUIRE_NOTHROW(test_1_node.to_integer()); - REQUIRE(test_1_node.to_integer() == test_0_node.to_integer()); + REQUIRE_NOTHROW(test_1_node.get_value()); + REQUIRE(test_1_node.get_value() == test_0_node.get_value()); } SECTION("Input source No.6.") @@ -291,14 +291,14 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockSequenceTest", "[DeserializerCl REQUIRE(test_0_node.has_anchor_name()); REQUIRE(test_0_node.get_anchor_name().compare("anchor") == 0); REQUIRE(test_0_node.is_float_number()); - REQUIRE_NOTHROW(test_0_node.to_float_number()); - REQUIRE(test_0_node.to_float_number() == 3.14); + REQUIRE_NOTHROW(test_0_node.get_value()); + REQUIRE(test_0_node.get_value() == 3.14); REQUIRE_NOTHROW(test_node[1]); fkyaml::node& test_1_node = test_node[1]; REQUIRE(test_1_node.is_float_number()); - REQUIRE_NOTHROW(test_1_node.to_float_number()); - REQUIRE(test_1_node.to_float_number() == test_0_node.to_float_number()); + REQUIRE_NOTHROW(test_1_node.get_value()); + REQUIRE(test_1_node.get_value() == test_0_node.get_value()); } SECTION("Input source No.7.") @@ -323,16 +323,16 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockSequenceTest", "[DeserializerCl REQUIRE(test_0_node.is_string()); REQUIRE_NOTHROW(test_0_node.size()); REQUIRE(test_0_node.size() == 3); - REQUIRE_NOTHROW(test_0_node.to_string()); - REQUIRE(test_0_node.to_string().compare("foo") == 0); + REQUIRE_NOTHROW(test_0_node.get_value_ref()); + REQUIRE(test_0_node.get_value_ref().compare("foo") == 0); REQUIRE_NOTHROW(test_node[1]); fkyaml::node& test_1_node = test_node[1]; REQUIRE(test_1_node.is_string()); REQUIRE_NOTHROW(test_1_node.size()); REQUIRE(test_1_node.size() == 3); - REQUIRE_NOTHROW(test_1_node.to_string()); - REQUIRE(test_1_node.to_string().compare("foo") == 0); + REQUIRE_NOTHROW(test_1_node.get_value_ref()); + REQUIRE(test_1_node.get_value_ref().compare("foo") == 0); } } @@ -352,20 +352,20 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockMappingTest", "[DeserializerCla REQUIRE_NOTHROW(root["foo"]); fkyaml::node& foo_node = root["foo"]; REQUIRE(foo_node.is_string()); - REQUIRE_NOTHROW(foo_node.to_string()); - REQUIRE(foo_node.to_string().compare("one") == 0); + REQUIRE_NOTHROW(foo_node.get_value_ref()); + REQUIRE(foo_node.get_value_ref().compare("one") == 0); REQUIRE_NOTHROW(root["bar"]); fkyaml::node& bar_node = root["bar"]; REQUIRE(bar_node.is_boolean()); - REQUIRE_NOTHROW(bar_node.to_boolean()); - REQUIRE(bar_node.to_boolean() == true); + REQUIRE_NOTHROW(bar_node.get_value()); + REQUIRE(bar_node.get_value() == true); REQUIRE_NOTHROW(root["pi"]); fkyaml::node& pi_node = root["pi"]; REQUIRE(pi_node.is_float_number()); - REQUIRE_NOTHROW(pi_node.to_float_number()); - REQUIRE(pi_node.to_float_number() == 3.14); + REQUIRE_NOTHROW(pi_node.get_value()); + REQUIRE(pi_node.get_value() == 3.14); } SECTION("Input source No.2.") @@ -387,20 +387,20 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockMappingTest", "[DeserializerCla REQUIRE_NOTHROW(test_node["bool"]); fkyaml::node& test_bool_node = test_node["bool"]; REQUIRE(test_bool_node.is_boolean()); - REQUIRE_NOTHROW(test_bool_node.to_boolean()); - REQUIRE(test_bool_node.to_boolean() == true); + REQUIRE_NOTHROW(test_bool_node.get_value()); + REQUIRE(test_bool_node.get_value() == true); REQUIRE_NOTHROW(test_node["foo"]); fkyaml::node& test_foo_node = test_node["foo"]; REQUIRE(test_foo_node.is_string()); - REQUIRE_NOTHROW(test_foo_node.to_string()); - REQUIRE(test_foo_node.to_string().compare("bar") == 0); + REQUIRE_NOTHROW(test_foo_node.get_value_ref()); + REQUIRE(test_foo_node.get_value_ref().compare("bar") == 0); REQUIRE_NOTHROW(test_node["pi"]); fkyaml::node& test_pi_node = test_node["pi"]; REQUIRE(test_pi_node.is_float_number()); - REQUIRE_NOTHROW(test_pi_node.to_float_number()); - REQUIRE(test_pi_node.to_float_number() == 3.14); + REQUIRE_NOTHROW(test_pi_node.get_value()); + REQUIRE(test_pi_node.get_value() == 3.14); } SECTION("Input source No.3.") @@ -416,14 +416,14 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockMappingTest", "[DeserializerCla REQUIRE(foo_node.has_anchor_name()); REQUIRE(foo_node.get_anchor_name().compare("anchor") == 0); REQUIRE(foo_node.is_boolean()); - REQUIRE_NOTHROW(foo_node.to_boolean()); - REQUIRE(foo_node.to_boolean() == true); + REQUIRE_NOTHROW(foo_node.get_value()); + REQUIRE(foo_node.get_value() == true); REQUIRE_NOTHROW(root["bar"]); fkyaml::node& bar_node = root["bar"]; REQUIRE(bar_node.is_boolean()); - REQUIRE_NOTHROW(bar_node.to_boolean()); - REQUIRE(bar_node.to_boolean() == foo_node.to_boolean()); + REQUIRE_NOTHROW(bar_node.get_value()); + REQUIRE(bar_node.get_value() == foo_node.get_value()); } SECTION("Input source No.4.") @@ -439,14 +439,14 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockMappingTest", "[DeserializerCla REQUIRE(foo_node.has_anchor_name()); REQUIRE(foo_node.get_anchor_name().compare("anchor") == 0); REQUIRE(foo_node.is_integer()); - REQUIRE_NOTHROW(foo_node.to_integer()); - REQUIRE(foo_node.to_integer() == -123); + REQUIRE_NOTHROW(foo_node.get_value()); + REQUIRE(foo_node.get_value() == -123); REQUIRE_NOTHROW(root["bar"]); fkyaml::node& bar_node = root["bar"]; REQUIRE(bar_node.is_integer()); - REQUIRE_NOTHROW(bar_node.to_integer()); - REQUIRE(bar_node.to_integer() == foo_node.to_integer()); + REQUIRE_NOTHROW(bar_node.get_value()); + REQUIRE(bar_node.get_value() == foo_node.get_value()); } SECTION("Input source No.5.") @@ -462,14 +462,14 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockMappingTest", "[DeserializerCla REQUIRE(foo_node.has_anchor_name()); REQUIRE(foo_node.get_anchor_name().compare("anchor") == 0); REQUIRE(foo_node.is_integer()); - REQUIRE_NOTHROW(foo_node.to_integer()); - REQUIRE(foo_node.to_integer() == 567); + REQUIRE_NOTHROW(foo_node.get_value()); + REQUIRE(foo_node.get_value() == 567); REQUIRE_NOTHROW(root["bar"]); fkyaml::node& bar_node = root["bar"]; REQUIRE(bar_node.is_integer()); - REQUIRE_NOTHROW(bar_node.to_integer()); - REQUIRE(bar_node.to_integer() == foo_node.to_integer()); + REQUIRE_NOTHROW(bar_node.get_value()); + REQUIRE(bar_node.get_value() == foo_node.get_value()); } SECTION("Input source No.6.") @@ -485,14 +485,14 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockMappingTest", "[DeserializerCla REQUIRE(foo_node.has_anchor_name()); REQUIRE(foo_node.get_anchor_name().compare("anchor") == 0); REQUIRE(foo_node.is_float_number()); - REQUIRE_NOTHROW(foo_node.to_float_number()); - REQUIRE(foo_node.to_float_number() == 3.14); + REQUIRE_NOTHROW(foo_node.get_value()); + REQUIRE(foo_node.get_value() == 3.14); REQUIRE_NOTHROW(root["bar"]); fkyaml::node& bar_node = root["bar"]; REQUIRE(bar_node.is_float_number()); - REQUIRE_NOTHROW(bar_node.to_float_number()); - REQUIRE(bar_node.to_float_number() == foo_node.to_float_number()); + REQUIRE_NOTHROW(bar_node.get_value()); + REQUIRE(bar_node.get_value() == foo_node.get_value()); } SECTION("Input source No.7.") @@ -508,14 +508,14 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockMappingTest", "[DeserializerCla REQUIRE(foo_node.has_anchor_name()); REQUIRE(foo_node.get_anchor_name().compare("anchor") == 0); REQUIRE(foo_node.is_string()); - REQUIRE_NOTHROW(foo_node.to_string()); - REQUIRE(foo_node.to_string().compare("one") == 0); + REQUIRE_NOTHROW(foo_node.get_value_ref()); + REQUIRE(foo_node.get_value_ref().compare("one") == 0); REQUIRE_NOTHROW(root["bar"]); fkyaml::node& bar_node = root["bar"]; REQUIRE(bar_node.is_string()); - REQUIRE_NOTHROW(bar_node.to_string()); - REQUIRE(bar_node.to_string() == foo_node.to_string()); + REQUIRE_NOTHROW(bar_node.get_value_ref()); + REQUIRE(bar_node.get_value_ref() == foo_node.get_value_ref()); } SECTION("Input source No.8.") @@ -532,18 +532,18 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockMappingTest", "[DeserializerCla REQUIRE(root["foo"].size() == 1); REQUIRE(root["foo"].contains("bar")); REQUIRE(root["foo"]["bar"].is_string()); - REQUIRE(root["foo"]["bar"].to_string() == "baz"); + REQUIRE(root["foo"]["bar"].get_value_ref() == "baz"); REQUIRE(root.contains("qux")); REQUIRE(root["qux"].is_integer()); - REQUIRE(root["qux"].to_integer() == 123); + REQUIRE(root["qux"].get_value() == 123); REQUIRE(root.contains("quux")); REQUIRE(root["quux"].is_mapping()); REQUIRE(root["quux"].size() == 1); REQUIRE(root["quux"].contains("corge")); REQUIRE(root["quux"]["corge"].is_string()); - REQUIRE(root["quux"]["corge"].to_string() == "grault"); + REQUIRE(root["quux"]["corge"].get_value_ref() == "grault"); } SECTION("Input source No.9.") @@ -564,11 +564,11 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockMappingTest", "[DeserializerCla REQUIRE(root["foo"]["bar"].contains("baz")); REQUIRE(root["foo"]["bar"]["baz"].is_integer()); - REQUIRE(root["foo"]["bar"]["baz"].to_integer() == 123); + REQUIRE(root["foo"]["bar"]["baz"].get_value() == 123); REQUIRE(root.contains("qux")); REQUIRE(root["qux"].is_boolean()); - REQUIRE(root["qux"].to_boolean() == true); + REQUIRE(root["qux"].get_value() == true); } } @@ -594,14 +594,14 @@ TEST_CASE("DeserializerClassTest_DeserializeFlowSequenceTest", "[DeserializerCla REQUIRE_NOTHROW(test_node[0]); fkyaml::node& test_0_node = test_node[0]; REQUIRE(test_0_node.is_string()); - REQUIRE_NOTHROW(test_0_node.to_string()); - REQUIRE(test_0_node.to_string().compare("foo") == 0); + REQUIRE_NOTHROW(test_0_node.get_value_ref()); + REQUIRE(test_0_node.get_value_ref().compare("foo") == 0); REQUIRE_NOTHROW(test_node[1]); fkyaml::node& test_1_node = test_node[1]; REQUIRE(test_1_node.is_string()); - REQUIRE_NOTHROW(test_1_node.to_string()); - REQUIRE(test_1_node.to_string().compare("bar") == 0); + REQUIRE_NOTHROW(test_1_node.get_value_ref()); + REQUIRE(test_1_node.get_value_ref().compare("bar") == 0); } } @@ -628,20 +628,20 @@ TEST_CASE("DeserializerClassTest_DeserializeFlowMappingTest", "[DeserializerClas REQUIRE_NOTHROW(test_node["bool"]); fkyaml::node& test_bool_node = test_node["bool"]; REQUIRE(test_bool_node.is_boolean()); - REQUIRE_NOTHROW(test_bool_node.to_boolean()); - REQUIRE(test_bool_node.to_boolean() == true); + REQUIRE_NOTHROW(test_bool_node.get_value()); + REQUIRE(test_bool_node.get_value() == true); REQUIRE_NOTHROW(test_node["foo"]); fkyaml::node& test_foo_node = test_node["foo"]; REQUIRE(test_foo_node.is_string()); - REQUIRE_NOTHROW(test_foo_node.to_string()); - REQUIRE(test_foo_node.to_string().compare("bar") == 0); + REQUIRE_NOTHROW(test_foo_node.get_value_ref()); + REQUIRE(test_foo_node.get_value_ref().compare("bar") == 0); REQUIRE_NOTHROW(test_node["pi"]); fkyaml::node& test_pi_node = test_node["pi"]; REQUIRE(test_pi_node.is_float_number()); - REQUIRE_NOTHROW(test_pi_node.to_float_number()); - REQUIRE(test_pi_node.to_float_number() == 3.14); + REQUIRE_NOTHROW(test_pi_node.get_value()); + REQUIRE(test_pi_node.get_value() == 3.14); } SECTION("Input source No.2. (invalid)") @@ -664,20 +664,20 @@ TEST_CASE("DeserializerClassTest_DeserializeInputWithCommentTest", "[Deserialize REQUIRE_NOTHROW(root["foo"]); fkyaml::node& foo_node = root["foo"]; REQUIRE(foo_node.is_string()); - REQUIRE_NOTHROW(foo_node.to_string()); - REQUIRE(foo_node.to_string().compare("one") == 0); + REQUIRE_NOTHROW(foo_node.get_value_ref()); + REQUIRE(foo_node.get_value_ref().compare("one") == 0); REQUIRE_NOTHROW(root["bar"]); fkyaml::node& bar_node = root["bar"]; REQUIRE(bar_node.is_boolean()); - REQUIRE_NOTHROW(bar_node.to_boolean()); - REQUIRE(bar_node.to_boolean() == true); + REQUIRE_NOTHROW(bar_node.get_value()); + REQUIRE(bar_node.get_value() == true); REQUIRE_NOTHROW(root["pi"]); fkyaml::node& pi_node = root["pi"]; REQUIRE(pi_node.is_float_number()); - REQUIRE_NOTHROW(pi_node.to_float_number()); - REQUIRE(pi_node.to_float_number() == 3.14); + REQUIRE_NOTHROW(pi_node.get_value()); + REQUIRE(pi_node.get_value() == 3.14); } TEST_CASE("DeserializerClassTest_DeserializeYAMLVerDirectiveTest", "[DeserializerClassTest]") @@ -697,8 +697,8 @@ TEST_CASE("DeserializerClassTest_DeserializeYAMLVerDirectiveTest", "[Deserialize fkyaml::node& foo_node = root["foo"]; REQUIRE(root.get_yaml_version() == fkyaml::node::yaml_version_t::VER_1_1); REQUIRE(foo_node.is_string()); - REQUIRE_NOTHROW(foo_node.to_string()); - REQUIRE(foo_node.to_string().compare("one") == 0); + REQUIRE_NOTHROW(foo_node.get_value_ref()); + REQUIRE(foo_node.get_value_ref().compare("one") == 0); } SECTION("YAML 1.2") @@ -713,8 +713,8 @@ TEST_CASE("DeserializerClassTest_DeserializeYAMLVerDirectiveTest", "[Deserialize fkyaml::node& foo_node = root["foo"]; REQUIRE(root.get_yaml_version() == fkyaml::node::yaml_version_t::VER_1_2); REQUIRE(foo_node.is_string()); - REQUIRE_NOTHROW(foo_node.to_string()); - REQUIRE(foo_node.to_string().compare("one") == 0); + REQUIRE_NOTHROW(foo_node.get_value_ref()); + REQUIRE(foo_node.get_value_ref().compare("one") == 0); } } diff --git a/test/unit_test/test_iterator_class.cpp b/test/unit_test/test_iterator_class.cpp index b557f2cf..1fdeb2d0 100644 --- a/test/unit_test/test_iterator_class.cpp +++ b/test/unit_test/test_iterator_class.cpp @@ -15,7 +15,7 @@ TEST_CASE("IteratorClassTest_SequenceCtorTest", "[IteratorClassTest]") { fkyaml::node sequence = fkyaml::node::sequence(); fkyaml::detail::iterator iterator( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); REQUIRE(iterator.type() == fkyaml::detail::iterator_t::SEQUENCE); } @@ -23,7 +23,7 @@ TEST_CASE("IteratorClassTest_MappingCtorTest", "[IteratorClassTest]") { fkyaml::node mapping = fkyaml::node::mapping(); fkyaml::detail::iterator iterator( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE(iterator.type() == fkyaml::detail::iterator_t::MAPPING); } @@ -31,7 +31,7 @@ TEST_CASE("IteratorClassTest_SequenceCopyCtorTest", "[IteratorClassTest]") { fkyaml::node sequence = fkyaml::node::sequence({fkyaml::node()}); fkyaml::detail::iterator copied( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); fkyaml::detail::iterator iterator(copied); REQUIRE(iterator.type() == fkyaml::detail::iterator_t::SEQUENCE); REQUIRE(iterator->is_null()); @@ -41,7 +41,7 @@ TEST_CASE("IteratorClassTest_MappingCopyCtorTest", "[IteratorClassTest]") { fkyaml::node mapping = fkyaml::node::mapping({{"test", fkyaml::node()}}); fkyaml::detail::iterator copied( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); fkyaml::detail::iterator iterator(copied); REQUIRE(iterator.type() == fkyaml::detail::iterator_t::MAPPING); REQUIRE(iterator.key().compare("test") == 0); @@ -52,17 +52,17 @@ TEST_CASE("IteratorClassTest_SequenceMoveCtorTest", "[IteratorClassTest]") { fkyaml::node sequence = {std::string("test")}; fkyaml::detail::iterator moved( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); fkyaml::detail::iterator iterator(std::move(moved)); REQUIRE(iterator.type() == fkyaml::detail::iterator_t::SEQUENCE); REQUIRE(iterator->is_string()); - REQUIRE(iterator->to_string().compare("test") == 0); + REQUIRE(iterator->get_value_ref().compare("test") == 0); } TEST_CASE("IteratorClassTest_MappingMoveCtorTest", "[IteratorClassTest]") { fkyaml::node mapping = fkyaml::node::mapping({{"test", fkyaml::node()}}); - fkyaml::detail::iterator moved(fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::iterator moved(fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); fkyaml::detail::iterator iterator(std::move(moved)); REQUIRE(iterator.type() == fkyaml::detail::iterator_t::MAPPING); REQUIRE(iterator.key().compare("test") == 0); @@ -75,7 +75,7 @@ TEST_CASE("IteratorClassTest_AssignmentOperatorTest", "[IteratorClassTest]") { fkyaml::node sequence = fkyaml::node::sequence({fkyaml::node()}); fkyaml::detail::iterator iterator( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); SECTION("Test lvalue iterator.") { @@ -96,17 +96,17 @@ TEST_CASE("IteratorClassTest_AssignmentOperatorTest", "[IteratorClassTest]") { fkyaml::node copied_seq = {std::string("test")}; fkyaml::detail::iterator copied_itr( - fkyaml::detail::sequence_iterator_tag {}, copied_seq.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, copied_seq.get_value_ref().begin()); fkyaml::node sequence = {false}; fkyaml::detail::iterator iterator( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); SECTION("Test lvalue iterator.") { iterator = copied_itr; REQUIRE(iterator.type() == fkyaml::detail::iterator_t::SEQUENCE); REQUIRE(iterator->is_string()); - REQUIRE(iterator->to_string().compare("test") == 0); + REQUIRE(iterator->get_value_ref().compare("test") == 0); } SECTION("Test rvalue iterator.") @@ -114,7 +114,7 @@ TEST_CASE("IteratorClassTest_AssignmentOperatorTest", "[IteratorClassTest]") iterator = std::move(copied_itr); REQUIRE(iterator.type() == fkyaml::detail::iterator_t::SEQUENCE); REQUIRE(iterator->is_string()); - REQUIRE(iterator->to_string().compare("test") == 0); + REQUIRE(iterator->get_value_ref().compare("test") == 0); } } @@ -122,10 +122,10 @@ TEST_CASE("IteratorClassTest_AssignmentOperatorTest", "[IteratorClassTest]") { fkyaml::node copied_map = {{std::string("key"), std::string("test")}}; fkyaml::detail::iterator copied_itr( - fkyaml::detail::mapping_iterator_tag {}, copied_map.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, copied_map.get_value_ref().begin()); fkyaml::node map = {{std::string("foo"), false}}; fkyaml::detail::iterator iterator( - fkyaml::detail::mapping_iterator_tag {}, map.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, map.get_value_ref().begin()); SECTION("Test lvalue iterator.") { @@ -133,7 +133,7 @@ TEST_CASE("IteratorClassTest_AssignmentOperatorTest", "[IteratorClassTest]") REQUIRE(iterator.type() == fkyaml::detail::iterator_t::MAPPING); REQUIRE(iterator.key().compare("key") == 0); REQUIRE(iterator.value().is_string()); - REQUIRE(iterator.value().to_string().compare("test") == 0); + REQUIRE(iterator.value().get_value_ref().compare("test") == 0); } SECTION("Test rvalue iterator.") @@ -142,7 +142,7 @@ TEST_CASE("IteratorClassTest_AssignmentOperatorTest", "[IteratorClassTest]") REQUIRE(iterator.type() == fkyaml::detail::iterator_t::MAPPING); REQUIRE(iterator.key().compare("key") == 0); REQUIRE(iterator.value().is_string()); - REQUIRE(iterator.value().to_string().compare("test") == 0); + REQUIRE(iterator.value().get_value_ref().compare("test") == 0); } } } @@ -153,16 +153,16 @@ TEST_CASE("IteratorClassTest_ArrowOperatorTest", "[IteratorClassTest]") { fkyaml::node seq = {std::string("test")}; fkyaml::detail::iterator iterator( - fkyaml::detail::sequence_iterator_tag {}, seq.to_sequence().begin()); - REQUIRE(iterator.operator->() == &(seq.to_sequence().operator[](0))); + fkyaml::detail::sequence_iterator_tag {}, seq.get_value_ref().begin()); + REQUIRE(iterator.operator->() == &(seq.get_value_ref().operator[](0))); } SECTION("Test mapping iterator.") { fkyaml::node map = {{std::string("key"), std::string("test")}}; fkyaml::detail::iterator iterator( - fkyaml::detail::mapping_iterator_tag {}, map.to_mapping().begin()); - REQUIRE(iterator.operator->() == &(map.to_mapping().operator[]("key"))); + fkyaml::detail::mapping_iterator_tag {}, map.get_value_ref().begin()); + REQUIRE(iterator.operator->() == &(map.get_value_ref().operator[]("key"))); } } @@ -172,16 +172,16 @@ TEST_CASE("IteratorClassTest_DereferenceOperatorTest", "[IteratorClassTest]") { fkyaml::node seq = {std::string("test")}; fkyaml::detail::iterator iterator( - fkyaml::detail::sequence_iterator_tag {}, seq.to_sequence().begin()); - REQUIRE(&(iterator.operator*()) == &(seq.to_sequence().operator[](0))); + fkyaml::detail::sequence_iterator_tag {}, seq.get_value_ref().begin()); + REQUIRE(&(iterator.operator*()) == &(seq.get_value_ref().operator[](0))); } SECTION("Test mapping iterator.") { fkyaml::node map = fkyaml::node::mapping({{"key", std::string("test")}}); fkyaml::detail::iterator iterator( - fkyaml::detail::mapping_iterator_tag {}, map.to_mapping().begin()); - REQUIRE(&(iterator.operator*()) == &(map.to_mapping().operator[]("key"))); + fkyaml::detail::mapping_iterator_tag {}, map.get_value_ref().begin()); + REQUIRE(&(iterator.operator*()) == &(map.get_value_ref().operator[]("key"))); } } @@ -191,21 +191,21 @@ TEST_CASE("IteratorClassTest_CompoundAssignmentOperatorBySumTest", "[IteratorCla { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); iterator += 1; REQUIRE(iterator->is_boolean()); - REQUIRE(iterator->to_boolean() == true); + REQUIRE(iterator->get_value() == true); } SECTION("Test mapping iterator.") { fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); iterator += 1; REQUIRE(iterator.key().compare("test1") == 0); REQUIRE(iterator.value().is_boolean()); - REQUIRE(iterator.value().to_boolean() == true); + REQUIRE(iterator.value().get_value() == true); } } @@ -215,21 +215,21 @@ TEST_CASE("IteratorClassTest_PlusOperatorTest", "[IteratorClassTest]") { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); fkyaml::detail::iterator after_plus_itr = iterator + 1; REQUIRE(after_plus_itr->is_boolean()); - REQUIRE(after_plus_itr->to_boolean() == true); + REQUIRE(after_plus_itr->get_value() == true); } SECTION("Test mapping iterator.") { fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); fkyaml::detail::iterator after_plus_itr = iterator + 1; REQUIRE(after_plus_itr.key().compare("test1") == 0); REQUIRE(after_plus_itr.value().is_boolean()); - REQUIRE(after_plus_itr.value().to_boolean() == true); + REQUIRE(after_plus_itr.value().get_value() == true); } } @@ -239,21 +239,21 @@ TEST_CASE("IteratorClassTest_PreIncrementOperatorTest", "[IteratorClassTest]") { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); ++iterator; REQUIRE(iterator->is_boolean()); - REQUIRE(iterator->to_boolean() == true); + REQUIRE(iterator->get_value() == true); } SECTION("Test mapping iterator.") { fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); ++iterator; REQUIRE(iterator.key().compare("test1") == 0); REQUIRE(iterator.value().is_boolean()); - REQUIRE(iterator.value().to_boolean() == true); + REQUIRE(iterator.value().get_value() == true); } } @@ -263,21 +263,21 @@ TEST_CASE("IteratorClassTest_PostIncrementOperatorTest", "[IteratorClassTest]") { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); iterator++; REQUIRE(iterator->is_boolean()); - REQUIRE(iterator->to_boolean() == true); + REQUIRE(iterator->get_value() == true); } SECTION("Test mapping iterator.") { fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); iterator++; REQUIRE(iterator.key().compare("test1") == 0); REQUIRE(iterator.value().is_boolean()); - REQUIRE(iterator.value().to_boolean() == true); + REQUIRE(iterator.value().get_value() == true); } } @@ -287,21 +287,21 @@ TEST_CASE("IteratorClassTest_CompoundAssignmentOperatorByDifferenceTest", "[Iter { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().end()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().end()); iterator -= 1; REQUIRE(iterator->is_boolean()); - REQUIRE(iterator->to_boolean() == true); + REQUIRE(iterator->get_value() == true); } SECTION("Test mapping iterator.") { fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().end()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().end()); iterator -= 1; REQUIRE(iterator.key().compare("test1") == 0); REQUIRE(iterator.value().is_boolean()); - REQUIRE(iterator.value().to_boolean() == true); + REQUIRE(iterator.value().get_value() == true); } } @@ -311,21 +311,21 @@ TEST_CASE("IteratorClassTest_MinusOperatorTest", "[IteratorClassTest]") { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().end()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().end()); fkyaml::detail::iterator after_minus_itr = iterator - 1; REQUIRE(after_minus_itr->is_boolean()); - REQUIRE(after_minus_itr->to_boolean() == true); + REQUIRE(after_minus_itr->get_value() == true); } SECTION("Test mapping iterator.") { fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().end()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().end()); fkyaml::detail::iterator after_minus_itr = iterator - 1; REQUIRE(after_minus_itr.key().compare("test1") == 0); REQUIRE(after_minus_itr.value().is_boolean()); - REQUIRE(after_minus_itr.value().to_boolean() == true); + REQUIRE(after_minus_itr.value().get_value() == true); } } @@ -335,21 +335,21 @@ TEST_CASE("IteratorClassTest_PreDecrementOperatorTest", "[IteratorClassTest]") { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().end()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().end()); --iterator; REQUIRE(iterator->is_boolean()); - REQUIRE(iterator->to_boolean() == true); + REQUIRE(iterator->get_value() == true); } SECTION("Test mapping iterator.") { fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().end()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().end()); --iterator; REQUIRE(iterator.key().compare("test1") == 0); REQUIRE(iterator.value().is_boolean()); - REQUIRE(iterator.value().to_boolean() == true); + REQUIRE(iterator.value().get_value() == true); } } @@ -359,21 +359,21 @@ TEST_CASE("IteratorClassTest_PostDecrementOperatorTest", "[IteratorClassTest]") { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().end()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().end()); iterator--; REQUIRE(iterator->is_boolean()); - REQUIRE(iterator->to_boolean() == true); + REQUIRE(iterator->get_value() == true); } SECTION("Test mapping iterator.") { fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().end()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().end()); iterator--; REQUIRE(iterator.key().compare("test1") == 0); REQUIRE(iterator.value().is_boolean()); - REQUIRE(iterator.value().to_boolean() == true); + REQUIRE(iterator.value().get_value() == true); } } @@ -383,9 +383,9 @@ TEST_CASE("IteratorClassTest_EqualToOperatorTest", "[IteratorClassTest]") { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); fkyaml::detail::iterator rhs( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); REQUIRE(lhs == rhs); } @@ -393,9 +393,9 @@ TEST_CASE("IteratorClassTest_EqualToOperatorTest", "[IteratorClassTest]") { fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator lhs( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); fkyaml::detail::iterator rhs( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE(lhs == rhs); } @@ -403,10 +403,10 @@ TEST_CASE("IteratorClassTest_EqualToOperatorTest", "[IteratorClassTest]") { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator rhs( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE_THROWS_AS(lhs == rhs, fkyaml::exception); } } @@ -417,9 +417,9 @@ TEST_CASE("IteratorClassTest_NotEqualToOperatorTest", "[IteratorClassTest]") { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); fkyaml::detail::iterator rhs( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); ++rhs; REQUIRE(lhs != rhs); } @@ -428,9 +428,9 @@ TEST_CASE("IteratorClassTest_NotEqualToOperatorTest", "[IteratorClassTest]") { fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator lhs( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); fkyaml::detail::iterator rhs( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); ++rhs; REQUIRE(lhs != rhs); } @@ -439,10 +439,10 @@ TEST_CASE("IteratorClassTest_NotEqualToOperatorTest", "[IteratorClassTest]") { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator rhs( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE_THROWS_AS(lhs == rhs, fkyaml::exception); } } @@ -453,9 +453,9 @@ TEST_CASE("IteratorClassTest_LessThanOperatorTest", "[IteratorClassTest]") { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); fkyaml::detail::iterator rhs( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); REQUIRE_FALSE(lhs < rhs); ++rhs; REQUIRE(lhs < rhs); @@ -465,9 +465,9 @@ TEST_CASE("IteratorClassTest_LessThanOperatorTest", "[IteratorClassTest]") { fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator lhs( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); fkyaml::detail::iterator rhs( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE_THROWS_AS(lhs < rhs, fkyaml::exception); } @@ -475,10 +475,10 @@ TEST_CASE("IteratorClassTest_LessThanOperatorTest", "[IteratorClassTest]") { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator rhs( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE_THROWS_AS(lhs < rhs, fkyaml::exception); } } @@ -489,9 +489,9 @@ TEST_CASE("IteratorClassTest_LessThanOrEqualToOperatorTest", "[IteratorClassTest { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); fkyaml::detail::iterator rhs( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); ++lhs; REQUIRE_FALSE(lhs <= rhs); --lhs; @@ -504,9 +504,9 @@ TEST_CASE("IteratorClassTest_LessThanOrEqualToOperatorTest", "[IteratorClassTest { fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator lhs( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); fkyaml::detail::iterator rhs( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE_THROWS_AS(lhs <= rhs, fkyaml::exception); } @@ -514,10 +514,10 @@ TEST_CASE("IteratorClassTest_LessThanOrEqualToOperatorTest", "[IteratorClassTest { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator rhs( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE_THROWS_AS(lhs <= rhs, fkyaml::exception); } } @@ -528,9 +528,9 @@ TEST_CASE("IteratorClassTest_GreaterThanOperatorTest", "[IteratorClassTest]") { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); fkyaml::detail::iterator rhs( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); REQUIRE_FALSE(lhs > rhs); ++lhs; REQUIRE(lhs > rhs); @@ -540,9 +540,9 @@ TEST_CASE("IteratorClassTest_GreaterThanOperatorTest", "[IteratorClassTest]") { fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator lhs( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); fkyaml::detail::iterator rhs( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE_THROWS_AS(lhs > rhs, fkyaml::exception); } @@ -550,10 +550,10 @@ TEST_CASE("IteratorClassTest_GreaterThanOperatorTest", "[IteratorClassTest]") { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator rhs( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE_THROWS_AS(lhs > rhs, fkyaml::exception); } } @@ -564,9 +564,9 @@ TEST_CASE("IteratorClassTest_GreaterThanOrEqualToOperatorTest", "[IteratorClassT { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); fkyaml::detail::iterator rhs( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); ++rhs; REQUIRE_FALSE(lhs >= rhs); --rhs; @@ -579,9 +579,9 @@ TEST_CASE("IteratorClassTest_GreaterThanOrEqualToOperatorTest", "[IteratorClassT { fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator lhs( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); fkyaml::detail::iterator rhs( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE_THROWS_AS(lhs >= rhs, fkyaml::exception); } @@ -589,10 +589,10 @@ TEST_CASE("IteratorClassTest_GreaterThanOrEqualToOperatorTest", "[IteratorClassT { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator rhs( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE_THROWS_AS(lhs >= rhs, fkyaml::exception); } } @@ -603,7 +603,7 @@ TEST_CASE("IteratorClassTest_TypeGetterTest", "[IteratorClassTest]") { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); REQUIRE(iterator.type() == fkyaml::detail::iterator_t::SEQUENCE); } @@ -611,7 +611,7 @@ TEST_CASE("IteratorClassTest_TypeGetterTest", "[IteratorClassTest]") { fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE(iterator.type() == fkyaml::detail::iterator_t::MAPPING); } } @@ -622,7 +622,7 @@ TEST_CASE("IteratorClassTest_KeyGetterTest", "[IteratorClassTest]") { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); REQUIRE_THROWS_AS(iterator.key(), fkyaml::exception); } @@ -630,7 +630,7 @@ TEST_CASE("IteratorClassTest_KeyGetterTest", "[IteratorClassTest]") { fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE_NOTHROW(iterator.key()); REQUIRE(iterator.key().compare("test0") == 0); } @@ -642,17 +642,17 @@ TEST_CASE("IteratorClassTest_ValueGetterTest", "[IteratorClassTest]") { fkyaml::node sequence = {false, true}; fkyaml::detail::iterator iterator( - fkyaml::detail::sequence_iterator_tag {}, sequence.to_sequence().begin()); + fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); REQUIRE(iterator.value().is_boolean()); - REQUIRE(iterator.value().to_boolean() == false); + REQUIRE(iterator.value().get_value() == false); } SECTION("Test mapping iterator.") { fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; fkyaml::detail::iterator iterator( - fkyaml::detail::mapping_iterator_tag {}, mapping.to_mapping().begin()); + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE(iterator.value().is_boolean()); - REQUIRE(iterator.value().to_boolean() == false); + REQUIRE(iterator.value().get_value() == false); } } diff --git a/test/unit_test/test_node_class.cpp b/test/unit_test/test_node_class.cpp index cb3a6d3f..90c7d334 100644 --- a/test/unit_test/test_node_class.cpp +++ b/test/unit_test/test_node_class.cpp @@ -49,21 +49,21 @@ TEST_CASE("NodeClassTest_BooleanTypeCtorTest", "[NodeClassTest]") { fkyaml::node node(fkyaml::node::node_t::BOOLEAN); REQUIRE(node.is_boolean()); - REQUIRE(node.to_boolean() == false); + REQUIRE(node.get_value_ref() == false); } TEST_CASE("NodeClassTest_IntegerTypeCtorTest", "[NodeClassTest]") { fkyaml::node node(fkyaml::node::node_t::INTEGER); REQUIRE(node.is_integer()); - REQUIRE(node.to_integer() == 0); + REQUIRE(node.get_value_ref() == 0); } TEST_CASE("NodeClassTest_FloatNumberTypeCtorTest", "[NodeClassTest]") { fkyaml::node node(fkyaml::node::node_t::FLOAT_NUMBER); REQUIRE(node.is_float_number()); - REQUIRE(node.to_float_number() == 0.0); + REQUIRE(node.get_value_ref() == 0.0); } TEST_CASE("NodeClassTest_StringTypeCtorTest", "[NodeClassTest]") @@ -94,9 +94,9 @@ TEST_CASE("NodeClassTest_SequenceCtorTest", "[NodeClassTest]") REQUIRE(node.is_sequence()); REQUIRE(node.size() == 2); REQUIRE(node[0].is_boolean()); - REQUIRE(node[0].to_boolean() == true); + REQUIRE(node[0].get_value_ref() == true); REQUIRE(node[1].is_boolean()); - REQUIRE(node[1].to_boolean() == false); + REQUIRE(node[1].get_value_ref() == false); } TEST_CASE("NodeClassTest_MappingCtorTest", "[NodeClassTest]") @@ -107,7 +107,7 @@ TEST_CASE("NodeClassTest_MappingCtorTest", "[NodeClassTest]") REQUIRE(node.size() == 1); REQUIRE(node.contains("test")); REQUIRE(node["test"].is_boolean()); - REQUIRE(node["test"].to_boolean() == true); + REQUIRE(node["test"].get_value_ref() == true); } TEST_CASE("NodeClassTest_NullCtorTest", "[NodeClassTest]") @@ -122,7 +122,7 @@ TEST_CASE("NodeClassTest_BooleanCtorTest", "[NodeClassTest]") fkyaml::node node(true); REQUIRE(node.type() == fkyaml::node::node_t::BOOLEAN); REQUIRE(node.is_boolean()); - REQUIRE(node.to_boolean() == true); + REQUIRE(node.get_value_ref() == true); } TEST_CASE("NodeClassTest_IntegerCtorTest", "[NodeClassTest]") @@ -130,7 +130,7 @@ TEST_CASE("NodeClassTest_IntegerCtorTest", "[NodeClassTest]") fkyaml::node node(23467); REQUIRE(node.type() == fkyaml::node::node_t::INTEGER); REQUIRE(node.is_integer()); - REQUIRE(node.to_integer() == 23467); + REQUIRE(node.get_value_ref() == 23467); } TEST_CASE("NodeClassTest_FloatNumberCtorTest", "[NodeClassTest]") @@ -138,7 +138,7 @@ TEST_CASE("NodeClassTest_FloatNumberCtorTest", "[NodeClassTest]") fkyaml::node node(3.14); REQUIRE(node.type() == fkyaml::node::node_t::FLOAT_NUMBER); REQUIRE(node.is_float_number()); - REQUIRE(node.to_float_number() == 3.14); + REQUIRE(node.get_value_ref() == 3.14); } TEST_CASE("NodeClassTest_StringCtorTest", "[NodeClassTest]") @@ -147,7 +147,7 @@ TEST_CASE("NodeClassTest_StringCtorTest", "[NodeClassTest]") REQUIRE(node.type() == fkyaml::node::node_t::STRING); REQUIRE(node.is_string()); REQUIRE(node.size() == 4); - REQUIRE(node.to_string() == "test"); + REQUIRE(node.get_value_ref() == "test"); } TEST_CASE("NodeClassTest_SequenceCopyCtorTest", "[NodeClassTest]") @@ -159,14 +159,14 @@ TEST_CASE("NodeClassTest_SequenceCopyCtorTest", "[NodeClassTest]") REQUIRE(node.size() == 2); REQUIRE_NOTHROW(node[0]); REQUIRE(node[0].is_boolean()); - REQUIRE_NOTHROW(node[0].to_boolean()); - REQUIRE(node[0].to_boolean() == true); + REQUIRE_NOTHROW(node[0].get_value_ref()); + REQUIRE(node[0].get_value_ref() == true); REQUIRE_NOTHROW(node[1]); REQUIRE(node[1].is_string()); - REQUIRE_NOTHROW(node[1].to_string()); - REQUIRE_NOTHROW(node[1].to_string().size()); - REQUIRE(node[1].to_string().size() == 4); - REQUIRE(node[1].to_string().compare("test") == 0); + REQUIRE_NOTHROW(node[1].get_value_ref()); + REQUIRE_NOTHROW(node[1].get_value_ref().size()); + REQUIRE(node[1].get_value_ref().size() == 4); + REQUIRE(node[1].get_value_ref().compare("test") == 0); } TEST_CASE("NodeClassTest_MappingCopyCtorTest", "[NodeClassTest]") @@ -178,12 +178,12 @@ TEST_CASE("NodeClassTest_MappingCopyCtorTest", "[NodeClassTest]") REQUIRE(node.size() == 2); REQUIRE_NOTHROW(node["test0"]); REQUIRE(node["test0"].is_integer()); - REQUIRE_NOTHROW(node["test0"].to_integer()); - REQUIRE(node["test0"].to_integer() == 123); + REQUIRE_NOTHROW(node["test0"].get_value_ref()); + REQUIRE(node["test0"].get_value_ref() == 123); REQUIRE_NOTHROW(node["test1"]); REQUIRE(node["test1"].is_float_number()); - REQUIRE_NOTHROW(node["test1"].to_float_number()); - REQUIRE(node["test1"].to_float_number() == 3.14); + REQUIRE_NOTHROW(node["test1"].get_value_ref()); + REQUIRE(node["test1"].get_value_ref() == 3.14); } TEST_CASE("NodeClassTest_NullCopyCtorTest", "[NodeClassTest]") @@ -198,8 +198,8 @@ TEST_CASE("NodeClassTest_BooleanCopyCtorTest", "[NodeClassTest]") fkyaml::node copied = true; fkyaml::node node(copied); REQUIRE(node.is_boolean()); - REQUIRE_NOTHROW(node.to_boolean()); - REQUIRE(node.to_boolean() == true); + REQUIRE_NOTHROW(node.get_value_ref()); + REQUIRE(node.get_value_ref() == true); } TEST_CASE("NodeClassTest_IntegerCopyCtorTest", "[NodeClassTest]") @@ -207,8 +207,8 @@ TEST_CASE("NodeClassTest_IntegerCopyCtorTest", "[NodeClassTest]") fkyaml::node copied = 123; fkyaml::node node(copied); REQUIRE(node.is_integer()); - REQUIRE_NOTHROW(node.to_integer()); - REQUIRE(node.to_integer() == 123); + REQUIRE_NOTHROW(node.get_value_ref()); + REQUIRE(node.get_value_ref() == 123); } TEST_CASE("NodeClassTest_FloatNumberCopyCtorTest", "[NodeClassTest]") @@ -216,8 +216,8 @@ TEST_CASE("NodeClassTest_FloatNumberCopyCtorTest", "[NodeClassTest]") fkyaml::node copied = 3.14; fkyaml::node node(copied); REQUIRE(node.is_float_number()); - REQUIRE_NOTHROW(node.to_float_number()); - REQUIRE(node.to_float_number() == 3.14); + REQUIRE_NOTHROW(node.get_value_ref()); + REQUIRE(node.get_value_ref() == 3.14); } TEST_CASE("NodeClassTest_StringCopyCtorTest", "[NodeClassTest]") @@ -227,8 +227,8 @@ TEST_CASE("NodeClassTest_StringCopyCtorTest", "[NodeClassTest]") REQUIRE(node.is_string()); REQUIRE_NOTHROW(node.size()); REQUIRE(node.size() == 4); - REQUIRE_NOTHROW(node.to_string()); - REQUIRE(node.to_string().compare("test") == 0); + REQUIRE_NOTHROW(node.get_value_ref()); + REQUIRE(node.get_value_ref().compare("test") == 0); } TEST_CASE("NodeClassTest_AliasCopyCtorTest", "[NodeClassTest]") @@ -238,8 +238,8 @@ TEST_CASE("NodeClassTest_AliasCopyCtorTest", "[NodeClassTest]") fkyaml::node tmp_alias = fkyaml::node::alias_of(tmp); fkyaml::node alias(tmp_alias); REQUIRE(alias.is_boolean()); - REQUIRE_NOTHROW(alias.to_boolean()); - REQUIRE(alias.to_boolean() == true); + REQUIRE_NOTHROW(alias.get_value_ref()); + REQUIRE(alias.get_value_ref() == true); } TEST_CASE("NodeClassTest_SequenceMoveCtorTest", "[NodeClassTest]") @@ -251,14 +251,14 @@ TEST_CASE("NodeClassTest_SequenceMoveCtorTest", "[NodeClassTest]") REQUIRE(node.size() == 2); REQUIRE_NOTHROW(node[0]); REQUIRE(node[0].is_boolean()); - REQUIRE_NOTHROW(node[0].to_boolean()); - REQUIRE(node[0].to_boolean() == true); + REQUIRE_NOTHROW(node[0].get_value_ref()); + REQUIRE(node[0].get_value_ref() == true); REQUIRE_NOTHROW(node[1]); REQUIRE(node[1].is_string()); - REQUIRE_NOTHROW(node[1].to_string()); - REQUIRE_NOTHROW(node[1].to_string().size()); - REQUIRE(node[1].to_string().size() == 4); - REQUIRE(node[1].to_string().compare("test") == 0); + REQUIRE_NOTHROW(node[1].get_value_ref()); + REQUIRE_NOTHROW(node[1].get_value_ref().size()); + REQUIRE(node[1].get_value_ref().size() == 4); + REQUIRE(node[1].get_value_ref().compare("test") == 0); } TEST_CASE("NodeClassTest_MappingMoveCtorTest", "[NodeClassTest]") @@ -270,12 +270,12 @@ TEST_CASE("NodeClassTest_MappingMoveCtorTest", "[NodeClassTest]") REQUIRE(node.size() == 2); REQUIRE_NOTHROW(node["test0"]); REQUIRE(node["test0"].is_integer()); - REQUIRE_NOTHROW(node["test0"].to_integer()); - REQUIRE(node["test0"].to_integer() == 123); + REQUIRE_NOTHROW(node["test0"].get_value_ref()); + REQUIRE(node["test0"].get_value_ref() == 123); REQUIRE_NOTHROW(node["test1"]); REQUIRE(node["test1"].is_float_number()); - REQUIRE_NOTHROW(node["test1"].to_float_number()); - REQUIRE(node["test1"].to_float_number() == 3.14); + REQUIRE_NOTHROW(node["test1"].get_value_ref()); + REQUIRE(node["test1"].get_value_ref() == 3.14); } TEST_CASE("NodeClassTest_NullMoveCtorTest", "[NodeClassTest]") @@ -290,8 +290,8 @@ TEST_CASE("NodeClassTest_BooleanMoveCtorTest", "[NodeClassTest]") fkyaml::node moved = true; fkyaml::node node(std::move(moved)); REQUIRE(node.is_boolean()); - REQUIRE_NOTHROW(node.to_boolean()); - REQUIRE(node.to_boolean() == true); + REQUIRE_NOTHROW(node.get_value_ref()); + REQUIRE(node.get_value_ref() == true); } TEST_CASE("NodeClassTest_IntegerMoveCtorTest", "[NodeClassTest]") @@ -299,8 +299,8 @@ TEST_CASE("NodeClassTest_IntegerMoveCtorTest", "[NodeClassTest]") fkyaml::node moved = 123; fkyaml::node node(std::move(moved)); REQUIRE(node.is_integer()); - REQUIRE_NOTHROW(node.to_integer()); - REQUIRE(node.to_integer() == 123); + REQUIRE_NOTHROW(node.get_value_ref()); + REQUIRE(node.get_value_ref() == 123); } TEST_CASE("NodeClassTest_FloatNumberMoveCtorTest", "[NodeClassTest]") @@ -308,8 +308,8 @@ TEST_CASE("NodeClassTest_FloatNumberMoveCtorTest", "[NodeClassTest]") fkyaml::node moved = 3.14; fkyaml::node node(std::move(moved)); REQUIRE(node.is_float_number()); - REQUIRE_NOTHROW(node.to_float_number()); - REQUIRE(node.to_float_number() == 3.14); + REQUIRE_NOTHROW(node.get_value_ref()); + REQUIRE(node.get_value_ref() == 3.14); } TEST_CASE("NodeClassTest_StringMoveCtorTest", "[NodeClassTest]") @@ -319,8 +319,8 @@ TEST_CASE("NodeClassTest_StringMoveCtorTest", "[NodeClassTest]") REQUIRE(node.is_string()); REQUIRE_NOTHROW(node.size()); REQUIRE(node.size() == 4); - REQUIRE_NOTHROW(node.to_string()); - REQUIRE(node.to_string().compare("test") == 0); + REQUIRE_NOTHROW(node.get_value_ref()); + REQUIRE(node.get_value_ref().compare("test") == 0); } TEST_CASE("NodeClassTest_AliasMoveCtorTest", "[NodeClassTest]") @@ -330,8 +330,8 @@ TEST_CASE("NodeClassTest_AliasMoveCtorTest", "[NodeClassTest]") fkyaml::node tmp_alias = fkyaml::node::alias_of(tmp); fkyaml::node alias(std::move(tmp_alias)); REQUIRE(alias.is_boolean()); - REQUIRE_NOTHROW(alias.to_boolean()); - REQUIRE(alias.to_boolean() == true); + REQUIRE_NOTHROW(alias.get_value_ref()); + REQUIRE(alias.get_value_ref() == true); } TEST_CASE("NodeClassTest_InitializerListCtorTest", "[NodeClassTest]") @@ -345,19 +345,20 @@ TEST_CASE("NodeClassTest_InitializerListCtorTest", "[NodeClassTest]") REQUIRE(node.contains("foo")); REQUIRE(node["foo"].is_float_number()); - REQUIRE(node["foo"].to_float_number() == 3.14); + REQUIRE(node["foo"].get_value_ref() == 3.14); REQUIRE(node.contains("bar")); REQUIRE(node["bar"].is_integer()); - REQUIRE(node["bar"].to_integer() == 123); + REQUIRE(node["bar"].get_value_ref() == 123); REQUIRE(node.contains("baz")); REQUIRE(node["baz"].is_sequence()); REQUIRE(node["baz"].size() == 2); - REQUIRE(node["baz"].to_sequence()[0].is_boolean()); - REQUIRE(node["baz"].to_sequence()[0].to_boolean() == true); - REQUIRE(node["baz"].to_sequence()[1].is_boolean()); - REQUIRE(node["baz"].to_sequence()[1].to_boolean() == false); + auto& baz_seq = node["baz"].get_value_ref(); + REQUIRE(baz_seq[0].is_boolean()); + REQUIRE(baz_seq[0].get_value_ref() == true); + REQUIRE(baz_seq[1].is_boolean()); + REQUIRE(baz_seq[1].get_value_ref() == false); REQUIRE(node.contains("qux")); REQUIRE(node["qux"].is_null()); @@ -453,7 +454,7 @@ TEST_CASE("NodeClassTest_MappingNodeFactoryTest", "[NodeClassTest]") REQUIRE(node.is_mapping()); REQUIRE(node.size() == 1); REQUIRE(node["test"].is_boolean()); - REQUIRE(node["test"].to_boolean() == true); + REQUIRE(node["test"].get_value_ref() == true); } SECTION("Test rvalue mapping node factory method.") @@ -462,7 +463,7 @@ TEST_CASE("NodeClassTest_MappingNodeFactoryTest", "[NodeClassTest]") REQUIRE(node.is_mapping()); REQUIRE(node.size() == 1); REQUIRE(node["test"].is_boolean()); - REQUIRE(node["test"].to_boolean() == true); + REQUIRE(node["test"].get_value_ref() == true); } } } @@ -472,7 +473,7 @@ TEST_CASE("NodeClassTest_BooleanNodeFactoryTest", "[NodeClassTest]") auto boolean = GENERATE(true, false); fkyaml::node node = boolean; REQUIRE(node.is_boolean()); - REQUIRE(node.to_boolean() == boolean); + REQUIRE(node.get_value_ref() == boolean); } TEST_CASE("NodeClassTest_IntegerNodeFactoryTest", "[NodeClassTest]") @@ -483,7 +484,7 @@ TEST_CASE("NodeClassTest_IntegerNodeFactoryTest", "[NodeClassTest]") std::numeric_limits::max()); fkyaml::node node = integer; REQUIRE(node.is_integer()); - REQUIRE(node.to_integer() == integer); + REQUIRE(node.get_value_ref() == integer); } TEST_CASE("NodeClassTest_FloatNumberNodeFactoryTest", "[NodeClassTest]") @@ -494,7 +495,7 @@ TEST_CASE("NodeClassTest_FloatNumberNodeFactoryTest", "[NodeClassTest]") std::numeric_limits::max()); fkyaml::node node = float_val; REQUIRE(node.is_float_number()); - REQUIRE(node.to_float_number() == float_val); + REQUIRE(node.get_value_ref() == float_val); } TEST_CASE("NodeClassTest_StringNodeFactoryTest", "[NodeClassTest]") @@ -512,7 +513,7 @@ TEST_CASE("NodeClassTest_StringNodeFactoryTest", "[NodeClassTest]") fkyaml::node node = std::string(str); REQUIRE(node.is_string()); REQUIRE(node.size() == str.size()); - REQUIRE(node.to_string() == str); + REQUIRE(node.get_value_ref() == str); } SECTION("Test rvalue string node factory method.") @@ -520,7 +521,7 @@ TEST_CASE("NodeClassTest_StringNodeFactoryTest", "[NodeClassTest]") fkyaml::node node = std::string("test"); REQUIRE(node.is_string()); REQUIRE(node.size() == 4); - REQUIRE(node.to_string().compare("test") == 0); + REQUIRE(node.get_value_ref().compare("test") == 0); } } @@ -545,7 +546,7 @@ TEST_CASE("NodeClassTest_AliasNodeFactoryTest", "[NodeClassTest]") REQUIRE_NOTHROW(fkyaml::node::alias_of(anchor)); fkyaml::node alias = fkyaml::node::alias_of(anchor); REQUIRE(alias.is_string()); - REQUIRE(alias.to_string().compare("alias_test") == 0); + REQUIRE(alias.get_value_ref().compare("alias_test") == 0); } } @@ -655,7 +656,7 @@ TEST_CASE("NodeClassTest_IntegerSubscriptOperatorTest", "[NodeClassTest]") SECTION("Test nothrow expected integer subscript operators.") { fkyaml::node node = fkyaml::node::sequence(); - node.to_sequence().emplace_back(); + node.get_value_ref().emplace_back(); SECTION("Test non-const non-alias integer subscript operators") { @@ -1421,7 +1422,7 @@ TEST_CASE("NodeClassTest_GetValueTest", "[NodeClassTest]") SECTION("test for sequence value.") { - auto seq = node.get_value(); + auto& seq = node.get_value_ref(); REQUIRE(seq.size() == 2); REQUIRE(seq[0].is_boolean()); REQUIRE(seq[0].get_value() == true); @@ -1443,11 +1444,11 @@ TEST_CASE("NodeClassTest_GetValueTest", "[NodeClassTest]") SECTION("test mapping node value.") { fkyaml::node node( - fkyaml::node_mapping_type {{"test", fkyaml::node(3.14)}, {"foo", fkyaml::node(std::string("bar"))}}); + fkyaml::node::mapping_type {{"test", fkyaml::node(3.14)}, {"foo", fkyaml::node(std::string("bar"))}}); SECTION("test for mapping value.") { - auto map = node.get_value(); + auto& map = node.get_value_ref(); REQUIRE(map.size() == 2); REQUIRE(map.find("test") != map.end()); REQUIRE(map.at("test").is_float_number()); @@ -1600,7 +1601,7 @@ TEST_CASE("NodeClassTest_GetValueTest", "[NodeClassTest]") SECTION("test for string value.") { - auto str = node.get_value(); + auto& str = node.get_value_ref(); REQUIRE(str.size() == 4); REQUIRE(str == "test"); } @@ -1630,22 +1631,22 @@ TEST_CASE("NodeClassTest_ToSequenceTest", "[NodeClassTest]") SECTION("Test non-alias sequence node.") { - REQUIRE_NOTHROW(node.to_sequence()); - REQUIRE(node.to_sequence().size() == 3); + REQUIRE_NOTHROW(node.get_value_ref()); + REQUIRE(node.get_value_ref().size() == 3); for (int i = 0; i < 3; ++i) { - REQUIRE(node.to_sequence()[i].is_null()); + REQUIRE(node.get_value_ref()[i].is_null()); } } SECTION("Test const non-alias sequence node.") { const fkyaml::node const_node = node; - REQUIRE_NOTHROW(const_node.to_sequence()); - REQUIRE(const_node.to_sequence().size() == 3); + REQUIRE_NOTHROW(const_node.get_value_ref()); + REQUIRE(const_node.get_value_ref().size() == 3); for (int i = 0; i < 3; ++i) { - REQUIRE(node.to_sequence()[i].is_null()); + REQUIRE(node.get_value_ref()[i].is_null()); } } @@ -1653,11 +1654,11 @@ TEST_CASE("NodeClassTest_ToSequenceTest", "[NodeClassTest]") { node.add_anchor_name("anchor_name"); fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_NOTHROW(alias.to_sequence()); - REQUIRE(alias.to_sequence().size() == 3); + REQUIRE_NOTHROW(alias.get_value_ref()); + REQUIRE(alias.get_value_ref().size() == 3); for (int i = 0; i < 3; ++i) { - REQUIRE(alias.to_sequence()[i].is_null()); + REQUIRE(alias.get_value_ref()[i].is_null()); } } @@ -1665,11 +1666,11 @@ TEST_CASE("NodeClassTest_ToSequenceTest", "[NodeClassTest]") { node.add_anchor_name("anchor_name"); const fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_NOTHROW(alias.to_sequence()); - REQUIRE(alias.to_sequence().size() == 3); + REQUIRE_NOTHROW(alias.get_value_ref()); + REQUIRE(alias.get_value_ref().size() == 3); for (int i = 0; i < 3; ++i) { - REQUIRE(alias.to_sequence()[i].is_null()); + REQUIRE(alias.get_value_ref()[i].is_null()); } } } @@ -1686,27 +1687,27 @@ TEST_CASE("NodeClassTest_ToSequenceTest", "[NodeClassTest]") SECTION("Test non-alias non-sequence nodes.") { - REQUIRE_THROWS_AS(node.to_sequence(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value_ref(), fkyaml::exception); } SECTION("Test const non-alias non-sequence nodes.") { const fkyaml::node const_node = node; - REQUIRE_THROWS_AS(const_node.to_sequence(), fkyaml::exception); + REQUIRE_THROWS_AS(const_node.get_value_ref(), fkyaml::exception); } SECTION("Test alias non-sequence nodes.") { node.add_anchor_name("anchor_name"); fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_THROWS_AS(alias.to_sequence(), fkyaml::exception); + REQUIRE_THROWS_AS(alias.get_value_ref(), fkyaml::exception); } SECTION("Test const alias non-sequence nodes.") { node.add_anchor_name("anchor_name"); const fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_THROWS_AS(alias.to_sequence(), fkyaml::exception); + REQUIRE_THROWS_AS(alias.get_value_ref(), fkyaml::exception); } } } @@ -1720,8 +1721,8 @@ TEST_CASE("NodeClassTest_ToMappingTest", "[NodeClassTest]") SECTION("Test non-alias mapping node.") { - REQUIRE_NOTHROW(node.to_mapping()); - REQUIRE(node.to_mapping().size() == 3); + REQUIRE_NOTHROW(node.get_value_ref()); + REQUIRE(node.get_value_ref().size() == 3); REQUIRE(node["test0"].is_null()); REQUIRE(node["test1"].is_null()); REQUIRE(node["test2"].is_null()); @@ -1730,8 +1731,8 @@ TEST_CASE("NodeClassTest_ToMappingTest", "[NodeClassTest]") SECTION("Test const non-alias mapping node.") { const fkyaml::node const_node = node; - REQUIRE_NOTHROW(const_node.to_mapping()); - REQUIRE(const_node.to_mapping().size() == 3); + REQUIRE_NOTHROW(const_node.get_value_ref()); + REQUIRE(const_node.get_value_ref().size() == 3); REQUIRE(const_node["test0"].is_null()); REQUIRE(const_node["test1"].is_null()); REQUIRE(const_node["test2"].is_null()); @@ -1741,8 +1742,8 @@ TEST_CASE("NodeClassTest_ToMappingTest", "[NodeClassTest]") { node.add_anchor_name("anchor_name"); fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_NOTHROW(alias.to_mapping()); - REQUIRE(alias.to_mapping().size() == 3); + REQUIRE_NOTHROW(alias.get_value_ref()); + REQUIRE(alias.get_value_ref().size() == 3); REQUIRE(alias["test0"].is_null()); REQUIRE(alias["test1"].is_null()); REQUIRE(alias["test2"].is_null()); @@ -1752,7 +1753,7 @@ TEST_CASE("NodeClassTest_ToMappingTest", "[NodeClassTest]") { node.add_anchor_name("anchor_name"); const fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_NOTHROW(alias.to_mapping()); + REQUIRE_NOTHROW(alias.get_value_ref()); REQUIRE(alias["test0"].is_null()); REQUIRE(alias["test1"].is_null()); REQUIRE(alias["test2"].is_null()); @@ -1771,27 +1772,27 @@ TEST_CASE("NodeClassTest_ToMappingTest", "[NodeClassTest]") SECTION("Test non-alias non-mapping nodes.") { - REQUIRE_THROWS_AS(node.to_mapping(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value_ref(), fkyaml::exception); } SECTION("Test const non-alias non-mapping nodes.") { const fkyaml::node const_node = node; - REQUIRE_THROWS_AS(const_node.to_mapping(), fkyaml::exception); + REQUIRE_THROWS_AS(const_node.get_value_ref(), fkyaml::exception); } SECTION("Test alias non-mapping nodes.") { node.add_anchor_name("anchor_name"); fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_THROWS_AS(alias.to_mapping(), fkyaml::exception); + REQUIRE_THROWS_AS(alias.get_value_ref(), fkyaml::exception); } SECTION("Test const alias non-mapping nodes.") { node.add_anchor_name("anchor_name"); const fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_THROWS_AS(alias.to_mapping(), fkyaml::exception); + REQUIRE_THROWS_AS(alias.get_value_ref(), fkyaml::exception); } } } @@ -1804,31 +1805,31 @@ TEST_CASE("NodeClassTest_ToBooleanTest", "[NodeClassTest]") SECTION("Test non-alias boolean node.") { - REQUIRE_NOTHROW(node.to_boolean()); - REQUIRE(node.to_boolean() == true); + REQUIRE_NOTHROW(node.get_value_ref()); + REQUIRE(node.get_value_ref() == true); } SECTION("Test const non-alias boolean node.") { const fkyaml::node const_node = node; - REQUIRE_NOTHROW(const_node.to_boolean()); - REQUIRE(const_node.to_boolean() == true); + REQUIRE_NOTHROW(const_node.get_value_ref()); + REQUIRE(const_node.get_value_ref() == true); } SECTION("Test alias boolean node.") { node.add_anchor_name("anchor_name"); fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_NOTHROW(alias.to_boolean()); - REQUIRE(alias.to_boolean() == true); + REQUIRE_NOTHROW(alias.get_value_ref()); + REQUIRE(alias.get_value_ref() == true); } SECTION("Test const alias boolean node.") { node.add_anchor_name("anchor_name"); const fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_NOTHROW(alias.to_boolean()); - REQUIRE(alias.to_boolean() == true); + REQUIRE_NOTHROW(alias.get_value_ref()); + REQUIRE(alias.get_value_ref() == true); } } @@ -1844,27 +1845,27 @@ TEST_CASE("NodeClassTest_ToBooleanTest", "[NodeClassTest]") SECTION("Test non-alias non-boolean nodes.") { - REQUIRE_THROWS_AS(node.to_boolean(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value_ref(), fkyaml::exception); } SECTION("Test const non-alias non-boolean nodes.") { const fkyaml::node const_node = node; - REQUIRE_THROWS_AS(const_node.to_boolean(), fkyaml::exception); + REQUIRE_THROWS_AS(const_node.get_value_ref(), fkyaml::exception); } SECTION("Test alias non-boolean nodes.") { node.add_anchor_name("anchor_name"); fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_THROWS_AS(alias.to_boolean(), fkyaml::exception); + REQUIRE_THROWS_AS(alias.get_value_ref(), fkyaml::exception); } SECTION("Test const alias non-boolean nodes.") { node.add_anchor_name("anchor_name"); const fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_THROWS_AS(alias.to_boolean(), fkyaml::exception); + REQUIRE_THROWS_AS(alias.get_value_ref(), fkyaml::exception); } } } @@ -1878,31 +1879,31 @@ TEST_CASE("NodeClassTest_ToIntegerTest", "[NodeClassTest]") SECTION("Test non-alias integer node.") { - REQUIRE_NOTHROW(node.to_integer()); - REQUIRE(node.to_integer() == integer); + REQUIRE_NOTHROW(node.get_value_ref()); + REQUIRE(node.get_value_ref() == integer); } SECTION("Test const non-alias integer node.") { const fkyaml::node const_node = node; - REQUIRE_NOTHROW(const_node.to_integer()); - REQUIRE(const_node.to_integer() == integer); + REQUIRE_NOTHROW(const_node.get_value_ref()); + REQUIRE(const_node.get_value_ref() == integer); } SECTION("Test alias integer node.") { node.add_anchor_name("anchor_name"); fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_NOTHROW(alias.to_integer()); - REQUIRE(alias.to_integer() == integer); + REQUIRE_NOTHROW(alias.get_value_ref()); + REQUIRE(alias.get_value_ref() == integer); } SECTION("Test const alias integer node.") { node.add_anchor_name("anchor_name"); const fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_NOTHROW(alias.to_integer()); - REQUIRE(alias.to_integer() == integer); + REQUIRE_NOTHROW(alias.get_value_ref()); + REQUIRE(alias.get_value_ref() == integer); } } @@ -1918,27 +1919,27 @@ TEST_CASE("NodeClassTest_ToIntegerTest", "[NodeClassTest]") SECTION("Test non-alias non-integer nodes.") { - REQUIRE_THROWS_AS(node.to_integer(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value_ref(), fkyaml::exception); } SECTION("Test const non-alias non-integer nodes.") { const fkyaml::node const_node = node; - REQUIRE_THROWS_AS(const_node.to_integer(), fkyaml::exception); + REQUIRE_THROWS_AS(const_node.get_value_ref(), fkyaml::exception); } SECTION("Test alias non-integer nodes.") { node.add_anchor_name("anchor_name"); fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_THROWS_AS(alias.to_integer(), fkyaml::exception); + REQUIRE_THROWS_AS(alias.get_value_ref(), fkyaml::exception); } SECTION("Test const alias non-integer nodes.") { node.add_anchor_name("anchor_name"); const fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_THROWS_AS(alias.to_integer(), fkyaml::exception); + REQUIRE_THROWS_AS(alias.get_value_ref(), fkyaml::exception); } } } @@ -1952,31 +1953,31 @@ TEST_CASE("NodeClassTest_ToFloatNumberTest", "[NodeClassTest]") SECTION("Test non-alias float number node.") { - REQUIRE_NOTHROW(node.to_float_number()); - REQUIRE(node.to_float_number() == float_val); + REQUIRE_NOTHROW(node.get_value_ref()); + REQUIRE(node.get_value_ref() == float_val); } SECTION("Test const non-alias float number node.") { const fkyaml::node const_node = node; - REQUIRE_NOTHROW(const_node.to_float_number()); - REQUIRE(const_node.to_float_number() == float_val); + REQUIRE_NOTHROW(const_node.get_value_ref()); + REQUIRE(const_node.get_value_ref() == float_val); } SECTION("Test alias float number node.") { node.add_anchor_name("anchor_name"); fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_NOTHROW(alias.to_float_number()); - REQUIRE(alias.to_float_number() == float_val); + REQUIRE_NOTHROW(alias.get_value_ref()); + REQUIRE(alias.get_value_ref() == float_val); } SECTION("Test const alias float number node.") { node.add_anchor_name("anchor_name"); const fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_NOTHROW(alias.to_float_number()); - REQUIRE(alias.to_float_number() == float_val); + REQUIRE_NOTHROW(alias.get_value_ref()); + REQUIRE(alias.get_value_ref() == float_val); } } @@ -1992,27 +1993,27 @@ TEST_CASE("NodeClassTest_ToFloatNumberTest", "[NodeClassTest]") SECTION("Test non-alias non-float-number nodes.") { - REQUIRE_THROWS_AS(node.to_float_number(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value_ref(), fkyaml::exception); } SECTION("Test const non-alias non-float-number nodes.") { const fkyaml::node const_node = node; - REQUIRE_THROWS_AS(const_node.to_float_number(), fkyaml::exception); + REQUIRE_THROWS_AS(const_node.get_value_ref(), fkyaml::exception); } SECTION("Test alias non-float-number nodes.") { node.add_anchor_name("anchor_name"); fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_THROWS_AS(alias.to_float_number(), fkyaml::exception); + REQUIRE_THROWS_AS(alias.get_value_ref(), fkyaml::exception); } SECTION("Test const alias non-float-number nodes.") { node.add_anchor_name("anchor_name"); const fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_THROWS_AS(alias.to_float_number(), fkyaml::exception); + REQUIRE_THROWS_AS(alias.get_value_ref(), fkyaml::exception); } } } @@ -2026,31 +2027,31 @@ TEST_CASE("NodeClassTest_ToStringTest", "[NodeClassTest]") SECTION("Test non-alias string node.") { - REQUIRE_NOTHROW(node.to_string()); - REQUIRE(node.to_string() == str); + REQUIRE_NOTHROW(node.get_value_ref()); + REQUIRE(node.get_value_ref() == str); } SECTION("Test const non-alias string node.") { const fkyaml::node const_node = node; - REQUIRE_NOTHROW(const_node.to_string()); - REQUIRE(const_node.to_string() == str); + REQUIRE_NOTHROW(const_node.get_value_ref()); + REQUIRE(const_node.get_value_ref() == str); } SECTION("Test alias string node.") { node.add_anchor_name("anchor_name"); fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_NOTHROW(alias.to_string()); - REQUIRE(alias.to_string() == str); + REQUIRE_NOTHROW(alias.get_value_ref()); + REQUIRE(alias.get_value_ref() == str); } SECTION("Test const alias string node.") { node.add_anchor_name("anchor_name"); const fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_NOTHROW(alias.to_string()); - REQUIRE(alias.to_string() == str); + REQUIRE_NOTHROW(alias.get_value_ref()); + REQUIRE(alias.get_value_ref() == str); } } @@ -2066,27 +2067,27 @@ TEST_CASE("NodeClassTest_ToStringTest", "[NodeClassTest]") SECTION("Test non-alias non-string nodes.") { - REQUIRE_THROWS_AS(node.to_string(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value_ref(), fkyaml::exception); } SECTION("Test const non-alias non-string nodes.") { const fkyaml::node const_node = node; - REQUIRE_THROWS_AS(const_node.to_string(), fkyaml::exception); + REQUIRE_THROWS_AS(const_node.get_value_ref(), fkyaml::exception); } SECTION("Test alias non-string nodes.") { node.add_anchor_name("anchor_name"); fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_THROWS_AS(alias.to_string(), fkyaml::exception); + REQUIRE_THROWS_AS(alias.get_value_ref(), fkyaml::exception); } SECTION("Test const alias non-string nodes.") { node.add_anchor_name("anchor_name"); const fkyaml::node alias = fkyaml::node::alias_of(node); - REQUIRE_THROWS_AS(alias.to_string(), fkyaml::exception); + REQUIRE_THROWS_AS(alias.get_value_ref(), fkyaml::exception); } } } @@ -2227,9 +2228,9 @@ TEST_CASE("NodeClassTest_SwapTest", "[NodeClassTest]") fkyaml::node rhs_node = 123; lhs_node.swap(rhs_node); REQUIRE(lhs_node.is_integer()); - REQUIRE(lhs_node.to_integer() == 123); + REQUIRE(lhs_node.get_value_ref() == 123); REQUIRE(rhs_node.is_boolean()); - REQUIRE(rhs_node.to_boolean() == true); + REQUIRE(rhs_node.get_value_ref() == true); } TEST_CASE("NodeClassTest_ADLSwapTest", "[NodeClassTest]") @@ -2241,7 +2242,7 @@ TEST_CASE("NodeClassTest_ADLSwapTest", "[NodeClassTest]") swap(lhs_node, rhs_node); REQUIRE(lhs_node.is_integer()); - REQUIRE(lhs_node.to_integer() == 123); + REQUIRE(lhs_node.get_value_ref() == 123); REQUIRE(rhs_node.is_boolean()); - REQUIRE(rhs_node.to_boolean() == true); + REQUIRE(rhs_node.get_value_ref() == true); } diff --git a/test/unit_test/test_node_ref_storage_class.cpp b/test/unit_test/test_node_ref_storage_class.cpp index 34401b23..129363f8 100644 --- a/test/unit_test/test_node_ref_storage_class.cpp +++ b/test/unit_test/test_node_ref_storage_class.cpp @@ -21,7 +21,7 @@ TEST_CASE("NodeRefStorageTest_CtorWithLvalueNodeTest", "[NodeRefStorageTest]") fkyaml::node retrieved_node = storage.release(); REQUIRE(retrieved_node.is_boolean()); - REQUIRE(retrieved_node.to_boolean() == true); + REQUIRE(retrieved_node.get_value() == true); } TEST_CASE("NodeRefStorageTest_CtorWithRvalueNodeTest", "[NodeRefStorageTest]") @@ -32,7 +32,7 @@ TEST_CASE("NodeRefStorageTest_CtorWithRvalueNodeTest", "[NodeRefStorageTest]") fkyaml::node retrieved_node = storage.release(); REQUIRE(retrieved_node.is_float_number()); - REQUIRE(retrieved_node.to_float_number() == 3.14); + REQUIRE(retrieved_node.get_value() == 3.14); } TEST_CASE("NodeRefStorageTest_ArrowOperatorTest", "[NodeRefStorageTest]") @@ -41,7 +41,7 @@ TEST_CASE("NodeRefStorageTest_ArrowOperatorTest", "[NodeRefStorageTest]") fkyaml::detail::node_ref_storage storage(node); REQUIRE(storage.operator->() == &node); REQUIRE(storage->is_integer()); - REQUIRE(storage->to_integer() == 123); + REQUIRE(storage->get_value() == 123); fkyaml::node node2 = {true, false}; fkyaml::detail::node_ref_storage storage2(std::move(node2)); @@ -56,7 +56,7 @@ TEST_CASE("NodeRefStorageTest_ReleaseTest", "[NodeRefStorageTest]") fkyaml::node released_node = storage.release(); REQUIRE(&released_node != &node); REQUIRE(released_node.is_integer()); - REQUIRE(released_node.to_integer() == 123); + REQUIRE(released_node.get_value() == 123); fkyaml::node node2 = {true, false}; fkyaml::detail::node_ref_storage storage2(std::move(node2)); From e7c4c1af4b36c4f6316b31ba5279c719bb238089 Mon Sep 17 00:00:00 2001 From: fktn Date: Tue, 31 Oct 2023 02:07:54 +0900 Subject: [PATCH 28/48] deleted one-sided type aliases --- include/fkYAML/detail/input/deserializer.hpp | 3 +- include/fkYAML/node.hpp | 18 --- test/unit_test/test_deserializer_class.cpp | 21 +++- test/unit_test/test_iterator_class.cpp | 3 +- .../unit_test/test_lexical_analyzer_class.cpp | 80 ++++++------ test/unit_test/test_node_class.cpp | 118 +++++++++--------- test/unit_test/test_serializer_class.cpp | 4 +- 7 files changed, 120 insertions(+), 127 deletions(-) diff --git a/include/fkYAML/detail/input/deserializer.hpp b/include/fkYAML/detail/input/deserializer.hpp index 32917d8b..df455f20 100644 --- a/include/fkYAML/detail/input/deserializer.hpp +++ b/include/fkYAML/detail/input/deserializer.hpp @@ -155,7 +155,8 @@ class basic_deserializer } // for the second or later mapping items in a sequence node. - m_node_stack.back()->template get_value_ref().emplace_back(BasicNodeType::mapping()); + m_node_stack.back()->template get_value_ref().emplace_back( + BasicNodeType::mapping()); m_current_node = &(m_node_stack.back()->template get_value_ref().back()); set_yaml_version(*m_current_node); break; diff --git a/include/fkYAML/node.hpp b/include/fkYAML/node.hpp index 4d04342b..f0ee2e9d 100644 --- a/include/fkYAML/node.hpp +++ b/include/fkYAML/node.hpp @@ -1101,24 +1101,6 @@ inline void swap( /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/node/ using node = basic_node<>; -/// @brief A default type for sequence node values. -using node_sequence_type = typename node::sequence_type; - -/// @brief A default type for mapping node values. -using node_mapping_type = typename node::mapping_type; - -/// @brief A default type for boolean node values. -using node_boolean_type = typename node::boolean_type; - -/// @brief A default type for integer node values. -using node_integer_type = typename node::integer_type; - -/// @brief A default type for float number node values. -using node_float_number_type = typename node::float_number_type; - -/// @brief A default type for string node values. -using node_string_type = typename node::string_type; - FK_YAML_NAMESPACE_END #endif /* FK_YAML_NODE_HPP_ */ diff --git a/test/unit_test/test_deserializer_class.cpp b/test/unit_test/test_deserializer_class.cpp index d573637d..6754f28e 100644 --- a/test/unit_test/test_deserializer_class.cpp +++ b/test/unit_test/test_deserializer_class.cpp @@ -208,7 +208,8 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockSequenceTest", "[DeserializerCl fkyaml::node& test_1_node = test_node[1]; REQUIRE(test_1_node.is_boolean()); REQUIRE_NOTHROW(test_1_node.get_value()); - REQUIRE(test_1_node.get_value() == test_0_node.get_value()); + REQUIRE( + test_1_node.get_value() == test_0_node.get_value()); } SECTION("Input source No.4.") @@ -238,7 +239,8 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockSequenceTest", "[DeserializerCl fkyaml::node& test_1_node = test_node[1]; REQUIRE(test_1_node.is_integer()); REQUIRE_NOTHROW(test_1_node.get_value()); - REQUIRE(test_1_node.get_value() == test_0_node.get_value()); + REQUIRE( + test_1_node.get_value() == test_0_node.get_value()); } SECTION("Input source No.5.") @@ -268,7 +270,8 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockSequenceTest", "[DeserializerCl fkyaml::node& test_1_node = test_node[1]; REQUIRE(test_1_node.is_integer()); REQUIRE_NOTHROW(test_1_node.get_value()); - REQUIRE(test_1_node.get_value() == test_0_node.get_value()); + REQUIRE( + test_1_node.get_value() == test_0_node.get_value()); } SECTION("Input source No.6.") @@ -298,7 +301,9 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockSequenceTest", "[DeserializerCl fkyaml::node& test_1_node = test_node[1]; REQUIRE(test_1_node.is_float_number()); REQUIRE_NOTHROW(test_1_node.get_value()); - REQUIRE(test_1_node.get_value() == test_0_node.get_value()); + REQUIRE( + test_1_node.get_value() == + test_0_node.get_value()); } SECTION("Input source No.7.") @@ -492,7 +497,9 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockMappingTest", "[DeserializerCla fkyaml::node& bar_node = root["bar"]; REQUIRE(bar_node.is_float_number()); REQUIRE_NOTHROW(bar_node.get_value()); - REQUIRE(bar_node.get_value() == foo_node.get_value()); + REQUIRE( + bar_node.get_value() == + foo_node.get_value()); } SECTION("Input source No.7.") @@ -515,7 +522,9 @@ TEST_CASE("DeserializerClassTest_DeserializeBlockMappingTest", "[DeserializerCla fkyaml::node& bar_node = root["bar"]; REQUIRE(bar_node.is_string()); REQUIRE_NOTHROW(bar_node.get_value_ref()); - REQUIRE(bar_node.get_value_ref() == foo_node.get_value_ref()); + REQUIRE( + bar_node.get_value_ref() == + foo_node.get_value_ref()); } SECTION("Input source No.8.") diff --git a/test/unit_test/test_iterator_class.cpp b/test/unit_test/test_iterator_class.cpp index 1fdeb2d0..2fa3287c 100644 --- a/test/unit_test/test_iterator_class.cpp +++ b/test/unit_test/test_iterator_class.cpp @@ -62,7 +62,8 @@ TEST_CASE("IteratorClassTest_SequenceMoveCtorTest", "[IteratorClassTest]") TEST_CASE("IteratorClassTest_MappingMoveCtorTest", "[IteratorClassTest]") { fkyaml::node mapping = fkyaml::node::mapping({{"test", fkyaml::node()}}); - fkyaml::detail::iterator moved(fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); + fkyaml::detail::iterator moved( + fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); fkyaml::detail::iterator iterator(std::move(moved)); REQUIRE(iterator.type() == fkyaml::detail::iterator_t::MAPPING); REQUIRE(iterator.key().compare("test") == 0); diff --git a/test/unit_test/test_lexical_analyzer_class.cpp b/test/unit_test/test_lexical_analyzer_class.cpp index 055273ba..1420d15d 100644 --- a/test/unit_test/test_lexical_analyzer_class.cpp +++ b/test/unit_test/test_lexical_analyzer_class.cpp @@ -238,7 +238,7 @@ TEST_CASE("LexicalAnalyzerClassTest_ScanIntegerTokenTest", "[LexicalAnalyzerClas SECTION("Test nothrow expected tokens.") { - using value_pair_t = std::pair; + using value_pair_t = std::pair; auto value_pair = GENERATE( value_pair_t(std::string("-1234"), -1234), value_pair_t(std::string("-853255"), -853255), @@ -265,7 +265,7 @@ TEST_CASE("LexicalAnalyzerClassTest_ScanIntegerTokenTest", "[LexicalAnalyzerClas TEST_CASE("LexicalAnalyzerClassTest_ScanOctalNumberTokenTest", "[LexicalAnalyzerClassTest]") { - using value_pair_t = std::pair; + using value_pair_t = std::pair; auto value_pair = GENERATE( value_pair_t(std::string("0o27"), 027), value_pair_t(std::string("0o5"), 05), @@ -283,7 +283,7 @@ TEST_CASE("LexicalAnalyzerClassTest_ScanOctalNumberTokenTest", "[LexicalAnalyzer TEST_CASE("LexicalAnalyzerClassTest_ScanHexadecimalNumberTokenTest", "[LexicalAnalyzerClassTest]") { - using value_pair_t = std::pair; + using value_pair_t = std::pair; auto value_pair = GENERATE( value_pair_t(std::string("0xA04F"), 0xA04F), value_pair_t(std::string("0xa7F3"), 0xa7F3), @@ -304,7 +304,7 @@ TEST_CASE("LexicalAnalyzerClassTest_ScanFloatNumberTokenTest", "[LexicalAnalyzer SECTION("Test nothrow expected tokens.") { - using value_pair_t = std::pair; + using value_pair_t = std::pair; auto value_pair = GENERATE( value_pair_t(std::string("-1.234"), -1.234), value_pair_t(std::string("567.8"), 567.8), @@ -387,43 +387,43 @@ TEST_CASE("LexicalAnalyzerClassTest_ScanInvalidNumberTokenTest", "[LexicalAnalyz TEST_CASE("LexicalAnalyzerClassTest_ScanStringTokenTest", "[LexicalAnalyzerClassTest]") { - using value_pair_t = std::pair; + using value_pair_t = std::pair; auto value_pair = GENERATE( - value_pair_t(std::string("\"\""), fkyaml::node_string_type("")), - value_pair_t(std::string("\'\'"), fkyaml::node_string_type("")), - value_pair_t(std::string("test"), fkyaml::node_string_type("test")), - value_pair_t(std::string("nop"), fkyaml::node_string_type("nop")), - value_pair_t(std::string("none"), fkyaml::node_string_type("none")), - value_pair_t(std::string(".NET"), fkyaml::node_string_type(".NET")), - value_pair_t(std::string(".on"), fkyaml::node_string_type(".on")), - value_pair_t(std::string("foo]"), fkyaml::node_string_type("foo")), - value_pair_t(std::string("foo:bar"), fkyaml::node_string_type("foo:bar")), - value_pair_t(std::string("\"foo bar\""), fkyaml::node_string_type("foo bar")), - value_pair_t(std::string("\"foo:bar\""), fkyaml::node_string_type("foo:bar")), - value_pair_t(std::string("\"foo,bar\""), fkyaml::node_string_type("foo,bar")), - value_pair_t(std::string("\"foo]bar\""), fkyaml::node_string_type("foo]bar")), - value_pair_t(std::string("\"foo}bar\""), fkyaml::node_string_type("foo}bar")), - value_pair_t(std::string("\"foo\\abar\""), fkyaml::node_string_type("foo\abar")), - value_pair_t(std::string("\"foo\\bbar\""), fkyaml::node_string_type("foo\bbar")), - value_pair_t(std::string("\"foo\\tbar\""), fkyaml::node_string_type("foo\tbar")), - value_pair_t(std::string("\"foo\tbar\""), fkyaml::node_string_type("foo\tbar")), - value_pair_t(std::string("\"foo\\nbar\""), fkyaml::node_string_type("foo\nbar")), - value_pair_t(std::string("\"foo\\vbar\""), fkyaml::node_string_type("foo\vbar")), - value_pair_t(std::string("\"foo\\fbar\""), fkyaml::node_string_type("foo\fbar")), - value_pair_t(std::string("\"foo\\rbar\""), fkyaml::node_string_type("foo\rbar")), - value_pair_t(std::string("\"foo\\ebar\""), fkyaml::node_string_type("foo\u001Bbar")), - value_pair_t(std::string("\"foo\\ bar\""), fkyaml::node_string_type("foo bar")), - value_pair_t(std::string("\"foo\\\"bar\""), fkyaml::node_string_type("foo\"bar")), - value_pair_t(std::string("\"foo\\/bar\""), fkyaml::node_string_type("foo/bar")), - value_pair_t(std::string("\"foo\\\\bar\""), fkyaml::node_string_type("foo\\bar")), - value_pair_t(std::string("\"\\x30\\x2B\\x6d\""), fkyaml::node_string_type("0+m")), - value_pair_t(std::string("\'foo bar\'"), fkyaml::node_string_type("foo bar")), - value_pair_t(std::string("\'foo\'\'bar\'"), fkyaml::node_string_type("foo\'bar")), - value_pair_t(std::string("\'foo,bar\'"), fkyaml::node_string_type("foo,bar")), - value_pair_t(std::string("\'foo]bar\'"), fkyaml::node_string_type("foo]bar")), - value_pair_t(std::string("\'foo}bar\'"), fkyaml::node_string_type("foo}bar")), - value_pair_t(std::string("\'foo\"bar\'"), fkyaml::node_string_type("foo\"bar")), - value_pair_t(std::string("\'foo:bar\'"), fkyaml::node_string_type("foo:bar"))); + value_pair_t(std::string("\"\""), fkyaml::node::string_type("")), + value_pair_t(std::string("\'\'"), fkyaml::node::string_type("")), + value_pair_t(std::string("test"), fkyaml::node::string_type("test")), + value_pair_t(std::string("nop"), fkyaml::node::string_type("nop")), + value_pair_t(std::string("none"), fkyaml::node::string_type("none")), + value_pair_t(std::string(".NET"), fkyaml::node::string_type(".NET")), + value_pair_t(std::string(".on"), fkyaml::node::string_type(".on")), + value_pair_t(std::string("foo]"), fkyaml::node::string_type("foo")), + value_pair_t(std::string("foo:bar"), fkyaml::node::string_type("foo:bar")), + value_pair_t(std::string("\"foo bar\""), fkyaml::node::string_type("foo bar")), + value_pair_t(std::string("\"foo:bar\""), fkyaml::node::string_type("foo:bar")), + value_pair_t(std::string("\"foo,bar\""), fkyaml::node::string_type("foo,bar")), + value_pair_t(std::string("\"foo]bar\""), fkyaml::node::string_type("foo]bar")), + value_pair_t(std::string("\"foo}bar\""), fkyaml::node::string_type("foo}bar")), + value_pair_t(std::string("\"foo\\abar\""), fkyaml::node::string_type("foo\abar")), + value_pair_t(std::string("\"foo\\bbar\""), fkyaml::node::string_type("foo\bbar")), + value_pair_t(std::string("\"foo\\tbar\""), fkyaml::node::string_type("foo\tbar")), + value_pair_t(std::string("\"foo\tbar\""), fkyaml::node::string_type("foo\tbar")), + value_pair_t(std::string("\"foo\\nbar\""), fkyaml::node::string_type("foo\nbar")), + value_pair_t(std::string("\"foo\\vbar\""), fkyaml::node::string_type("foo\vbar")), + value_pair_t(std::string("\"foo\\fbar\""), fkyaml::node::string_type("foo\fbar")), + value_pair_t(std::string("\"foo\\rbar\""), fkyaml::node::string_type("foo\rbar")), + value_pair_t(std::string("\"foo\\ebar\""), fkyaml::node::string_type("foo\u001Bbar")), + value_pair_t(std::string("\"foo\\ bar\""), fkyaml::node::string_type("foo bar")), + value_pair_t(std::string("\"foo\\\"bar\""), fkyaml::node::string_type("foo\"bar")), + value_pair_t(std::string("\"foo\\/bar\""), fkyaml::node::string_type("foo/bar")), + value_pair_t(std::string("\"foo\\\\bar\""), fkyaml::node::string_type("foo\\bar")), + value_pair_t(std::string("\"\\x30\\x2B\\x6d\""), fkyaml::node::string_type("0+m")), + value_pair_t(std::string("\'foo bar\'"), fkyaml::node::string_type("foo bar")), + value_pair_t(std::string("\'foo\'\'bar\'"), fkyaml::node::string_type("foo\'bar")), + value_pair_t(std::string("\'foo,bar\'"), fkyaml::node::string_type("foo,bar")), + value_pair_t(std::string("\'foo]bar\'"), fkyaml::node::string_type("foo]bar")), + value_pair_t(std::string("\'foo}bar\'"), fkyaml::node::string_type("foo}bar")), + value_pair_t(std::string("\'foo\"bar\'"), fkyaml::node::string_type("foo\"bar")), + value_pair_t(std::string("\'foo:bar\'"), fkyaml::node::string_type("foo:bar"))); str_lexer_t lexer(fkyaml::detail::input_adapter(value_pair.first)); fkyaml::detail::lexical_token_t token; diff --git a/test/unit_test/test_node_class.cpp b/test/unit_test/test_node_class.cpp index 90c7d334..88fb19c5 100644 --- a/test/unit_test/test_node_class.cpp +++ b/test/unit_test/test_node_class.cpp @@ -89,7 +89,7 @@ TEST_CASE("NodeClassTest_ThrowingSpecializationTypeCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_SequenceCtorTest", "[NodeClassTest]") { - fkyaml::node node(fkyaml::node_sequence_type {fkyaml::node(true), fkyaml::node(false)}); + fkyaml::node node(fkyaml::node::sequence_type {fkyaml::node(true), fkyaml::node(false)}); REQUIRE(node.type() == fkyaml::node::node_t::SEQUENCE); REQUIRE(node.is_sequence()); REQUIRE(node.size() == 2); @@ -101,7 +101,7 @@ TEST_CASE("NodeClassTest_SequenceCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_MappingCtorTest", "[NodeClassTest]") { - fkyaml::node node(fkyaml::node_mapping_type {{"test", fkyaml::node(true)}}); + fkyaml::node node(fkyaml::node::mapping_type {{"test", fkyaml::node(true)}}); REQUIRE(node.type() == fkyaml::node::node_t::MAPPING); REQUIRE(node.is_mapping()); REQUIRE(node.size() == 1); @@ -143,7 +143,7 @@ TEST_CASE("NodeClassTest_FloatNumberCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_StringCtorTest", "[NodeClassTest]") { - auto node = GENERATE(fkyaml::node(fkyaml::node_string_type("test"))); + auto node = GENERATE(fkyaml::node(fkyaml::node::string_type("test"))); REQUIRE(node.type() == fkyaml::node::node_t::STRING); REQUIRE(node.is_string()); REQUIRE(node.size() == 4); @@ -409,7 +409,7 @@ TEST_CASE("NodeClassTest_SequenceNodeFactoryTest", "[NodeClassTest]") SECTION("Test non-empty sequence node factory methods.") { - fkyaml::node_sequence_type seq(3); + fkyaml::node::sequence_type seq(3); SECTION("Test lvalue sequence node factory method.") { @@ -446,7 +446,7 @@ TEST_CASE("NodeClassTest_MappingNodeFactoryTest", "[NodeClassTest]") SECTION("Test non-empty mapping node factory methods.") { - fkyaml::node_mapping_type map {{std::string("test"), true}}; + fkyaml::node::mapping_type map {{std::string("test"), true}}; SECTION("Test lvalue mapping node factory method.") { @@ -479,9 +479,9 @@ TEST_CASE("NodeClassTest_BooleanNodeFactoryTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_IntegerNodeFactoryTest", "[NodeClassTest]") { auto integer = GENERATE( - std::numeric_limits::min(), + std::numeric_limits::min(), 0, - std::numeric_limits::max()); + std::numeric_limits::max()); fkyaml::node node = integer; REQUIRE(node.is_integer()); REQUIRE(node.get_value_ref() == integer); @@ -490,9 +490,9 @@ TEST_CASE("NodeClassTest_IntegerNodeFactoryTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_FloatNumberNodeFactoryTest", "[NodeClassTest]") { auto float_val = GENERATE( - std::numeric_limits::min(), + std::numeric_limits::min(), 3.141592, - std::numeric_limits::max()); + std::numeric_limits::max()); fkyaml::node node = float_val; REQUIRE(node.is_float_number()); REQUIRE(node.get_value_ref() == float_val); @@ -509,7 +509,7 @@ TEST_CASE("NodeClassTest_StringNodeFactoryTest", "[NodeClassTest]") SECTION("Test lvalue string node factory method.") { - fkyaml::node_string_type str("test"); + fkyaml::node::string_type str("test"); fkyaml::node node = std::string(str); REQUIRE(node.is_string()); REQUIRE(node.size() == str.size()); @@ -558,7 +558,7 @@ TEST_CASE("NodeClassTest_StringSubscriptOperatorTest", "[NodeClassTest]") { SECTION("Test nothrow expected string subscript operators.") { - fkyaml::node_mapping_type map {{"test", fkyaml::node()}}; + fkyaml::node::mapping_type map {{"test", fkyaml::node()}}; SECTION("Test the non-const string subscript operators.") { @@ -1123,8 +1123,8 @@ TEST_CASE("NodeClassTest_emptyTest", "[NodeClassTest]") SECTION("Test non-empty container node emptiness.") { auto node = GENERATE( - fkyaml::node::sequence(fkyaml::node_sequence_type(3)), - fkyaml::node::mapping(fkyaml::node_mapping_type {{"test", fkyaml::node()}}), + fkyaml::node::sequence(fkyaml::node::sequence_type(3)), + fkyaml::node::mapping(fkyaml::node::mapping_type {{"test", fkyaml::node()}}), fkyaml::node(std::string("test"))); SECTION("Test non-empty non-alias container node emptiness.") @@ -1418,7 +1418,7 @@ TEST_CASE("NodeClassTest_GetValueTest", "[NodeClassTest]") { SECTION("test sequence node value.") { - fkyaml::node node(fkyaml::node_sequence_type {fkyaml::node(true), fkyaml::node(false)}); + fkyaml::node node(fkyaml::node::sequence_type {fkyaml::node(true), fkyaml::node(false)}); SECTION("test for sequence value.") { @@ -1432,12 +1432,12 @@ TEST_CASE("NodeClassTest_GetValueTest", "[NodeClassTest]") SECTION("test for non-sequence value.") { - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); } } @@ -1460,12 +1460,12 @@ TEST_CASE("NodeClassTest_GetValueTest", "[NodeClassTest]") SECTION("test for non-mapping values.") { - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); } } @@ -1481,12 +1481,12 @@ TEST_CASE("NodeClassTest_GetValueTest", "[NodeClassTest]") SECTION("test for non-null values.") { - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); } } @@ -1501,12 +1501,12 @@ TEST_CASE("NodeClassTest_GetValueTest", "[NodeClassTest]") SECTION("test for non-boolean values.") { - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); } } @@ -1528,12 +1528,12 @@ TEST_CASE("NodeClassTest_GetValueTest", "[NodeClassTest]") SECTION("test for non-integer values.") { - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); } SECTION("test for non-integer node value.") @@ -1544,13 +1544,13 @@ TEST_CASE("NodeClassTest_GetValueTest", "[NodeClassTest]") SECTION("test underflowable integer type.") { - fkyaml::node negative_int_node(std::numeric_limits::min()); + fkyaml::node negative_int_node(std::numeric_limits::min()); REQUIRE_THROWS_AS(negative_int_node.get_value(), fkyaml::exception); } SECTION("test overflowable integer type.") { - fkyaml::node large_int_node(std::numeric_limits::max()); + fkyaml::node large_int_node(std::numeric_limits::max()); REQUIRE_THROWS_AS(large_int_node.get_value(), fkyaml::exception); } } @@ -1568,12 +1568,12 @@ TEST_CASE("NodeClassTest_GetValueTest", "[NodeClassTest]") SECTION("test for non-float-number values.") { - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); } SECTION("test for non-float-number node value.") @@ -1584,13 +1584,13 @@ TEST_CASE("NodeClassTest_GetValueTest", "[NodeClassTest]") SECTION("test underflowable float number type.") { - fkyaml::node negative_float_node(std::numeric_limits::min()); + fkyaml::node negative_float_node(std::numeric_limits::min()); REQUIRE_THROWS_AS(negative_float_node.get_value(), fkyaml::exception); } SECTION("test overflowable float number type.") { - fkyaml::node large_float_node(std::numeric_limits::max()); + fkyaml::node large_float_node(std::numeric_limits::max()); REQUIRE_THROWS_AS(large_float_node.get_value(), fkyaml::exception); } } @@ -1608,12 +1608,12 @@ TEST_CASE("NodeClassTest_GetValueTest", "[NodeClassTest]") SECTION("test for non-string values.") { - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); - REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); + REQUIRE_THROWS_AS(node.get_value(), fkyaml::exception); } } } @@ -1627,7 +1627,7 @@ TEST_CASE("NodeClassTest_ToSequenceTest", "[NodeClassTest]") SECTION("Test nothrow expected nodes.") { fkyaml::node node = - fkyaml::node::sequence(fkyaml::node_sequence_type {fkyaml::node(), fkyaml::node(), fkyaml::node()}); + fkyaml::node::sequence(fkyaml::node::sequence_type {fkyaml::node(), fkyaml::node(), fkyaml::node()}); SECTION("Test non-alias sequence node.") { @@ -1716,7 +1716,7 @@ TEST_CASE("NodeClassTest_ToMappingTest", "[NodeClassTest]") { SECTION("Test nothrow expected nodes.") { - fkyaml::node node = fkyaml::node::mapping(fkyaml::node_mapping_type { + fkyaml::node node = fkyaml::node::mapping(fkyaml::node::mapping_type { {"test0", fkyaml::node()}, {"test1", fkyaml::node()}, {"test2", fkyaml::node()}}); SECTION("Test non-alias mapping node.") @@ -1874,7 +1874,7 @@ TEST_CASE("NodeClassTest_ToIntegerTest", "[NodeClassTest]") { SECTION("Test nothrow expected nodes.") { - fkyaml::node_integer_type integer = -123; + fkyaml::node::integer_type integer = -123; fkyaml::node node = integer; SECTION("Test non-alias integer node.") @@ -1948,7 +1948,7 @@ TEST_CASE("NodeClassTest_ToFloatNumberTest", "[NodeClassTest]") { SECTION("Test nothrow expected nodes.") { - fkyaml::node_float_number_type float_val = 123.45; + fkyaml::node::float_number_type float_val = 123.45; fkyaml::node node = float_val; SECTION("Test non-alias float number node.") @@ -2022,7 +2022,7 @@ TEST_CASE("NodeClassTest_ToStringTest", "[NodeClassTest]") { SECTION("Test nothrow expected nodes.") { - fkyaml::node_string_type str = "test"; + fkyaml::node::string_type str = "test"; fkyaml::node node = str; SECTION("Test non-alias string node.") diff --git a/test/unit_test/test_serializer_class.cpp b/test/unit_test/test_serializer_class.cpp index 22ef0d5c..b0e07071 100644 --- a/test/unit_test/test_serializer_class.cpp +++ b/test/unit_test/test_serializer_class.cpp @@ -62,8 +62,8 @@ TEST_CASE("SerializeClassTest_SerializeFloatNumberNode", "[SerializeClassTest]") auto node_str_pair = GENERATE( NodeStrPair(fkyaml::node(3.14), "3.14"), NodeStrPair(fkyaml::node(-53.97), "-53.97"), - NodeStrPair(fkyaml::node(std::numeric_limits::infinity()), ".inf"), - NodeStrPair(fkyaml::node(-1 * std::numeric_limits::infinity()), "-.inf"), + NodeStrPair(fkyaml::node(std::numeric_limits::infinity()), ".inf"), + NodeStrPair(fkyaml::node(-1 * std::numeric_limits::infinity()), "-.inf"), NodeStrPair(fkyaml::node(std::nan("")), ".nan")); fkyaml::detail::basic_serializer serializer; REQUIRE(serializer.serialize(node_str_pair.first) == node_str_pair.second); From 7c3e7ab5c0edd7f0be7a7baff2f6c33cf5a365fa Mon Sep 17 00:00:00 2001 From: fktn Date: Tue, 31 Oct 2023 02:24:49 +0900 Subject: [PATCH 29/48] recovered coverage loss & fixed test case names --- test/unit_test/test_node_class.cpp | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/unit_test/test_node_class.cpp b/test/unit_test/test_node_class.cpp index 88fb19c5..dbadc828 100644 --- a/test/unit_test/test_node_class.cpp +++ b/test/unit_test/test_node_class.cpp @@ -736,7 +736,7 @@ TEST_CASE("NodeClassTest_TypeGetterTest", "[NodeClassTest]") } } -TEST_CASE("NodeClassTest_is_sequenceTest", "[NodeClassTest]") +TEST_CASE("NodeClassTest_IsSequenceTest", "[NodeClassTest]") { SECTION("Test sequence node type.") { @@ -779,7 +779,7 @@ TEST_CASE("NodeClassTest_is_sequenceTest", "[NodeClassTest]") } } -TEST_CASE("NodeClassTest_is_mappingTest", "[NodeClassTest]") +TEST_CASE("NodeClassTest_IsMappingTest", "[NodeClassTest]") { SECTION("Test mapping node type.") { @@ -822,7 +822,7 @@ TEST_CASE("NodeClassTest_is_mappingTest", "[NodeClassTest]") } } -TEST_CASE("NodeClassTest_is_nullTest", "[NodeClassTest]") +TEST_CASE("NodeClassTest_IsNullTest", "[NodeClassTest]") { SECTION("Test null node type.") { @@ -865,7 +865,7 @@ TEST_CASE("NodeClassTest_is_nullTest", "[NodeClassTest]") } } -TEST_CASE("NodeClassTest_is_booleanTest", "[NodeClassTest]") +TEST_CASE("NodeClassTest_IsBooleanTest", "[NodeClassTest]") { SECTION("Test boolean node type.") { @@ -908,7 +908,7 @@ TEST_CASE("NodeClassTest_is_booleanTest", "[NodeClassTest]") } } -TEST_CASE("NodeClassTest_is_integerTest", "[NodeClassTest]") +TEST_CASE("NodeClassTest_IsIntegerTest", "[NodeClassTest]") { SECTION("Test integer node type.") { @@ -1037,7 +1037,7 @@ TEST_CASE("NodeClassTest_IsStringTest", "[NodeClassTest]") } } -TEST_CASE("NodeClassTest_is_scalarTest", "[NodeClassTest]") +TEST_CASE("NodeClassTest_IsScalarTest", "[NodeClassTest]") { SECTION("Test scalar node types.") { @@ -1097,7 +1097,7 @@ TEST_CASE("NodeClassTest_IsAliasTest", "[NodeClassTest]") // test cases for emptiness checker // -TEST_CASE("NodeClassTest_emptyTest", "[NodeClassTest]") +TEST_CASE("NodeClassTest_EmptyTest", "[NodeClassTest]") { SECTION("Test nothrow expected node emptiness.") { @@ -1251,7 +1251,7 @@ TEST_CASE("NodeClassTest_ContainsTest", "[NodeClassTest]") // test cases for container size getter // -TEST_CASE("NodeClassTest_sizeGetterTest", "[NodeClassTest]") +TEST_CASE("NodeClassTest_SizeGetterTest", "[NodeClassTest]") { SECTION("Test nothrow expected node size.") { @@ -1422,7 +1422,7 @@ TEST_CASE("NodeClassTest_GetValueTest", "[NodeClassTest]") SECTION("test for sequence value.") { - auto& seq = node.get_value_ref(); + auto seq = node.get_value(); REQUIRE(seq.size() == 2); REQUIRE(seq[0].is_boolean()); REQUIRE(seq[0].get_value() == true); @@ -1448,7 +1448,7 @@ TEST_CASE("NodeClassTest_GetValueTest", "[NodeClassTest]") SECTION("test for mapping value.") { - auto& map = node.get_value_ref(); + auto map = node.get_value(); REQUIRE(map.size() == 2); REQUIRE(map.find("test") != map.end()); REQUIRE(map.at("test").is_float_number()); @@ -1622,7 +1622,7 @@ TEST_CASE("NodeClassTest_GetValueTest", "[NodeClassTest]") // test cases for value reference getters // -TEST_CASE("NodeClassTest_ToSequenceTest", "[NodeClassTest]") +TEST_CASE("NodeClassTest_GetValueRefForSequenceTest", "[NodeClassTest]") { SECTION("Test nothrow expected nodes.") { @@ -1712,7 +1712,7 @@ TEST_CASE("NodeClassTest_ToSequenceTest", "[NodeClassTest]") } } -TEST_CASE("NodeClassTest_ToMappingTest", "[NodeClassTest]") +TEST_CASE("NodeClassTest_GetValueRefForMappingTest", "[NodeClassTest]") { SECTION("Test nothrow expected nodes.") { @@ -1797,7 +1797,7 @@ TEST_CASE("NodeClassTest_ToMappingTest", "[NodeClassTest]") } } -TEST_CASE("NodeClassTest_ToBooleanTest", "[NodeClassTest]") +TEST_CASE("NodeClassTest_GetValueRefForBooleanTest", "[NodeClassTest]") { SECTION("Test nothrow expected nodes.") { @@ -1870,7 +1870,7 @@ TEST_CASE("NodeClassTest_ToBooleanTest", "[NodeClassTest]") } } -TEST_CASE("NodeClassTest_ToIntegerTest", "[NodeClassTest]") +TEST_CASE("NodeClassTest_GetValueRefForIntegerTest", "[NodeClassTest]") { SECTION("Test nothrow expected nodes.") { @@ -1944,7 +1944,7 @@ TEST_CASE("NodeClassTest_ToIntegerTest", "[NodeClassTest]") } } -TEST_CASE("NodeClassTest_ToFloatNumberTest", "[NodeClassTest]") +TEST_CASE("NodeClassTest_GetValueRefForFloatNumberTest", "[NodeClassTest]") { SECTION("Test nothrow expected nodes.") { @@ -2018,7 +2018,7 @@ TEST_CASE("NodeClassTest_ToFloatNumberTest", "[NodeClassTest]") } } -TEST_CASE("NodeClassTest_ToStringTest", "[NodeClassTest]") +TEST_CASE("NodeClassTest_GetValueRefForStringTest", "[NodeClassTest]") { SECTION("Test nothrow expected nodes.") { From 763d5c10564904af76096b49a5a94d89902620f0 Mon Sep 17 00:00:00 2001 From: fktn Date: Tue, 31 Oct 2023 02:45:58 +0900 Subject: [PATCH 30/48] resolved errors in cmake integration tests --- test/cmake_add_subdirectory_test/project/main.cpp | 2 +- test/cmake_fetch_content_test/project/main.cpp | 2 +- test/cmake_find_package_test/project/main.cpp | 2 +- test/cmake_target_include_directories_test/project/main.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/cmake_add_subdirectory_test/project/main.cpp b/test/cmake_add_subdirectory_test/project/main.cpp index ab8d8b5f..78cb8940 100644 --- a/test/cmake_add_subdirectory_test/project/main.cpp +++ b/test/cmake_add_subdirectory_test/project/main.cpp @@ -14,7 +14,7 @@ int main() { fkyaml::node node = fkyaml::node::deserialize("test: true"); - std::cout << "test: " << node["test"].to_string() << std::endl; + std::cout << "test: " << node["test"].get_value() << std::endl; return 0; } diff --git a/test/cmake_fetch_content_test/project/main.cpp b/test/cmake_fetch_content_test/project/main.cpp index ab8d8b5f..78cb8940 100644 --- a/test/cmake_fetch_content_test/project/main.cpp +++ b/test/cmake_fetch_content_test/project/main.cpp @@ -14,7 +14,7 @@ int main() { fkyaml::node node = fkyaml::node::deserialize("test: true"); - std::cout << "test: " << node["test"].to_string() << std::endl; + std::cout << "test: " << node["test"].get_value() << std::endl; return 0; } diff --git a/test/cmake_find_package_test/project/main.cpp b/test/cmake_find_package_test/project/main.cpp index ab8d8b5f..78cb8940 100644 --- a/test/cmake_find_package_test/project/main.cpp +++ b/test/cmake_find_package_test/project/main.cpp @@ -14,7 +14,7 @@ int main() { fkyaml::node node = fkyaml::node::deserialize("test: true"); - std::cout << "test: " << node["test"].to_string() << std::endl; + std::cout << "test: " << node["test"].get_value() << std::endl; return 0; } diff --git a/test/cmake_target_include_directories_test/project/main.cpp b/test/cmake_target_include_directories_test/project/main.cpp index ab8d8b5f..78cb8940 100644 --- a/test/cmake_target_include_directories_test/project/main.cpp +++ b/test/cmake_target_include_directories_test/project/main.cpp @@ -14,7 +14,7 @@ int main() { fkyaml::node node = fkyaml::node::deserialize("test: true"); - std::cout << "test: " << node["test"].to_string() << std::endl; + std::cout << "test: " << node["test"].get_value() << std::endl; return 0; } From b4b27aca4406fbf4fd83f5b1cc7dcbbd386809c7 Mon Sep 17 00:00:00 2001 From: fktn Date: Tue, 31 Oct 2023 03:04:01 +0900 Subject: [PATCH 31/48] fixed missing calls for fclose() in input adapter tests --- test/unit_test/test_input_adapter.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/unit_test/test_input_adapter.cpp b/test/unit_test/test_input_adapter.cpp index 96e60d95..6ec2a83e 100644 --- a/test/unit_test/test_input_adapter.cpp +++ b/test/unit_test/test_input_adapter.cpp @@ -69,6 +69,8 @@ TEST_CASE("InputAdapterTest_FileInputAdapterProviderTest", "[InputAdapterTest]") REQUIRE(p_file != nullptr); auto input_adapter = fkyaml::detail::input_adapter(p_file); REQUIRE(std::is_same::value); + + std::fclose(p_file); } } @@ -129,6 +131,8 @@ TEST_CASE("InputAdapterTest_GetCharacterTest", "[InputAdapterTest]") REQUIRE(input_adapter.get_character() == 'e'); REQUIRE(input_adapter.get_character() == '.'); REQUIRE(input_adapter.get_character() == char_traits_type::eof()); + + std::fclose(p_file); } SECTION("stream_input_adapter") From f00228b7aca4e2823beb18c6b3f5eaea121c63ed Mon Sep 17 00:00:00 2001 From: fktn Date: Wed, 1 Nov 2023 23:14:30 +0900 Subject: [PATCH 32/48] support compatible strings as an argument of basic_node ctors --- include/fkYAML/detail/conversions/to_node.hpp | 42 ++++++++- include/fkYAML/detail/meta/stl_supplement.hpp | 14 +++ include/fkYAML/detail/node_ref_storage.hpp | 11 +-- test/unit_test/test_iterator_class.cpp | 62 ++++++------- test/unit_test/test_node_class.cpp | 92 +++++++++---------- .../unit_test/test_node_ref_storage_class.cpp | 1 - test/unit_test/test_serializer_class.cpp | 11 +-- 7 files changed, 137 insertions(+), 96 deletions(-) diff --git a/include/fkYAML/detail/conversions/to_node.hpp b/include/fkYAML/detail/conversions/to_node.hpp index ca7b192a..fb94a9d5 100644 --- a/include/fkYAML/detail/conversions/to_node.hpp +++ b/include/fkYAML/detail/conversions/to_node.hpp @@ -195,6 +195,20 @@ struct external_node_constructor n.m_node_value.p_string = BasicNodeType::template create_object(std::move(s)); } + + template < + typename BasicNodeType, typename CompatibleStringType, + enable_if_t< + conjunction< + is_basic_node, + negation>>::value, + int> = 0> + static void construct(BasicNodeType& n, const CompatibleStringType& s) noexcept + { + n.m_node_value.destroy(n.m_node_type); + n.m_node_type = node_t::STRING; + n.m_node_value.p_string = BasicNodeType::template create_object(s); + } }; ///////////////// @@ -307,15 +321,37 @@ inline void to_node(BasicNodeType& n, T f) noexcept external_node_constructor::construct(n, f); } +/** + * @brief to_node function for compatible strings. + * + * @tparam BasicNodeType A basic_node template instance type. + * @tparam T A compatible string type. + * @param n A basic_node object. + * @param s A compatible string object. + */ template < typename BasicNodeType, typename T, enable_if_t< conjunction< - is_basic_node, std::is_same>>::value, + is_basic_node, negation>, + std::is_constructible>::value, int> = 0> -inline void to_node(BasicNodeType& n, T&& s) noexcept +inline void to_node(BasicNodeType& n, const T& s) +{ + external_node_constructor::construct(n, s); +} + +/** + * @brief to_node function for rvalue string node values + * + * @tparam BasicNodeType A basic_node template instance type + * @param n A basic_node object. + * @param s An rvalue string node value. + */ +template ::value, int> = 0> +inline void to_node(BasicNodeType& n, typename BasicNodeType::string_type&& s) noexcept { - external_node_constructor::construct(n, std::forward(s)); + external_node_constructor::construct(n, std::move(s)); } /** diff --git a/include/fkYAML/detail/meta/stl_supplement.hpp b/include/fkYAML/detail/meta/stl_supplement.hpp index 09304c8d..61844264 100644 --- a/include/fkYAML/detail/meta/stl_supplement.hpp +++ b/include/fkYAML/detail/meta/stl_supplement.hpp @@ -13,6 +13,7 @@ #ifndef FK_YAML_DETAIL_META_STL_SUPPLEMENT_HPP_ #define FK_YAML_DETAIL_META_STL_SUPPLEMENT_HPP_ +#include #include #include @@ -62,6 +63,18 @@ using add_pointer_t = typename std::add_pointer::type; template using enable_if_t = typename std::enable_if::type; +/** + * @brief A simple implementation to use std::is_null_pointer with C++11. + * @note std::is_null_pointer is available since C++14. + * @sa https://en.cppreference.com/w/cpp/types/is_null_pointer + * + * @tparam T The type to be checked if it's equal to std::nullptr_t. + */ +template +struct is_null_pointer : std::is_same::type> +{ +}; + /** * @brief An alias template for std::remove_cv::type with C++11. * @note std::remove_cv_t is available since C++14. @@ -96,6 +109,7 @@ using remove_reference_t = typename std::remove_reference::type; using std::add_pointer_t; using std::enable_if_t; +using std::is_null_pointer; using std::remove_cv_t; using std::remove_pointer_t; using std::remove_reference_t; diff --git a/include/fkYAML/detail/node_ref_storage.hpp b/include/fkYAML/detail/node_ref_storage.hpp index 92f94c63..2e62aafe 100644 --- a/include/fkYAML/detail/node_ref_storage.hpp +++ b/include/fkYAML/detail/node_ref_storage.hpp @@ -53,7 +53,7 @@ class node_ref_storage * * @param n An rvalue basic_node object. */ - explicit node_ref_storage(node_type&& n) + node_ref_storage(node_type&& n) : owned_value(std::move(n)) { } @@ -63,7 +63,7 @@ class node_ref_storage * * @param n An lvalue basic_node object. */ - explicit node_ref_storage(const node_type& n) + node_ref_storage(const node_type& n) : value_ref(&n) { } @@ -84,12 +84,7 @@ class node_ref_storage * @tparam Args Types of arguments to construct a basic_node object. * @param args Arguments to construct a basic_node object. */ - template < - typename... Args, enable_if_t< - conjunction< - negation>>, - std::is_constructible>::value, - int> = 0> + template ::value, int> = 0> node_ref_storage(Args&&... args) : owned_value(std::forward(args)...) { diff --git a/test/unit_test/test_iterator_class.cpp b/test/unit_test/test_iterator_class.cpp index 2fa3287c..8d2855d1 100644 --- a/test/unit_test/test_iterator_class.cpp +++ b/test/unit_test/test_iterator_class.cpp @@ -50,7 +50,7 @@ TEST_CASE("IteratorClassTest_MappingCopyCtorTest", "[IteratorClassTest]") TEST_CASE("IteratorClassTest_SequenceMoveCtorTest", "[IteratorClassTest]") { - fkyaml::node sequence = {std::string("test")}; + fkyaml::node sequence = {"test"}; fkyaml::detail::iterator moved( fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); fkyaml::detail::iterator iterator(std::move(moved)); @@ -95,7 +95,7 @@ TEST_CASE("IteratorClassTest_AssignmentOperatorTest", "[IteratorClassTest]") SECTION("Test sequence iterators.") { - fkyaml::node copied_seq = {std::string("test")}; + fkyaml::node copied_seq = {"test"}; fkyaml::detail::iterator copied_itr( fkyaml::detail::sequence_iterator_tag {}, copied_seq.get_value_ref().begin()); fkyaml::node sequence = {false}; @@ -121,10 +121,10 @@ TEST_CASE("IteratorClassTest_AssignmentOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterators.") { - fkyaml::node copied_map = {{std::string("key"), std::string("test")}}; + fkyaml::node copied_map = {{"key", "test"}}; fkyaml::detail::iterator copied_itr( fkyaml::detail::mapping_iterator_tag {}, copied_map.get_value_ref().begin()); - fkyaml::node map = {{std::string("foo"), false}}; + fkyaml::node map = {{"foo", false}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, map.get_value_ref().begin()); @@ -152,7 +152,7 @@ TEST_CASE("IteratorClassTest_ArrowOperatorTest", "[IteratorClassTest]") { SECTION("Test sequence iterator.") { - fkyaml::node seq = {std::string("test")}; + fkyaml::node seq = {"test"}; fkyaml::detail::iterator iterator( fkyaml::detail::sequence_iterator_tag {}, seq.get_value_ref().begin()); REQUIRE(iterator.operator->() == &(seq.get_value_ref().operator[](0))); @@ -160,7 +160,7 @@ TEST_CASE("IteratorClassTest_ArrowOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node map = {{std::string("key"), std::string("test")}}; + fkyaml::node map = {{"key", "test"}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, map.get_value_ref().begin()); REQUIRE(iterator.operator->() == &(map.get_value_ref().operator[]("key"))); @@ -171,7 +171,7 @@ TEST_CASE("IteratorClassTest_DereferenceOperatorTest", "[IteratorClassTest]") { SECTION("Test sequence iterator.") { - fkyaml::node seq = {std::string("test")}; + fkyaml::node seq = {"test"}; fkyaml::detail::iterator iterator( fkyaml::detail::sequence_iterator_tag {}, seq.get_value_ref().begin()); REQUIRE(&(iterator.operator*()) == &(seq.get_value_ref().operator[](0))); @@ -179,7 +179,7 @@ TEST_CASE("IteratorClassTest_DereferenceOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node map = fkyaml::node::mapping({{"key", std::string("test")}}); + fkyaml::node map = fkyaml::node::mapping({{"key", "test"}}); fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, map.get_value_ref().begin()); REQUIRE(&(iterator.operator*()) == &(map.get_value_ref().operator[]("key"))); @@ -200,7 +200,7 @@ TEST_CASE("IteratorClassTest_CompoundAssignmentOperatorBySumTest", "[IteratorCla SECTION("Test mapping iterator.") { - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); iterator += 1; @@ -224,7 +224,7 @@ TEST_CASE("IteratorClassTest_PlusOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); fkyaml::detail::iterator after_plus_itr = iterator + 1; @@ -248,7 +248,7 @@ TEST_CASE("IteratorClassTest_PreIncrementOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); ++iterator; @@ -272,7 +272,7 @@ TEST_CASE("IteratorClassTest_PostIncrementOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); iterator++; @@ -296,7 +296,7 @@ TEST_CASE("IteratorClassTest_CompoundAssignmentOperatorByDifferenceTest", "[Iter SECTION("Test mapping iterator.") { - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().end()); iterator -= 1; @@ -320,7 +320,7 @@ TEST_CASE("IteratorClassTest_MinusOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().end()); fkyaml::detail::iterator after_minus_itr = iterator - 1; @@ -344,7 +344,7 @@ TEST_CASE("IteratorClassTest_PreDecrementOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().end()); --iterator; @@ -368,7 +368,7 @@ TEST_CASE("IteratorClassTest_PostDecrementOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().end()); iterator--; @@ -392,7 +392,7 @@ TEST_CASE("IteratorClassTest_EqualToOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator lhs( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); fkyaml::detail::iterator rhs( @@ -405,7 +405,7 @@ TEST_CASE("IteratorClassTest_EqualToOperatorTest", "[IteratorClassTest]") fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator rhs( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE_THROWS_AS(lhs == rhs, fkyaml::exception); @@ -427,7 +427,7 @@ TEST_CASE("IteratorClassTest_NotEqualToOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator lhs( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); fkyaml::detail::iterator rhs( @@ -441,7 +441,7 @@ TEST_CASE("IteratorClassTest_NotEqualToOperatorTest", "[IteratorClassTest]") fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator rhs( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE_THROWS_AS(lhs == rhs, fkyaml::exception); @@ -464,7 +464,7 @@ TEST_CASE("IteratorClassTest_LessThanOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator lhs( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); fkyaml::detail::iterator rhs( @@ -477,7 +477,7 @@ TEST_CASE("IteratorClassTest_LessThanOperatorTest", "[IteratorClassTest]") fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator rhs( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE_THROWS_AS(lhs < rhs, fkyaml::exception); @@ -503,7 +503,7 @@ TEST_CASE("IteratorClassTest_LessThanOrEqualToOperatorTest", "[IteratorClassTest SECTION("Test mapping iterator.") { - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator lhs( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); fkyaml::detail::iterator rhs( @@ -516,7 +516,7 @@ TEST_CASE("IteratorClassTest_LessThanOrEqualToOperatorTest", "[IteratorClassTest fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator rhs( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE_THROWS_AS(lhs <= rhs, fkyaml::exception); @@ -539,7 +539,7 @@ TEST_CASE("IteratorClassTest_GreaterThanOperatorTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator lhs( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); fkyaml::detail::iterator rhs( @@ -552,7 +552,7 @@ TEST_CASE("IteratorClassTest_GreaterThanOperatorTest", "[IteratorClassTest]") fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator rhs( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE_THROWS_AS(lhs > rhs, fkyaml::exception); @@ -578,7 +578,7 @@ TEST_CASE("IteratorClassTest_GreaterThanOrEqualToOperatorTest", "[IteratorClassT SECTION("Test mapping iterator.") { - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator lhs( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); fkyaml::detail::iterator rhs( @@ -591,7 +591,7 @@ TEST_CASE("IteratorClassTest_GreaterThanOrEqualToOperatorTest", "[IteratorClassT fkyaml::node sequence = {false, true}; fkyaml::detail::iterator lhs( fkyaml::detail::sequence_iterator_tag {}, sequence.get_value_ref().begin()); - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator rhs( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE_THROWS_AS(lhs >= rhs, fkyaml::exception); @@ -610,7 +610,7 @@ TEST_CASE("IteratorClassTest_TypeGetterTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE(iterator.type() == fkyaml::detail::iterator_t::MAPPING); @@ -629,7 +629,7 @@ TEST_CASE("IteratorClassTest_KeyGetterTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE_NOTHROW(iterator.key()); @@ -650,7 +650,7 @@ TEST_CASE("IteratorClassTest_ValueGetterTest", "[IteratorClassTest]") SECTION("Test mapping iterator.") { - fkyaml::node mapping = {{std::string("test0"), false}, {std::string("test1"), true}}; + fkyaml::node mapping = {{"test0", false}, {"test1", true}}; fkyaml::detail::iterator iterator( fkyaml::detail::mapping_iterator_tag {}, mapping.get_value_ref().begin()); REQUIRE(iterator.value().is_boolean()); diff --git a/test/unit_test/test_node_class.cpp b/test/unit_test/test_node_class.cpp index dbadc828..f37e6691 100644 --- a/test/unit_test/test_node_class.cpp +++ b/test/unit_test/test_node_class.cpp @@ -143,7 +143,7 @@ TEST_CASE("NodeClassTest_FloatNumberCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_StringCtorTest", "[NodeClassTest]") { - auto node = GENERATE(fkyaml::node(fkyaml::node::string_type("test"))); + auto node = GENERATE(fkyaml::node(std::string("test"))); REQUIRE(node.type() == fkyaml::node::node_t::STRING); REQUIRE(node.is_string()); REQUIRE(node.size() == 4); @@ -152,7 +152,9 @@ TEST_CASE("NodeClassTest_StringCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_SequenceCopyCtorTest", "[NodeClassTest]") { - fkyaml::node copied = {true, std::string("test")}; + fkyaml::node n = "test"; + + fkyaml::node copied = {true, "test"}; fkyaml::node node(copied); REQUIRE(node.is_sequence()); REQUIRE_NOTHROW(node.size()); @@ -171,7 +173,7 @@ TEST_CASE("NodeClassTest_SequenceCopyCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_MappingCopyCtorTest", "[NodeClassTest]") { - fkyaml::node copied = {{std::string("test0"), 123}, {std::string("test1"), 3.14}}; + fkyaml::node copied = {{"test0", 123}, {"test1", 3.14}}; fkyaml::node node(copied); REQUIRE(node.is_mapping()); REQUIRE_NOTHROW(node.size()); @@ -222,7 +224,7 @@ TEST_CASE("NodeClassTest_FloatNumberCopyCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_StringCopyCtorTest", "[NodeClassTest]") { - fkyaml::node copied = std::string("test"); + fkyaml::node copied = "test"; fkyaml::node node(copied); REQUIRE(node.is_string()); REQUIRE_NOTHROW(node.size()); @@ -244,7 +246,7 @@ TEST_CASE("NodeClassTest_AliasCopyCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_SequenceMoveCtorTest", "[NodeClassTest]") { - fkyaml::node moved = {true, std::string("test")}; + fkyaml::node moved = {true, "test"}; fkyaml::node node(std::move(moved)); REQUIRE(node.is_sequence()); REQUIRE_NOTHROW(node.size()); @@ -263,7 +265,7 @@ TEST_CASE("NodeClassTest_SequenceMoveCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_MappingMoveCtorTest", "[NodeClassTest]") { - fkyaml::node moved = {{std::string("test0"), 123}, {std::string("test1"), 3.14}}; + fkyaml::node moved = {{"test0", 123}, {"test1", 3.14}}; fkyaml::node node(std::move(moved)); REQUIRE(node.is_mapping()); REQUIRE_NOTHROW(node.size()); @@ -314,7 +316,7 @@ TEST_CASE("NodeClassTest_FloatNumberMoveCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_StringMoveCtorTest", "[NodeClassTest]") { - fkyaml::node moved = std::string("test"); + fkyaml::node moved = "test"; fkyaml::node node(std::move(moved)); REQUIRE(node.is_string()); REQUIRE_NOTHROW(node.size()); @@ -337,10 +339,10 @@ TEST_CASE("NodeClassTest_AliasMoveCtorTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_InitializerListCtorTest", "[NodeClassTest]") { fkyaml::node node = { - {std::string("foo"), 3.14}, - {std::string("bar"), 123}, - {std::string("baz"), {true, false}}, - {std::string("qux"), nullptr}, + {"foo", 3.14}, + {"bar", 123}, + {"baz", {true, false}}, + {"qux", nullptr}, }; REQUIRE(node.contains("foo")); @@ -385,7 +387,7 @@ TEST_CASE("NodeClassTest_DeserializeTest", "[NodeClassTest]") REQUIRE(node.size() == 1); REQUIRE(node.contains("foo")); REQUIRE(node["foo"].is_string()); - REQUIRE(node["foo"].get_value() == "bar"); + REQUIRE(node["foo"].get_value_ref() == "bar"); } TEST_CASE("NodeClassTest_SerializeTest", "[NodeClassTest]") @@ -446,7 +448,7 @@ TEST_CASE("NodeClassTest_MappingNodeFactoryTest", "[NodeClassTest]") SECTION("Test non-empty mapping node factory methods.") { - fkyaml::node::mapping_type map {{std::string("test"), true}}; + fkyaml::node::mapping_type map {{"test", true}}; SECTION("Test lvalue mapping node factory method.") { @@ -502,7 +504,7 @@ TEST_CASE("NodeClassTest_StringNodeFactoryTest", "[NodeClassTest]") { SECTION("Test empty string node factory method.") { - fkyaml::node node = std::string(); + fkyaml::node node = ""; REQUIRE(node.is_string()); REQUIRE(node.size() == 0); } @@ -510,7 +512,7 @@ TEST_CASE("NodeClassTest_StringNodeFactoryTest", "[NodeClassTest]") SECTION("Test lvalue string node factory method.") { fkyaml::node::string_type str("test"); - fkyaml::node node = std::string(str); + fkyaml::node node = str; REQUIRE(node.is_string()); REQUIRE(node.size() == str.size()); REQUIRE(node.get_value_ref() == str); @@ -518,7 +520,7 @@ TEST_CASE("NodeClassTest_StringNodeFactoryTest", "[NodeClassTest]") SECTION("Test rvalue string node factory method.") { - fkyaml::node node = std::string("test"); + fkyaml::node node = "test"; REQUIRE(node.is_string()); REQUIRE(node.size() == 4); REQUIRE(node.get_value_ref().compare("test") == 0); @@ -527,7 +529,7 @@ TEST_CASE("NodeClassTest_StringNodeFactoryTest", "[NodeClassTest]") TEST_CASE("NodeClassTest_AliasNodeFactoryTest", "[NodeClassTest]") { - fkyaml::node anchor = std::string("alias_test"); + fkyaml::node anchor = "alias_test"; SECTION("Make sure BasicNode::alias_of() throws an exception without anchor name.") { @@ -623,7 +625,7 @@ TEST_CASE("NodeClassTest_StringSubscriptOperatorTest", "[NodeClassTest]") fkyaml::node(false), fkyaml::node(0), fkyaml::node(0.0), - fkyaml::node(std::string())); + fkyaml::node("")); SECTION("Test non-const lvalue throwing invocation.") { @@ -692,7 +694,7 @@ TEST_CASE("NodeClassTest_IntegerSubscriptOperatorTest", "[NodeClassTest]") fkyaml::node(false), fkyaml::node(0), fkyaml::node(0.0), - fkyaml::node(std::string())); + fkyaml::node("")); SECTION("Test non-const non-sequence nodes.") { @@ -721,7 +723,7 @@ TEST_CASE("NodeClassTest_TypeGetterTest", "[NodeClassTest]") NodeTypePair(fkyaml::node(false), fkyaml::node::node_t::BOOLEAN), NodeTypePair(fkyaml::node(0), fkyaml::node::node_t::INTEGER), NodeTypePair(fkyaml::node(0.0), fkyaml::node::node_t::FLOAT_NUMBER), - NodeTypePair(fkyaml::node(std::string()), fkyaml::node::node_t::STRING)); + NodeTypePair(fkyaml::node(""), fkyaml::node::node_t::STRING)); SECTION("Test non-alias node types.") { @@ -763,7 +765,7 @@ TEST_CASE("NodeClassTest_IsSequenceTest", "[NodeClassTest]") fkyaml::node(false), fkyaml::node(0), fkyaml::node(0.0), - fkyaml::node(std::string())); + fkyaml::node("")); SECTION("Test non-alias non-sequence node types") { @@ -806,7 +808,7 @@ TEST_CASE("NodeClassTest_IsMappingTest", "[NodeClassTest]") fkyaml::node(false), fkyaml::node(0), fkyaml::node(0.0), - fkyaml::node(std::string())); + fkyaml::node("")); SECTION("Test non-alias non-mapping node types") { @@ -849,7 +851,7 @@ TEST_CASE("NodeClassTest_IsNullTest", "[NodeClassTest]") fkyaml::node(false), fkyaml::node(0), fkyaml::node(0.0), - fkyaml::node(std::string())); + fkyaml::node("")); SECTION("Test non-alias non-null node types") { @@ -892,7 +894,7 @@ TEST_CASE("NodeClassTest_IsBooleanTest", "[NodeClassTest]") fkyaml::node(), fkyaml::node(0), fkyaml::node(0.0), - fkyaml::node(std::string())); + fkyaml::node("")); SECTION("Test non-alias non-boolean node types") { @@ -935,7 +937,7 @@ TEST_CASE("NodeClassTest_IsIntegerTest", "[NodeClassTest]") fkyaml::node(), fkyaml::node(false), fkyaml::node(0.0), - fkyaml::node(std::string())); + fkyaml::node("")); SECTION("Test non-alias non-integer node types") { @@ -978,7 +980,7 @@ TEST_CASE("NodeClassTest_IsFloatNumberTest", "[NodeClassTest]") fkyaml::node(), fkyaml::node(false), fkyaml::node(0), - fkyaml::node(std::string())); + fkyaml::node("")); SECTION("Test non-alias non-float-number node types") { @@ -998,7 +1000,7 @@ TEST_CASE("NodeClassTest_IsStringTest", "[NodeClassTest]") { SECTION("Test string node type.") { - fkyaml::node node = std::string(); + fkyaml::node node = ""; SECTION("Test non-alias string node type.") { @@ -1041,8 +1043,7 @@ TEST_CASE("NodeClassTest_IsScalarTest", "[NodeClassTest]") { SECTION("Test scalar node types.") { - auto node = GENERATE( - fkyaml::node(), fkyaml::node(false), fkyaml::node(0), fkyaml::node(0.0), fkyaml::node(std::string())); + auto node = GENERATE(fkyaml::node(), fkyaml::node(false), fkyaml::node(0), fkyaml::node(0.0), fkyaml::node("")); SECTION("Test non-alias scalar node types.") { @@ -1084,7 +1085,7 @@ TEST_CASE("NodeClassTest_IsAliasTest", "[NodeClassTest]") fkyaml::node(false), fkyaml::node(0), fkyaml::node(0.0), - fkyaml::node(std::string())); + fkyaml::node("")); SECTION("Test alias node types.") { @@ -1103,7 +1104,7 @@ TEST_CASE("NodeClassTest_EmptyTest", "[NodeClassTest]") { SECTION("Test empty container node emptiness.") { - auto node = GENERATE(fkyaml::node::sequence(), fkyaml::node::mapping(), fkyaml::node(std::string())); + auto node = GENERATE(fkyaml::node::sequence(), fkyaml::node::mapping(), fkyaml::node("")); SECTION("Test empty non-alias container node emptiness.") { @@ -1125,7 +1126,7 @@ TEST_CASE("NodeClassTest_EmptyTest", "[NodeClassTest]") auto node = GENERATE( fkyaml::node::sequence(fkyaml::node::sequence_type(3)), fkyaml::node::mapping(fkyaml::node::mapping_type {{"test", fkyaml::node()}}), - fkyaml::node(std::string("test"))); + fkyaml::node("test")); SECTION("Test non-empty non-alias container node emptiness.") { @@ -1218,7 +1219,7 @@ TEST_CASE("NodeClassTest_ContainsTest", "[NodeClassTest]") fkyaml::node(false), fkyaml::node(0), fkyaml::node(0.0), - fkyaml::node(std::string())); + fkyaml::node("")); std::string key = "test"; SECTION("Test non-alias non-mapping node with lvalue key.") @@ -1258,7 +1259,7 @@ TEST_CASE("NodeClassTest_SizeGetterTest", "[NodeClassTest]") auto node = GENERATE( fkyaml::node::sequence({fkyaml::node(), fkyaml::node(), fkyaml::node()}), fkyaml::node::mapping({{"test0", fkyaml::node()}, {"test1", fkyaml::node()}, {"test2", fkyaml::node()}}), - fkyaml::node(std::string("tmp"))); + fkyaml::node("tmp")); SECTION("Test container node size.") { @@ -1443,8 +1444,7 @@ TEST_CASE("NodeClassTest_GetValueTest", "[NodeClassTest]") SECTION("test mapping node value.") { - fkyaml::node node( - fkyaml::node::mapping_type {{"test", fkyaml::node(3.14)}, {"foo", fkyaml::node(std::string("bar"))}}); + fkyaml::node node(fkyaml::node::mapping_type {{"test", fkyaml::node(3.14)}, {"foo", fkyaml::node("bar")}}); SECTION("test for mapping value.") { @@ -1455,7 +1455,7 @@ TEST_CASE("NodeClassTest_GetValueTest", "[NodeClassTest]") REQUIRE(map.at("test").get_value() == 3.14); REQUIRE(map.find("foo") != map.end()); REQUIRE(map.at("foo").is_string()); - REQUIRE(map.at("foo").get_value() == "bar"); + REQUIRE(map.at("foo").get_value_ref() == "bar"); } SECTION("test for non-mapping values.") @@ -1597,7 +1597,7 @@ TEST_CASE("NodeClassTest_GetValueTest", "[NodeClassTest]") SECTION("test string node value.") { - fkyaml::node node(std::string("test")); + fkyaml::node node("test"); SECTION("test for string value.") { @@ -1683,7 +1683,7 @@ TEST_CASE("NodeClassTest_GetValueRefForSequenceTest", "[NodeClassTest]") fkyaml::node(false), fkyaml::node(0), fkyaml::node(0.0), - fkyaml::node(std::string())); + fkyaml::node("")); SECTION("Test non-alias non-sequence nodes.") { @@ -1768,7 +1768,7 @@ TEST_CASE("NodeClassTest_GetValueRefForMappingTest", "[NodeClassTest]") fkyaml::node(false), fkyaml::node(0), fkyaml::node(0.0), - fkyaml::node(std::string())); + fkyaml::node("")); SECTION("Test non-alias non-mapping nodes.") { @@ -1841,7 +1841,7 @@ TEST_CASE("NodeClassTest_GetValueRefForBooleanTest", "[NodeClassTest]") fkyaml::node(), fkyaml::node(0), fkyaml::node(0.0), - fkyaml::node(std::string())); + fkyaml::node("")); SECTION("Test non-alias non-boolean nodes.") { @@ -1915,7 +1915,7 @@ TEST_CASE("NodeClassTest_GetValueRefForIntegerTest", "[NodeClassTest]") fkyaml::node(), fkyaml::node(false), fkyaml::node(0.0), - fkyaml::node(std::string())); + fkyaml::node("")); SECTION("Test non-alias non-integer nodes.") { @@ -1989,7 +1989,7 @@ TEST_CASE("NodeClassTest_GetValueRefForFloatNumberTest", "[NodeClassTest]") fkyaml::node(), fkyaml::node(false), fkyaml::node(0), - fkyaml::node(std::string())); + fkyaml::node("")); SECTION("Test non-alias non-float-number nodes.") { @@ -2141,8 +2141,7 @@ TEST_CASE("NodeClassTest_BeginTest", "[NodeClassTest]") SECTION("Test nothrow unexpected nodes.") { - auto node = GENERATE( - fkyaml::node(), fkyaml::node(false), fkyaml::node(0), fkyaml::node(0.0), fkyaml::node(std::string())); + auto node = GENERATE(fkyaml::node(), fkyaml::node(false), fkyaml::node(0), fkyaml::node(0.0), fkyaml::node("")); SECTION("Test non-const throwing node.") { @@ -2202,8 +2201,7 @@ TEST_CASE("NodeClassTest_EndTest", "[NodeClassTest]") SECTION("Test nothrow unexpected nodes.") { - auto node = GENERATE( - fkyaml::node(), fkyaml::node(false), fkyaml::node(0), fkyaml::node(0.0), fkyaml::node(std::string())); + auto node = GENERATE(fkyaml::node(), fkyaml::node(false), fkyaml::node(0), fkyaml::node(0.0), fkyaml::node("")); SECTION("Test non-const throwing node.") { diff --git a/test/unit_test/test_node_ref_storage_class.cpp b/test/unit_test/test_node_ref_storage_class.cpp index 129363f8..b4629d8f 100644 --- a/test/unit_test/test_node_ref_storage_class.cpp +++ b/test/unit_test/test_node_ref_storage_class.cpp @@ -39,7 +39,6 @@ TEST_CASE("NodeRefStorageTest_ArrowOperatorTest", "[NodeRefStorageTest]") { fkyaml::node node = 123; fkyaml::detail::node_ref_storage storage(node); - REQUIRE(storage.operator->() == &node); REQUIRE(storage->is_integer()); REQUIRE(storage->get_value() == 123); diff --git a/test/unit_test/test_serializer_class.cpp b/test/unit_test/test_serializer_class.cpp index b0e07071..01b5652f 100644 --- a/test/unit_test/test_serializer_class.cpp +++ b/test/unit_test/test_serializer_class.cpp @@ -18,7 +18,7 @@ TEST_CASE("SerializerClassTest_SerializeSequenceNode", "[SerializerClassTest]") using NodeStrPair = std::pair; auto node_str_pair = GENERATE( NodeStrPair({true, false}, "- true\n- false\n"), - NodeStrPair({{{std::string("foo"), -1234}, {std::string("bar"), nullptr}}}, "-\n bar: null\n foo: -1234\n")); + NodeStrPair({{{"foo", -1234}, {"bar", nullptr}}}, "-\n bar: null\n foo: -1234\n")); fkyaml::detail::basic_serializer serializer; REQUIRE(serializer.serialize(node_str_pair.first) == node_str_pair.second); } @@ -27,8 +27,8 @@ TEST_CASE("SerializerClassTest_SerializeMappingNode", "[SerializerClassTest]") { using NodeStrPair = std::pair; auto node_str_pair = GENERATE( - NodeStrPair({{std::string("foo"), -1234}, {std::string("bar"), nullptr}}, "bar: null\nfoo: -1234\n"), - NodeStrPair({{std::string("foo"), {true, false}}}, "foo:\n - true\n - false\n")); + NodeStrPair({{"foo", -1234}, {"bar", nullptr}}, "bar: null\nfoo: -1234\n"), + NodeStrPair({{"foo", {true, false}}}, "foo:\n - true\n - false\n")); fkyaml::detail::basic_serializer serializer; REQUIRE(serializer.serialize(node_str_pair.first) == node_str_pair.second); } @@ -72,9 +72,8 @@ TEST_CASE("SerializeClassTest_SerializeFloatNumberNode", "[SerializeClassTest]") TEST_CASE("SerializerClassTest_SerializeStringNode", "[SerializerClassTest]") { using node_str_pair_t = std::pair; - auto node_str_pair = GENERATE( - node_str_pair_t(fkyaml::node(std::string("test")), "test"), - node_str_pair_t(fkyaml::node(std::string("foo bar")), "foo bar")); + auto node_str_pair = + GENERATE(node_str_pair_t(fkyaml::node("test"), "test"), node_str_pair_t(fkyaml::node("foo bar"), "foo bar")); fkyaml::detail::basic_serializer serializer; REQUIRE(serializer.serialize(node_str_pair.first) == node_str_pair.second); From 080136fd34ced72db97fb3119434329d6a6bde19 Mon Sep 17 00:00:00 2001 From: fktn Date: Wed, 1 Nov 2023 23:38:57 +0900 Subject: [PATCH 33/48] updated example codes in README.md --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 09fd1700..4e58d84f 100644 --- a/README.md +++ b/README.md @@ -181,7 +181,7 @@ assert(root["bar"].get_value_ref() == 3.14); assert(root["baz"].get_value_ref() == true); // You can get values of YAML node like the followings: -assert(root["foo"].get_value() == "test"); +assert(root["foo"].get_value_ref() == "test"); assert(root["bar"].get_value() == 3.14); assert(root["baz"].get_value() == true); ``` @@ -202,9 +202,9 @@ The `Serializer` class provides an API for serializing YAML node values into a s // ... fkyaml::node root = { - { std::string("foo"), std::string("test") }, - { std::string("bar"), { 3.14, std::nan("") } }, - { std::string("baz"), true } + { "foo", "test" }, + { "bar", { 3.14, std::nan("") } }, + { "baz", true } }; std::string str = fkyaml::node::serialize(root); @@ -233,7 +233,7 @@ The `node` class provides APIs for building YAML nodes programatically. fkyaml::node root = fkyaml::node::mapping(); // Add a string scalar node. -root["foo"] = std::string("test"); +root["foo"] = "test"; // Add a sequence node containing floating number scalar nodes. root["bar"] = { 3.14, std::nan("") }; @@ -243,9 +243,9 @@ root["baz"] = true; // Instead, you can build YAML nodes all at once. fkyaml::node another_root = { - { std::string("foo"), std::string("test") }, - { std::string("bar"), { 3.14, std::nan("") } }, - { std::string("baz"), true } + { "foo", "test" }, + { "bar", { 3.14, std::nan("") } }, + { "baz", true } }; ``` From 21bfac820962f5de1ff15f45e25065b1751024c8 Mon Sep 17 00:00:00 2001 From: fktn Date: Fri, 3 Nov 2023 19:02:42 +0900 Subject: [PATCH 34/48] moved docs for basic_node APIs with MkDocs --- .../docs/api/basic_node/add_anchor_name.md | 49 +++++++ docs/mkdocs/docs/api/basic_node/alias_of.md | 52 +++++++- docs/mkdocs/docs/api/basic_node/begin.md | 2 +- .../docs/api/basic_node/boolean_type.md | 2 +- .../docs/api/basic_node/const_iterator.md | 2 +- .../mkdocs/docs/api/basic_node/constructor.md | 20 +-- docs/mkdocs/docs/api/basic_node/contains.md | 56 ++++++++ .../mkdocs/docs/api/basic_node/deserialize.md | 12 +- docs/mkdocs/docs/api/basic_node/empty.md | 4 +- docs/mkdocs/docs/api/basic_node/end.md | 2 +- .../docs/api/basic_node/float_number_type.md | 2 +- .../docs/api/basic_node/get_anchor_name.md | 56 ++++++++ docs/mkdocs/docs/api/basic_node/get_value.md | 18 +++ .../docs/api/basic_node/get_value_ref.md | 80 ++++++++++++ .../docs/api/basic_node/get_yaml_version.md | 8 +- .../docs/api/basic_node/has_anchor_name.md | 49 +++++++ docs/mkdocs/docs/api/basic_node/index.md | 32 ++--- .../docs/api/basic_node/integer_type.md | 2 +- docs/mkdocs/docs/api/basic_node/is_boolean.md | 2 +- .../docs/api/basic_node/is_float_number.md | 2 +- docs/mkdocs/docs/api/basic_node/is_integer.md | 2 +- docs/mkdocs/docs/api/basic_node/is_mapping.md | 2 +- docs/mkdocs/docs/api/basic_node/is_null.md | 2 +- docs/mkdocs/docs/api/basic_node/is_scalar.md | 2 +- .../mkdocs/docs/api/basic_node/is_sequence.md | 2 +- docs/mkdocs/docs/api/basic_node/is_string.md | 2 +- docs/mkdocs/docs/api/basic_node/iterator.md | 2 +- docs/mkdocs/docs/api/basic_node/mapping.md | 2 +- .../docs/api/basic_node/mapping_type.md | 2 +- docs/mkdocs/docs/api/basic_node/node.md | 2 +- docs/mkdocs/docs/api/basic_node/node_t.md | 2 +- docs/mkdocs/docs/api/basic_node/operator=.md | 54 +++++++- docs/mkdocs/docs/api/basic_node/operator[].md | 122 +++++++++++++++++- docs/mkdocs/docs/api/basic_node/sequence.md | 2 +- .../docs/api/basic_node/sequence_type.md | 2 +- docs/mkdocs/docs/api/basic_node/serialize.md | 4 +- .../docs/api/basic_node/set_yaml_version.md | 9 +- docs/mkdocs/docs/api/basic_node/size.md | 4 +- .../mkdocs/docs/api/basic_node/string_type.md | 2 +- docs/mkdocs/docs/api/basic_node/swap.md | 111 ++++++++++++++++ docs/mkdocs/docs/api/basic_node/to_boolean.md | 9 -- .../docs/api/basic_node/to_float_number.md | 9 -- docs/mkdocs/docs/api/basic_node/to_integer.md | 9 -- docs/mkdocs/docs/api/basic_node/to_mapping.md | 9 -- .../mkdocs/docs/api/basic_node/to_sequence.md | 9 -- docs/mkdocs/docs/api/basic_node/to_string.md | 9 -- docs/mkdocs/docs/api/basic_node/type.md | 2 +- .../api/basic_node/value_converter_type.md | 2 +- .../docs/api/basic_node/yaml_version_t.md | 2 +- docs/mkdocs/docs/api/exception/constructor.md | 4 +- docs/mkdocs/mkdocs.yml | 9 +- include/fkYAML/node.hpp | 113 +++++++++++++--- 52 files changed, 813 insertions(+), 157 deletions(-) create mode 100644 docs/mkdocs/docs/api/basic_node/get_anchor_name.md create mode 100644 docs/mkdocs/docs/api/basic_node/get_value_ref.md create mode 100644 docs/mkdocs/docs/api/basic_node/swap.md delete mode 100644 docs/mkdocs/docs/api/basic_node/to_boolean.md delete mode 100644 docs/mkdocs/docs/api/basic_node/to_float_number.md delete mode 100644 docs/mkdocs/docs/api/basic_node/to_integer.md delete mode 100644 docs/mkdocs/docs/api/basic_node/to_mapping.md delete mode 100644 docs/mkdocs/docs/api/basic_node/to_sequence.md delete mode 100644 docs/mkdocs/docs/api/basic_node/to_string.md diff --git a/docs/mkdocs/docs/api/basic_node/add_anchor_name.md b/docs/mkdocs/docs/api/basic_node/add_anchor_name.md index e69de29b..b9d838ce 100644 --- a/docs/mkdocs/docs/api/basic_node/add_anchor_name.md +++ b/docs/mkdocs/docs/api/basic_node/add_anchor_name.md @@ -0,0 +1,49 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::add_anchor_name + +```cpp +void add_anchor_name(const std::string& anchor_name); +void add_anchor_name(std::string&& anchor_name); +``` + +Adds an anchor name to the YAML node. +If the basic_node has already had any anchor name, the new anchor name overwrites the old one. + +## **Parameters** + +***anchor_name*** +: An anchor name. This should not be empty. + +???+ Example + + ```cpp + #include + #include + + int main() + { + // create a YAML node. + fkyaml::node n = 123; + + // add an anchor name to the node. + n.add_anchor_name("anchor"); + std::cout << n.get_anchor_name() << std::endl; + + // overwrite it with a new one. + n.add_anchor_name("anchor2"); + std::cout << n.get_anchor_name() << std::endl; + + return 0; + } + ``` + + ```bash + anchor + anchor2 + ``` + +## **See Also** + +* [basic_node](index.md) +* [get_anchor_name](get_anchor_name.md) diff --git a/docs/mkdocs/docs/api/basic_node/alias_of.md b/docs/mkdocs/docs/api/basic_node/alias_of.md index cef5402f..04082c62 100644 --- a/docs/mkdocs/docs/api/basic_node/alias_of.md +++ b/docs/mkdocs/docs/api/basic_node/alias_of.md @@ -3,5 +3,55 @@ # fkyaml::basic_node::alias_of ```cpp -yaml_version_t alias_of(const basic_node& anchor) const noexcept; +static basic_node alias_of(const basic_node& anchor); ``` + +Creates an alias YAML node from an anchor node. + +## **Parameters** + +***anchor*** [in] +: A basic_node object with an anchor name. + This node must have some anchor name. + +## **Return Value** + +An alias YAML node which is created from the given anchor node. +If the given anchor node does not have any non-empty anchor name, an [`fkyaml::exception`](../exception/index.md) will be thrown. + +!!! Note + + If this API throws an exception, the internally stored YAML node value in the given anchor node stays intact. + +???+ Example + + ```cpp + #include + #include + + int main() + { + // create a YAML node. + fkyaml::node anchor_node = "test"; + + // add an anchor name to the node. + anchor_node.add_anchor_name("anchor"); + + // create an alias YAML node. + fkyaml::node alias_node = fkyaml::node::alias_of(anchor_node); + + // print the value in the alias node. + std::cout<< alias_node.get_value_ref << std::endl; + + return 0; + } + ``` + + ```bash + test + ``` + +## **See Also** + +* [basic_node](index.md) +* [add_anchor_name](add_anchor_name.md) diff --git a/docs/mkdocs/docs/api/basic_node/begin.md b/docs/mkdocs/docs/api/basic_node/begin.md index dcedad5e..f040f805 100644 --- a/docs/mkdocs/docs/api/basic_node/begin.md +++ b/docs/mkdocs/docs/api/basic_node/begin.md @@ -16,7 +16,7 @@ Throws a [`fkyaml::exception`](../exception/index.md) if a basic_node does not h An iterator to the first element of a container node value (either sequence or mapping). -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/boolean_type.md b/docs/mkdocs/docs/api/basic_node/boolean_type.md index 6fe213f2..efba9190 100644 --- a/docs/mkdocs/docs/api/basic_node/boolean_type.md +++ b/docs/mkdocs/docs/api/basic_node/boolean_type.md @@ -16,7 +16,7 @@ To store boolean objects in [`basic_node`](index.md) class, the type is defined If not explicitly specified, the default type `bool` will be chosen. With the decided type, boolean objects are stored directly inside a [`basic_node`](index.md). -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/const_iterator.md b/docs/mkdocs/docs/api/basic_node/const_iterator.md index b028201e..063b87c8 100644 --- a/docs/mkdocs/docs/api/basic_node/const_iterator.md +++ b/docs/mkdocs/docs/api/basic_node/const_iterator.md @@ -9,7 +9,7 @@ using const_iterator = detail::iterator; The type for constant iterators of [`basic_node`](index.md) containers. This iterator type is commonly used for sequence and mapping container values. -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/constructor.md b/docs/mkdocs/docs/api/basic_node/constructor.md index b57faa57..00fc89b3 100644 --- a/docs/mkdocs/docs/api/basic_node/constructor.md +++ b/docs/mkdocs/docs/api/basic_node/constructor.md @@ -39,7 +39,7 @@ basic_node() = default; Default constructor. Constructs a basic_node with a null value. The resulting basic_node has the [`node_t::NULL_OBJECT`](node_t.md) type. -??? example +???+ Example ```cpp #include @@ -69,9 +69,9 @@ The resulting basic_node has a default value for the given type. ### **Parameters** ***`type`*** [in] -: A YAML node value. +: A YAML node type. -??? example +???+ Example ```cpp #include @@ -101,9 +101,9 @@ The resulting basic_node has the same type and value as `rhs`. ### **Parameters** ***`rhs`*** [in] -: A basic node to be copied with. +: A basic_node object to be copied with. -??? example +???+ Example ```cpp #include @@ -135,9 +135,9 @@ The value of the argument `rhs` after calling this move constructor, will be the ### **Parameters** ***`rhs`*** [in] -: A basic node to be moved from. +: A basic_node object to be moved from. -??? example +???+ Example ```cpp #include @@ -185,7 +185,7 @@ The resulting basic_node has the value of `val` and the type which is associated ***`val`*** [in] : The value of a compatible type. -??? example +???+ Example ```cpp #include @@ -232,7 +232,7 @@ The resulting basic_node has the value of the referenced basic_node by `node_ref ***`node_ref_storage`*** [in] : A node_ref_storage template class object. -??? example +???+ Example ```cpp #include @@ -279,7 +279,7 @@ If `init` contains a sequence of basic_node objects in which the number of basic ***`init`*** [in] : A initializer list of basic_node objects. -??? example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/contains.md b/docs/mkdocs/docs/api/basic_node/contains.md index 967214e4..581de41c 100644 --- a/docs/mkdocs/docs/api/basic_node/contains.md +++ b/docs/mkdocs/docs/api/basic_node/contains.md @@ -10,3 +10,59 @@ template < int> = 0> bool contains(KeyType&& key) const; ``` + +Checks if the YAML node has the given key. +If the node value is not a mapping, this API will throw an [`fkyaml::exception`](../exception/index.md). + +## **Template Parameters** + +***KeyType*** +: A type compatible with the key type of mapping node values. + +## **Parameters** + +***key*** [in] +: A key to the target value in the YAML mapping node value. + +## **Return Value** + +`true` if the YAML node is a mapping and has the given key, `false` otherwise. + +???+ Example + + ```cpp + #include + #include + #include + + int main() + { + // create a YAML mapping node. + fkyaml::node n = {{"foo", true}, {"bar", 123}}; + + // check if the node has the following keys. + std::cout << std::boolalpha; + std::cout << n.contains("foo") << std::endl; + std::cout << n.contains("baz") << std::endl; + + // create a YAML node. (not mapping) + fkyaml::node n2 = "qux"; + + // check if the node has the following key. + std::cout << std::boolalpha << n2.contains("qux") << std::endl; + + return 0; + } + ``` + + output: + ```bash + true + false + false + ``` + +## **See Also** + +* [basic_node](index.md) +* [mapping_type](mapping_type.md) diff --git a/docs/mkdocs/docs/api/basic_node/deserialize.md b/docs/mkdocs/docs/api/basic_node/deserialize.md index b91cb613..dd1bbb3c 100644 --- a/docs/mkdocs/docs/api/basic_node/deserialize.md +++ b/docs/mkdocs/docs/api/basic_node/deserialize.md @@ -40,7 +40,7 @@ static basic_node deserialize(InputType&& input); ***`input`*** [in] : An input source in the YAML format. -### **Return Values** +### **Return Value** The resulting `basic_node` object deserialized from the input source. @@ -67,13 +67,13 @@ static basic_node deserialize(ItrType&& begin, ItrType&& end); ***`end`*** [in] : An iterator to the past-the-last element of an input sequence -### **Return Values** +### **Return Value** The resulting `basic_node` object deserialized from the pair of iterators. ## Examples -??? Example "Example (a character array)" +???+ Example "Example (a character array)" ```cpp #include @@ -106,7 +106,7 @@ The resulting `basic_node` object deserialized from the pair of iterators. 3.14 ``` -??? Example "Example (a std::string object)" +???+ Example "Example (a std::string object)" ```cpp #include @@ -140,7 +140,7 @@ The resulting `basic_node` object deserialized from the pair of iterators. 3.14 ``` -??? Example "Example (a FILE pointer)" +???+ Example "Example (a FILE pointer)" ```yaml title="input.yaml" foo: true @@ -181,7 +181,7 @@ The resulting `basic_node` object deserialized from the pair of iterators. 3.14 ``` -??? Example "Example (a pair of iterators)" +???+ Example "Example (a pair of iterators)" ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/empty.md b/docs/mkdocs/docs/api/basic_node/empty.md index 488abfbd..25fd7977 100644 --- a/docs/mkdocs/docs/api/basic_node/empty.md +++ b/docs/mkdocs/docs/api/basic_node/empty.md @@ -11,9 +11,9 @@ Throws a [`fkyaml::exception`](../exception/index.md) if a basic_node does not h ### **Return Value** -Returns `true` if the node value is empty, `false` otherwise. +`true` if the node value is empty, `false` otherwise. -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/end.md b/docs/mkdocs/docs/api/basic_node/end.md index 17ccc657..5604b748 100644 --- a/docs/mkdocs/docs/api/basic_node/end.md +++ b/docs/mkdocs/docs/api/basic_node/end.md @@ -16,7 +16,7 @@ Throws a [`fkyaml::exception`](../exception/index.md) if a basic_node does not h An iterator to the past-the-last element of a container node value (either sequence or mapping). -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/float_number_type.md b/docs/mkdocs/docs/api/basic_node/float_number_type.md index aa1c4b7c..d98b9cc4 100644 --- a/docs/mkdocs/docs/api/basic_node/float_number_type.md +++ b/docs/mkdocs/docs/api/basic_node/float_number_type.md @@ -16,7 +16,7 @@ To store floating point number objects in [`basic_node`](index.md) class, the ty If not explicitly specified, the default type `double` will be chosen. With the decided type, floating point number objects are stored directly inside a [`basic_node`](index.md). -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/get_anchor_name.md b/docs/mkdocs/docs/api/basic_node/get_anchor_name.md new file mode 100644 index 00000000..63e81d73 --- /dev/null +++ b/docs/mkdocs/docs/api/basic_node/get_anchor_name.md @@ -0,0 +1,56 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::get_anchor_name + +```cpp +const std::string& get_anchor_name() const; +``` + +Gets the anchor name associated to the YAML node. +Some anchor name must be set before calling this API. +Calling [`has_anchor_name`](has_anchor_name.md) to see if the node has any anchor name beforehand. + +## **Return Value** + +The anchor name associated to the node. +If no anchor name has been set, an [`fkyaml::exception`](../exception/index.md) will be thrown. + +???+ Example + + ```cpp + #include + #include + + int main() + { + // create a YAML node. + fkyaml::node n = 123; + + // try to get an anchor name before any anchor name has been set. + try + { + std::cout << n.get_anchor_name() << std::endl; + } + catch (const fkyaml::exception& e) + { + std::cout << e.what() << std::endl; + } + + // add an anchor name to the node. + n.add_anchor_name("anchor"); + std::cout << n.get_anchor_name() << std::endl; + + return 0; + } + ``` + + output: + ```bash + No anchor name has been set. + anchor + ``` + +## **See Also** + +* [basic_node](index.md) +* [set_anchor_name](get_anchor_name.md) diff --git a/docs/mkdocs/docs/api/basic_node/get_value.md b/docs/mkdocs/docs/api/basic_node/get_value.md index 3a850af4..50b8510a 100644 --- a/docs/mkdocs/docs/api/basic_node/get_value.md +++ b/docs/mkdocs/docs/api/basic_node/get_value.md @@ -12,3 +12,21 @@ template < T get_value() const noexcept( noexcept(ConverterType::from_node(std::declval(), std::declval()))); ``` + +Explicit type conversion between the internally stored YAML node value and a compatible value which is [copy-constructible](https://en.cppreference.com/w/cpp/named_req/CopyConstructible) and [default-constructible](https://en.cppreference.com/w/cpp/named_req/DefaultConstructible). +The conversion relies on the [`node_value_converter`](../node_value_converter/index.md)::[`from_node`](../node_value_converter/from_node.md). +This API makes a copy of the value. +If the copying costs a lot, or if you need an address of the original value, then it might be more suitable to call [`get_value_ref`](get_value_ref.md) instead. + +## **Template Parameters** + +***T*** +: A compatible value type which might be cv-qualified or a reference type. + +***ValueType*** +: A compatible value type. + This is, by default, a result of [std::remove_cvref_t](https://en.cppreference.com/w/cpp/types/remove_cvref). + +## **Return Value** + +A compatible native data value converted from the basic_node object. diff --git a/docs/mkdocs/docs/api/basic_node/get_value_ref.md b/docs/mkdocs/docs/api/basic_node/get_value_ref.md new file mode 100644 index 00000000..c42580ff --- /dev/null +++ b/docs/mkdocs/docs/api/basic_node/get_value_ref.md @@ -0,0 +1,80 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::get_value_ref + +```cpp +template ::value, int> = 0> +ReferenceType get_value_ref() const noexcept( + noexcept(ConverterType::from_node(std::declval(), std::declval()))); + +template < + typename ReferenceType, + detail::enable_if_t< + detail::conjunction< + std::is_reference, std::is_const>>::value, + int> = 0> +ReferenceType get_value_ref() const; +``` + +Explicit reference access to the internally stored YAML node value. +This API makes no copies. + +## **Template Parameters** + +***ReferenceType*** +: reference type to the target YAML node value. + This must be a reference to [`sequence_type`](sequence_type.md), [`mapping_type`](mapping_type.md), [`boolean_type`](boolean_type.md), [`integer_type`](integer_type.md), [`float_number_type`](float_number_type.md) or [`string_type`](string_type.md). + The above restriction is enforced by a static assertion. + +## **Return Value** + +Reference to the internally stored YAML node value if the requested reference type fits to the YAML node value. +A [`fkyaml::exception`](../exception/index.md) would be thrown otherwise. + +!!! Note + + If this API throws an exception, the internally stored YAML node value stays intact. + +???+ Example + + ```cpp + #include + #include + + int main() + { + // create a YAML node. + fkyaml::node n = 123; + + // get references to the value. + auto ref = n.get_value_ref(); + auto cref = n.get_value_ref(); + + // print the referenced values + std::cout << ref << std::endl; + std::cout << cref << std::endl; + + // specifying incompatible reference type throws an exception + try + { + auto iref = value.get_value_ref(); + } + catch (const fkyaml::exception& e) + { + std::cout << e.what() << std::endl; + } + + return 0; + } + ``` + + output: + ```bash + 123 + 123 + The node value is not a mapping. + ``` + +## **See Also** + +* [basic_node](index.md) diff --git a/docs/mkdocs/docs/api/basic_node/get_yaml_version.md b/docs/mkdocs/docs/api/basic_node/get_yaml_version.md index 4a68d2a6..dd928b9f 100644 --- a/docs/mkdocs/docs/api/basic_node/get_yaml_version.md +++ b/docs/mkdocs/docs/api/basic_node/get_yaml_version.md @@ -8,14 +8,16 @@ yaml_version_t get_yaml_version() const noexcept; Returns the version of the YAML format applied for the `basic_node` object. -### **Return Values** +### **Return Value** + +The version of the YAML format applied to the basic_node object. | YAML version | Return Value | | ------------ | ----------------------- | | 1.1 | yaml_version_t::VER_1_1 | | 1.2 | yaml_version_t::VER_1_2 | -??? Example +???+ Example ```cpp #include @@ -34,4 +36,4 @@ Returns the version of the YAML format applied for the `basic_node` object. * [basic_node](index.md) * [yaml_verion_t](yaml_version_t.md) -* [set_yaml_version](set_yaml_version.md) \ No newline at end of file +* [set_yaml_version](set_yaml_version.md) diff --git a/docs/mkdocs/docs/api/basic_node/has_anchor_name.md b/docs/mkdocs/docs/api/basic_node/has_anchor_name.md index e69de29b..0bd98312 100644 --- a/docs/mkdocs/docs/api/basic_node/has_anchor_name.md +++ b/docs/mkdocs/docs/api/basic_node/has_anchor_name.md @@ -0,0 +1,49 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::has_anchor_name + +```cpp +bool has_anchor_name() const noexcept; +``` + +Check if the YAML node has an anchor name. + +## **Return Value** + +`true` if the YAML node has an anchor name, `false` otherwise. + +???+ Example + + ```cpp + #include + #include + + int main() + { + // create a YAML node. + fkyaml::node n = {{"foo", true}}; + + // check if the node has an anchor name. + std::cout << std::boolalpha << n.has_anchor_name() << std::endl; + + // set an anchor name. + n.add_anchor_name("anchor"); + + // check if the node has an anchor name again. + std::cout << std::boolalpha << n.has_anchor_name() << std::endl; + + return 0; + } + ``` + + output: + ```bash + false + true + false + ``` + +## **See Also** + +* [basic_node](index.md) +* [add_anchor_name](add_anchor_name.md) diff --git a/docs/mkdocs/docs/api/basic_node/index.md b/docs/mkdocs/docs/api/basic_node/index.md index ee66262e..8d847d29 100644 --- a/docs/mkdocs/docs/api/basic_node/index.md +++ b/docs/mkdocs/docs/api/basic_node/index.md @@ -74,17 +74,12 @@ This class provides features to handle YAML nodes. | [is_string](is_string.md) | checks if a basic_node has a string node value. | ### Conversions -| Name | Description | -| ------------------------------------- | ------------------------------------------------------- | -| [deserialize](deserialize.md) | deserializes a YAML formatted string into a basic_node. | -| [serialize](serialize.md) | serializes a basic_node into a YAML formatted string. | -| [get_value](get_value.md) | converts a basic_node into a target native data type. | -| [to_sequence](to_sequence.md) | gets reference to the sequence node value. | -| [to_mapping](to_mapping.md) | gets reference to the mapping node value. | -| [to_boolean](to_boolean.md) | gets reference to the boolean node value. | -| [to_integer](to_integer.md) | gets reference to the integer node value. | -| [to_float_number](to_float_number.md) | gets reference to the floating point number node value. | -| [to_string](to_string.md) | gets reference to the string node value. | +| Name | | Description | +| --------------------------------- | -------- | ------------------------------------------------------------------ | +| [deserialize](deserialize.md) | (static) | deserializes a YAML formatted string into a basic_node. | +| [serialize](serialize.md) | (static) | serializes a basic_node into a YAML formatted string. | +| [get_value](get_value.md) | | converts a basic_node into a target native data type. | +| [get_value_ref](get_value_ref.md) | | converts a basic_node into reference to a target native data type. | ### Iterators | Name | Description | @@ -105,7 +100,14 @@ This class provides features to handle YAML nodes. | [operator[]](operator[].md) | accesses an item specified by the key/index | ### Aliasing Nodes -| Name | Description | -| ------------------------------------- | ------------------------------------------------ | -| [add_anchor_name](add_anchor_name.md) | registers an anchor name to a basic_node object. | -| [has_anchor_name](has_anchor_name.md) | checks if a basic_node has any anchor name. | +| Name | Description | +| ------------------------------------- | -------------------------------------------------------- | +| [add_anchor_name](add_anchor_name.md) | registers an anchor name to a basic_node object. | +| [get_anchor_name](get_anchor_name.md) | gets an anchor name associated with a basic_node object. | +| [has_anchor_name](has_anchor_name.md) | checks if a basic_node has any anchor name. | + +### Modifiers + +| Name | Description | +| --------------- | -------------------------------- | +| [swap](swap.md) | swaps the internally stored data | diff --git a/docs/mkdocs/docs/api/basic_node/integer_type.md b/docs/mkdocs/docs/api/basic_node/integer_type.md index 890486d2..3cdc0679 100644 --- a/docs/mkdocs/docs/api/basic_node/integer_type.md +++ b/docs/mkdocs/docs/api/basic_node/integer_type.md @@ -12,7 +12,7 @@ To store integer objects in [`basic_node`](index.md) class, the type is defined If not explicitly specified, the default type `std::int64_t` will be chosen. With the decided type, integer objects are stored directly inside a [`basic_node`](index.md). -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/is_boolean.md b/docs/mkdocs/docs/api/basic_node/is_boolean.md index 1dca1007..8b7e488f 100644 --- a/docs/mkdocs/docs/api/basic_node/is_boolean.md +++ b/docs/mkdocs/docs/api/basic_node/is_boolean.md @@ -12,7 +12,7 @@ Tests whether the node value type is [`node_t::BOOLEAN`](node_t.md). `true` if the type is [`node_t::BOOLEAN`](node_t.md), `false` otherwise. -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/is_float_number.md b/docs/mkdocs/docs/api/basic_node/is_float_number.md index e67f95b2..5e495b07 100644 --- a/docs/mkdocs/docs/api/basic_node/is_float_number.md +++ b/docs/mkdocs/docs/api/basic_node/is_float_number.md @@ -12,7 +12,7 @@ Tests whether the node value type is [`node_t::FLOAT_NUMBER`](node_t.md). `true` if the type is [`node_t::FLOAT_NUMBER`](node_t.md), `false` otherwise. -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/is_integer.md b/docs/mkdocs/docs/api/basic_node/is_integer.md index 7e95764b..d8305fd2 100644 --- a/docs/mkdocs/docs/api/basic_node/is_integer.md +++ b/docs/mkdocs/docs/api/basic_node/is_integer.md @@ -12,7 +12,7 @@ Tests whether the node value type is [`node_t::INTEGER`](node_t.md). `true` if the type is [`node_t::INTEGER`](node_t.md), `false` otherwise. -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/is_mapping.md b/docs/mkdocs/docs/api/basic_node/is_mapping.md index 181424f4..bf1c44fa 100644 --- a/docs/mkdocs/docs/api/basic_node/is_mapping.md +++ b/docs/mkdocs/docs/api/basic_node/is_mapping.md @@ -12,7 +12,7 @@ Tests whether the node value type is [`node_t::MAPPING`](node_t.md). `true` if the type is [`node_t::MAPPING`](node_t.md), `false` otherwise. -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/is_null.md b/docs/mkdocs/docs/api/basic_node/is_null.md index c561cca4..a13e70df 100644 --- a/docs/mkdocs/docs/api/basic_node/is_null.md +++ b/docs/mkdocs/docs/api/basic_node/is_null.md @@ -12,7 +12,7 @@ Tests whether the node value type is [`node_t::NULL_OBJECT`](node_t.md). `true` if the type is [`node_t::NULL_OBJECT`](node_t.md), `false` otherwise. -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/is_scalar.md b/docs/mkdocs/docs/api/basic_node/is_scalar.md index b7e2d12c..dd477474 100644 --- a/docs/mkdocs/docs/api/basic_node/is_scalar.md +++ b/docs/mkdocs/docs/api/basic_node/is_scalar.md @@ -17,7 +17,7 @@ Tests whether the node value type is one of the followings: `true` if the type is a scalar type, `false` otherwise. -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/is_sequence.md b/docs/mkdocs/docs/api/basic_node/is_sequence.md index 034eeab4..e7026c6a 100644 --- a/docs/mkdocs/docs/api/basic_node/is_sequence.md +++ b/docs/mkdocs/docs/api/basic_node/is_sequence.md @@ -12,7 +12,7 @@ Tests whether the node value type is [`node_t::SEQUENCE`](node_t.md). `true` if the type is [`node_t::SEQUENCE`](node_t.md), `false` otherwise. -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/is_string.md b/docs/mkdocs/docs/api/basic_node/is_string.md index 55f2a678..6f083c7a 100644 --- a/docs/mkdocs/docs/api/basic_node/is_string.md +++ b/docs/mkdocs/docs/api/basic_node/is_string.md @@ -12,7 +12,7 @@ Tests whether the node value type is [`node_t::STRING`](node_t.md). `true` if the type is [`node_t::STRING`](node_t.md), `false` otherwise. -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/iterator.md b/docs/mkdocs/docs/api/basic_node/iterator.md index c08910cf..65cc81f0 100644 --- a/docs/mkdocs/docs/api/basic_node/iterator.md +++ b/docs/mkdocs/docs/api/basic_node/iterator.md @@ -9,7 +9,7 @@ using iterator = detail::iterator; The type for iterators of [`basic_node`](index.md) containers. This iterator type is commonly used for sequence and mapping container values. -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/mapping.md b/docs/mkdocs/docs/api/basic_node/mapping.md index d85e269c..0576d1d5 100644 --- a/docs/mkdocs/docs/api/basic_node/mapping.md +++ b/docs/mkdocs/docs/api/basic_node/mapping.md @@ -12,7 +12,7 @@ The factory method which constructs a basic_node with the [`node_t::MAPPING`](no Calling this API with no arguments will constructs a basic_node with an empty mapping node value. The resulting basic_node has the [`node_t::MAPPING`](node_t.md) type. -??? example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/mapping_type.md b/docs/mkdocs/docs/api/basic_node/mapping_type.md index 60ed80ef..5ab566e2 100644 --- a/docs/mkdocs/docs/api/basic_node/mapping_type.md +++ b/docs/mkdocs/docs/api/basic_node/mapping_type.md @@ -33,7 +33,7 @@ Note that mapping objects are stored as pointers in a [`basic_node`](index.md) s `StringType` : The type of keys and string scalar values. Defaults to `std::string`. -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/node.md b/docs/mkdocs/docs/api/basic_node/node.md index 50bea0b9..1d451ac9 100644 --- a/docs/mkdocs/docs/api/basic_node/node.md +++ b/docs/mkdocs/docs/api/basic_node/node.md @@ -8,7 +8,7 @@ using node = basic_node<>; This type is the default specialization of the [basic_node](index.md) class which uses the standard template types. -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/node_t.md b/docs/mkdocs/docs/api/basic_node/node_t.md index f271b9d3..631b3461 100644 --- a/docs/mkdocs/docs/api/basic_node/node_t.md +++ b/docs/mkdocs/docs/api/basic_node/node_t.md @@ -26,7 +26,7 @@ This enumeration collects the different YAML value types. They are internally us * [`float_number_type`](float_number_type.md) for float number scalar values * [`string_type`](string_type.md) for string scalar values -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/operator=.md b/docs/mkdocs/docs/api/basic_node/operator=.md index 52db2a3a..4247c0b9 100644 --- a/docs/mkdocs/docs/api/basic_node/operator=.md +++ b/docs/mkdocs/docs/api/basic_node/operator=.md @@ -20,7 +20,16 @@ basic_node& operator=(const basic_node& rhs) noexcept; Copy assignment operator. Copies a YAML node value via the "copy and swap" strategy to enhance exception safety. -??? Example +### **Parameters** + +***`rhs`*** [in] +: A lvalue basic_node object to be copied with. + +### **Return Value** + +Reference to this basic_node object. + +???+ Example ```cpp #include @@ -45,6 +54,49 @@ Copies a YAML node value via the "copy and swap" strategy to enhance exception s 123 ``` +## Overload (2) + +```cpp +basic_node& operator=(basic_node&& rhs) noexcept; +``` + +Move assignment operator. +Moves a YAML node value from the given node. + +### **Parameters** + +***`rhs`*** [in] +: A rvalue basic_node object to be moved from. + +### **Return Value** + +Reference to this basic_node object. + +???+ Example + + ```cpp + #include + #include + + int main() + { + fkyaml::node n = true; + fkyaml::node n2 = 123; + n = std::move(n2); + + std::cout << std::boolalpha << n.is_integer() << std::endl; + std::cout << n.get_value() << std::endl; + + return 0; + } + ``` + + output: + ```bash + true + 123 + ``` + ## **See Also** * [basic_node](index.md) diff --git a/docs/mkdocs/docs/api/basic_node/operator[].md b/docs/mkdocs/docs/api/basic_node/operator[].md index 8f34536a..80e4a9f8 100644 --- a/docs/mkdocs/docs/api/basic_node/operator[].md +++ b/docs/mkdocs/docs/api/basic_node/operator[].md @@ -3,21 +3,135 @@ # fkyaml::basic_node::operator[] ```cpp -basic_node& operator[](std::size_t index); +basic_node& operator[](std::size_t index); // (1) -const basic_node& operator[](std::size_t index) const; +const basic_node& operator[](std::size_t index) const; // (2) template < typename KeyType, detail::enable_if_t< detail::is_usable_as_key_type< typename mapping_type::key_compare, typename mapping_type::key_type, KeyType>::value, int> = 0> -basic_node& operator[](KeyType&& key); +basic_node& operator[](KeyType&& key); // (3) template < typename KeyType, detail::enable_if_t< detail::is_usable_as_key_type< typename mapping_type::key_compare, typename mapping_type::key_type, KeyType>::value, int> = 0> -const basic_node& operator[](KeyType&& key) const; +const basic_node& operator[](KeyType&& key) const; // (4) ``` + +Access to a YAML node element with either a key or an index. +If the node is neither a mapping nor a sequence, a [`fkyaml::exception`](../exception/index.md) will be thrown. + +## Overload (1), (2) + +```cpp +basic_node& operator[](std::size_t index); // (1) +const basic_node& operator[](std::size_t index) const; // (2) +``` + +Accesses to an element in the YAML sequence node with the given index. +If the node is not a sequence, a [`fkyaml::exception`](../exception/index.md) will be thrown. + +!!! Danger + + This API does not check the size of a sequence node before accessing the element. + To avoid undefined behaviors, please make sure the argument `index` is smaller than the actual sequence size with a return value of [`size()`](size.md). + +### **Parameters** + +***`index`*** [in] +: An index for an element in the YAML sequence node. + +### **Return Value** + +Reference, or constant reference, to the YAML node at the given index. + +???+ Example + + ```cpp + #include + #include + + int main() + { + // create a YAML sequence node. + fkyaml::node n = {123, 234, 345, 456}; + + // print YAML nodes at the following indexes. + std::cout << fkyaml::node::serialize(n[0]) << std::endl; + std::cout << fkyaml::node::serialize(n[1]) << std::endl; + std::cout << fkyaml::node::serialize(n[2]) << std::endl; + std::cout << fkyaml::node::serialize(n[3]) << std::endl; + return 0; + } + ``` + +## Overload (3), (4) + +```cpp +template < + typename KeyType, detail::enable_if_t< + detail::is_usable_as_key_type< + typename mapping_type::key_compare, typename mapping_type::key_type, KeyType>::value, + int> = 0> +basic_node& operator[](KeyType&& key); // (3) + +template < + typename KeyType, detail::enable_if_t< + detail::is_usable_as_key_type< + typename mapping_type::key_compare, typename mapping_type::key_type, KeyType>::value, + int> = 0> +const basic_node& operator[](KeyType&& key) const; // (4) +``` + +Accesses to an element in the YAML mapping node with the given key. +The given key must be of a compatible type with [`fkyaml::string_type`](string_type.md), i.e., a [`fkyaml::string_type`](string_type.md) object can be constructible with the given key. +If the node is not a mapping, a [`fkyaml::exception`](../exception/index.md) will be thrown. + +!!! Warning + + This API does not check the existence of the given key in the YAML mapping node. + If the given key does not exist, a default [basic_node](index.md) object will be created. + Please make sure that the node has the given key beforehand by calling the [`contains`](contains.md) API. + +### **Template Parameters** + +***KeyType*** +: A type compatible with the key type of mapping node values. + +### **Parameters** + +***key*** [in] +: A key to the target value in the YAML mapping node. + +### **Return Value** + +Reference, or constant reference, to the YAML node associated with the given key. + +???+ Example + + ```cpp + #include + #include + + int main() + { + // create a YAML node. + fkyaml::node n = {{"foo", true}, {"bar", 123}}; + + // print YAML nodes associated with the following keys. + std::cout << std::boolalpha << fkyaml::node::serialize(n["foo"]) << std::endl; + std::cout << fkyaml::node::serialize(n["bar"]) << std::endl; + + return 0; + } + ``` + +## **See Also** + +* [basic_node](index.md) +* [size](size.md) +* [contains](contains.md) diff --git a/docs/mkdocs/docs/api/basic_node/sequence.md b/docs/mkdocs/docs/api/basic_node/sequence.md index 8a0a2928..d240bbb4 100644 --- a/docs/mkdocs/docs/api/basic_node/sequence.md +++ b/docs/mkdocs/docs/api/basic_node/sequence.md @@ -12,7 +12,7 @@ The factory method which constructs a basic_node with the [`node_t::SEQUENCE`](n Calling this API with no arguments will constructs a basic_node with an empty sequence node value. The resulting basic_node has the [`node_t::SEQUENCE`](node_t.md) type. -??? example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/sequence_type.md b/docs/mkdocs/docs/api/basic_node/sequence_type.md index dc9a6171..871a4e94 100644 --- a/docs/mkdocs/docs/api/basic_node/sequence_type.md +++ b/docs/mkdocs/docs/api/basic_node/sequence_type.md @@ -12,7 +12,7 @@ To store sequence objects in [`basic_node`](index.md) class, the type is defined If not explicitly specified, the default type `std::vector` will be chosen. Note that sequence objects are stored as pointers to the decided type in a [`basic_node`](index.md) so that the internal storage size will at most be 8 bytes. -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/serialize.md b/docs/mkdocs/docs/api/basic_node/serialize.md index 8aa00186..a9751320 100644 --- a/docs/mkdocs/docs/api/basic_node/serialize.md +++ b/docs/mkdocs/docs/api/basic_node/serialize.md @@ -15,11 +15,11 @@ That means that, even if a deserialized source input is written in flow styles, ***node*** [in] : A `basic_node` object to be serialized. -### **Return Values** +### **Return Value** The resulting string object from the serialization of the `node` object. -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/set_yaml_version.md b/docs/mkdocs/docs/api/basic_node/set_yaml_version.md index b1f2408a..05d549b0 100644 --- a/docs/mkdocs/docs/api/basic_node/set_yaml_version.md +++ b/docs/mkdocs/docs/api/basic_node/set_yaml_version.md @@ -13,14 +13,7 @@ Sets the version of the YAML format to the `basic_node` object. ***version*** [in] : A version of the YAML format. -### **Return Values** - -| YAML version | Return Value | -| ------------ | ----------------------- | -| 1.1 | yaml_version_t::VER_1_1 | -| 1.2 | yaml_version_t::VER_1_2 | - -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/size.md b/docs/mkdocs/docs/api/basic_node/size.md index 1ba48a2a..8c4b386e 100644 --- a/docs/mkdocs/docs/api/basic_node/size.md +++ b/docs/mkdocs/docs/api/basic_node/size.md @@ -11,9 +11,9 @@ Throws a [`fkyaml::exception`](../exception/index.md) if a basic_node does not h ### **Return Value** -Returns the size of a node value. +The size of a node value. -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/string_type.md b/docs/mkdocs/docs/api/basic_node/string_type.md index 19f68df3..0cde8b17 100644 --- a/docs/mkdocs/docs/api/basic_node/string_type.md +++ b/docs/mkdocs/docs/api/basic_node/string_type.md @@ -12,7 +12,7 @@ To store string objects in [`basic_node`](index.md) class, the type is defined b If not explicitly specified, the default type `std::string` will be chosen. Note that string objects are stored as pointers to the decided type in a [`basic_node`](index.md) so that the internal storage size will at most be 8 bytes. -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/swap.md b/docs/mkdocs/docs/api/basic_node/swap.md new file mode 100644 index 00000000..e9c10cf8 --- /dev/null +++ b/docs/mkdocs/docs/api/basic_node/swap.md @@ -0,0 +1,111 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) + +# fkyaml::basic_node::swap + +```cpp +void swap(basic_node& rhs) noexcept; // (1) + +template < + template class SequenceType, template class MappingType, + typename BooleanType, typename IntegerType, typename FloatNumberType, typename StringType, + template class ConverterType> +inline void swap( + basic_node& lhs, + basic_node& rhs) noexcept(noexcept(lhs.swap(rhs))); // (2) +``` + +Swaps the internally stored data with the given basic_node object. + +## Overload (1) + +```cpp +void swap(basic_node& rhs) noexcept; // (1) +``` + +### **Parameters** + +***`rhs`*** [in] +: A basic_node object to be swapped with. + +???+ Example + + ```cpp + #include + #include + + int main() + { + // create YAML nodes. + fkyaml::node n1 = 123; + fkyaml::node n2 = "foo"; + + // swap the internally stored data between n1 & n2. + n1.swap(n2); + + // print the swapped values. + std::cout << n1.get_value_ref() << std::endl; + std::cout << n2.get_value() << std::endl; + return 0; + } + ``` + + output: + ```bash + foo + 123 + ``` + +## Overload (2) + +```cpp +template < + template class SequenceType, template class MappingType, + typename BooleanType, typename IntegerType, typename FloatNumberType, typename StringType, + template class ConverterType> +inline void swap( + basic_node& lhs, + basic_node& rhs) noexcept(noexcept(lhs.swap(rhs))); // (2) +``` + +### **Parameters** + +***`lhs`*** [in] +: A left-hand-side basic_node object to be swapped with. + +***`rhs`*** +: A right-hand-side basic_node object to be swapped with. + +???+ Example + + ```cpp + #include + #include + + int main() + { + // create YAML nodes. + fkyaml::node n1 = 123; + fkyaml::node n2 = "foo"; + + // swap the internally stored data between n1 & n2. + using std::swap; + swap(n1, n2); + + // print the swapped values. + std::cout << n1.get_value_ref() << std::endl; + std::cout << n2.get_value() << std::endl; + return 0; + } + ``` + + output: + ```bash + foo + 123 + ``` + +## **See Also** + +* [basic_node](index.md) +* [get_value](get_value.md) +* [get_value_ref](get_value_ref.md) diff --git a/docs/mkdocs/docs/api/basic_node/to_boolean.md b/docs/mkdocs/docs/api/basic_node/to_boolean.md deleted file mode 100644 index a186936c..00000000 --- a/docs/mkdocs/docs/api/basic_node/to_boolean.md +++ /dev/null @@ -1,9 +0,0 @@ -Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) - -# fkyaml::basic_node::to_boolean - -```cpp -boolean_type& to_boolean(); - -const boolean_type& to_boolean() const; -``` diff --git a/docs/mkdocs/docs/api/basic_node/to_float_number.md b/docs/mkdocs/docs/api/basic_node/to_float_number.md deleted file mode 100644 index 666ea335..00000000 --- a/docs/mkdocs/docs/api/basic_node/to_float_number.md +++ /dev/null @@ -1,9 +0,0 @@ -Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) - -# fkyaml::basic_node::to_float_number - -```cpp -float_number_type& to_float_number(); - -const float_number_type& to_float_number() const; -``` diff --git a/docs/mkdocs/docs/api/basic_node/to_integer.md b/docs/mkdocs/docs/api/basic_node/to_integer.md deleted file mode 100644 index 52d6799c..00000000 --- a/docs/mkdocs/docs/api/basic_node/to_integer.md +++ /dev/null @@ -1,9 +0,0 @@ -Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) - -# fkyaml::basic_node::to_integer - -```cpp -integer_type& to_integer(); - -const integer_type& to_integer() const; -``` diff --git a/docs/mkdocs/docs/api/basic_node/to_mapping.md b/docs/mkdocs/docs/api/basic_node/to_mapping.md deleted file mode 100644 index 4022b983..00000000 --- a/docs/mkdocs/docs/api/basic_node/to_mapping.md +++ /dev/null @@ -1,9 +0,0 @@ -Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) - -# fkyaml::basic_node::to_mapping - -```cpp -mapping_type& to_mapping(); - -const mapping_type& to_mapping() const; -``` diff --git a/docs/mkdocs/docs/api/basic_node/to_sequence.md b/docs/mkdocs/docs/api/basic_node/to_sequence.md deleted file mode 100644 index 808e98fc..00000000 --- a/docs/mkdocs/docs/api/basic_node/to_sequence.md +++ /dev/null @@ -1,9 +0,0 @@ -Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) - -# fkyaml::basic_node::to_sequence - -```cpp -sequence_type& to_sequence(); - -const sequence_type& to_sequence() const; -``` diff --git a/docs/mkdocs/docs/api/basic_node/to_string.md b/docs/mkdocs/docs/api/basic_node/to_string.md deleted file mode 100644 index e1bca62f..00000000 --- a/docs/mkdocs/docs/api/basic_node/to_string.md +++ /dev/null @@ -1,9 +0,0 @@ -Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp) - -# fkyaml::basic_node::to_string - -```cpp -string_type& to_string(); - -const string_type& to_string() const; -``` diff --git a/docs/mkdocs/docs/api/basic_node/type.md b/docs/mkdocs/docs/api/basic_node/type.md index 60684f4d..1e9abd50 100644 --- a/docs/mkdocs/docs/api/basic_node/type.md +++ b/docs/mkdocs/docs/api/basic_node/type.md @@ -22,7 +22,7 @@ The type of the YAML node value. | floating point number | node_t::FLOAT_NUMBER | | string | node_t::STRING | -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/value_converter_type.md b/docs/mkdocs/docs/api/basic_node/value_converter_type.md index 480fa548..00d4b193 100644 --- a/docs/mkdocs/docs/api/basic_node/value_converter_type.md +++ b/docs/mkdocs/docs/api/basic_node/value_converter_type.md @@ -21,7 +21,7 @@ If you want to convert some type from/to `basic_node`, however, it is recommende ***SFINAE*** : Type to add compile type checks via SFINAE. Usually `void` is given. -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/basic_node/yaml_version_t.md b/docs/mkdocs/docs/api/basic_node/yaml_version_t.md index 9448a66e..8473a4f7 100644 --- a/docs/mkdocs/docs/api/basic_node/yaml_version_t.md +++ b/docs/mkdocs/docs/api/basic_node/yaml_version_t.md @@ -12,7 +12,7 @@ enum class yaml_version_t This enumeration collects the used versions of YAML specification. It is used as meta data of a basic_node and the functions [`get_yaml_version`](get_yaml_version.md) and [`set_yaml_version`](set_yaml_version.md) rely on it. -??? Example +???+ Example ```cpp #include diff --git a/docs/mkdocs/docs/api/exception/constructor.md b/docs/mkdocs/docs/api/exception/constructor.md index cb2aa7dc..46f8cec4 100644 --- a/docs/mkdocs/docs/api/exception/constructor.md +++ b/docs/mkdocs/docs/api/exception/constructor.md @@ -9,7 +9,7 @@ exception() = default; Constructs an exception without an error message. You can specify an error message on constructing an exception with an overloaded constructor. -??? example +???+ Example ```cpp #include @@ -48,7 +48,7 @@ The given error message can be retrieved by calling [`exception::what()`](what.m ***`msg`*** [in] : An error message for the exception. If `nullptr` is given, the resulting error message will be empty. -??? example +???+ Example ```cpp #include diff --git a/docs/mkdocs/mkdocs.yml b/docs/mkdocs/mkdocs.yml index 4350c455..3821d80c 100644 --- a/docs/mkdocs/mkdocs.yml +++ b/docs/mkdocs/mkdocs.yml @@ -104,7 +104,9 @@ nav: - empty: api/basic_node/empty.md - end: api/basic_node/end.md - float_number_type: api/basic_node/float_number_type.md + - get_anchor_name: api/basic_node/get_anchor_name.md - get_value: api/basic_node/get_value.md + - get_value_ref: api/basic_node/get_value_ref.md - get_yaml_version: api/basic_node/get_yaml_version.md - has_anchor_name: api/basic_node/has_anchor_name.md - integer_type: api/basic_node/integer_type.md @@ -127,12 +129,7 @@ nav: - set_yaml_version: api/basic_node/set_yaml_version.md - size: api/basic_node/size.md - string_type: api/basic_node/string_type.md - - to_boolean: api/basic_node/to_boolean.md - - to_float_number: api/basic_node/to_float_number.md - - to_integer: api/basic_node/to_integer.md - - to_mapping: api/basic_node/to_mapping.md - - to_sequence: api/basic_node/to_sequence.md - - to_string: api/basic_node/to_string.md + - swap: api/basic_node/swap.md - type: api/basic_node/type.md - value_converter_type: api/basic_node/value_converter_type.md - yaml_version_t: api/basic_node/yaml_version_t.md diff --git a/include/fkYAML/node.hpp b/include/fkYAML/node.hpp index f0ee2e9d..1250d58b 100644 --- a/include/fkYAML/node.hpp +++ b/include/fkYAML/node.hpp @@ -111,16 +111,16 @@ class basic_node /// @brief The actual storage for a YAML node value of the @ref basic_node class. /// @details This union combines the different sotrage types for the YAML value types defined in @ref node_t. - /// @note Container types are stored as pointers so that the size of this union should not exceed 64 bits by + /// @note Container types are stored as pointers so that the size of this union will not exceed 64 bits by /// default. union node_value { - /// @brief Construct a new basic_node Value object for null types. + /// @brief Constructs a new basic_node Value object for null types. node_value() = default; - /// @brief Construct a new basic_node Value object with basic_node types. The default value for the specified + /// @brief Constructs a new basic_node value object with a node type. The default value for the specified /// type will be assigned. - /// @param[in] type A Node type. + /// @param[in] type A node type. explicit node_value(node_t type) { switch (type) @@ -151,9 +151,9 @@ class basic_node } } - /// @brief Destroy the existing Node value. This process is recursive if the specified node type is fpr + /// @brief Destroys the existing Node value. This process is recursive if the specified node type is for /// containers. - /// @param[in] type A Node type to determine which Node value is destroyed. + /// @param[in] type A Node type to determine the value to be destroyed. void destroy(node_t type) { if (type == node_t::SEQUENCE || type == node_t::MAPPING) @@ -217,22 +217,22 @@ class basic_node } } - /** A pointer to the value of sequence type. */ + /// A pointer to the value of sequence type. sequence_type* p_sequence; - /** A pointer to the value of mapping type. This pointer is also used when node type is null. */ + /// A pointer to the value of mapping type. This pointer is also used when node type is null. mapping_type* p_mapping {nullptr}; - /** A value of boolean type. */ + /// A value of boolean type. boolean_type boolean; - /** A value of integer type. */ + /// A value of integer type. integer_type integer; - /** A value of float number type. */ + /// A value of float number type. float_number_type float_val; - /** A pointer to the value of string type. */ + /// A pointer to the value of string type. string_type* p_string; }; private: - /// @brief Allocates and constructs an object with specified type and arguments. + /// @brief Allocates and constructs an object with a given type and arguments. /// @tparam ObjType The target object type. /// @tparam ArgTypes The packed argument types for constructor arguments. /// @param[in] args A parameter pack for constructor arguments of the target object type. @@ -273,11 +273,12 @@ class basic_node } public: - /// @brief Construct a new basic_node object of null type. + /// @brief Constructs a new basic_node object of null type. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor/ basic_node() = default; - /// @brief Construct a new basic_node object with a specified type. + /// @brief Constructs a new basic_node object with a specified type. + /// @param[in] type A YAML node type. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor/ explicit basic_node(const node_t type) : m_node_type(type), @@ -286,6 +287,7 @@ class basic_node } /// @brief Copy constructor of the basic_node class. + /// @param[in] rhs A basic_node object to be copied with. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor/ basic_node(const basic_node& rhs) : m_node_type(rhs.m_node_type), @@ -330,6 +332,7 @@ class basic_node } /// @brief Move constructor of the basic_node class. + /// @param[in] rhs A basic_node object to be moved from. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor/ basic_node(basic_node&& rhs) noexcept : m_node_type(rhs.m_node_type), @@ -378,6 +381,9 @@ class basic_node } /// @brief Construct a new basic_node object from a value of compatible types. + /// @tparam CompatibleType Type of native data which is compatible with node values. + /// @tparam U Type of compatible native data without cv-qualifiers and reference. + /// @param[in] val The value of a compatible type. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor/ template < typename CompatibleType, typename U = detail::remove_cvref_t, @@ -393,6 +399,8 @@ class basic_node } /// @brief Construct a new basic node object with a node_ref_storage object. + /// @tparam NodeRefStorageType Type of basic_node with reference. + /// @param[in] node_ref_storage A node_ref_storage template class object. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor/ template < typename NodeRefStorageType, @@ -403,6 +411,7 @@ class basic_node } /// @brief Construct a new basic node object with std::initializer_list. + /// @param[in] init A initializer list of basic_node objects. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/constructor/ basic_node(initializer_list_t init) { @@ -443,6 +452,9 @@ class basic_node public: /// @brief Deserialize an input source into a basic_node object. + /// @tparam InputType Type of a compatible input. + /// @param[in] input An input source in the YAML format. + /// @return The resulting basic_node object deserialized from the input source. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/deserialize/ template static basic_node deserialize(InputType&& input) @@ -451,6 +463,10 @@ class basic_node } /// @brief Deserialize input iterators into a basic_node object. + /// @tparam ItrType Type of a compatible iterator. + /// @param[in] begin An iterator to the first element of an input sequence. + /// @param[in] end An iterator to the past-the-last element of an input sequence. + /// @return The resulting basic_node object deserialized from the pair of iterators. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/deserialize/ template static basic_node deserialize(ItrType&& begin, ItrType&& end) @@ -460,6 +476,8 @@ class basic_node } /// @brief Serialize a basic_node object into a string. + /// @param[in] node A basic_node object to be serialized. + /// @return The resulting string object from the serialization of the node object. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/serialize/ static std::string serialize(const basic_node& node) { @@ -467,6 +485,7 @@ class basic_node } /// @brief A factory method for sequence basic_node objects without sequence_type objects. + /// @return A YAML sequence node. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/sequence/ static basic_node sequence() { @@ -478,6 +497,8 @@ class basic_node } // LCOV_EXCL_LINE /// @brief A factory method for sequence basic_node objects with lvalue sequence_type objects. + /// @param[in] seq A lvalue sequence node value. + /// @return A YAML sequence node. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/sequence/ static basic_node sequence(const sequence_type& seq) { @@ -489,6 +510,8 @@ class basic_node } // LCOV_EXCL_LINE /// @brief A factory method for sequence basic_node objects with rvalue sequence_type objects. + /// @param[in] seq A rvalue sequence node value. + /// @return A YAML sequence node. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/sequence/ static basic_node sequence(sequence_type&& seq) { @@ -500,6 +523,7 @@ class basic_node } // LCOV_EXCL_LINE /// @brief A factory method for mapping basic_node objects without mapping_type objects. + /// @return A YAML mapping node. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/mapping/ static basic_node mapping() { @@ -511,6 +535,8 @@ class basic_node } // LCOV_EXCL_LINE /// @brief A factory method for mapping basic_node objects with lvalue mapping_type objects. + /// @param[in] map A lvalue mapping node value. + /// @return A YAML mapping node. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/mapping/ static basic_node mapping(const mapping_type& map) { @@ -522,6 +548,8 @@ class basic_node } // LCOV_EXCL_LINE /// @brief A factory method for mapping basic_node objects with rvalue mapping_type objects. + /// @param[in] map A rvalue mapping node value. + /// @return A YAML mapping node. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/mapping/ static basic_node mapping(mapping_type&& map) { @@ -534,6 +562,8 @@ class basic_node /// @brief A factory method for alias basic_node objects referencing the given anchor basic_node object. /// @note The given anchor basic_node must have a non-empty anchor name. + /// @param[in] anchor_node A basic_node object with an anchor name. + /// @return An alias YAML node created from the given anchor node. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/alias_of/ static basic_node alias_of(const basic_node& anchor_node) { @@ -548,6 +578,8 @@ class basic_node public: /// @brief A copy assignment operator of the basic_node class. + /// @param[in] rhs A lvalue basic_node object to be copied with. + /// @return Reference to this basic_node object. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/operator=/ basic_node& operator=(const basic_node& rhs) noexcept { @@ -556,6 +588,8 @@ class basic_node } /// @brief A move assignment operator of the basic_node class. + /// @param[in] rhs A rvalue basic_node object to be moved from. + /// @return Reference to this basic_node object. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/operator=/ basic_node& operator=(basic_node&& rhs) noexcept { @@ -564,6 +598,8 @@ class basic_node } /// @brief A subscript operator for non-const basic_node objects. + /// @param[in] index An index for an element in the YAML sequence node. + /// @return Reference to the YAML node at the given index. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/operator[]/ basic_node& operator[](std::size_t index) // NOLINT(readability-make-member-function-const) { @@ -578,6 +614,8 @@ class basic_node } /// @brief A subscript operator for const basic_node objects. + /// @param[in] index An index for an element in the YAML sequence node. + /// @return Constant reference to the YAML node at the given index. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/operator[]/ const basic_node& operator[](std::size_t index) const { @@ -592,6 +630,9 @@ class basic_node } /// @brief A subscript operator for non-const basic_node objects. + /// @tparam KeyType A type compatible with the key type of mapping node values. + /// @param[in] key A key to the target value in the YAML mapping node. + /// @return Reference to the YAML node associated with the given key. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/operator[]/ template < typename KeyType, detail::enable_if_t< @@ -610,6 +651,9 @@ class basic_node } /// @brief A subscript operator for const basic_node objects. + /// @tparam KeyType A type compatible with the key type of mapping node values. + /// @param[in] key A key to the target value in the YAML mapping node. + /// @return Constant reference to the YAML node associated with the given key. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/operator[]/ template < typename KeyType, detail::enable_if_t< @@ -629,6 +673,7 @@ class basic_node public: /// @brief Returns the type of the current basic_node value. + /// @return The type of the YAML node value. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/type/ node_t type() const noexcept { @@ -636,6 +681,7 @@ class basic_node } /// @brief Tests whether the current basic_node value is of sequence type. + /// @return true if the type is sequence, false otherwise. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/is_sequence/ bool is_sequence() const noexcept { @@ -643,6 +689,7 @@ class basic_node } /// @brief Tests whether the current basic_node value is of mapping type. + /// @return true if the type is mapping, false otherwise. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/is_mapping/ bool is_mapping() const noexcept { @@ -650,6 +697,7 @@ class basic_node } /// @brief Tests whether the current basic_node value is of null type. + /// @return true if the type is null, false otherwise. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/is_null/ bool is_null() const noexcept { @@ -657,6 +705,7 @@ class basic_node } /// @brief Tests whether the current basic_node value is of boolean type. + /// @return true if the type is boolean, false otherwise /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/is_boolean/ bool is_boolean() const noexcept { @@ -664,6 +713,7 @@ class basic_node } /// @brief Tests whether the current basic_node value is of integer type. + /// @return true if the type is integer, false otherwise. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/is_integer/ bool is_integer() const noexcept { @@ -671,6 +721,7 @@ class basic_node } /// @brief Tests whether the current basic_node value is of float number type. + /// @return true if the type is floating point number, false otherwise. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/is_float_number/ bool is_float_number() const noexcept { @@ -678,6 +729,7 @@ class basic_node } /// @brief Tests whether the current basic_node value is of string type. + /// @return true if the type is string, false otherwise. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/is_string/ bool is_string() const noexcept { @@ -685,6 +737,7 @@ class basic_node } /// @brief Tests whether the current basic_node value is of scalar types. + /// @return true if the type is scalar, false otherwise. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/is_scalar/ bool is_scalar() const noexcept { @@ -692,6 +745,7 @@ class basic_node } /// @brief Tests whether the current basic_node value (sequence, mapping, string) is empty. + /// @return true if the node value is empty, false otherwise. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/empty/ bool empty() const { @@ -712,6 +766,7 @@ class basic_node } /// @brief Returns the size of the current basic_node value (sequence, mapping, string). + /// @return The size of a node value. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/size/ std::size_t size() const { @@ -732,6 +787,9 @@ class basic_node } /// @brief Check whether or not this basic_node object has a given key in its inner mapping Node value. + /// @tparam KeyType A type compatible with the key type of mapping node values. + /// @param[in] key A key to the target value in the YAML mapping node value. + /// @return true if the YAML node is a mapping and has the given key, false otherwise. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/contains/ template < typename KeyType, detail::enable_if_t< @@ -753,6 +811,7 @@ class basic_node } /// @brief Get the YAML version specification for this basic_node object. + /// @return The version of the YAML format applied to the basic_node object. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/get_yaml_version/ yaml_version_t get_yaml_version() const noexcept { @@ -760,6 +819,7 @@ class basic_node } /// @brief Set the YAML version specification for this basic_node object. + /// @param[in] A version of the YAML format. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/set_yaml_version/ void set_yaml_version(const yaml_version_t version) noexcept { @@ -767,6 +827,7 @@ class basic_node } /// @brief Check whether or not this basic_node object has already had any anchor name. + /// @return true if ths basic_node has an anchor name, false otherwise. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/has_anchor_name/ bool has_anchor_name() const noexcept { @@ -776,6 +837,7 @@ class basic_node /// @brief Get the anchor name associated to this basic_node object. /// @note Some anchor name must be set before calling this method. Call basic_node::HasAnchorName() to see if this /// basic_node object has any anchor name. + /// @return The anchor name associated to the node. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/get_anchor_name/ const std::string& get_anchor_name() const { @@ -798,6 +860,7 @@ class basic_node /// @brief Add an anchor name to this basic_node object. /// @note If this basic_node object has already had any anchor name, the new anchor name will overwrite the old one. + /// @param[in] anchor_name An anchor name.This should not be empty. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/add_anchor_name/ void add_anchor_name(std::string&& anchor_name) { @@ -808,6 +871,9 @@ class basic_node /// @brief Get the node value object converted into a given type. /// @note This function requires T objects to be default constructible. + /// @tparam T A compatible value type which might be cv-qualified or a reference type. + /// @tparam ValueType A compatible value type, without cv-qualifiers and reference by default. + /// @return A compatible native data value converted from the basic_node object. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/get_value/ template < typename T, typename ValueType = detail::remove_cvref_t, @@ -823,12 +889,20 @@ class basic_node return ret; } + /// @brief Explicit reference access to the internally stored YAML node value. + /// @tparam ReferenceType Reference type to the target YAML node value. + /// @return Reference to the internally stored YAML node value. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/get_value_ref/ template ::value, int> = 0> ReferenceType get_value_ref() { return get_value_ref_impl(static_cast>(nullptr)); } + /// @brief Explicit reference access to the internally stored YAML node value. + /// @tparam ReferenceType Constant reference type to the target YAML node value. + /// @return Constant reference to the internally stored YAML node value. + /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/get_value_ref/ template < typename ReferenceType, detail::enable_if_t< @@ -840,7 +914,8 @@ class basic_node return get_value_ref_impl(static_cast>(nullptr)); } - /// @brief Swaps data with the specified basic_node object. + /// @brief Swaps the internally stored data with the specified basic_node object. + /// @param[in] rhs A basic_node object to be swapped with. /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/swap/ void swap(basic_node& rhs) noexcept { @@ -858,6 +933,7 @@ class basic_node /// @brief Returns the first iterator of basic_node values of container types (sequence or mapping) from a non-const /// basic_node object. Throws exception if the basic_node value is not of container types. + /// @return An iterator to the first element of a YAML node value (either sequence or mapping). /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/begin/ iterator begin() { @@ -876,6 +952,7 @@ class basic_node /// @brief Returns the first iterator of basic_node values of container types (sequence or mapping) from a const /// basic_node object. Throws exception if the basic_node value is not of container types. + /// @return A constant iterator to the first element of a YAML node value (either sequence or mapping). /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/begin/ const_iterator begin() const { @@ -894,6 +971,7 @@ class basic_node /// @brief Returns the last iterator of basic_node values of container types (sequence or mapping) from a non-const /// basic_node object. Throws exception if the basic_node value is not of container types. + /// @return An iterator to the past-the end element of a YAML node value (either sequence or mapping). /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/end/ iterator end() { @@ -912,6 +990,7 @@ class basic_node /// @brief Returns the last iterator of basic_node values of container types (sequence or mapping) from a const /// basic_node object. Throws exception if the basic_node value is not of container types. + /// @return A constant iterator to the past-the end element of a YAML node value (either sequence or mapping). /// @sa https://fktn-k.github.io/fkYAML/api/basic_node/end/ const_iterator end() const { @@ -1084,6 +1163,8 @@ class basic_node }; /// @brief Swap function for basic_node objects. +/// @param[in] lhs A left-side-hand basic_node object to be swapped with. +/// @param[in] rhs A right-side-hand basic_node object to be swapped with. /// @sa https://fktn-k.github.io/fkYAML/api/swap/ template < template class SequenceType, template class MappingType, From 73d112edac798d71ae99b4e4bfbe0a75c02cb615 Mon Sep 17 00:00:00 2001 From: fktn Date: Fri, 3 Nov 2023 19:40:46 +0900 Subject: [PATCH 35/48] moved docs for exception APIs with MkDocs --- docs/mkdocs/docs/api/exception/constructor.md | 25 +++++++++++++---- docs/mkdocs/docs/api/exception/destructor.md | 4 +++ docs/mkdocs/docs/api/exception/what.md | 28 ++++++++++++++++++- include/fkYAML/exception.hpp | 2 ++ 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/docs/mkdocs/docs/api/exception/constructor.md b/docs/mkdocs/docs/api/exception/constructor.md index 46f8cec4..4f1fbe5d 100644 --- a/docs/mkdocs/docs/api/exception/constructor.md +++ b/docs/mkdocs/docs/api/exception/constructor.md @@ -3,12 +3,22 @@ # fkyaml::exception::(constructor) ```cpp -exception() = default; +exception() = default; // (1) + +explicit exception(const char* msg); // (2) ``` -Constructs an exception without an error message. +Constructs an exception object. You can specify an error message on constructing an exception with an overloaded constructor. +## Overload (1) + +```cpp +exception() = default; // (1) +``` + +Constructs an exception object without an error message. + ???+ Example ```cpp @@ -34,10 +44,10 @@ You can specify an error message on constructing an exception with an overloaded ``` -## Overloads +## Overloads (2) ```cpp -explicit exception(const char* msg); +explicit exception(const char* msg); // (2) ``` Constructs an exception with a given error message. @@ -71,4 +81,9 @@ The given error message can be retrieved by calling [`exception::what()`](what.m output: ```bash An error message. - ``` \ No newline at end of file + ``` + +## **See Also** + +* [exception](index.md) +* [what](what.md) diff --git a/docs/mkdocs/docs/api/exception/destructor.md b/docs/mkdocs/docs/api/exception/destructor.md index 2d5f0bde..b490ca46 100644 --- a/docs/mkdocs/docs/api/exception/destructor.md +++ b/docs/mkdocs/docs/api/exception/destructor.md @@ -7,3 +7,7 @@ ``` Destroy an exception. + +## **See Also** + +* [exception](index.md) diff --git a/docs/mkdocs/docs/api/exception/what.md b/docs/mkdocs/docs/api/exception/what.md index 6b4cae08..cb2d0203 100644 --- a/docs/mkdocs/docs/api/exception/what.md +++ b/docs/mkdocs/docs/api/exception/what.md @@ -8,6 +8,32 @@ const char* what(); Returns an error message for an exception. If nothing, a non-null, empty string will be returned. +???+ Example + + ```cpp + #include + #include + + int main() + { + try + { + throw fkyaml::exception("An error message."); + } + catch (const fkyaml::exception& e) + { + std::cout << e.what() << std::endl; + } + + return 0; + } + ``` + + output: + ```bash + An error message. + ``` + ### **See Also** -* [(constructor)](constructor.md) \ No newline at end of file +* [(constructor)](constructor.md) diff --git a/include/fkYAML/exception.hpp b/include/fkYAML/exception.hpp index a7961e29..f5f4ec98 100644 --- a/include/fkYAML/exception.hpp +++ b/include/fkYAML/exception.hpp @@ -31,6 +31,7 @@ class exception : public std::exception exception() = default; /// @brief Construct a new exception object with an error message. + /// @param[in] msg An error message. /// @sa https://fktn-k.github.io/fkYAML/api/exception/constructor/ explicit exception(const char* msg) { @@ -42,6 +43,7 @@ class exception : public std::exception public: /// @brief Returns an error message internally held. If nothing, a non-null, empty string will be returned. + /// @return An error message internally held. The message might be empty. /// @sa https://fktn-k.github.io/fkYAML/api/exception/what/ const char* what() const noexcept override { From 8d078ba6d26df2f1b0b374e7e2997a8693b28f9c Mon Sep 17 00:00:00 2001 From: fktn Date: Fri, 3 Nov 2023 23:18:40 +0900 Subject: [PATCH 36/48] moved docs for node_value_converter APIs with MkDocs --- .../api/node_value_converter/from_node.md | 79 +++++++++++++++++++ .../docs/api/node_value_converter/to_node.md | 77 ++++++++++++++++++ include/fkYAML/node_value_converter.hpp | 40 ++++------ 3 files changed, 171 insertions(+), 25 deletions(-) diff --git a/docs/mkdocs/docs/api/node_value_converter/from_node.md b/docs/mkdocs/docs/api/node_value_converter/from_node.md index 3d5fe21c..650d3ffd 100644 --- a/docs/mkdocs/docs/api/node_value_converter/from_node.md +++ b/docs/mkdocs/docs/api/node_value_converter/from_node.md @@ -8,3 +8,82 @@ static auto from_node(BasicNodeType&& n, TargetType& val) noexcept( noexcept(::fkyaml::from_node(std::forward(n), val))) -> decltype(::fkyaml::from_node(std::forward(n), val), void()) ``` + +Converts a [`basic_node`](../basic_node/index.md) object to the target native data object. +This function is usually called by the [`get_value()`](../basic_node/get_value.md) function of the [`basic_node`](../basic_node/index.md) class. +Note that the `TargetType` must be default-constructible. + +!!! Tips + + This function can be used for user-defined types by implementing (partial) specialization for `from_node()` function which is called internally by this function. + Note that the specialization **must be implemented in the same namespace as the user-defined types** so that the specialization can successfully be found by ADL (Argument Dependent Lookup). + See the example below for more information. + +## **Template Parameters** + +***BasicNodeType*** +: A basic_node template instance type. + +***TargetType*** +: A target native data type. + +## **Parameters** + +***`n`*** [in] +: A basic_node object used for conversion. + +***`val`*** [out] +: A native data object to which the converted value is assigned. + +???+ Example + + ```cpp + #include + #include + + namespace ns + { + + struct book + { + std::string title; + std::string author; + int year; + }; + + void from_node(const fkyaml::node& n, book& b) + { + b.title = n["title"].get_value_ref(); + b.author = n["author"].get_value_ref(); + b.year = n["year"].get_value(); + } + + } // namespace ns + + int main() + { + fkyaml::node n = { + { "title", "Noman's Journey" }, + { "author", "John Doe" }, + { "year", 2023 }, + }; + + auto b = n.get_value(); + + std::cout << "\"" << b.title << "\" was written by " << b.author + << " in " << b.year << "." << std::endl; + + return 0; + } + ``` + + output: + ```bash + "Noman's Journey" was written by John Doe in 2023. + ``` + +## **See Also** + +* [node](../basic_node/node.md) +* [basic_node::get_value](../basic_node/get_value.md) +* [basic_node::get_value_ref](../basic_node/get_value_ref.md) diff --git a/docs/mkdocs/docs/api/node_value_converter/to_node.md b/docs/mkdocs/docs/api/node_value_converter/to_node.md index b4c626aa..d2ef38e4 100644 --- a/docs/mkdocs/docs/api/node_value_converter/to_node.md +++ b/docs/mkdocs/docs/api/node_value_converter/to_node.md @@ -8,3 +8,80 @@ static auto to_node(BasicNodeType& n, TargetType&& val) noexcept( noexcept(::fkyaml::to_node(n, std::forward(val)))) -> decltype(::fkyaml::to_node(n, std::forward(val))) ``` + +Converts a native data to a [`basic_node`](../basic_node/index.md) object. +This function is usually called by the constructors of the [`basic_node`](../basic_node/index.md) class. + +!!! Tips + + This function can be used for user-defined types by implementing (partial) specialization for `to_node()` function which is called internally by this function. + Note that the specialization **must be implemented in the same namespace as the user-defined types** so that the specialization can successfully be found by ADL (Argument Dependent Lookup). + See the example below for more information. + +## **Template Parameters** + +***BasicNodeType*** +: A basic_node template instance type. + +***TargetType*** +: A target native data type. + +## **Parameters** + +***`n`*** [out] +: A basic_node object to which the converted value is assigned. + +***`val`*** [in] +: A native data object used for conversion. + +???+ Example + + ```cpp + #include + #include + + namespace ns + { + + struct book + { + std::string title; + std::string author; + int year; + }; + + void to_node(fkyaml::node& n, const book& b) + { + n = fkyaml::node { + { "title", b.title }, + { "author", b.author }, + { "year", b.year } + }; + } + + } // namespace ns + + int main() + { + ns::book b = { "Noman's Journey", "John Doe", 2023 }; + + fkyaml::node n = b; + + std::cout << fkyaml::node::serialize(n) << std::endl; + + return 0; + } + ``` + + output: + ```yaml + title: Noman's Journey + author: John Doe + year: 2023 + ``` + +## **See Also** + +* [node](../basic_node/node.md) +* [basic_node::(constructor)](../basic_node/constructor.md) +* [basic_node::serialize](../basic_node/serialize.md) diff --git a/include/fkYAML/node_value_converter.hpp b/include/fkYAML/node_value_converter.hpp index dd7c6f06..f090a097 100644 --- a/include/fkYAML/node_value_converter.hpp +++ b/include/fkYAML/node_value_converter.hpp @@ -21,26 +21,19 @@ FK_YAML_NAMESPACE_BEGIN -/** - * @class node_value_converter - * @brief An ADL friendly converter between basic_node objects and native data objects. - * - * @tparam ValueType A default target data type. - * @tparam typename N/A - */ +/// @brief An ADL friendly converter between basic_node objects and native data objects. +/// @tparam ValueType A default target data type. +/// @sa https://fktn-k.github.io/fkYAML/api/node_value_converter/ template class node_value_converter { public: - /** - * @brief Convert a YAML node value into compatible native data. - * - * @tparam BasicNodeType A basic_node template instance type. - * @tparam TargetType A native data type for conversion. - * @param n A basic_node object. - * @param val A native data object. - * @return decltype(::fkyaml::from_node(std::forward(n), val), void()) - */ + /// @brief Convert a YAML node value into compatible native data. + /// @tparam BasicNodeType A basic_node template instance type. + /// @tparam TargetType A native data type for conversion. + /// @param n A basic_node object. + /// @param val A native data object. + /// @sa https://fktn-k.github.io/fkYAML/api/node_value_converter/from_node/ template static auto from_node(BasicNodeType&& n, TargetType& val) noexcept( noexcept(::fkyaml::from_node(std::forward(n), val))) @@ -49,15 +42,12 @@ class node_value_converter ::fkyaml::from_node(std::forward(n), val); } - /** - * @brief Convert compatible native data into a YAML node. - * - * @tparam BasicNodeType A basic_node template instance type. - * @tparam TargetType A native data type for conversion. - * @param n A basic_node object. - * @param val A native data object. - * @return decltype(::fkyaml::to_node(n, std::forward(val))) - */ + /// @brief Convert compatible native data into a YAML node. + /// @tparam BasicNodeType A basic_node template instance type. + /// @tparam TargetType A native data type for conversion. + /// @param n A basic_node object. + /// @param val A native data object. + /// @sa https://fktn-k.github.io/fkYAML/api/node_value_converter/to_node/ template static auto to_node(BasicNodeType& n, TargetType&& val) noexcept( noexcept(::fkyaml::to_node(n, std::forward(val)))) From 45cefb8bff13c6f437561959eace1e3e6c8119b5 Mon Sep 17 00:00:00 2001 From: fktn Date: Sat, 4 Nov 2023 03:05:26 +0900 Subject: [PATCH 37/48] moved docs for ordered_map APIs with MkDocs --- docs/mkdocs/docs/api/ordered_map/at.md | 78 +++++++++++ .../docs/api/ordered_map/constructor.md | 91 +++++++++++++ .../mkdocs/docs/api/ordered_map/destructor.md | 9 ++ docs/mkdocs/docs/api/ordered_map/emplace.md | 76 +++++++++++ docs/mkdocs/docs/api/ordered_map/find.md | 76 +++++++++++ docs/mkdocs/docs/api/ordered_map/index.md | 39 +++++- .../mkdocs/docs/api/ordered_map/operator[].md | 71 ++++++++++ docs/mkdocs/mkdocs.yml | 4 + include/fkYAML/ordered_map.hpp | 123 ++++++++---------- 9 files changed, 493 insertions(+), 74 deletions(-) create mode 100644 docs/mkdocs/docs/api/ordered_map/at.md create mode 100644 docs/mkdocs/docs/api/ordered_map/emplace.md create mode 100644 docs/mkdocs/docs/api/ordered_map/find.md create mode 100644 docs/mkdocs/docs/api/ordered_map/operator[].md diff --git a/docs/mkdocs/docs/api/ordered_map/at.md b/docs/mkdocs/docs/api/ordered_map/at.md new file mode 100644 index 00000000..f6e6c3cf --- /dev/null +++ b/docs/mkdocs/docs/api/ordered_map/at.md @@ -0,0 +1,78 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/ordered_map.hpp) + +# fkyaml::ordered_map::at + +```cpp +template < + typename KeyType, + detail::enable_if_t::value, int> = 0> +mapped_type& at(KeyType&& key) noexcept; + +template < + typename KeyType, + detail::enable_if_t::value, int> = 0> +const mapped_type& at(KeyType&& key) const +``` + +Accesses an element with the given key. +This API throws a [`fkyaml::exception`] if the given key does not exist in the ordered_map object. + +## **Template Parameters** + +***KeyType*** +: A type compatible with the key type. + +## **Parameters** + +***`key`*** [in] +: A key to the target value. + +## **Return Value** + +Reference, or constant reference, to a `mapped_type` object associated with the given key. + +???+ Example + + ```cpp + #include + #include + #include + + int main() + { + fkyaml::ordered_map om = { + { "foo", 123 }, + { "bar", "baz" } + }; + + std::cout << fkyaml::node::serialize(om.at("foo")) << std::endl; + std::cout << fkyaml::node::serialize(om.at("bar")) << std::endl; + + // accesses with a unknown key will throw an exception. + try + { + + } + catch (const fkyaml::exception& e) + { + std::cout << e.what() << std::endl; + } + + return 0; + } + ``` + + output: + ```bash + 123 + baz + key not found. + ``` + +## **See Also** + +* [ordered_map](index.md) +* [operator[]](operator[].md) +* [node](../basic_node/node.md) +* [basic_node::serialize](../basic_node/serialize.md) +* [exception::what](../exception/what.md) diff --git a/docs/mkdocs/docs/api/ordered_map/constructor.md b/docs/mkdocs/docs/api/ordered_map/constructor.md index e69de29b..7866d775 100644 --- a/docs/mkdocs/docs/api/ordered_map/constructor.md +++ b/docs/mkdocs/docs/api/ordered_map/constructor.md @@ -0,0 +1,91 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/ordered_map.hpp) + +# fkyaml::ordered_map::(constructor) + +```cpp +ordered_map(); // (1) + +ordered_map(std::initializer_list init); // (2) +``` + +Constructs a new ordered_map. +You can specify the initial value on constructing an ordered_map with an overloaded constructor. + +## Overload (1) + +```cpp +ordered_map(); // (1) +``` + +Constructs an ordered_map object without an initial value. +The content of a newly constructed ordered_map is an empty list of key-value pairs. + +???+ Example + + ```cpp + #include + #include + #include + #include + + int main() + { + fkyaml::ordered_map om; + std::cout << std::boolalpha << om.empty() << std::endl; + return 0; + } + ``` + + output: + ```bash + true + ``` + +## Overload (2) + +```cpp +ordered_map(std::initializer_list init); // (2) +``` + +Constructs a new ordered_map with an initializer list. +The resulting ordered_map object has the same list of key-value pairs as the given initializer list. + +## **Parameters** + +***`init`*** [in] +: An initializer list of key-value pairs. + +???+ Example + + ```cpp + #include + #include + #include + + int main() + { + fkyaml::ordered_map om = { + { "foo", 123 }, + { "bar", "baz" } + }; + + for (auto& pair : om) + { + std::cout << pair.first << ": " << fkyaml::node::serialize(pair.second) << std::endl; + } + return 0; + } + ``` + + output: + ```yaml + foo: 123 + bar: baz + ``` + +## **See Also** + +* [ordered_map](index.md) +* [basic_node](../basic_node/index.md) +* [basic_node::(constructor)](../basic_node/constructor.md) +* [basic_node::serialize](../basic_node/serialize.md) diff --git a/docs/mkdocs/docs/api/ordered_map/destructor.md b/docs/mkdocs/docs/api/ordered_map/destructor.md index e69de29b..aeb8eef3 100644 --- a/docs/mkdocs/docs/api/ordered_map/destructor.md +++ b/docs/mkdocs/docs/api/ordered_map/destructor.md @@ -0,0 +1,9 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/ordered_map.hpp) + +# fkyaml::ordered_map::(constructor) + +```cpp +~ordered_map() = default; +``` + +Destroys an ordered_map object. diff --git a/docs/mkdocs/docs/api/ordered_map/emplace.md b/docs/mkdocs/docs/api/ordered_map/emplace.md new file mode 100644 index 00000000..4ae5848f --- /dev/null +++ b/docs/mkdocs/docs/api/ordered_map/emplace.md @@ -0,0 +1,76 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/ordered_map.hpp) + +# fkyaml::ordered_map::emplace + +```cpp +template < + typename KeyType, + detail::enable_if_t::value, int> = 0> +std::pair emplace(KeyType&& key, const mapped_type& value) noexcept; +``` + +Emplaces a new key-value pair if the new key does not exist in the ordered_map object. + +***KeyType*** +: A type compatible with the key type. + +## **Parameters** + +***`key`*** [in] +: A key to the target value. + +***`value`*** [in] +: A value associated to the key. + +## **Return Value** + +A pair consisting of an iterator to the inserted element, or the already-existing element if no insertion happend, and a boolean denoting the insertion took place (`true` if insertion happened, `false` otherwise). + +???+ Example + + ```cpp + #include + #include + #include + #include + + int main() + { + fkyaml::ordered_map om = { + { "foo", 123 }, + { "bar", "baz" } + }; + + // insert a value with a new key. + auto ret = om.emplace("qux", 3.14); + if (ret.second) + { + std::cout << "insertion took place." << std::endl; + } + std::cout << fkyaml::node::serialize(ret.first->second) << std::endl; + + // insert a value with an existing key. + auto ret2 = om.emplace("foo", true); + if (!ret2.second) + { + std::cout << "insertion did not take place." << std::endl; + } + std::cout << fkyaml::node::serialize(ret2.first->second) << std::endl; + + return 0; + } + ``` + + output: + ```bash + insertion took place. + 3.14 + insertion did not take place. + 123 + ``` + +## **See Also** + +* [ordered_map](index.md) +* [node](../basic_node/node.md) +* [basic_node::serialize](../basic_node/serialize.md) diff --git a/docs/mkdocs/docs/api/ordered_map/find.md b/docs/mkdocs/docs/api/ordered_map/find.md new file mode 100644 index 00000000..a4cd9933 --- /dev/null +++ b/docs/mkdocs/docs/api/ordered_map/find.md @@ -0,0 +1,76 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/ordered_map.hpp) + +# fkyaml::ordered_map::find + +```cpp +template < + typename KeyType, + detail::enable_if_t::value, int> = 0> +iterator find(KeyType&& key) noexcept; + +template < + typename KeyType, + detail::enable_if_t::value, int> = 0> +const_iterator find(KeyType&& key) const noexcept; +``` + +Find a value with the given key. + +## **Template Parameters** + +***KeyType*** +: A type compatible with the key type. + +## **Parameters** + +***`key`*** [in] +: A key to the target value. + +## **Return Value** + +An iterator to the target value if found, the result of end() otherwise. + +???+ Example + + ```cpp + #include + #include + #include + #include + + int main() + { + fkyaml::ordered_map om = { + { "foo", 123 }, + { "bar", "baz" } + }; + + // search for a value with an existing key. + auto itr = om.find("foo"); + if (itr != om.end()) + { + std::cout << fkyaml::node::serialize(*itr) << std::endl; + } + + // search for a value with a key which does not exist. + auto itr2 = om.emplace("qux"); + if (itr2 == om.end()) + { + std::cout << "key does not exist." << std::endl; + } + + return 0; + } + ``` + + output: + ```bash + 123 + key does not exist. + ``` + +## **See Also** + +* [ordered_map](index.md) +* [node](../basic_node/node.md) +* [basic_node::serialize](../basic_node/serialize.md) diff --git a/docs/mkdocs/docs/api/ordered_map/index.md b/docs/mkdocs/docs/api/ordered_map/index.md index a11a01b1..60203f41 100644 --- a/docs/mkdocs/docs/api/ordered_map/index.md +++ b/docs/mkdocs/docs/api/ordered_map/index.md @@ -6,10 +6,18 @@ template< typename Key, typename Value, typename IgnoredCompare = std::less, typename Allocator = std::allocator>> -class ordered_map; +class ordered_map : public std::vector>; ``` -A minimal map-like container which preserves insertion order. +A minimal map-like container which preserves insertion order. +This documentation only describes APIs which are not of the parent class [`std::vector>`](https://en.cppreference.com/w/cpp/container/vector). + +!!! Question annotate "How is this class useful?" + + This class could be useful in case that **the order of insertion in YAML mapping nodes needs to be preserved**. + This is because the YAML specification recommends that [a sequence of mappings should be used in such cases](https://yaml.org/spec/1.2.2/#3221-mapping-key-order), since YAML mapping nodes are defined as *unordered* sets of key-value pairs. + However, the above recommendation with a sequence of key-value pair does not work so efficiently on the application layer because it cannot be a direct representation of the deserialization result and could also break the original order when the deserialized node is serialized again. + The ordered_map class is thus provided to help resolve those issues. ## Template Parameters @@ -34,4 +42,29 @@ A minimal map-like container which preserves insertion order. | size_type | The type for size parameters used in the class. | | key_compare | The type for comparison between keys. | -## Member Functions \ No newline at end of file +## Member Functions + +### Construction/Destruction +| Name | Description | +| ------------------------------- | -------------------------- | +| [(constructor)](constructor.md) | constructs an ordered_map. | +| [(destructor)](destructor.md) | destroys an ordered_map. | + +### Element Access + +| Name | Description | +| --------------------------- | ------------------------------------------------- | +| [at](at.md) | forces to accesses an element with the given key. | +| [operator[]](operator[].md) | accesses an element with the given key. | + +### Modifiers + +| Name | Description | +| --------------------- | ------------------------------------------------------------ | +| [emplace](emplace.md) | emplaces a new key-value pair if the new key does not exist. | + +### Lookup + +| Name | Description | +| --------------- | ------------------------------------------ | +| [find](find.md) | finds a value associated to the given key. | diff --git a/docs/mkdocs/docs/api/ordered_map/operator[].md b/docs/mkdocs/docs/api/ordered_map/operator[].md new file mode 100644 index 00000000..a964356a --- /dev/null +++ b/docs/mkdocs/docs/api/ordered_map/operator[].md @@ -0,0 +1,71 @@ +Defined in header [``](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/ordered_map.hpp) + +# fkyaml::ordered_map::operator[] + +```cpp +template < + typename KeyType, + detail::enable_if_t::value, int> = 0> +mapped_type& operator[](KeyType&& key) noexcept; +``` + +Accesses an element with the given key. + +!!! Tip + + This API behaves like the [`std::map`](https://en.cppreference.com/w/cpp/container/map) class does. + In other words, it does not check the existence of the given key, and could return a default value if the key does not exist. + To avoid such a behavior, you can use [`at()`](at.md) function which throws a [`fkyaml::exception`](../exception/index.md) if the given key does not match any keys in the ordered_map object. + +## **Template Parameters** + +***KeyType*** +: A type compatible with the key type. + +## **Parameters** + +***`key`*** [in] +: A key to the target value. + +## **Return Value** + +Reference to a `mapped_type` object associated with the given key. +Possibly a default value of the `mapped_type` if the ordered_map does not contain the given key. + +???+ Example + + ```cpp + #include + #include + #include + + int main() + { + fkyaml::ordered_map om = { + { "foo", 123 }, + { "bar", "baz" } + }; + + std::cout << fkyaml::node::serialize(om["foo"]) << std::endl; + std::cout << fkyaml::node::serialize(om["bar"]) << std::endl; + + // accesses with a unknown key will create a new key-value pair with the default value. + std::cout << fkyaml::node::serialize(om["qux"]) << std::endl; + + return 0; + } + ``` + + output: + ```bash + 123 + baz + null + ``` + +## **See Also** + +* [ordered_map](index.md) +* [at](at.md) +* [node](../basic_node/node.md) +* [basic_node::serialize](../basic_node/serialize.md) diff --git a/docs/mkdocs/mkdocs.yml b/docs/mkdocs/mkdocs.yml index 3821d80c..ed5b7507 100644 --- a/docs/mkdocs/mkdocs.yml +++ b/docs/mkdocs/mkdocs.yml @@ -149,4 +149,8 @@ nav: - ordered_map: api/ordered_map/index.md - (constructor): api/ordered_map/constructor.md - (destructor): api/ordered_map/destructor.md + - at: api/ordered_map/at.md + - emplace: api/ordered_map/emplace.md + - find: api/ordered_map/find.md + - operator[]: api/ordered_map/operator[].md - Tutorials: tutorials.md diff --git a/include/fkYAML/ordered_map.hpp b/include/fkYAML/ordered_map.hpp index 76624d4d..86c90583 100644 --- a/include/fkYAML/ordered_map.hpp +++ b/include/fkYAML/ordered_map.hpp @@ -23,70 +23,60 @@ #include #include -/** - * @namespace fkyaml - * @brief namespace for fkYAML library. - */ +/// @brief namespace for fkYAML library. FK_YAML_NAMESPACE_BEGIN -/** - * @brief A minimal map-like container which preserves insertion order. - * - * @tparam Key A type for keys. - * @tparam Value A type for values. - * @tparam IgnoredCompare A placeholder for key comparison. This will be ignored. - * @tparam Allocator A class for allocators. - */ +/// @brief A minimal map-like container which preserves insertion order. +/// @tparam Key A type for keys. +/// @tparam Value A type for values. +/// @tparam IgnoredCompare A placeholder for key comparison. This will be ignored. +/// @tparam Allocator A class for allocators. +/// @sa https://fktn-k.github.io/fkYAML/api/ordered_map/ template < typename Key, typename Value, typename IgnoredCompare = std::less, typename Allocator = std::allocator>> class ordered_map : public std::vector, Allocator> { public: - /** A type for keys. */ + /// A type for keys. using key_type = Key; - /** A type for values. */ + /// A type for values. using mapped_type = Value; - /** A type for internal key-value containers */ + /// A type for internal key-value containers. using Container = std::vector, Allocator>; - /** A type for key-value pairs */ + /// A type for key-value pairs. using value_type = typename Container::value_type; - /** A type for non-const iterators */ + /// A type for non-const iterators. using iterator = typename Container::iterator; - /** A type for const iterators. */ + /// A type for const iterators. using const_iterator = typename Container::const_iterator; - /** A type for size parameters used in this class. */ + /// A type for size parameters used in this class. using size_type = typename Container::size_type; - /** A type for comparison between keys. */ + /// A type for comparison between keys. using key_compare = std::equal_to; public: - /** - * @brief Construct a new ordered_map object. - */ + /// @brief Construct a new ordered_map object. + /// @sa https://fktn-k.github.io/fkYAML/api/ordered_map/constructor/ ordered_map() noexcept(noexcept(Container())) : Container() { } - /** - * @brief Construct a new ordered_map object with an initializer list. - * - * @param init An initializer list to construct the inner container object. - */ + /// @brief Construct a new ordered_map object with an initializer list. + /// @param init An initializer list to construct the inner container object. + /// @sa https://fktn-k.github.io/fkYAML/api/ordered_map/constructor/ ordered_map(std::initializer_list init) : Container {init} { } public: - /** - * @brief A subscript operator for ordered_map objects. - * - * @tparam KeyType A type for the input key. - * @param key A key to the target value. - * @return mapped_type& Reference to a mapped_type object associated with the given key. - */ + /// @brief A subscript operator for ordered_map objects. + /// @tparam KeyType A type for the input key. + /// @param key A key to the target value. + /// @return mapped_type& Reference to a mapped_type object associated with the given key. + /// @sa https://fktn-k.github.io/fkYAML/api/ordered_map/operator[]/ template < typename KeyType, detail::enable_if_t::value, int> = 0> @@ -96,13 +86,12 @@ class ordered_map : public std::vector, Allocator> } public: - /** - * @brief Emplace a new key-value pair if the new key does not exist. - * - * @param key A key to be emplaced to this ordered_map object. - * @param value A value to be emplaced to this ordered_map object. - * @return std::pair A result of emplacement of the new key-value pair. - */ + /// @brief Emplace a new key-value pair if the new key does not exist. + /// @tparam KeyType A type for the input key. + /// @param key A key to be emplaced to this ordered_map object. + /// @param value A value to be emplaced to this ordered_map object. + /// @return std::pair A result of emplacement of the new key-value pair. + /// @sa https://fktn-k.github.io/fkYAML/api/ordered_map/emplace/ template < typename KeyType, detail::enable_if_t::value, int> = 0> @@ -119,13 +108,11 @@ class ordered_map : public std::vector, Allocator> return {std::prev(this->end()), true}; } - /** - * @brief Find a value associated to the given key. Throws an exception if the search fails. - * - * @tparam KeyType A type for the input key. - * @param key A key to find a value with. - * @return mapped_type& The value associated to the given key. - */ + /// @brief Find a value associated to the given key. Throws an exception if the search fails. + /// @tparam KeyType A type for the input key. + /// @param key A key to find a value with. + /// @return mapped_type& The value associated to the given key. + /// @sa https://fktn-k.github.io/fkYAML/api/ordered_map/at/ template < typename KeyType, detail::enable_if_t::value, int> = 0> @@ -141,13 +128,11 @@ class ordered_map : public std::vector, Allocator> throw fkyaml::exception("key not found."); } - /** - * @brief Find a value associated to the given key. Throws an exception if the search fails. - * - * @tparam KeyType A type for the input key. - * @param key A key to find a value with. - * @return const mapped_type& The value associated to the given key. - */ + /// @brief Find a value associated to the given key. Throws an exception if the search fails. + /// @tparam KeyType A type for the input key. + /// @param key A key to find a value with. + /// @return const mapped_type& The value associated to the given key. + /// @sa https://fktn-k.github.io/fkYAML/api/ordered_map/at/ template < typename KeyType, detail::enable_if_t::value, int> = 0> @@ -163,13 +148,11 @@ class ordered_map : public std::vector, Allocator> throw fkyaml::exception("key not found."); } - /** - * @brief Find a value with the given key. - * - * @tparam KeyType A type for the input key. - * @param key A key to find a value with. - * @return iterator The iterator for the found value, or the result of end(). - */ + /// @brief Find a value with the given key. + /// @tparam KeyType A type for the input key. + /// @param key A key to find a value with. + /// @return iterator The iterator for the found value, or the result of end(). + /// @sa https://fktn-k.github.io/fkYAML/api/ordered_map/find/ template < typename KeyType, detail::enable_if_t::value, int> = 0> @@ -185,13 +168,11 @@ class ordered_map : public std::vector, Allocator> return this->end(); } - /** - * @brief Find a value with the given key. - * - * @tparam KeyType A type for the input key. - * @param key A key to find a value with. - * @return const_iterator The constant iterator for the found value, or the result of end(). - */ + /// @brief Find a value with the given key. + /// @tparam KeyType A type for the input key. + /// @param key A key to find a value with. + /// @return const_iterator The constant iterator for the found value, or the result of end(). + /// @sa https://fktn-k.github.io/fkYAML/api/ordered_map/find/ template < typename KeyType, detail::enable_if_t::value, int> = 0> @@ -208,7 +189,7 @@ class ordered_map : public std::vector, Allocator> } private: - /** The object for comparing keys. */ + /// The object for comparing keys. key_compare m_compare {}; }; From 72f9815f3f00687b287ca646badf2d99f2ca8439 Mon Sep 17 00:00:00 2001 From: fktn Date: Sat, 4 Nov 2023 05:24:00 +0900 Subject: [PATCH 38/48] added API docs for macros --- docs/mkdocs/docs/api/macros.md | 98 ++++++++++++++++++++++++++++ docs/mkdocs/docs/api/macros/index.md | 0 docs/mkdocs/mkdocs.yml | 3 +- 3 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 docs/mkdocs/docs/api/macros.md delete mode 100644 docs/mkdocs/docs/api/macros/index.md diff --git a/docs/mkdocs/docs/api/macros.md b/docs/mkdocs/docs/api/macros.md new file mode 100644 index 00000000..94199409 --- /dev/null +++ b/docs/mkdocs/docs/api/macros.md @@ -0,0 +1,98 @@ +# Macros + +Some aspects of the fkYAML library can be configured by defining preprocessor macros **BEFORE** including the header files of the library. +The following preprocessor macros are currently available. + +## Library Version + +The fkYAML library defines the following preprocessor macros for the library version numbers according to [Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.0.html). +These macros are available for client applications as the metadata of this library. + +| Name | Description | +| --------------------- | --------------------------------------- | +| FK_YAML_MAJOR_VERSION | the major version of the fkYAML library | +| FK_YAML_MINOR_VERSION | the minor version of the fkYAML library | +| FK_YAML_PATCH_VERSION | the patch version of the fkYAML library | + +??? Example annotate "Example: print the library version" + + ```cpp + #include + #include + + int main() + { + std::cout << "fkYAML version " + << FK_YAML_MAJOR_VERSION << "." + << FK_YAML_MINOR_VERSION << "." + << FK_YAML_PATCH_VERSION << std::endl + return 0; + } + ``` + + output: + ```bash + fkYAML version 0.1.3 + ``` + +## Library Namespaces + +| Name | Description | +| ----------------------- | --------------------------------------------- | +| FK_YAML_NAMESPACE_BEGIN | the beginning of the fkYAML library namespace | +| FK_YAML_NAMESPACE_END | the end of the fkYAML library namespace | + +## Runtime Assertions + +The fkYAML library calls [`assert()`](https://en.cppreference.com/w/cpp/error/assert) for runtime assertions by default. +Thus, the runtime assertions can be disabled just by defining `NDEBUG`. +You can also override the implementation by defining the following preprocessor macro. + +| Name | Description | +| ----------------- | ---------------------------------------- | +| FK_YAML_ASSERT(x) | controls behavior of runtime assertions. | + +??? Example annotate "Example: disable runtime assertions" + + ```cpp + #define NDEBUG + #include + + ... + ``` + +??? Example annotate "Example: override the implementation of runtime assertions" + + ```cpp + #include + #include + #define FK_YAML_ASSERT(x) \ + if(!(x)){std::fprintf(stderr, "assertion failed in %s", __FUNC__);std::abort();} + #include + + ... + ``` + +## Language Supports + +The fkYAML library targets C++11, but also supports some features introduced in later C++ standards. +For those new features, the library implements some preprocessor checks to determine the C++ standard based on preprocessor macros such as `__cplusplus`, `_HAS_CXX14` or `_MSVC_LANG`. +By defining any of the following symbols, the internal check is overridden and the provided C++ standard is unconditionally assumed. +This can be helpful for compilers that only implement parts of the standard and would be detected incorrectly. + +| Name | Description | +| ------------------ | ----------------------------------------- | +| FK_YAML_HAS_CXX_11 | supports C++11 features. (always enabled) | +| FK_YAML_HAS_CXX_14 | supports C++14 features. | +| FK_YAML_HAS_CXX_17 | supports C++17 features. | +| FK_YAML_HAS_CXX_20 | supports C++20 features. | + +??? Example annotate "Example: force the fkYAML library to use a specific C++ standard" + + ```cpp + // force the library to use the C++14 standard. + #define FK_YAML_HAS_CXX_14 1 + #include + + ... + ``` diff --git a/docs/mkdocs/docs/api/macros/index.md b/docs/mkdocs/docs/api/macros/index.md deleted file mode 100644 index e69de29b..00000000 diff --git a/docs/mkdocs/mkdocs.yml b/docs/mkdocs/mkdocs.yml index ed5b7507..3031f1f6 100644 --- a/docs/mkdocs/mkdocs.yml +++ b/docs/mkdocs/mkdocs.yml @@ -139,8 +139,7 @@ nav: - (constructor): api/exception/constructor.md - (destructor): api/exception/destructor.md - what: api/exception/what.md - - macros: - - macros: api/macros/index.md + - macros: api/macros.md - node_value_converter: - node_value_converter: api/node_value_converter/index.md - from_node: api/node_value_converter/from_node.md From d6eb3b0fe96f3cba695b0105961b3c6ebfa555fa Mon Sep 17 00:00:00 2001 From: fktn Date: Sat, 4 Nov 2023 05:40:08 +0900 Subject: [PATCH 39/48] updated example codes for the API docs --- docs/mkdocs/docs/api/basic_node/begin.md | 2 +- docs/mkdocs/docs/api/basic_node/constructor.md | 16 ++-------------- docs/mkdocs/docs/api/basic_node/empty.md | 4 ++-- docs/mkdocs/docs/api/basic_node/end.md | 2 +- docs/mkdocs/docs/api/basic_node/is_mapping.md | 2 +- docs/mkdocs/docs/api/basic_node/is_scalar.md | 2 +- docs/mkdocs/docs/api/basic_node/is_string.md | 2 +- docs/mkdocs/docs/api/basic_node/mapping.md | 4 ++-- docs/mkdocs/docs/api/basic_node/node.md | 12 ++++++------ docs/mkdocs/docs/api/basic_node/node_t.md | 4 ++-- docs/mkdocs/docs/api/basic_node/serialize.md | 10 +++++----- docs/mkdocs/docs/api/basic_node/size.md | 4 ++-- docs/mkdocs/docs/api/basic_node/type.md | 4 ++-- 13 files changed, 28 insertions(+), 40 deletions(-) diff --git a/docs/mkdocs/docs/api/basic_node/begin.md b/docs/mkdocs/docs/api/basic_node/begin.md index f040f805..ddc577cf 100644 --- a/docs/mkdocs/docs/api/basic_node/begin.md +++ b/docs/mkdocs/docs/api/basic_node/begin.md @@ -25,7 +25,7 @@ An iterator to the first element of a container node value (either sequence or m int main() { // create a sequence node. - fkyaml::node n = {std::string("foo"), std::string("bar")}; + fkyaml::node n = {"foo", "bar"}; // get an iterator to the first element. fkyaml::node::iterator it = n.begin(); std::cout << fkyaml::node::serialize(*it) << std::endl; diff --git a/docs/mkdocs/docs/api/basic_node/constructor.md b/docs/mkdocs/docs/api/basic_node/constructor.md index 00fc89b3..4bc9b4b4 100644 --- a/docs/mkdocs/docs/api/basic_node/constructor.md +++ b/docs/mkdocs/docs/api/basic_node/constructor.md @@ -194,7 +194,7 @@ The resulting basic_node has the value of `val` and the type which is associated int main() { double pi = 3.141592; - fkyaml::node n(pi); + fkyaml::node n = pi; std::cout << fkyaml::node::serialize(n) << std::endl; return 0; } @@ -262,18 +262,6 @@ The resulting basic_node has the value of a container (sequence or mapping) whic Basically, the basic_node objects in `init` are considered as a sequence node. If `init` contains a sequence of basic_node objects in which the number of basic_node objects is 2 and the first has the type of `node_t::STRING`, however, such a sequence is reinterpreted as a mapping node. -!!! Note - - To avoid ambiguity between a sequence of `char` and a `std::string`, c-style char arrays are intentionally unsupported in this constructor. - To contain a string in a `initializer_list_t` object, you must explicitly pass a `std::string` object as follows: - ```cpp - // this is not supported. - fkyaml::node n = {"foo", "bar"}; - - // you must do this instead. - fkyaml::node n2 = {std::string("foo"), std::string("bar")}; - ``` - ### **Parameters** ***`init`*** [in] @@ -290,7 +278,7 @@ If `init` contains a sequence of basic_node objects in which the number of basic fkyaml::node n = {true, false}; std::cout << fkyaml::node::serialize(n) << std::endl; - fkyaml::node n2 = {std::string("foo"), 1024}; + fkyaml::node n2 = {"foo", 1024}; std::cout << fkyaml::node::serialize(n2) << std::endl; return 0; } diff --git a/docs/mkdocs/docs/api/basic_node/empty.md b/docs/mkdocs/docs/api/basic_node/empty.md index 25fd7977..461724db 100644 --- a/docs/mkdocs/docs/api/basic_node/empty.md +++ b/docs/mkdocs/docs/api/basic_node/empty.md @@ -26,12 +26,12 @@ Throws a [`fkyaml::exception`](../exception/index.md) if a basic_node does not h std::vector nodes = { {1, 2, 3}, - {{std::string("foo"), true}, {std::string("bar"), false}}, + {{"foo", true}, {"bar", false}}, fkyaml::node(), true, 256, 3.14, - std::string("Hello, world!") + "Hello, world!" }; for (const auto& n : nodes) diff --git a/docs/mkdocs/docs/api/basic_node/end.md b/docs/mkdocs/docs/api/basic_node/end.md index 5604b748..ed9ed281 100644 --- a/docs/mkdocs/docs/api/basic_node/end.md +++ b/docs/mkdocs/docs/api/basic_node/end.md @@ -25,7 +25,7 @@ An iterator to the past-the-last element of a container node value (either seque int main() { // create a sequence node. - fkyaml::node n = {std::string("foo"), std::string("bar")}; + fkyaml::node n = {"foo", "bar"}; // get an iterator to the past-the-last element. fkyaml::node::iterator it = n.end(); // decrement the iterator to point to the last element. diff --git a/docs/mkdocs/docs/api/basic_node/is_mapping.md b/docs/mkdocs/docs/api/basic_node/is_mapping.md index bf1c44fa..ff54f292 100644 --- a/docs/mkdocs/docs/api/basic_node/is_mapping.md +++ b/docs/mkdocs/docs/api/basic_node/is_mapping.md @@ -21,7 +21,7 @@ Tests whether the node value type is [`node_t::MAPPING`](node_t.md). int main() { - fkyaml::node n = {{std::string("foo"), true}}; + fkyaml::node n = {{"foo", true}}; std::cout << std::boolalpha << n.is_mapping() << std::endl; return 0; } diff --git a/docs/mkdocs/docs/api/basic_node/is_scalar.md b/docs/mkdocs/docs/api/basic_node/is_scalar.md index dd477474..7a5ec269 100644 --- a/docs/mkdocs/docs/api/basic_node/is_scalar.md +++ b/docs/mkdocs/docs/api/basic_node/is_scalar.md @@ -31,7 +31,7 @@ Tests whether the node value type is one of the followings: fkyaml::node boolean_node = true; fkyaml::node integer_node = 256; fkyaml::node float_node = 3.14; - fkyaml::node string_node = std::string("Hello, world!"); + fkyaml::node string_node = "Hello, world!"; // call type() std::cout << std::boolalpha; diff --git a/docs/mkdocs/docs/api/basic_node/is_string.md b/docs/mkdocs/docs/api/basic_node/is_string.md index 6f083c7a..69ad8dca 100644 --- a/docs/mkdocs/docs/api/basic_node/is_string.md +++ b/docs/mkdocs/docs/api/basic_node/is_string.md @@ -21,7 +21,7 @@ Tests whether the node value type is [`node_t::STRING`](node_t.md). int main() { - fkyaml::node n = std::string("foo"); + fkyaml::node n = "foo"; std::cout << std::boolalpha << n.is_string() << std::endl; return 0; } diff --git a/docs/mkdocs/docs/api/basic_node/mapping.md b/docs/mkdocs/docs/api/basic_node/mapping.md index 0576d1d5..e48beb59 100644 --- a/docs/mkdocs/docs/api/basic_node/mapping.md +++ b/docs/mkdocs/docs/api/basic_node/mapping.md @@ -21,8 +21,8 @@ The resulting basic_node has the [`node_t::MAPPING`](node_t.md) type. int main() { fkyaml::node::mapping_type m = { - {fkyaml::node(std::string("foo")), fkyaml::node(false)}, - {fkyaml::node(std::string("bar")), fkyaml::node(3.14)} + {"foo", false}, + {"bar", 3.14} }; fkyaml::node n = fkyaml::node::mapping(m); std::cout << fkyaml::node::serialize(n) << std::endl; diff --git a/docs/mkdocs/docs/api/basic_node/node.md b/docs/mkdocs/docs/api/basic_node/node.md index 1d451ac9..cd427554 100644 --- a/docs/mkdocs/docs/api/basic_node/node.md +++ b/docs/mkdocs/docs/api/basic_node/node.md @@ -19,16 +19,16 @@ This type is the default specialization of the [basic_node](index.md) class whic // create a YAML node. fkyaml::node n = { - {std::string("foo"), 3.14}, - {std::string("bar"), true}, - {std::string("baz"), nullptr}, - {std::string("qux"), { - {std::string("corge"), {1, 2, 3}} + {"foo", 3.14}, + {"bar", true}, + {"baz", nullptr}, + {"qux", { + {"corge", {1, 2, 3}} }} }; // add a new value. - n["qux"]["key"] = {std::string("another"), std::string("value")}; + n["qux"]["key"] = {"another", "value"}; // output a YAML formatted string. std::cout << fkyaml::node::serialize(n) << std::endl; diff --git a/docs/mkdocs/docs/api/basic_node/node_t.md b/docs/mkdocs/docs/api/basic_node/node_t.md index 631b3461..b757b363 100644 --- a/docs/mkdocs/docs/api/basic_node/node_t.md +++ b/docs/mkdocs/docs/api/basic_node/node_t.md @@ -37,12 +37,12 @@ This enumeration collects the different YAML value types. They are internally us { // create YAML nodes. fkyaml::node sequence_node = {1, 2, 3}; - fkyaml::node mapping_node = {{std::string("foo"), true}, {std::string("bar"), false}}; + fkyaml::node mapping_node = {{"foo", true}, {"bar", false}}; fkyaml::node null_node; fkyaml::node boolean_node = true; fkyaml::node integer_node = 256; fkyaml::node float_node = 3.14; - fkyaml::node string_node = std::string("Hello, world!"); + fkyaml::node string_node = "Hello, world!"; // call type() std::cout << std::boolalpha; diff --git a/docs/mkdocs/docs/api/basic_node/serialize.md b/docs/mkdocs/docs/api/basic_node/serialize.md index a9751320..32e8484f 100644 --- a/docs/mkdocs/docs/api/basic_node/serialize.md +++ b/docs/mkdocs/docs/api/basic_node/serialize.md @@ -29,11 +29,11 @@ The resulting string object from the serialization of the `node` object. { // create a basic_node object. fkyaml::node n = { - {std::string("foo"), true}, - {std::string("bar"), {1, 2, 3}}, - {std::string("baz"), { - {std::string("qux"), 3.14}, - {std::string("corge"), nullptr} + {"foo", true}, + {"bar", {1, 2, 3}}, + {"baz", { + {"qux", 3.14}, + {"corge", nullptr} }} }; diff --git a/docs/mkdocs/docs/api/basic_node/size.md b/docs/mkdocs/docs/api/basic_node/size.md index 8c4b386e..3530a252 100644 --- a/docs/mkdocs/docs/api/basic_node/size.md +++ b/docs/mkdocs/docs/api/basic_node/size.md @@ -26,12 +26,12 @@ The size of a node value. std::vector nodes = { {1, 2, 3}, - {{std::string("foo"), true}, {std::string("bar"), false}. {std::string("baz"), true}}, + {{"foo", true}, {"bar", false}. {"baz", true}}, fkyaml::node(), true, 256, 3.14, - std::string("foo") + "foo" }; for (const auto& n : nodes) diff --git a/docs/mkdocs/docs/api/basic_node/type.md b/docs/mkdocs/docs/api/basic_node/type.md index 1e9abd50..72a50106 100644 --- a/docs/mkdocs/docs/api/basic_node/type.md +++ b/docs/mkdocs/docs/api/basic_node/type.md @@ -33,12 +33,12 @@ The type of the YAML node value. { // create YAML nodes. fkyaml::node sequence_node = {1, 2, 3}; - fkyaml::node mapping_node = {{std::string("foo"), true}, {std::string("bar"), false}}; + fkyaml::node mapping_node = {{"foo", true}, {"bar", false}}; fkyaml::node null_node; fkyaml::node boolean_node = true; fkyaml::node integer_node = 256; fkyaml::node float_node = 3.14; - fkyaml::node string_node = std::string("Hello, world!"); + fkyaml::node string_node = "Hello, world!"; // call type() std::cout << std::boolalpha; From 7969b1469294bde738f3ba434e1cecea61eb7175 Mon Sep 17 00:00:00 2001 From: fktn Date: Sun, 5 Nov 2023 18:13:30 +0900 Subject: [PATCH 40/48] added tutorial pages --- docs/mkdocs/docs/tutorials.md | 1 - .../docs/tutorials/cmake_integration.md | 66 ++++ docs/mkdocs/docs/tutorials/index.md | 344 ++++++++++++++++++ docs/mkdocs/mkdocs.yml | 6 +- 4 files changed, 414 insertions(+), 3 deletions(-) delete mode 100644 docs/mkdocs/docs/tutorials.md create mode 100644 docs/mkdocs/docs/tutorials/cmake_integration.md create mode 100644 docs/mkdocs/docs/tutorials/index.md diff --git a/docs/mkdocs/docs/tutorials.md b/docs/mkdocs/docs/tutorials.md deleted file mode 100644 index 944558be..00000000 --- a/docs/mkdocs/docs/tutorials.md +++ /dev/null @@ -1 +0,0 @@ -This is the top page for tutorials for the fkYAML library. \ No newline at end of file diff --git a/docs/mkdocs/docs/tutorials/cmake_integration.md b/docs/mkdocs/docs/tutorials/cmake_integration.md new file mode 100644 index 00000000..bbd1096d --- /dev/null +++ b/docs/mkdocs/docs/tutorials/cmake_integration.md @@ -0,0 +1,66 @@ +# CMake Integration + +Since we use CMake to build fkYAML, we also provide a couple of integration points for our users. +You can use the `fkYAML::fkYAML` interface target in CMake. +This target popultes the appropriate usage requirements for `INTERFACE_INCLUDE_DIRECTORIES`(https://cmake.org/cmake/help/latest/prop_tgt/INTERFACE_INCLUDE_DIRECTORIES.html) to point to the appropriate include directories and `INTERFACE_COMPILE_FEATURES`(https://cmake.org/cmake/help/latest/prop_tgt/INTERFACE_COMPILE_FEATURES.html) for the necessary C++11 flags. + +## Possible solutions + +The following sub-sections show some possible ways in which you can integrate an existing CMake projct with fkYAML. + +### With `find_package()` + +To use fkYAML from a CMake project, you can locate it directly with [`find_package()`](https://cmake.org/cmake/help/latest/command/find_package.html) and use the namespaced imported target from the generated package configuration. +Note that this method requires a release package to be installed somewhere on your machine. +The package configuration file, `fkYAMLConfig.cmake`, can be used either from an install tree or directly out of the build tree. + +???+ Example + + ```cmake title="CMakeLists.txt" + cmake_minimum_required(VERSION 3.8) + project(ExampleProject LANGUAGES CXX) + + find_package(fkYAML 0.1.3 REQUIRED) + + add_executable(example example.cpp) + target_link_library(example PRIVATE fkYAML::fkYAML) + ``` + +### With `add_subdirectory()` + +To embed the library directory into an existing CMake project, place the entire source tree in a subdirectory and call [`add_subdirectory()`](https://cmake.org/cmake/help/latest/command/add_subdirectory.html) in your `CMakeLists.txt` file. + +???+ Example + + ```cmake title="CMakeLists.txt" + cmake_minimum_required(VERSION 3.8) + project(ExampleProject LANGUAGE CXX) + + add_subdirectory(./path/to/fkYAML) + + add_executable(example example.cpp) + target_link_libraries(example PRIVATE fkYAML::fkYAML) + ``` + +### With the `FetchContent` CMake module + +Since CMake v3.11, [`FetchContent`](https://cmake.org/cmake/help/latest/module/FetchContent.html) is available which automatically downloads a release as a dependency during configuration. + +???+ Example + + ```cmake title="CMakeLists.txt" + cmake_minimum_required(VERSION 3.11) + project(ExampleProject LANGUAGES CXX) + + include(FetchContent) + + FetchContent_Declare( + fkYAML + GIT_REPOSITORY https://github.com/fktn-k/fkYAML.git + GIT_TAG v0.1.3 + ) + FetchContent_MakeAvailable(fkYAML) + + add_executable(example example.cpp) + target_link_library(example PRIVATE fkYAML::fkYAML) + ``` diff --git a/docs/mkdocs/docs/tutorials/index.md b/docs/mkdocs/docs/tutorials/index.md new file mode 100644 index 00000000..16ea9816 --- /dev/null +++ b/docs/mkdocs/docs/tutorials/index.md @@ -0,0 +1,344 @@ +# The First Steps + +The goal of this page is to help you understand what is possible with fkYAML, and to provide some tips of how you can use it within your own project with CMake. +As a tutorial, we will make a very simple project which utilizes fkYAML so that your understanding can be fostered with an actual, executable example. + +## :rocket: Getting fkYAML + +Ideally you should be using fkYAML through its [CMake](https://cmake.org/) integration. +Although fkYAML also provides a pkg-config file, this documentation will assume you are using CMake. +fkYAML provides release packages in the releases pages which contain the all the necessary header files and CMake config files. +Although you can just copy, paste and include the header files in your C++ project, it is highly recommended to use the library with CMake because the exported CMake target `fkYAML::fkYAML` will save you most of your work for the integration. +The followings are possible ways of preparing for the use of fkYAML: + +### :file_folder: Download a release package +You can [download the latest package (fkYAML.tgz for UNIX or fkYAML.zip for Windows) from here](https://github.com/fktn-k/fkYAML/releases/latest). +After the download gets completed, unzip and put the package in some directory on your machine. +The destination path can be whatever you want, and you're all set! + +### :inbox_tray: Install with CMake +You can also clone the fkYAML repository and execute the following commands to install the fkYAML package on your machine. +Make sure the CMake executable is registered to the PATH environment variable. + +```bash +$ cd /path/to/fkYAML +$ cmake -B build -S . [-DCMAKE_INSTALL_PREFIX=] +$ cmake --build build --target install +``` + +With `-DCMAKE_INSTALL_PREFIX=`, you can override the default installation path. +The default installation path would be the followings: + +| OS | Path | +| ------- | ------------------------- | +| UNIX | /usr/local | +| Windows | C:\\Program Files\\fkYAML | + +And you're all set! You can now `find_package()` the fkYAML package. + +### :pushpin: Use fkYAML as a Git submodule +If you want to avoid system-wide installation, you can use the fkYAML library as a Git submodule in you C++ project instead. +The commands would be the following (Make sure the Git executable is registered to the PATH environment.): + +```bash +$ cd /path/to/your/repo +$ git submodule add https://github.com/fktn-k/fkYAML.git [path/to/clone/fkYAML] +``` + +And you're all set! +Note that you must execute the CMake `add_subdirectory()` command for the submoduled fkYAML library in your CMakeLists.txt file as explained in the CMake integration section. + +## :bulb: Use fkYAML in your C++ project + +### :seedling: Create a tutorial project. + +Let's start with a really simple example. +Say you have an example.yaml file and now you want to load the contents. +Note that the following example files assumes that you have installed the fkYAML library somewhere on your machine. +See [the CMake Integration section]() for the other ways and modify the implementation if necessary. + +```title="Project Structure" +. +├── CMakeLists.txt +├── example.yaml +└── tutorial.cpp +``` + +=== "example.yaml" + + ```yaml + novels: + - title: "Robinson Crusoe" + author: "Daniel Defoe" + year: 1678 + - title: "Frankenstein" + author: "Jane Austen" + year: 1818 + - title: "Moby-Dick" + author: "Herman Melville" + year: 1851 + - title: "Brave New World" + author: "Aldous Huxley" + year: 1932 + - title: "Never Let Me Go" + author: "Kazuo Ishiguro" + year: 2005 + ``` +=== "tutorial.cpp" + + ```cpp + #include + #include + #include + + int main() + { + // open a YAML file. Other streams or strings are also usable as an input. + std::ifstream ifs("example.yaml"); + + // deserialize the loaded file contents. + fkyaml::node root = fkyaml::node::deserialize(ifs); + + // print the deserialized YAML nodes by serializing them back. + std::cout << fkyaml::node::serialize() << std::endl; + return 0; + } + ``` +=== "CMakeLists.txt" + + ```cmake + + cmake_minimum_required(VERSION 3.8) + project(tutorial LANGUAGES CXX) + + find_package(fkYAML REQUIRED) + + add_executable(tutorial tutorial.cpp) + + # This exported CMake target sets the necessary configurations for the project. + target_link_library(tutorial PUBLIC fkYAML::fkYAML) + ``` + +After creating a tutorial project with the above files, execute the following commands to build the project with CMake. + +```bash +$ cd /path/to/tutorial/ +$ cmake -B build -S . -DCMAKE_BUILD_TYPE=Release +$ cmake --build build --config --config Release +``` + +Congratulation! You've got an application which loads a YAML file and then outputs the content on the console. +If you run the tutorial executable file, you will see the output like: + +```bash +novels: + - + title: "Robinson Crusoe" + author: "Daniel Defoe" + year: 1678 + - + title: "Frankenstein" + author: "Jane Austen" + year: 1818 + - + title: "Moby-Dick" + author: "Herman Melville" + year: 1851 + - + title: "Brave New World" + author: "Aldous Huxley" + year: 1932 + - + title: "Never Let Me Go" + author: "Kazuo Ishiguro" + year: 2005 +``` + +### :mag: Access individual YAML nodes +You can also access each YAML node with the fkYAML APIs. +Say you just want to care about values associated with the `title` key and ignore the others. +You can do it by modifying the tutorial.cpp file as follows: + +```cpp title="tutorial.cpp" hl_lines="13-18" +#include +#include +#include + +int main() +{ + // open a YAML file. Other streams or strings are also usable as an input. + std::ifstream ifs("example.yaml"); + + // deserialize the loaded file contents. + fkyaml::node root = fkyaml::node::deserialize(ifs); + + // print only values associated with "title" key. + for (auto& novel_node : root["novels"]) + { + // get reference to the "title" value with `get_value_ref` function. + std::cout << novel_node["title"].get_value_ref() << std::endl; + } + + return 0; +} +``` + +Rebuild and run the application, and you'll see the output like: + +```bash +Robinson Crusoe +Frankenstein +Moby-Dick +Brave New World +Never Let Me Go +``` + +### :hammer: Generate YAML nodes from code + +When you can access the specific values, you might want to generate YAML nodes programatically, for instance, to make a response parameter. +The fkYAML library also provides a feature to realize such a need. + +You can achieve that by changing the highlighted part of the code snippet: + +```cpp title="tutorial.cpp" hl_lines="14-16 18 21-26 29-30" +#include +#include +#include +#include + +int main() +{ + // open a YAML file. Other streams or strings are also usable as an input. + std::ifstream ifs("example.yaml"); + + // deserialize the loaded file contents. + fkyaml::node root = fkyaml::node::deserialize(ifs); + + // create an empty YAML sequence node. + fkyaml::node response = { "recommends", fkyaml::node::sequence() }; + auto& recommends = response["recommends"].get_value_ref(); + + // generate recommendations by extracting "title" & "author" values. + for (auto& novel_node : root["novels"]) + { + // create a recommendation node with an initializer list. + fkyaml::node recommend = { + { "title", novel_node["title"] }, + { "author", novel_node["author"] } + }; + recommends.emplace_back(std::move(recommends)); + } + + // print the response YAML nodes. + std::cout << fkyaml::node::serialize(response) << std::endl; + + return 0; +} +``` + +Rebuild and run the application, and you'll see the output like: + +```bash +recommends: + - + title: "Robinson Crusoe" + author: "Daniel Defoe" + - + title: "Frankenstein" + author: "Jane Austen" + - + title: "Moby-Dick" + author: "Herman Melville" + - + title: "Brave New World" + author: "Aldous Huxley" + - + title: "Never Let Me Go" + author: "Kazuo Ishiguro" +``` + +### :pill: Integrate with user-defined types + +As described in the API Reference pages for [`from_node()`](../api/node_value_converter/from_node.md) and [`to_node()`](../api/node_value_converter/to_node.md) functions, you can specialize deserialization for user-defined types. +Note that you don't need to implement specializations for STL types (such as std::vector or std::string) because the fkYAML library has already implemented them. + +The updated code snippet down below shows how the specializations for user-defined types can reduce boilerplate code. + +```cpp title="tutorial.cpp" hl_lines="6-38 55-60" +#include +#include +#include +#include + +// creating a namespace is not mandatory. +namespace ns +{ + +struct novel +{ + std::string title; + std::string author; + int year; +}; + +struct recommend +{ + std::string title; + std::string author; +}; + +// overloads must be defined in the same namespace as user-defined types. +void from_node(const fkyaml::node& node, novel& novel) +{ + novel.title = node["title"].get_value_ref(); + novel.author = node["author"].get_value_ref(); +} + +void to_node(fkyaml::node& node, const recommend& recommend) +{ + node = fkyaml::node { + { "title", recommend.title }, + { "author", recommend.author } + }; +} + +} // namespace ns + +int main() +{ + // open a YAML file. Other streams or strings are also usable as an input. + std::ifstream ifs("example.yaml"); + + // deserialize the loaded file contents. + fkyaml::node root = fkyaml::node::deserialize(ifs); + + // create an empty YAML sequence node. + fkyaml::node response = { "recommends", fkyaml::node::sequence() }; + auto& recommends = response["recommends"].get_value_ref(); + + // generate recommendations by extracting "title" & "author" values. + for (auto& novel_node : root["novels"]) + { + // get novel directly from the node. + ns::novel novel = novel_node.get_value(); + + // create a recommendation node directly with a recommend object. + ns::recommend recommend = { std::move(novel.title), std::move(novel.author) }; + recommends.emplace_back(recommend); + } + + // print the response YAML nodes. + std::cout << fkyaml::node::serialize(response) << std::endl; + + return 0; +} +``` + +The specializations highlighted above do not change the output, but they allow us to focus more on what the code is to achive. +Note that the specialization with user-defined types requires the types to be default-constructible. + +## :tada: Next Steps + +This page is a brief introduction to get you up and running with fkYAML, and to show the basic features of fkYAML. +The features mentioned here can get you quite far, but there are many more. +For more information, please visit [the API Documentation section](../api/basic_node/index.md) which has a lot of descriptions for each fkYAML APIs with example code snippets. diff --git a/docs/mkdocs/mkdocs.yml b/docs/mkdocs/mkdocs.yml index 3031f1f6..f2091c37 100644 --- a/docs/mkdocs/mkdocs.yml +++ b/docs/mkdocs/mkdocs.yml @@ -88,7 +88,10 @@ nav: - Overview: index.md - License: home/license.md - Changelog: home/CHANGELOG.md - - "API Documentation": + - Tutorials: + The First Steps: tutorials/index.md + CMake Integration: tutorials/cmake_integration.md + - API References: - basic_node: - basic_node: api/basic_node/index.md - (constructor): api/basic_node/constructor.md @@ -152,4 +155,3 @@ nav: - emplace: api/ordered_map/emplace.md - find: api/ordered_map/find.md - operator[]: api/ordered_map/operator[].md - - Tutorials: tutorials.md From 67017a34e8e44e88f3cc1896581111a78063e6a3 Mon Sep 17 00:00:00 2001 From: fktn Date: Sun, 5 Nov 2023 19:22:30 +0900 Subject: [PATCH 41/48] fixed broken link format in tutorial pages --- docs/mkdocs/docs/tutorials/cmake_integration.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/mkdocs/docs/tutorials/cmake_integration.md b/docs/mkdocs/docs/tutorials/cmake_integration.md index bbd1096d..c2846c24 100644 --- a/docs/mkdocs/docs/tutorials/cmake_integration.md +++ b/docs/mkdocs/docs/tutorials/cmake_integration.md @@ -1,8 +1,8 @@ # CMake Integration -Since we use CMake to build fkYAML, we also provide a couple of integration points for our users. +Since we use [CMake](https://cmake.org/) to build fkYAML, we also provide a couple of integration points for our users. You can use the `fkYAML::fkYAML` interface target in CMake. -This target popultes the appropriate usage requirements for `INTERFACE_INCLUDE_DIRECTORIES`(https://cmake.org/cmake/help/latest/prop_tgt/INTERFACE_INCLUDE_DIRECTORIES.html) to point to the appropriate include directories and `INTERFACE_COMPILE_FEATURES`(https://cmake.org/cmake/help/latest/prop_tgt/INTERFACE_COMPILE_FEATURES.html) for the necessary C++11 flags. +This target popultes the appropriate usage requirements for [`INTERFACE_INCLUDE_DIRECTORIES`](https://cmake.org/cmake/help/latest/prop_tgt/INTERFACE_INCLUDE_DIRECTORIES.html) to point to the appropriate include directories and [`INTERFACE_COMPILE_FEATURES`](https://cmake.org/cmake/help/latest/prop_tgt/INTERFACE_COMPILE_FEATURES.html) for the necessary C++11 flags. ## Possible solutions From 4317b72a7de1eebd0256226f0605a4884dc06c95 Mon Sep 17 00:00:00 2001 From: fktn Date: Sun, 5 Nov 2023 19:42:51 +0900 Subject: [PATCH 42/48] fixed warnings for mkdocs navigation settings --- docs/mkdocs/mkdocs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/mkdocs/mkdocs.yml b/docs/mkdocs/mkdocs.yml index f2091c37..13ad4d05 100644 --- a/docs/mkdocs/mkdocs.yml +++ b/docs/mkdocs/mkdocs.yml @@ -89,8 +89,8 @@ nav: - License: home/license.md - Changelog: home/CHANGELOG.md - Tutorials: - The First Steps: tutorials/index.md - CMake Integration: tutorials/cmake_integration.md + - The First Steps: tutorials/index.md + - CMake Integration: tutorials/cmake_integration.md - API References: - basic_node: - basic_node: api/basic_node/index.md From 215122d3ee4fdc5bbf59660eab79259f0153c691 Mon Sep 17 00:00:00 2001 From: fktn Date: Sun, 5 Nov 2023 19:53:11 +0900 Subject: [PATCH 43/48] migration from Doxygen to MkDocs to publish the documentation on gh-pages --- .github/workflows/publish_docs.yml | 23 +- CMakeLists.txt | 9 - Makefile | 11 - README.md | 4 +- docs/CMakeLists.txt | 14 - docs/Doxyfile.in | 2811 ---------------------------- 6 files changed, 17 insertions(+), 2855 deletions(-) delete mode 100644 docs/CMakeLists.txt delete mode 100644 docs/Doxyfile.in diff --git a/.github/workflows/publish_docs.yml b/.github/workflows/publish_docs.yml index 0657028d..dfd0fe0a 100644 --- a/.github/workflows/publish_docs.yml +++ b/.github/workflows/publish_docs.yml @@ -1,11 +1,19 @@ name: PublishDocs +# make the documentation up to date with the develop branch on: push: branches: - - main + - develop + paths: + - docs/mkdocs/** workflow_dispatch: +# no cancellation during uploads to avoid broken publications +concurrency: + group: documentation + cancel-in-progress: false + permissions: contents: read pages: write @@ -13,6 +21,7 @@ permissions: jobs: build: + if: github.repository == 'fktn-k/fkYAML' runs-on: ubuntu-latest steps: @@ -20,13 +29,8 @@ jobs: with: submodules: recursive - - name: Install graphviz and doxygen - run: | - sudo apt update - sudo apt install -y --no-install-recommends graphviz doxygen - - - name: Configure CMake - run: make doxygen + - name: Build documentation + run: make build -C docs/mkdocs - name: Setup Pages uses: actions/configure-pages@v3 @@ -34,9 +38,10 @@ jobs: - name: Upload API documents uses: actions/upload-pages-artifact@v2 with: - path: ${{github.workspace}}/build_doxygen/doxygen/html + path: ${{github.workspace}}/docs/mkdocs/site deploy: + if: github.repository == 'fktn-k/fkYAML' needs: build environment: name: github-pages diff --git a/CMakeLists.txt b/CMakeLists.txt index 56c8f308..fbc8e498 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -114,15 +114,6 @@ if(FK_YAML_BUILD_TEST OR FK_YAML_BUILD_ALL_TEST) add_subdirectory(test) endif() -################################## -# Generate API documentation # -################################## - -if(FK_YAML_RUN_DOXYGEN) - set(FK_YAML_DOXYGEN_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/doxygen") - add_subdirectory(docs) -endif() - ####################### # Install package # ####################### diff --git a/Makefile b/Makefile index 013ef596..33b8297f 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,6 @@ all: @echo "clang-sanitizers - check whether no runtime issue is detected while running the unit test app." @echo "clang-tidy - check whether source files detect no issues during static code analysis." @echo "cmake-format - check whether CMake scripts are well formatted." - @echo "doxygen - generate the API documentation for the project with Doxygen." @echo "html-coverage - generate HTML coverage report." @echo "iwyu - check whether source files are each self-contained." @echo "lcov-coverage - generate coverage data with lcov." @@ -82,15 +81,6 @@ valgrind: cmake-format: cmake-format $(CMAKE_SCRIPTS) -i -c .cmake-format.yaml -##################### -# Documentation # -##################### - -# pre-requisites: doxygen, graphviz -doxygen: - cmake -B build_doxygen -S . -DFK_YAML_RUN_DOXYGEN=ON - cmake --build build_doxygen --target doxygen -j $(JOBS) - ############### # Version # ############### @@ -164,6 +154,5 @@ clean: build_clang_sanitizers \ build_clang_tidy \ build_coverage \ - build_doxygen \ build_iwyu \ build_valgrind diff --git a/README.md b/README.md index 4e58d84f..9f979f9d 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ [![Codacy Badge](https://app.codacy.com/project/badge/Grade/cded6969c7344ea5be60ab472e13000f)](https://app.codacy.com/gh/fktn-k/fkYAML/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) [![CodeQL](https://github.com/fktn-k/fkYAML/workflows/CodeQL/badge.svg)](https://github.com/fktn-k/fkYAML/actions?query=workflow%3ACodeQL) [![GitHub Releases](https://img.shields.io/github/release/fktn-k/fkYAML.svg)](https://github.com/fktn-k/fkYAML/releases/latest) +[![Documentation](https://img.shields.io/badge/docs-here-blue.svg)](https://fktn-k.github.io/fkYAML) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/fktn-k/fkYAML/develop/LICENSE.txt) [![GitHub Issues](https://img.shields.io/github/issues/fktn-k/fkYAML.svg)](https://github.com/fktn-k/fkYAML/issues) [![REUSE status](https://api.reuse.software/badge/github.com/fktn-k/fkYAML)](https://api.reuse.software/info/github.com/fktn-k/fkYAML) @@ -398,9 +399,10 @@ Thanks a lot! - [**cmake-format**](https://github.com/cheshirekow/cmake_format) as a linter for CMake scripts. - [**Coveralls**](https://coveralls.io/) to measure [code coverage](https://coveralls.io/github/fktn-k/fkYAML?branch=develop). - [**Catch2**](https://github.com/catchorg/Catch2) as a unit-test framework. -- [**Doxygen**](https://www.doxygen.nl/) as the API documentation generator. - [**github-changelog-generator**](https://github.com/github-changelog-generator/github-changelog-generator) to generate the [CHANGELOG.md](https://github.com/fktn-k/fkYAML/tree/develop/CHANGELOG.md) file. - [**include-what-you-use**](https://github.com/include-what-you-use/include-what-you-use) to check the fkYAML library source files are each self-contained. - [**lcov**](https://ltp.sourceforge.net/coverage/lcov.php) to generate coverage data. +- [**Material for MkDocs**](https://squidfunk.github.io/mkdocs-material/) for the style of the documentation site. +- [**MkDocs**](https://www.mkdocs.org/) as the documentation site generator. - [**reuse-tool**](https://github.com/fsfe/reuse-tool) to generate license/copyright headers in source files to meet [REUSE software](https://reuse.software/) recommendations. - [**Valgrind**](https://valgrind.org/) for runtime memory leak check. diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt deleted file mode 100644 index 7437655e..00000000 --- a/docs/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -find_package(Doxygen REQUIRED) - -set(FK_YAML_DOXYFILE_IN "${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in") -set(FK_YAML_DOXYFILE_OUT "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile") -set(FK_YAML_DOXYGEN_INPUT_DIR "${FK_YAML_INCLUDE_BUILD_DIR}") - -configure_file("${FK_YAML_DOXYFILE_IN}" "${FK_YAML_DOXYFILE_OUT}" @ONLY) - -add_custom_target( - doxygen - COMMAND "${DOXYGEN_EXECUTABLE}" "${FK_YAML_DOXYFILE_OUT}" - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" - COMMENT "Generating API documentation with doxygen." - VERBATIM) diff --git a/docs/Doxyfile.in b/docs/Doxyfile.in deleted file mode 100644 index fe2d92e3..00000000 --- a/docs/Doxyfile.in +++ /dev/null @@ -1,2811 +0,0 @@ -# Doxyfile 1.9.7 - -# This file describes the settings to be used by the documentation system -# doxygen (www.doxygen.org) for a project. -# -# All text after a double hash (##) is considered a comment and is placed in -# front of the TAG it is preceding. -# -# All text after a single hash (#) is considered a comment and will be ignored. -# The format is: -# TAG = value [value, ...] -# For lists, items can also be appended using: -# TAG += value [value, ...] -# Values that contain spaces should be placed between quotes (\" \"). -# -# Note: -# -# Use doxygen to compare the used configuration file with the template -# configuration file: -# doxygen -x [configFile] -# Use doxygen to compare the used configuration file with the template -# configuration file without replacing the environment variables or CMake type -# replacement variables: -# doxygen -x_noenv [configFile] - -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- - -# This tag specifies the encoding used for all characters in the configuration -# file that follow. The default is UTF-8 which is also the encoding used for all -# text before the first occurrence of this tag. Doxygen uses libiconv (or the -# iconv built into libc) for the transcoding. See -# https://www.gnu.org/software/libiconv/ for the list of possible encodings. -# The default value is: UTF-8. - -DOXYFILE_ENCODING = UTF-8 - -# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by -# double-quotes, unless you are using Doxywizard) that should identify the -# project for which the documentation is generated. This name is used in the -# title of most generated pages and in a few other places. -# The default value is: My Project. - -PROJECT_NAME = @FK_YAML_TARGET_NAME@ - -# The PROJECT_NUMBER tag can be used to enter a project or revision number. This -# could be handy for archiving the generated documentation or if some version -# control system is used. - -PROJECT_NUMBER = @FK_YAML_VERSION_STRING@ - -# Using the PROJECT_BRIEF tag one can provide an optional one line description -# for a project that appears at the top of each page and should give viewer a -# quick idea about the purpose of the project. Keep the description short. - -PROJECT_BRIEF = A C++ header-only YAML library - -# With the PROJECT_LOGO tag one can specify a logo or an icon that is included -# in the documentation. The maximum height of the logo should not exceed 55 -# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy -# the logo to the output directory. - -PROJECT_LOGO = - -# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path -# into which the generated documentation will be written. If a relative path is -# entered, it will be relative to the location where doxygen was started. If -# left blank the current directory will be used. - -OUTPUT_DIRECTORY = @FK_YAML_DOXYGEN_OUTPUT_DIR@ - -# If the CREATE_SUBDIRS tag is set to YES then doxygen will create up to 4096 -# sub-directories (in 2 levels) under the output directory of each output format -# and will distribute the generated files over these directories. Enabling this -# option can be useful when feeding doxygen a huge amount of source files, where -# putting all generated files in the same directory would otherwise causes -# performance problems for the file system. Adapt CREATE_SUBDIRS_LEVEL to -# control the number of sub-directories. -# The default value is: NO. - -CREATE_SUBDIRS = YES - -# Controls the number of sub-directories that will be created when -# CREATE_SUBDIRS tag is set to YES. Level 0 represents 16 directories, and every -# level increment doubles the number of directories, resulting in 4096 -# directories at level 8 which is the default and also the maximum value. The -# sub-directories are organized in 2 levels, the first level always has a fixed -# number of 16 directories. -# Minimum value: 0, maximum value: 8, default value: 8. -# This tag requires that the tag CREATE_SUBDIRS is set to YES. - -CREATE_SUBDIRS_LEVEL = 8 - -# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII -# characters to appear in the names of generated files. If set to NO, non-ASCII -# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode -# U+3044. -# The default value is: NO. - -ALLOW_UNICODE_NAMES = NO - -# The OUTPUT_LANGUAGE tag is used to specify the language in which all -# documentation generated by doxygen is written. Doxygen will use this -# information to generate all constant output in the proper language. -# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Bulgarian, -# Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, Dutch, English -# (United States), Esperanto, Farsi (Persian), Finnish, French, German, Greek, -# Hindi, Hungarian, Indonesian, Italian, Japanese, Japanese-en (Japanese with -# English messages), Korean, Korean-en (Korean with English messages), Latvian, -# Lithuanian, Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, -# Romanian, Russian, Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, -# Swedish, Turkish, Ukrainian and Vietnamese. -# The default value is: English. - -OUTPUT_LANGUAGE = English - -# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member -# descriptions after the members that are listed in the file and class -# documentation (similar to Javadoc). Set to NO to disable this. -# The default value is: YES. - -BRIEF_MEMBER_DESC = YES - -# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief -# description of a member or function before the detailed description -# -# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the -# brief descriptions will be completely suppressed. -# The default value is: YES. - -REPEAT_BRIEF = YES - -# This tag implements a quasi-intelligent brief description abbreviator that is -# used to form the text in various listings. Each string in this list, if found -# as the leading text of the brief description, will be stripped from the text -# and the result, after processing the whole list, is used as the annotated -# text. Otherwise, the brief description is used as-is. If left blank, the -# following values are used ($name is automatically replaced with the name of -# the entity):The $name class, The $name widget, The $name file, is, provides, -# specifies, contains, represents, a, an and the. - -ABBREVIATE_BRIEF = "The $name class" \ - "The $name widget" \ - "The $name file" \ - is \ - provides \ - specifies \ - contains \ - represents \ - a \ - an \ - the - -# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then -# doxygen will generate a detailed section even if there is only a brief -# description. -# The default value is: NO. - -ALWAYS_DETAILED_SEC = NO - -# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all -# inherited members of a class in the documentation of that class as if those -# members were ordinary class members. Constructors, destructors and assignment -# operators of the base classes will not be shown. -# The default value is: NO. - -INLINE_INHERITED_MEMB = NO - -# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path -# before files name in the file list and in the header files. If set to NO the -# shortest path that makes the file name unique will be used -# The default value is: YES. - -FULL_PATH_NAMES = YES - -# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. -# Stripping is only done if one of the specified strings matches the left-hand -# part of the path. The tag can be used to show relative paths in the file list. -# If left blank the directory from which doxygen is run is used as the path to -# strip. -# -# Note that you can specify absolute paths here, but also relative paths, which -# will be relative from the directory where doxygen is started. -# This tag requires that the tag FULL_PATH_NAMES is set to YES. - -STRIP_FROM_PATH = @FK_YAML_INCLUDE_BUILD_DIR@ - -# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the -# path mentioned in the documentation of a class, which tells the reader which -# header file to include in order to use a class. If left blank only the name of -# the header file containing the class definition is used. Otherwise one should -# specify the list of include paths that are normally passed to the compiler -# using the -I flag. - -STRIP_FROM_INC_PATH = @FK_YAML_INCLUDE_BUILD_DIR@ - -# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but -# less readable) file names. This can be useful is your file systems doesn't -# support long names like on DOS, Mac, or CD-ROM. -# The default value is: NO. - -SHORT_NAMES = NO - -# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the -# first line (until the first dot) of a Javadoc-style comment as the brief -# description. If set to NO, the Javadoc-style will behave just like regular Qt- -# style comments (thus requiring an explicit @brief command for a brief -# description.) -# The default value is: NO. - -JAVADOC_AUTOBRIEF = NO - -# If the JAVADOC_BANNER tag is set to YES then doxygen will interpret a line -# such as -# /*************** -# as being the beginning of a Javadoc-style comment "banner". If set to NO, the -# Javadoc-style will behave just like regular comments and it will not be -# interpreted by doxygen. -# The default value is: NO. - -JAVADOC_BANNER = NO - -# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first -# line (until the first dot) of a Qt-style comment as the brief description. If -# set to NO, the Qt-style will behave just like regular Qt-style comments (thus -# requiring an explicit \brief command for a brief description.) -# The default value is: NO. - -QT_AUTOBRIEF = NO - -# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a -# multi-line C++ special comment block (i.e. a block of //! or /// comments) as -# a brief description. This used to be the default behavior. The new default is -# to treat a multi-line C++ comment block as a detailed description. Set this -# tag to YES if you prefer the old behavior instead. -# -# Note that setting this tag to YES also means that rational rose comments are -# not recognized any more. -# The default value is: NO. - -MULTILINE_CPP_IS_BRIEF = NO - -# By default Python docstrings are displayed as preformatted text and doxygen's -# special commands cannot be used. By setting PYTHON_DOCSTRING to NO the -# doxygen's special commands can be used and the contents of the docstring -# documentation blocks is shown as doxygen documentation. -# The default value is: YES. - -PYTHON_DOCSTRING = YES - -# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the -# documentation from any documented member that it re-implements. -# The default value is: YES. - -INHERIT_DOCS = YES - -# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new -# page for each member. If set to NO, the documentation of a member will be part -# of the file/class/namespace that contains it. -# The default value is: NO. - -SEPARATE_MEMBER_PAGES = NO - -# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen -# uses this value to replace tabs by spaces in code fragments. -# Minimum value: 1, maximum value: 16, default value: 4. - -TAB_SIZE = 4 - -# This tag can be used to specify a number of aliases that act as commands in -# the documentation. An alias has the form: -# name=value -# For example adding -# "sideeffect=@par Side Effects:^^" -# will allow you to put the command \sideeffect (or @sideeffect) in the -# documentation, which will result in a user-defined paragraph with heading -# "Side Effects:". Note that you cannot put \n's in the value part of an alias -# to insert newlines (in the resulting output). You can put ^^ in the value part -# of an alias to insert a newline as if a physical newline was in the original -# file. When you need a literal { or } or , in the value part of an alias you -# have to escape them by means of a backslash (\), this can lead to conflicts -# with the commands \{ and \} for these it is advised to use the version @{ and -# @} or use a double escape (\\{ and \\}) - -ALIASES = - -# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources -# only. Doxygen will then generate output that is more tailored for C. For -# instance, some of the names that are used will be different. The list of all -# members will be omitted, etc. -# The default value is: NO. - -OPTIMIZE_OUTPUT_FOR_C = NO - -# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or -# Python sources only. Doxygen will then generate output that is more tailored -# for that language. For instance, namespaces will be presented as packages, -# qualified scopes will look different, etc. -# The default value is: NO. - -OPTIMIZE_OUTPUT_JAVA = NO - -# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran -# sources. Doxygen will then generate output that is tailored for Fortran. -# The default value is: NO. - -OPTIMIZE_FOR_FORTRAN = NO - -# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL -# sources. Doxygen will then generate output that is tailored for VHDL. -# The default value is: NO. - -OPTIMIZE_OUTPUT_VHDL = NO - -# Set the OPTIMIZE_OUTPUT_SLICE tag to YES if your project consists of Slice -# sources only. Doxygen will then generate output that is more tailored for that -# language. For instance, namespaces will be presented as modules, types will be -# separated into more groups, etc. -# The default value is: NO. - -OPTIMIZE_OUTPUT_SLICE = NO - -# Doxygen selects the parser to use depending on the extension of the files it -# parses. With this tag you can assign which parser to use for a given -# extension. Doxygen has a built-in mapping, but you can override or extend it -# using this tag. The format is ext=language, where ext is a file extension, and -# language is one of the parsers supported by doxygen: IDL, Java, JavaScript, -# Csharp (C#), C, C++, Lex, D, PHP, md (Markdown), Objective-C, Python, Slice, -# VHDL, Fortran (fixed format Fortran: FortranFixed, free formatted Fortran: -# FortranFree, unknown formatted Fortran: Fortran. In the later case the parser -# tries to guess whether the code is fixed or free formatted code, this is the -# default for Fortran type files). For instance to make doxygen treat .inc files -# as Fortran files (default is PHP), and .f files as C (default is Fortran), -# use: inc=Fortran f=C. -# -# Note: For files without extension you can use no_extension as a placeholder. -# -# Note that for custom extensions you also need to set FILE_PATTERNS otherwise -# the files are not read by doxygen. When specifying no_extension you should add -# * to the FILE_PATTERNS. -# -# Note see also the list of default file extension mappings. - -EXTENSION_MAPPING = - -# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments -# according to the Markdown format, which allows for more readable -# documentation. See https://daringfireball.net/projects/markdown/ for details. -# The output of markdown processing is further processed by doxygen, so you can -# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in -# case of backward compatibilities issues. -# The default value is: YES. - -MARKDOWN_SUPPORT = YES - -# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up -# to that level are automatically included in the table of contents, even if -# they do not have an id attribute. -# Note: This feature currently applies only to Markdown headings. -# Minimum value: 0, maximum value: 99, default value: 5. -# This tag requires that the tag MARKDOWN_SUPPORT is set to YES. - -TOC_INCLUDE_HEADINGS = 5 - -# The MARKDOWN_ID_STYLE tag can be used to specify the algorithm used to -# generate identifiers for the Markdown headings. Note: Every identifier is -# unique. -# Possible values are: DOXYGEN Use a fixed 'autotoc_md' string followed by a -# sequence number starting at 0. and GITHUB Use the lower case version of title -# with any whitespace replaced by '-' and punctations characters removed.. -# The default value is: DOXYGEN. -# This tag requires that the tag MARKDOWN_SUPPORT is set to YES. - -MARKDOWN_ID_STYLE = DOXYGEN - -# When enabled doxygen tries to link words that correspond to documented -# classes, or namespaces to their corresponding documentation. Such a link can -# be prevented in individual cases by putting a % sign in front of the word or -# globally by setting AUTOLINK_SUPPORT to NO. -# The default value is: YES. - -AUTOLINK_SUPPORT = YES - -# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want -# to include (a tag file for) the STL sources as input, then you should set this -# tag to YES in order to let doxygen match functions declarations and -# definitions whose arguments contain STL classes (e.g. func(std::string); -# versus func(std::string) {}). This also make the inheritance and collaboration -# diagrams that involve STL classes more complete and accurate. -# The default value is: NO. - -BUILTIN_STL_SUPPORT = NO - -# If you use Microsoft's C++/CLI language, you should set this option to YES to -# enable parsing support. -# The default value is: NO. - -CPP_CLI_SUPPORT = NO - -# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: -# https://www.riverbankcomputing.com/software/sip/intro) sources only. Doxygen -# will parse them like normal C++ but will assume all classes use public instead -# of private inheritance when no explicit protection keyword is present. -# The default value is: NO. - -SIP_SUPPORT = NO - -# For Microsoft's IDL there are propget and propput attributes to indicate -# getter and setter methods for a property. Setting this option to YES will make -# doxygen to replace the get and set methods by a property in the documentation. -# This will only work if the methods are indeed getting or setting a simple -# type. If this is not the case, or you want to show the methods anyway, you -# should set this option to NO. -# The default value is: YES. - -IDL_PROPERTY_SUPPORT = YES - -# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC -# tag is set to YES then doxygen will reuse the documentation of the first -# member in the group (if any) for the other members of the group. By default -# all members of a group must be documented explicitly. -# The default value is: NO. - -DISTRIBUTE_GROUP_DOC = NO - -# If one adds a struct or class to a group and this option is enabled, then also -# any nested class or struct is added to the same group. By default this option -# is disabled and one has to add nested compounds explicitly via \ingroup. -# The default value is: NO. - -GROUP_NESTED_COMPOUNDS = NO - -# Set the SUBGROUPING tag to YES to allow class member groups of the same type -# (for instance a group of public functions) to be put as a subgroup of that -# type (e.g. under the Public Functions section). Set it to NO to prevent -# subgrouping. Alternatively, this can be done per class using the -# \nosubgrouping command. -# The default value is: YES. - -SUBGROUPING = YES - -# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions -# are shown inside the group in which they are included (e.g. using \ingroup) -# instead of on a separate page (for HTML and Man pages) or section (for LaTeX -# and RTF). -# -# Note that this feature does not work in combination with -# SEPARATE_MEMBER_PAGES. -# The default value is: NO. - -INLINE_GROUPED_CLASSES = NO - -# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions -# with only public data fields or simple typedef fields will be shown inline in -# the documentation of the scope in which they are defined (i.e. file, -# namespace, or group documentation), provided this scope is documented. If set -# to NO, structs, classes, and unions are shown on a separate page (for HTML and -# Man pages) or section (for LaTeX and RTF). -# The default value is: NO. - -INLINE_SIMPLE_STRUCTS = NO - -# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or -# enum is documented as struct, union, or enum with the name of the typedef. So -# typedef struct TypeS {} TypeT, will appear in the documentation as a struct -# with name TypeT. When disabled the typedef will appear as a member of a file, -# namespace, or class. And the struct will be named TypeS. This can typically be -# useful for C code in case the coding convention dictates that all compound -# types are typedef'ed and only the typedef is referenced, never the tag name. -# The default value is: NO. - -TYPEDEF_HIDES_STRUCT = NO - -# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This -# cache is used to resolve symbols given their name and scope. Since this can be -# an expensive process and often the same symbol appears multiple times in the -# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small -# doxygen will become slower. If the cache is too large, memory is wasted. The -# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range -# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 -# symbols. At the end of a run doxygen will report the cache usage and suggest -# the optimal cache size from a speed point of view. -# Minimum value: 0, maximum value: 9, default value: 0. - -LOOKUP_CACHE_SIZE = 0 - -# The NUM_PROC_THREADS specifies the number of threads doxygen is allowed to use -# during processing. When set to 0 doxygen will based this on the number of -# cores available in the system. You can set it explicitly to a value larger -# than 0 to get more control over the balance between CPU load and processing -# speed. At this moment only the input processing can be done using multiple -# threads. Since this is still an experimental feature the default is set to 1, -# which effectively disables parallel processing. Please report any issues you -# encounter. Generating dot graphs in parallel is controlled by the -# DOT_NUM_THREADS setting. -# Minimum value: 0, maximum value: 32, default value: 1. - -NUM_PROC_THREADS = 1 - -# If the TIMESTAMP tag is set different from NO then each generated page will -# contain the date or date and time when the page was generated. Setting this to -# NO can help when comparing the output of multiple runs. -# Possible values are: YES, NO, DATETIME and DATE. -# The default value is: NO. - -TIMESTAMP = NO - -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- - -# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in -# documentation are documented, even if no documentation was available. Private -# class members and static file members will be hidden unless the -# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. -# Note: This will also disable the warnings about undocumented members that are -# normally produced when WARNINGS is set to YES. -# The default value is: NO. - -EXTRACT_ALL = YES - -# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will -# be included in the documentation. -# The default value is: NO. - -EXTRACT_PRIVATE = NO - -# If the EXTRACT_PRIV_VIRTUAL tag is set to YES, documented private virtual -# methods of a class will be included in the documentation. -# The default value is: NO. - -EXTRACT_PRIV_VIRTUAL = NO - -# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal -# scope will be included in the documentation. -# The default value is: NO. - -EXTRACT_PACKAGE = NO - -# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be -# included in the documentation. -# The default value is: NO. - -EXTRACT_STATIC = YES - -# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined -# locally in source files will be included in the documentation. If set to NO, -# only classes defined in header files are included. Does not have any effect -# for Java sources. -# The default value is: YES. - -EXTRACT_LOCAL_CLASSES = YES - -# This flag is only useful for Objective-C code. If set to YES, local methods, -# which are defined in the implementation section but not in the interface are -# included in the documentation. If set to NO, only methods in the interface are -# included. -# The default value is: NO. - -EXTRACT_LOCAL_METHODS = NO - -# If this flag is set to YES, the members of anonymous namespaces will be -# extracted and appear in the documentation as a namespace called -# 'anonymous_namespace{file}', where file will be replaced with the base name of -# the file that contains the anonymous namespace. By default anonymous namespace -# are hidden. -# The default value is: NO. - -EXTRACT_ANON_NSPACES = NO - -# If this flag is set to YES, the name of an unnamed parameter in a declaration -# will be determined by the corresponding definition. By default unnamed -# parameters remain unnamed in the output. -# The default value is: YES. - -RESOLVE_UNNAMED_PARAMS = YES - -# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all -# undocumented members inside documented classes or files. If set to NO these -# members will be included in the various overviews, but no documentation -# section is generated. This option has no effect if EXTRACT_ALL is enabled. -# The default value is: NO. - -HIDE_UNDOC_MEMBERS = NO - -# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all -# undocumented classes that are normally visible in the class hierarchy. If set -# to NO, these classes will be included in the various overviews. This option -# will also hide undocumented C++ concepts if enabled. This option has no effect -# if EXTRACT_ALL is enabled. -# The default value is: NO. - -HIDE_UNDOC_CLASSES = NO - -# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend -# declarations. If set to NO, these declarations will be included in the -# documentation. -# The default value is: NO. - -HIDE_FRIEND_COMPOUNDS = NO - -# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any -# documentation blocks found inside the body of a function. If set to NO, these -# blocks will be appended to the function's detailed documentation block. -# The default value is: NO. - -HIDE_IN_BODY_DOCS = NO - -# The INTERNAL_DOCS tag determines if documentation that is typed after a -# \internal command is included. If the tag is set to NO then the documentation -# will be excluded. Set it to YES to include the internal documentation. -# The default value is: NO. - -INTERNAL_DOCS = NO - -# With the correct setting of option CASE_SENSE_NAMES doxygen will better be -# able to match the capabilities of the underlying filesystem. In case the -# filesystem is case sensitive (i.e. it supports files in the same directory -# whose names only differ in casing), the option must be set to YES to properly -# deal with such files in case they appear in the input. For filesystems that -# are not case sensitive the option should be set to NO to properly deal with -# output files written for symbols that only differ in casing, such as for two -# classes, one named CLASS and the other named Class, and to also support -# references to files without having to specify the exact matching casing. On -# Windows (including Cygwin) and MacOS, users should typically set this option -# to NO, whereas on Linux or other Unix flavors it should typically be set to -# YES. -# Possible values are: SYSTEM, NO and YES. -# The default value is: SYSTEM. - -CASE_SENSE_NAMES = SYSTEM - -# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with -# their full class and namespace scopes in the documentation. If set to YES, the -# scope will be hidden. -# The default value is: NO. - -HIDE_SCOPE_NAMES = NO - -# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will -# append additional text to a page's title, such as Class Reference. If set to -# YES the compound reference will be hidden. -# The default value is: NO. - -HIDE_COMPOUND_REFERENCE= NO - -# If the SHOW_HEADERFILE tag is set to YES then the documentation for a class -# will show which file needs to be included to use the class. -# The default value is: YES. - -SHOW_HEADERFILE = YES - -# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of -# the files that are included by a file in the documentation of that file. -# The default value is: YES. - -SHOW_INCLUDE_FILES = YES - -# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each -# grouped member an include statement to the documentation, telling the reader -# which file to include in order to use the member. -# The default value is: NO. - -SHOW_GROUPED_MEMB_INC = NO - -# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include -# files with double quotes in the documentation rather than with sharp brackets. -# The default value is: NO. - -FORCE_LOCAL_INCLUDES = YES - -# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the -# documentation for inline members. -# The default value is: YES. - -INLINE_INFO = YES - -# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the -# (detailed) documentation of file and class members alphabetically by member -# name. If set to NO, the members will appear in declaration order. -# The default value is: YES. - -SORT_MEMBER_DOCS = YES - -# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief -# descriptions of file, namespace and class members alphabetically by member -# name. If set to NO, the members will appear in declaration order. Note that -# this will also influence the order of the classes in the class list. -# The default value is: NO. - -SORT_BRIEF_DOCS = YES - -# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the -# (brief and detailed) documentation of class members so that constructors and -# destructors are listed first. If set to NO the constructors will appear in the -# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. -# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief -# member documentation. -# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting -# detailed member documentation. -# The default value is: NO. - -SORT_MEMBERS_CTORS_1ST = YES - -# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy -# of group names into alphabetical order. If set to NO the group names will -# appear in their defined order. -# The default value is: NO. - -SORT_GROUP_NAMES = NO - -# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by -# fully-qualified names, including namespaces. If set to NO, the class list will -# be sorted only by class name, not including the namespace part. -# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. -# Note: This option applies only to the class list, not to the alphabetical -# list. -# The default value is: NO. - -SORT_BY_SCOPE_NAME = NO - -# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper -# type resolution of all parameters of a function it will reject a match between -# the prototype and the implementation of a member function even if there is -# only one candidate or it is obvious which candidate to choose by doing a -# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still -# accept a match between prototype and implementation in such cases. -# The default value is: NO. - -STRICT_PROTO_MATCHING = NO - -# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo -# list. This list is created by putting \todo commands in the documentation. -# The default value is: YES. - -GENERATE_TODOLIST = YES - -# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test -# list. This list is created by putting \test commands in the documentation. -# The default value is: YES. - -GENERATE_TESTLIST = YES - -# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug -# list. This list is created by putting \bug commands in the documentation. -# The default value is: YES. - -GENERATE_BUGLIST = YES - -# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO) -# the deprecated list. This list is created by putting \deprecated commands in -# the documentation. -# The default value is: YES. - -GENERATE_DEPRECATEDLIST= YES - -# The ENABLED_SECTIONS tag can be used to enable conditional documentation -# sections, marked by \if ... \endif and \cond -# ... \endcond blocks. - -ENABLED_SECTIONS = - -# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the -# initial value of a variable or macro / define can have for it to appear in the -# documentation. If the initializer consists of more lines than specified here -# it will be hidden. Use a value of 0 to hide initializers completely. The -# appearance of the value of individual variables and macros / defines can be -# controlled using \showinitializer or \hideinitializer command in the -# documentation regardless of this setting. -# Minimum value: 0, maximum value: 10000, default value: 30. - -MAX_INITIALIZER_LINES = 30 - -# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at -# the bottom of the documentation of classes and structs. If set to YES, the -# list will mention the files that were used to generate the documentation. -# The default value is: YES. - -SHOW_USED_FILES = YES - -# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This -# will remove the Files entry from the Quick Index and from the Folder Tree View -# (if specified). -# The default value is: YES. - -SHOW_FILES = YES - -# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces -# page. This will remove the Namespaces entry from the Quick Index and from the -# Folder Tree View (if specified). -# The default value is: YES. - -SHOW_NAMESPACES = YES - -# The FILE_VERSION_FILTER tag can be used to specify a program or script that -# doxygen should invoke to get the current version for each file (typically from -# the version control system). Doxygen will invoke the program by executing (via -# popen()) the command command input-file, where command is the value of the -# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided -# by doxygen. Whatever the program writes to standard output is used as the file -# version. For an example see the documentation. - -FILE_VERSION_FILTER = - -# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed -# by doxygen. The layout file controls the global structure of the generated -# output files in an output format independent way. To create the layout file -# that represents doxygen's defaults, run doxygen with the -l option. You can -# optionally specify a file name after the option, if omitted DoxygenLayout.xml -# will be used as the name of the layout file. See also section "Changing the -# layout of pages" for information. -# -# Note that if you run doxygen from a directory containing a file called -# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE -# tag is left empty. - -LAYOUT_FILE = - -# The CITE_BIB_FILES tag can be used to specify one or more bib files containing -# the reference definitions. This must be a list of .bib files. The .bib -# extension is automatically appended if omitted. This requires the bibtex tool -# to be installed. See also https://en.wikipedia.org/wiki/BibTeX for more info. -# For LaTeX the style of the bibliography can be controlled using -# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the -# search path. See also \cite for info how to create references. - -CITE_BIB_FILES = - -#--------------------------------------------------------------------------- -# Configuration options related to warning and progress messages -#--------------------------------------------------------------------------- - -# The QUIET tag can be used to turn on/off the messages that are generated to -# standard output by doxygen. If QUIET is set to YES this implies that the -# messages are off. -# The default value is: NO. - -QUIET = NO - -# The WARNINGS tag can be used to turn on/off the warning messages that are -# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES -# this implies that the warnings are on. -# -# Tip: Turn warnings on while writing the documentation. -# The default value is: YES. - -WARNINGS = YES - -# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate -# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag -# will automatically be disabled. -# The default value is: YES. - -WARN_IF_UNDOCUMENTED = YES - -# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for -# potential errors in the documentation, such as documenting some parameters in -# a documented function twice, or documenting parameters that don't exist or -# using markup commands wrongly. -# The default value is: YES. - -WARN_IF_DOC_ERROR = YES - -# If WARN_IF_INCOMPLETE_DOC is set to YES, doxygen will warn about incomplete -# function parameter documentation. If set to NO, doxygen will accept that some -# parameters have no documentation without warning. -# The default value is: YES. - -WARN_IF_INCOMPLETE_DOC = YES - -# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that -# are documented, but have no documentation for their parameters or return -# value. If set to NO, doxygen will only warn about wrong parameter -# documentation, but not about the absence of documentation. If EXTRACT_ALL is -# set to YES then this flag will automatically be disabled. See also -# WARN_IF_INCOMPLETE_DOC -# The default value is: NO. - -WARN_NO_PARAMDOC = NO - -# If WARN_IF_UNDOC_ENUM_VAL option is set to YES, doxygen will warn about -# undocumented enumeration values. If set to NO, doxygen will accept -# undocumented enumeration values. If EXTRACT_ALL is set to YES then this flag -# will automatically be disabled. -# The default value is: NO. - -WARN_IF_UNDOC_ENUM_VAL = NO - -# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when -# a warning is encountered. If the WARN_AS_ERROR tag is set to FAIL_ON_WARNINGS -# then doxygen will continue running as if WARN_AS_ERROR tag is set to NO, but -# at the end of the doxygen process doxygen will return with a non-zero status. -# If the WARN_AS_ERROR tag is set to FAIL_ON_WARNINGS_PRINT then doxygen behaves -# like FAIL_ON_WARNINGS but in case no WARN_LOGFILE is defined doxygen will not -# write the warning messages in between other messages but write them at the end -# of a run, in case a WARN_LOGFILE is defined the warning messages will be -# besides being in the defined file also be shown at the end of a run, unless -# the WARN_LOGFILE is defined as - i.e. standard output (stdout) in that case -# the behavior will remain as with the setting FAIL_ON_WARNINGS. -# Possible values are: NO, YES, FAIL_ON_WARNINGS and FAIL_ON_WARNINGS_PRINT. -# The default value is: NO. - -WARN_AS_ERROR = NO - -# The WARN_FORMAT tag determines the format of the warning messages that doxygen -# can produce. The string should contain the $file, $line, and $text tags, which -# will be replaced by the file and line number from which the warning originated -# and the warning text. Optionally the format may contain $version, which will -# be replaced by the version of the file (if it could be obtained via -# FILE_VERSION_FILTER) -# See also: WARN_LINE_FORMAT -# The default value is: $file:$line: $text. - -WARN_FORMAT = "$file:$line: $text" - -# In the $text part of the WARN_FORMAT command it is possible that a reference -# to a more specific place is given. To make it easier to jump to this place -# (outside of doxygen) the user can define a custom "cut" / "paste" string. -# Example: -# WARN_LINE_FORMAT = "'vi $file +$line'" -# See also: WARN_FORMAT -# The default value is: at line $line of file $file. - -WARN_LINE_FORMAT = "at line $line of file $file" - -# The WARN_LOGFILE tag can be used to specify a file to which warning and error -# messages should be written. If left blank the output is written to standard -# error (stderr). In case the file specified cannot be opened for writing the -# warning and error messages are written to standard error. When as file - is -# specified the warning and error messages are written to standard output -# (stdout). - -WARN_LOGFILE = - -#--------------------------------------------------------------------------- -# Configuration options related to the input files -#--------------------------------------------------------------------------- - -# The INPUT tag is used to specify the files and/or directories that contain -# documented source files. You may enter file names like myfile.cpp or -# directories like /usr/src/myproject. Separate the files or directories with -# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING -# Note: If this tag is empty the current directory is searched. - -INPUT = @FK_YAML_DOXYGEN_INPUT_DIR@ - -# This tag can be used to specify the character encoding of the source files -# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses -# libiconv (or the iconv built into libc) for the transcoding. See the libiconv -# documentation (see: -# https://www.gnu.org/software/libiconv/) for the list of possible encodings. -# See also: INPUT_FILE_ENCODING -# The default value is: UTF-8. - -INPUT_ENCODING = UTF-8 - -# This tag can be used to specify the character encoding of the source files -# that doxygen parses The INPUT_FILE_ENCODING tag can be used to specify -# character encoding on a per file pattern basis. Doxygen will compare the file -# name with each pattern and apply the encoding instead of the default -# INPUT_ENCODING) if there is a match. The character encodings are a list of the -# form: pattern=encoding (like *.php=ISO-8859-1). See cfg_input_encoding -# "INPUT_ENCODING" for further information on supported encodings. - -INPUT_FILE_ENCODING = - -# If the value of the INPUT tag contains directories, you can use the -# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and -# *.h) to filter out the source-files in the directories. -# -# Note that for custom extensions or not directly supported extensions you also -# need to set EXTENSION_MAPPING for the extension otherwise the files are not -# read by doxygen. -# -# Note the list of default checked file patterns might differ from the list of -# default file extension mappings. -# -# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp, -# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, -# *.hh, *.hxx, *.hpp, *.h++, *.l, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, -# *.inc, *.m, *.markdown, *.md, *.mm, *.dox (to be provided as doxygen C -# comment), *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f18, *.f, *.for, *.vhd, -# *.vhdl, *.ucf, *.qsf and *.ice. - -FILE_PATTERNS = *.c \ - *.cc \ - *.cxx \ - *.cpp \ - *.c++ \ - *.java \ - *.ii \ - *.ixx \ - *.ipp \ - *.i++ \ - *.inl \ - *.idl \ - *.ddl \ - *.odl \ - *.h \ - *.hh \ - *.hxx \ - *.hpp \ - *.h++ \ - *.l \ - *.cs \ - *.d \ - *.php \ - *.php4 \ - *.php5 \ - *.phtml \ - *.inc \ - *.m \ - *.markdown \ - *.md \ - *.mm \ - *.dox \ - *.py \ - *.pyw \ - *.f90 \ - *.f95 \ - *.f03 \ - *.f08 \ - *.f18 \ - *.f \ - *.for \ - *.vhd \ - *.vhdl \ - *.ucf \ - *.qsf \ - *.ice - -# The RECURSIVE tag can be used to specify whether or not subdirectories should -# be searched for input files as well. -# The default value is: NO. - -RECURSIVE = YES - -# The EXCLUDE tag can be used to specify files and/or directories that should be -# excluded from the INPUT source files. This way you can easily exclude a -# subdirectory from a directory tree whose root is specified with the INPUT tag. -# -# Note that relative paths are relative to the directory from which doxygen is -# run. - -EXCLUDE = - -# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or -# directories that are symbolic links (a Unix file system feature) are excluded -# from the input. -# The default value is: NO. - -EXCLUDE_SYMLINKS = NO - -# If the value of the INPUT tag contains directories, you can use the -# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude -# certain files from those directories. -# -# Note that the wildcards are matched against the file with absolute path, so to -# exclude all test directories for example use the pattern */test/* - -EXCLUDE_PATTERNS = - -# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names -# (namespaces, classes, functions, etc.) that should be excluded from the -# output. The symbol name can be a fully qualified name, a word, or if the -# wildcard * is used, a substring. Examples: ANamespace, AClass, -# ANamespace::AClass, ANamespace::*Test - -EXCLUDE_SYMBOLS = - -# The EXAMPLE_PATH tag can be used to specify one or more files or directories -# that contain example code fragments that are included (see the \include -# command). - -EXAMPLE_PATH = - -# If the value of the EXAMPLE_PATH tag contains directories, you can use the -# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and -# *.h) to filter out the source-files in the directories. If left blank all -# files are included. - -EXAMPLE_PATTERNS = * - -# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be -# searched for input files to be used with the \include or \dontinclude commands -# irrespective of the value of the RECURSIVE tag. -# The default value is: NO. - -EXAMPLE_RECURSIVE = NO - -# The IMAGE_PATH tag can be used to specify one or more files or directories -# that contain images that are to be included in the documentation (see the -# \image command). - -IMAGE_PATH = - -# The INPUT_FILTER tag can be used to specify a program that doxygen should -# invoke to filter for each input file. Doxygen will invoke the filter program -# by executing (via popen()) the command: -# -# -# -# where is the value of the INPUT_FILTER tag, and is the -# name of an input file. Doxygen will then use the output that the filter -# program writes to standard output. If FILTER_PATTERNS is specified, this tag -# will be ignored. -# -# Note that the filter must not add or remove lines; it is applied before the -# code is scanned, but not when the output code is generated. If lines are added -# or removed, the anchors will not be placed correctly. -# -# Note that doxygen will use the data processed and written to standard output -# for further processing, therefore nothing else, like debug statements or used -# commands (so in case of a Windows batch file always use @echo OFF), should be -# written to standard output. -# -# Note that for custom extensions or not directly supported extensions you also -# need to set EXTENSION_MAPPING for the extension otherwise the files are not -# properly processed by doxygen. - -INPUT_FILTER = - -# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern -# basis. Doxygen will compare the file name with each pattern and apply the -# filter if there is a match. The filters are a list of the form: pattern=filter -# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how -# filters are used. If the FILTER_PATTERNS tag is empty or if none of the -# patterns match the file name, INPUT_FILTER is applied. -# -# Note that for custom extensions or not directly supported extensions you also -# need to set EXTENSION_MAPPING for the extension otherwise the files are not -# properly processed by doxygen. - -FILTER_PATTERNS = - -# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using -# INPUT_FILTER) will also be used to filter the input files that are used for -# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). -# The default value is: NO. - -FILTER_SOURCE_FILES = NO - -# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file -# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and -# it is also possible to disable source filtering for a specific pattern using -# *.ext= (so without naming a filter). -# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. - -FILTER_SOURCE_PATTERNS = - -# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that -# is part of the input, its contents will be placed on the main page -# (index.html). This can be useful if you have a project on for instance GitHub -# and want to reuse the introduction page also for the doxygen output. - -USE_MDFILE_AS_MAINPAGE = - -# The Fortran standard specifies that for fixed formatted Fortran code all -# characters from position 72 are to be considered as comment. A common -# extension is to allow longer lines before the automatic comment starts. The -# setting FORTRAN_COMMENT_AFTER will also make it possible that longer lines can -# be processed before the automatic comment starts. -# Minimum value: 7, maximum value: 10000, default value: 72. - -FORTRAN_COMMENT_AFTER = 72 - -#--------------------------------------------------------------------------- -# Configuration options related to source browsing -#--------------------------------------------------------------------------- - -# If the SOURCE_BROWSER tag is set to YES then a list of source files will be -# generated. Documented entities will be cross-referenced with these sources. -# -# Note: To get rid of all source code in the generated output, make sure that -# also VERBATIM_HEADERS is set to NO. -# The default value is: NO. - -SOURCE_BROWSER = NO - -# Setting the INLINE_SOURCES tag to YES will include the body of functions, -# classes and enums directly into the documentation. -# The default value is: NO. - -INLINE_SOURCES = NO - -# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any -# special comment blocks from generated source code fragments. Normal C, C++ and -# Fortran comments will always remain visible. -# The default value is: YES. - -STRIP_CODE_COMMENTS = YES - -# If the REFERENCED_BY_RELATION tag is set to YES then for each documented -# entity all documented functions referencing it will be listed. -# The default value is: NO. - -REFERENCED_BY_RELATION = NO - -# If the REFERENCES_RELATION tag is set to YES then for each documented function -# all documented entities called/used by that function will be listed. -# The default value is: NO. - -REFERENCES_RELATION = NO - -# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set -# to YES then the hyperlinks from functions in REFERENCES_RELATION and -# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will -# link to the documentation. -# The default value is: YES. - -REFERENCES_LINK_SOURCE = YES - -# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the -# source code will show a tooltip with additional information such as prototype, -# brief description and links to the definition and documentation. Since this -# will make the HTML file larger and loading of large files a bit slower, you -# can opt to disable this feature. -# The default value is: YES. -# This tag requires that the tag SOURCE_BROWSER is set to YES. - -SOURCE_TOOLTIPS = YES - -# If the USE_HTAGS tag is set to YES then the references to source code will -# point to the HTML generated by the htags(1) tool instead of doxygen built-in -# source browser. The htags tool is part of GNU's global source tagging system -# (see https://www.gnu.org/software/global/global.html). You will need version -# 4.8.6 or higher. -# -# To use it do the following: -# - Install the latest version of global -# - Enable SOURCE_BROWSER and USE_HTAGS in the configuration file -# - Make sure the INPUT points to the root of the source tree -# - Run doxygen as normal -# -# Doxygen will invoke htags (and that will in turn invoke gtags), so these -# tools must be available from the command line (i.e. in the search path). -# -# The result: instead of the source browser generated by doxygen, the links to -# source code will now point to the output of htags. -# The default value is: NO. -# This tag requires that the tag SOURCE_BROWSER is set to YES. - -USE_HTAGS = NO - -# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a -# verbatim copy of the header file for each class for which an include is -# specified. Set to NO to disable this. -# See also: Section \class. -# The default value is: YES. - -VERBATIM_HEADERS = YES - -# If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the -# clang parser (see: -# http://clang.llvm.org/) for more accurate parsing at the cost of reduced -# performance. This can be particularly helpful with template rich C++ code for -# which doxygen's built-in parser lacks the necessary type information. -# Note: The availability of this option depends on whether or not doxygen was -# generated with the -Duse_libclang=ON option for CMake. -# The default value is: NO. - -CLANG_ASSISTED_PARSING = NO - -# If the CLANG_ASSISTED_PARSING tag is set to YES and the CLANG_ADD_INC_PATHS -# tag is set to YES then doxygen will add the directory of each input to the -# include path. -# The default value is: YES. -# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. - -CLANG_ADD_INC_PATHS = YES - -# If clang assisted parsing is enabled you can provide the compiler with command -# line options that you would normally use when invoking the compiler. Note that -# the include paths will already be set by doxygen for the files and directories -# specified with INPUT and INCLUDE_PATH. -# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. - -CLANG_OPTIONS = - -# If clang assisted parsing is enabled you can provide the clang parser with the -# path to the directory containing a file called compile_commands.json. This -# file is the compilation database (see: -# http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html) containing the -# options used when the source files were built. This is equivalent to -# specifying the -p option to a clang tool, such as clang-check. These options -# will then be passed to the parser. Any options specified with CLANG_OPTIONS -# will be added as well. -# Note: The availability of this option depends on whether or not doxygen was -# generated with the -Duse_libclang=ON option for CMake. - -CLANG_DATABASE_PATH = - -#--------------------------------------------------------------------------- -# Configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- - -# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all -# compounds will be generated. Enable this if the project contains a lot of -# classes, structs, unions or interfaces. -# The default value is: YES. - -ALPHABETICAL_INDEX = YES - -# The IGNORE_PREFIX tag can be used to specify a prefix (or a list of prefixes) -# that should be ignored while generating the index headers. The IGNORE_PREFIX -# tag works for classes, function and member names. The entity will be placed in -# the alphabetical list under the first letter of the entity name that remains -# after removing the prefix. -# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. - -IGNORE_PREFIX = - -#--------------------------------------------------------------------------- -# Configuration options related to the HTML output -#--------------------------------------------------------------------------- - -# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output -# The default value is: YES. - -GENERATE_HTML = YES - -# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a -# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of -# it. -# The default directory is: html. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_OUTPUT = html - -# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each -# generated HTML page (for example: .htm, .php, .asp). -# The default value is: .html. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_FILE_EXTENSION = .html - -# The HTML_HEADER tag can be used to specify a user-defined HTML header file for -# each generated HTML page. If the tag is left blank doxygen will generate a -# standard header. -# -# To get valid HTML the header file that includes any scripts and style sheets -# that doxygen needs, which is dependent on the configuration options used (e.g. -# the setting GENERATE_TREEVIEW). It is highly recommended to start with a -# default header using -# doxygen -w html new_header.html new_footer.html new_stylesheet.css -# YourConfigFile -# and then modify the file new_header.html. See also section "Doxygen usage" -# for information on how to generate the default header that doxygen normally -# uses. -# Note: The header is subject to change so you typically have to regenerate the -# default header when upgrading to a newer version of doxygen. For a description -# of the possible markers and block names see the documentation. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_HEADER = - -# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each -# generated HTML page. If the tag is left blank doxygen will generate a standard -# footer. See HTML_HEADER for more information on how to generate a default -# footer and what special commands can be used inside the footer. See also -# section "Doxygen usage" for information on how to generate the default footer -# that doxygen normally uses. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_FOOTER = - -# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style -# sheet that is used by each HTML page. It can be used to fine-tune the look of -# the HTML output. If left blank doxygen will generate a default style sheet. -# See also section "Doxygen usage" for information on how to generate the style -# sheet that doxygen normally uses. -# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as -# it is more robust and this tag (HTML_STYLESHEET) will in the future become -# obsolete. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_STYLESHEET = - -# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined -# cascading style sheets that are included after the standard style sheets -# created by doxygen. Using this option one can overrule certain style aspects. -# This is preferred over using HTML_STYLESHEET since it does not replace the -# standard style sheet and is therefore more robust against future updates. -# Doxygen will copy the style sheet files to the output directory. -# Note: The order of the extra style sheet files is of importance (e.g. the last -# style sheet in the list overrules the setting of the previous ones in the -# list). -# Note: Since the styling of scrollbars can currently not be overruled in -# Webkit/Chromium, the styling will be left out of the default doxygen.css if -# one or more extra stylesheets have been specified. So if scrollbar -# customization is desired it has to be added explicitly. For an example see the -# documentation. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_EXTRA_STYLESHEET = - -# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or -# other source files which should be copied to the HTML output directory. Note -# that these files will be copied to the base HTML output directory. Use the -# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these -# files. In the HTML_STYLESHEET file, use the file name only. Also note that the -# files will be copied as-is; there are no commands or markers available. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_EXTRA_FILES = - -# The HTML_COLORSTYLE tag can be used to specify if the generated HTML output -# should be rendered with a dark or light theme. -# Possible values are: LIGHT always generate light mode output, DARK always -# generate dark mode output, AUTO_LIGHT automatically set the mode according to -# the user preference, use light mode if no preference is set (the default), -# AUTO_DARK automatically set the mode according to the user preference, use -# dark mode if no preference is set and TOGGLE allow to user to switch between -# light and dark mode via a button. -# The default value is: AUTO_LIGHT. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE = AUTO_LIGHT - -# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen -# will adjust the colors in the style sheet and background images according to -# this color. Hue is specified as an angle on a color-wheel, see -# https://en.wikipedia.org/wiki/Hue for more information. For instance the value -# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 -# purple, and 360 is red again. -# Minimum value: 0, maximum value: 359, default value: 220. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_HUE = 220 - -# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors -# in the HTML output. For a value of 0 the output will use gray-scales only. A -# value of 255 will produce the most vivid colors. -# Minimum value: 0, maximum value: 255, default value: 100. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_SAT = 100 - -# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the -# luminance component of the colors in the HTML output. Values below 100 -# gradually make the output lighter, whereas values above 100 make the output -# darker. The value divided by 100 is the actual gamma applied, so 80 represents -# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not -# change the gamma. -# Minimum value: 40, maximum value: 240, default value: 80. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_GAMMA = 80 - -# If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML -# documentation will contain a main index with vertical navigation menus that -# are dynamically created via JavaScript. If disabled, the navigation index will -# consists of multiple levels of tabs that are statically embedded in every HTML -# page. Disable this option to support browsers that do not have JavaScript, -# like the Qt help browser. -# The default value is: YES. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_DYNAMIC_MENUS = YES - -# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML -# documentation will contain sections that can be hidden and shown after the -# page has loaded. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_DYNAMIC_SECTIONS = NO - -# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries -# shown in the various tree structured indices initially; the user can expand -# and collapse entries dynamically later on. Doxygen will expand the tree to -# such a level that at most the specified number of entries are visible (unless -# a fully collapsed tree already exceeds this amount). So setting the number of -# entries 1 will produce a full collapsed tree by default. 0 is a special value -# representing an infinite number of entries and will result in a full expanded -# tree by default. -# Minimum value: 0, maximum value: 9999, default value: 100. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_INDEX_NUM_ENTRIES = 100 - -# If the GENERATE_DOCSET tag is set to YES, additional index files will be -# generated that can be used as input for Apple's Xcode 3 integrated development -# environment (see: -# https://developer.apple.com/xcode/), introduced with OSX 10.5 (Leopard). To -# create a documentation set, doxygen will generate a Makefile in the HTML -# output directory. Running make will produce the docset in that directory and -# running make install will install the docset in -# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at -# startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy -# genXcode/_index.html for more information. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_DOCSET = NO - -# This tag determines the name of the docset feed. A documentation feed provides -# an umbrella under which multiple documentation sets from a single provider -# (such as a company or product suite) can be grouped. -# The default value is: Doxygen generated docs. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_FEEDNAME = "Doxygen generated docs" - -# This tag determines the URL of the docset feed. A documentation feed provides -# an umbrella under which multiple documentation sets from a single provider -# (such as a company or product suite) can be grouped. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_FEEDURL = - -# This tag specifies a string that should uniquely identify the documentation -# set bundle. This should be a reverse domain-name style string, e.g. -# com.mycompany.MyDocSet. Doxygen will append .docset to the name. -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_BUNDLE_ID = org.doxygen.Project - -# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify -# the documentation publisher. This should be a reverse domain-name style -# string, e.g. com.mycompany.MyDocSet.documentation. -# The default value is: org.doxygen.Publisher. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_PUBLISHER_ID = org.doxygen.Publisher - -# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. -# The default value is: Publisher. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_PUBLISHER_NAME = Publisher - -# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three -# additional HTML index files: index.hhp, index.hhc, and index.hhk. The -# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop -# on Windows. In the beginning of 2021 Microsoft took the original page, with -# a.o. the download links, offline the HTML help workshop was already many years -# in maintenance mode). You can download the HTML help workshop from the web -# archives at Installation executable (see: -# http://web.archive.org/web/20160201063255/http://download.microsoft.com/downlo -# ad/0/A/9/0A939EF6-E31C-430F-A3DF-DFAE7960D564/htmlhelp.exe). -# -# The HTML Help Workshop contains a compiler that can convert all HTML output -# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML -# files are now used as the Windows 98 help format, and will replace the old -# Windows help format (.hlp) on all Windows platforms in the future. Compressed -# HTML files also contain an index, a table of contents, and you can search for -# words in the documentation. The HTML workshop also contains a viewer for -# compressed HTML files. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_HTMLHELP = NO - -# The CHM_FILE tag can be used to specify the file name of the resulting .chm -# file. You can add a path in front of the file if the result should not be -# written to the html output directory. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -CHM_FILE = - -# The HHC_LOCATION tag can be used to specify the location (absolute path -# including file name) of the HTML help compiler (hhc.exe). If non-empty, -# doxygen will try to run the HTML help compiler on the generated index.hhp. -# The file has to be specified with full path. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -HHC_LOCATION = - -# The GENERATE_CHI flag controls if a separate .chi index file is generated -# (YES) or that it should be included in the main .chm file (NO). -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -GENERATE_CHI = NO - -# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) -# and project file content. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -CHM_INDEX_ENCODING = - -# The BINARY_TOC flag controls whether a binary table of contents is generated -# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it -# enables the Previous and Next buttons. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -BINARY_TOC = NO - -# The TOC_EXPAND flag can be set to YES to add extra items for group members to -# the table of contents of the HTML help documentation and to the tree view. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -TOC_EXPAND = NO - -# The SITEMAP_URL tag is used to specify the full URL of the place where the -# generated documentation will be placed on the server by the user during the -# deployment of the documentation. The generated sitemap is called sitemap.xml -# and placed on the directory specified by HTML_OUTPUT. In case no SITEMAP_URL -# is specified no sitemap is generated. For information about the sitemap -# protocol see https://www.sitemaps.org -# This tag requires that the tag GENERATE_HTML is set to YES. - -SITEMAP_URL = - -# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and -# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that -# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help -# (.qch) of the generated HTML documentation. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_QHP = NO - -# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify -# the file name of the resulting .qch file. The path specified is relative to -# the HTML output folder. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QCH_FILE = - -# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help -# Project output. For more information please see Qt Help Project / Namespace -# (see: -# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace). -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_NAMESPACE = org.doxygen.Project - -# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt -# Help Project output. For more information please see Qt Help Project / Virtual -# Folders (see: -# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-folders). -# The default value is: doc. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_VIRTUAL_FOLDER = doc - -# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom -# filter to add. For more information please see Qt Help Project / Custom -# Filters (see: -# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_CUST_FILTER_NAME = - -# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the -# custom filter to add. For more information please see Qt Help Project / Custom -# Filters (see: -# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_CUST_FILTER_ATTRS = - -# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this -# project's filter section matches. Qt Help Project / Filter Attributes (see: -# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#filter-attributes). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_SECT_FILTER_ATTRS = - -# The QHG_LOCATION tag can be used to specify the location (absolute path -# including file name) of Qt's qhelpgenerator. If non-empty doxygen will try to -# run qhelpgenerator on the generated .qhp file. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHG_LOCATION = - -# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be -# generated, together with the HTML files, they form an Eclipse help plugin. To -# install this plugin and make it available under the help contents menu in -# Eclipse, the contents of the directory containing the HTML and XML files needs -# to be copied into the plugins directory of eclipse. The name of the directory -# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. -# After copying Eclipse needs to be restarted before the help appears. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_ECLIPSEHELP = NO - -# A unique identifier for the Eclipse help plugin. When installing the plugin -# the directory name containing the HTML and XML files should also have this -# name. Each documentation set should have its own identifier. -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. - -ECLIPSE_DOC_ID = org.doxygen.Project - -# If you want full control over the layout of the generated HTML pages it might -# be necessary to disable the index and replace it with your own. The -# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top -# of each HTML page. A value of NO enables the index and the value YES disables -# it. Since the tabs in the index contain the same information as the navigation -# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -DISABLE_INDEX = NO - -# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index -# structure should be generated to display hierarchical information. If the tag -# value is set to YES, a side panel will be generated containing a tree-like -# index structure (just like the one that is generated for HTML Help). For this -# to work a browser that supports JavaScript, DHTML, CSS and frames is required -# (i.e. any modern browser). Windows users are probably better off using the -# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can -# further fine tune the look of the index (see "Fine-tuning the output"). As an -# example, the default style sheet generated by doxygen has an example that -# shows how to put an image at the root of the tree instead of the PROJECT_NAME. -# Since the tree basically has the same information as the tab index, you could -# consider setting DISABLE_INDEX to YES when enabling this option. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_TREEVIEW = NO - -# When both GENERATE_TREEVIEW and DISABLE_INDEX are set to YES, then the -# FULL_SIDEBAR option determines if the side bar is limited to only the treeview -# area (value NO) or if it should extend to the full height of the window (value -# YES). Setting this to YES gives a layout similar to -# https://docs.readthedocs.io with more room for contents, but less room for the -# project logo, title, and description. If either GENERATE_TREEVIEW or -# DISABLE_INDEX is set to NO, this option has no effect. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -FULL_SIDEBAR = NO - -# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that -# doxygen will group on one line in the generated HTML documentation. -# -# Note that a value of 0 will completely suppress the enum values from appearing -# in the overview section. -# Minimum value: 0, maximum value: 20, default value: 4. -# This tag requires that the tag GENERATE_HTML is set to YES. - -ENUM_VALUES_PER_LINE = 4 - -# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used -# to set the initial width (in pixels) of the frame in which the tree is shown. -# Minimum value: 0, maximum value: 1500, default value: 250. -# This tag requires that the tag GENERATE_HTML is set to YES. - -TREEVIEW_WIDTH = 250 - -# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to -# external symbols imported via tag files in a separate window. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -EXT_LINKS_IN_WINDOW = NO - -# If the OBFUSCATE_EMAILS tag is set to YES, doxygen will obfuscate email -# addresses. -# The default value is: YES. -# This tag requires that the tag GENERATE_HTML is set to YES. - -OBFUSCATE_EMAILS = YES - -# If the HTML_FORMULA_FORMAT option is set to svg, doxygen will use the pdf2svg -# tool (see https://github.com/dawbarton/pdf2svg) or inkscape (see -# https://inkscape.org) to generate formulas as SVG images instead of PNGs for -# the HTML output. These images will generally look nicer at scaled resolutions. -# Possible values are: png (the default) and svg (looks nicer but requires the -# pdf2svg or inkscape tool). -# The default value is: png. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_FORMULA_FORMAT = png - -# Use this tag to change the font size of LaTeX formulas included as images in -# the HTML documentation. When you change the font size after a successful -# doxygen run you need to manually remove any form_*.png images from the HTML -# output directory to force them to be regenerated. -# Minimum value: 8, maximum value: 50, default value: 10. -# This tag requires that the tag GENERATE_HTML is set to YES. - -FORMULA_FONTSIZE = 10 - -# The FORMULA_MACROFILE can contain LaTeX \newcommand and \renewcommand commands -# to create new LaTeX commands to be used in formulas as building blocks. See -# the section "Including formulas" for details. - -FORMULA_MACROFILE = - -# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see -# https://www.mathjax.org) which uses client side JavaScript for the rendering -# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX -# installed or if you want to formulas look prettier in the HTML output. When -# enabled you may also need to install MathJax separately and configure the path -# to it using the MATHJAX_RELPATH option. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -USE_MATHJAX = NO - -# With MATHJAX_VERSION it is possible to specify the MathJax version to be used. -# Note that the different versions of MathJax have different requirements with -# regards to the different settings, so it is possible that also other MathJax -# settings have to be changed when switching between the different MathJax -# versions. -# Possible values are: MathJax_2 and MathJax_3. -# The default value is: MathJax_2. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_VERSION = MathJax_2 - -# When MathJax is enabled you can set the default output format to be used for -# the MathJax output. For more details about the output format see MathJax -# version 2 (see: -# http://docs.mathjax.org/en/v2.7-latest/output.html) and MathJax version 3 -# (see: -# http://docs.mathjax.org/en/latest/web/components/output.html). -# Possible values are: HTML-CSS (which is slower, but has the best -# compatibility. This is the name for Mathjax version 2, for MathJax version 3 -# this will be translated into chtml), NativeMML (i.e. MathML. Only supported -# for NathJax 2. For MathJax version 3 chtml will be used instead.), chtml (This -# is the name for Mathjax version 3, for MathJax version 2 this will be -# translated into HTML-CSS) and SVG. -# The default value is: HTML-CSS. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_FORMAT = HTML-CSS - -# When MathJax is enabled you need to specify the location relative to the HTML -# output directory using the MATHJAX_RELPATH option. The destination directory -# should contain the MathJax.js script. For instance, if the mathjax directory -# is located at the same level as the HTML output directory, then -# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax -# Content Delivery Network so you can quickly see the result without installing -# MathJax. However, it is strongly recommended to install a local copy of -# MathJax from https://www.mathjax.org before deployment. The default value is: -# - in case of MathJax version 2: https://cdn.jsdelivr.net/npm/mathjax@2 -# - in case of MathJax version 3: https://cdn.jsdelivr.net/npm/mathjax@3 -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_RELPATH = - -# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax -# extension names that should be enabled during MathJax rendering. For example -# for MathJax version 2 (see -# https://docs.mathjax.org/en/v2.7-latest/tex.html#tex-and-latex-extensions): -# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols -# For example for MathJax version 3 (see -# http://docs.mathjax.org/en/latest/input/tex/extensions/index.html): -# MATHJAX_EXTENSIONS = ams -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_EXTENSIONS = - -# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces -# of code that will be used on startup of the MathJax code. See the MathJax site -# (see: -# http://docs.mathjax.org/en/v2.7-latest/output.html) for more details. For an -# example see the documentation. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_CODEFILE = - -# When the SEARCHENGINE tag is enabled doxygen will generate a search box for -# the HTML output. The underlying search engine uses javascript and DHTML and -# should work on any modern browser. Note that when using HTML help -# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) -# there is already a search function so this one should typically be disabled. -# For large projects the javascript based search engine can be slow, then -# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to -# search using the keyboard; to jump to the search box use + S -# (what the is depends on the OS and browser, but it is typically -# , /