cgv
reflect_enum.h
1 #pragma once
2 
3 #include "reflection_handler.h"
4 #include "lib_begin.h"
5 
6 namespace 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 
32 template <typename T>
33 struct 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>
cgv::reflect::abst_reflection_traits
abstract interface for type reflection with basic type management and optional string conversion
Definition: reflection_traits.h:24
cgv::reflect::reflection_traits_impl
implementation of the reflection traits providing type specific interface for variable base class
Definition: reflection_traits.h:95
cgv::reflect::enum_reflection_traits::enum_reflection_traits
enum_reflection_traits(const std::string &_declarations="")
construct from declaration string which is of the same syntax as the C++ enum item declaration.
Definition: reflect_enum.h:40
cgv::reflect::ReflectionTraitsKind
ReflectionTraitsKind
different types of reflection traits
Definition: reflection_traits.h:20
cgv::reflect::abst_enum_reflection_traits
type independent functionality for all enum fallback implementations
Definition: reflect_enum.h:11
cgv::reflect::enum_reflection_traits::clone
abst_reflection_traits * clone()
clone function
Definition: reflect_enum.h:52
cgv::reflect::enum_reflection_traits
this type specific reflection traits class is used by the reflect_enum function to reflect enum types
Definition: reflect_enum.h:34
cgv::math::reflect
vec< T > reflect(const vec< T > &v, const vec< T > &n)
calculates the reflected direction of v; n is the normal of the reflecting surface
Definition: vec.h:822
cgv
the cgv namespace
Definition: vr_calib.cxx:9