cgv
Loading...
Searching...
No Matches
reflect_enum.h
1#pragma once
2
3#include "reflection_handler.h"
4#include "lib_begin.h"
5
6namespace cgv {
7 namespace reflect {
8
11{
13 static const bool has_enum = true;
14 static const ReflectionTraitsKind kind = RTK_STRING;
15
16 virtual std::vector<cgv::utils::token>& ref_names() = 0;
17 virtual std::vector<int>& ref_values() = 0;
18 virtual std::string& declarations() const = 0;
19
20 void parse_declarations();
21 bool has_string_conversions() const;
22 bool set_from_string(void* member_ptr, const std::string& str_val);
23 void get_to_string(const void* member_ptr, std::string& str_val);
24
25 bool has_enum_interface() const;
26 unsigned get_nr_enum_items() const;
27 std::string get_enum_name(unsigned i) const;
28 int get_enum_value(unsigned i) const;
29};
30
32template <typename T>
33struct enum_reflection_traits : public reflection_traits_impl<T, abst_enum_reflection_traits>
34{
35 std::vector<cgv::utils::token>& ref_names() { static std::vector<cgv::utils::token> names; return names; }
36 std::vector<int>& ref_values() { static std::vector<int> values; return values; }
37 std::string& declarations() const { static std::string decs; return decs; }
39
40 enum_reflection_traits(const std::string& _declarations = "")
41 {
42 if (!_declarations.empty()) {
43 declarations() = _declarations;
44 this->parse_declarations();
45 }
46#ifdef REFLECT_TRAITS_WITH_DECLTYPE
47 if (declarations().empty())
48 get_reflection_traits(T());
49#endif
50 }
53};
54
55 }
56}
57
58#include <cgv/config/lib_end.h>
ReflectionTraitsKind
different types of reflection traits
the cgv namespace
Definition print.h:11
type independent functionality for all enum fallback implementations
abstract interface for type reflection with basic type management and optional string conversion
this type specific reflection traits class is used by the reflect_enum function to reflect enum types
enum_reflection_traits(const std::string &_declarations="")
construct from declaration string which is of the same syntax as the C++ enum item declaration.
abst_reflection_traits * clone()
clone function
implementation of the reflection traits providing type specific interface for variable base class