From 0de799a1ae1fc660efaaae571e8e329f04fc34b7 Mon Sep 17 00:00:00 2001 From: roby2014 Date: Tue, 7 May 2024 20:56:36 +0100 Subject: [PATCH] docs: add inheritstrait feature writeup --- content/0-2-and-coffejam.rst | 73 +++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 6 deletions(-) diff --git a/content/0-2-and-coffejam.rst b/content/0-2-and-coffejam.rst index 8600772..c70faf2 100644 --- a/content/0-2-and-coffejam.rst +++ b/content/0-2-and-coffejam.rst @@ -1,11 +1,11 @@ -Hello World -########### +Coffe'n Jam and... 0.2! +######################## :date: 2024-05-07 19:00:00 :category: Meta -:summary: CUBOS. 0.2 Release and Coffe Jam! +:summary: CUBOS. 0.2 Release and Coffe'n Jam! -CoffeJam +Coffe'n Jam ======== insert very interesting text here, problems occurred, final result, etc, @@ -14,8 +14,69 @@ New 0.2 features ================ -Insert feature name here ------------------------- +Introducing Inheritance in Reflection +------------------------------------- +> Trait for representing inheritance relationships under reflection. (#693, @roby2014). + +``CUBOS.`` has a powerful reflection system to examine and interact with a structures and types at runtime. + +``InheritsTrait`` is a new feature in ``CUBOS.`` that allows you to represent and query inheritance relationships +in a reflective context. With this trait, you can define which types inherit from others and then check those relationships at runtime. + +You can define inheritance as the following: + +.. code-block:: c++ + + #include + + using cubos::core::reflection::InheritsTrait; + using cubos::core::reflection::Type; + + struct GrandParent + { + CUBOS_REFLECT; + }; + + struct Parent + { + CUBOS_REFLECT; + }; + + struct Son + { + CUBOS_REFLECT; + }; + + CUBOS_REFLECT_IMPL(GrandParent) + { + return Type::create("GrandParent"); + } + + CUBOS_REFLECT_IMPL(Parent) + {r + return Type::create("Parent").with(InheritsTrait::from()); + } + + CUBOS_REFLECT_IMPL(Son) + { + return Type::create("Son").with(InheritsTrait::from()); + } + +or you can also check inheritance: + +.. code-block:: c++ + + void reflectType() + { + const auto& type = reflect(); + if (type.has() && type.get().inherits()) + { + std::cout << type.name() << " inherits from Parent\n"; + } + } + +you can check more information on the documentation page: https://gamedevtecnico.github.io/cubos/docs/examples-core-reflection-traits-inherits.html. + insert feature text here