Releases: Manu343726/tinyrefl
Releases · Manu343726/tinyrefl
Global access to reflection metadata
- New metadata access points
tinyrefl::entity_metadata<>
andtinyrefl::has_entity_metadata<>()
that provide access to entity metadata by its full display name, regardless of its kind:
using namespace tinyrefl::literals;
constexpr auto enum_ = tinyrefl::entity_metadata<"mynamespace::Enum"_id>();
constexpr auto method = tinyrefl::entity_metadata<"mynamespace::Class::method(int)"_id>();
constexpr auto const_method = tintyrefl::entity_metadata<"mynamespace::Class::method(int) const"_id>();
- New functions
tinyrefl::display_name<Entity>()
andtinyrefl::full_display_name<Entity>()
to get the display name of an entity:
constexpr auto display_name = tinyrefl::display_name<TINYREFL_STATIC_VALUE(&Class::method)>();
constexpr auto full_display_name = tinyrefl::full_display_name<TINYREFL_STATIC_VALUE(&Class::method)>();
fmt::print("{}/n", display_name); // "method(int) const"
fmt::print("{}/n", full_display_name); // "mynamespace::Class::method(int) const"
- New global metadata access point
tinyrefl::entities<>
that returns the full list of reflected entities accesible in the translation unit:
#include <tinyrefl/api.hpp>
#include <myheader.hpp>
#include <myheader.hpp.tinyrefl>
#include <myotherheader.hpp>
#include <myotherheader.hpp.tinyrefl>
#include <tinyrefl/entities.hpp>
using entities_from_myheader_and_myotherheader = tinyrefl::entities;
- New visitation functions
tinyrefl::visit_entities()
,tinyrefl::visit_classes()
, andtinyrefl::visit_enums()
to traverse full translation unit entities:
#include <tinyrefl/api.hpp>
#include <myheader.hpp>
#include <myheader.hpp.tinyrefl>
#include <myotherheader.hpp>
#include <myotherheader.hpp.tinyrefl>
#include <tinyrefl/entities.hpp>
void print_all()
{
// Print all reflected entities
tinyrefl::visit_entities(
[](auto /* display_name */, auto index, auto entity, auto /* kind */) {
using Index = decltype(index);
using Entity = decltype(entity);
std::cout << "[entity " << Index::value << "] " << Entity::kind
<< " '" << tinyrefl::full_display_name<Entity>() << "'\n";
});
// Print all enums
tinyrefl::visit_enums([](auto /* display_name */, auto entity) {
using Entity = decltype(entity);
std::cout << "enum " << Entity::name.full_name() << "\n";
for(const auto value : entity)
{
std::cout << " - " << value.name() << "\n";
}
});
// Print all classes
tinyrefl::visit_classes([](auto /* display_name */, auto entity) {
using Entity = decltype(entity);
std::cout << "class " << Entity::name.full_name() << "\n";
});
// Print all member variables
tinyrefl::visit_entities<tinyrefl::entity::MEMBER_VARIABLE>(
[](auto /* display_name */, auto entity) {
using Entity = decltype(entity);
std::cout << "member variable " << Entity::name.full_name() << "\n";
});
}
See the API examples and the documentation for details.
Conan support
Changelog
This release adds Conan support:
- The project is distributed as two different Conan packages,
tinyrefl
andtinyrefl-tool
, for the C++14 reflection API and the metadata codegen tool respectively. See the docs for details. - Support for building tinyrefl without conan has been kept for backwards compatibility, but it may be removed in future releases.
- Cross building is supported in theory using the conan packages, but this is a hot topic right now in conan.
- The release also fixes a major bug in the generated code that prevented complex types (such as template instances) to be used for reflection. See the documentation for details.
What's next? (roadmap)
- Support for custom codegen templates: The work is almost done, I have to rebase the
jinja2_based_tool
branch to include the conan support. This also removes the dependency on LLVM'sCommandLine
module. - Better attribute introspection: Support for simple parsing of attributes using CTRE. The idea is to be able to parse arbitrary user defined attributes like
[[user::property("foo", Getter("getFoo"), Setter("setFoo"))]]
with a simple capture interface. - Windows (MSVC) support: Once libclang distribution is available through conan it's much easier to work on windows, which means I can start working in a command line interface for the codegen tool compatible with MSVC flags.