-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Full list of translation unit reflected entities
- Loading branch information
1 parent
6a524b2
commit e76e34b
Showing
10 changed files
with
297 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#ifndef TINYREFL_EXAMPLE2_HPP | ||
#define TINYREFL_EXAMPLE2_HPP | ||
|
||
#include <string> | ||
#include <tinyrefl/utils/enum_value_attributes.hpp> | ||
|
||
namespace example2 | ||
{ | ||
|
||
struct A | ||
{ | ||
int a = 42; | ||
}; | ||
|
||
|
||
struct B | ||
{ | ||
const char* b = "hello"; | ||
}; | ||
|
||
enum class Enum | ||
{ | ||
A, | ||
B, | ||
C, | ||
D, | ||
E = 42 | ||
}; | ||
|
||
struct C : public A, public B | ||
{ | ||
public: | ||
[[tinyrefl::ignore]] std::string ignore_me; | ||
std::string hey_im_here = "hey, I'm here"; | ||
B subobject; | ||
|
||
C() = default; | ||
explicit C(const std::string& str) {} | ||
[[C]] C(int a, int b) {} | ||
|
||
[[f, f1, f2]] void f(int a, int b) const {}; | ||
[[f]] void f(int a, int b){}; | ||
[[f]] void f(){}; | ||
[[f]] void f() const {}; | ||
|
||
enum class Enum | ||
{ | ||
A TINYREFL_ENUM_VALUE_ATTRIBUTE(A), | ||
B TINYREFL_ENUM_VALUE_ATTRIBUTE(B), | ||
C TINYREFL_ENUM_VALUE_ATTRIBUTE(C), | ||
D TINYREFL_ENUM_VALUE_ATTRIBUTE(D), | ||
E TINYREFL_ENUM_VALUE_ATTRIBUTE(E), | ||
F TINYREFL_ENUM_VALUE_ATTRIBUTE(F) | ||
}; | ||
|
||
[[e]] Enum e = Enum::A; | ||
}; | ||
|
||
std::ostream& operator<<(std::ostream& os, const B& b); | ||
std::ostream& operator<<(std::ostream& os, const Enum& value); | ||
std::ostream& operator<<(std::ostream& os, const C::Enum& value); | ||
} // namespace example2 | ||
|
||
#endif // TINYREFL_EXAMPLE2_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#ifndef TINYREFL_ENTITIES_HPP_INCLUDED | ||
#define TINYREFL_ENTITIES_HPP_INCLUDED | ||
|
||
#include <type_traits> | ||
|
||
#if !defined(TINYREFL_API_HPP) || !defined(TINYREFL_ENTITIES) | ||
#error \ | ||
"To use this header, first include your reflected headers, then <tinyrefl/api.hpp>, then your reflected headers generated code (.tinyrefl header files), and then this header" | ||
#endif | ||
|
||
namespace tinyrefl | ||
{ | ||
|
||
using entities = tinyrefl::meta::fmap_t< | ||
tinyrefl::meta::defer<tinyrefl::backend::metadata_of_entity_name>, | ||
TINYREFL_ENTITIES>; | ||
|
||
template<typename Entity> | ||
constexpr ctti::detail::cstring display_name(Entity entity = Entity{}) | ||
{ | ||
static_assert(std::is_class<Entity>::value, ""); | ||
return tinyrefl::backend::display_name<Entity>(); | ||
} | ||
|
||
template<typename Entity> | ||
constexpr ctti::detail::cstring full_display_name(Entity entity = Entity{}) | ||
{ | ||
static_assert(std::is_class<Entity>::value, ""); | ||
return tinyrefl::backend::full_display_name<Entity>(); | ||
} | ||
|
||
template<typename... Visitors> | ||
void visit_entities(Visitors... visitors) | ||
{ | ||
tinyrefl::meta::foreach<tinyrefl::entities>( | ||
[visitor = tinyrefl::overloaded_function_default(visitors...)]( | ||
auto type, auto index) { | ||
using Entity = typename decltype(type)::type; | ||
|
||
static_assert(std::is_class<Entity>::value, ""); | ||
|
||
visitor( | ||
tinyrefl::display_name<Entity>(), | ||
index, | ||
Entity{}, | ||
kind_tag_value<Entity::kind>); | ||
}); | ||
} | ||
|
||
template<tinyrefl::entity Kind, typename Visitor> | ||
void visit_entities(Visitor visitor) | ||
{ | ||
visit_entities( | ||
[visitor]( | ||
auto display_name, auto /* index */, auto entity, kind_tag<Kind>) { | ||
visitor(display_name, entity); | ||
}); | ||
} | ||
|
||
template<typename Visitor> | ||
void visit_classes(Visitor visitor) | ||
{ | ||
visit_entities<tinyrefl::entity::CLASS>(visitor); | ||
} | ||
|
||
template<typename Visitor> | ||
void visit_enums(Visitor visitor) | ||
{ | ||
visit_entities<tinyrefl::entity::ENUM>(visitor); | ||
} | ||
} // namespace tinyrefl | ||
|
||
#endif // TINYREFL_ENTITIES_HPP_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.