siplasplas
A library for C++ reflection and introspection
enum.hpp
1 #ifndef SIPLASPLAS_REFLECTION_DYNAMIC_ENUM_HPP
2 #define SIPLASPLAS_REFLECTION_DYNAMIC_ENUM_HPP
3 
4 #include "entity.hpp"
5 #include <siplasplas/typeerasure/typeinfo.hpp>
6 #include <siplasplas/typeerasure/simpleany.hpp>
7 
8 namespace cpp
9 {
10 
11 namespace dynamic_reflection
12 {
13 
18 class SIPLASPLAS_REFLECTION_DYNAMIC_EXPORT Enum : public Entity
19 {
20 public:
34  static std::shared_ptr<Enum> create(
35  const SourceInfo& sourceInfo,
36  const cpp::typeerasure::TypeInfo& type,
37  const cpp::typeerasure::TypeInfo& underlyingType,
38  const std::vector<std::string>& constantsNames,
39  const std::vector<std::int64_t>& constantsValues
40  );
41 
53  static Enum& fromEntity(const std::shared_ptr<Entity>& entity);
54 
58  std::size_t count() const;
59 
66  const std::string& name(std::size_t i) const;
67 
71  const std::vector<std::string>& names() const;
72 
84  std::int64_t value(std::size_t i) const;
85 
89  const std::vector<std::int64_t>& values() const;
90 
96  bool isUnsigned() const;
97 
104  std::int64_t fromString(const std::string& name) const;
105 
113  const std::string& toString(std::int64_t value) const;
114 
115 private:
116  Enum(
117  const SourceInfo& sourceInfo,
118  const cpp::typeerasure::TypeInfo& type,
119  const cpp::typeerasure::TypeInfo& underlyingType,
120  const std::vector<std::string>& constantsNames,
121  const std::vector<std::int64_t>& constantsValues
122  );
123 
125  cpp::typeerasure::TypeInfo _underlyingType;
126  std::vector<std::string> _names;
127  std::vector<std::int64_t> _values;
128 };
129 
130 }
131 
132 }
133 
134 #endif // SIPLASPLAS_REFLECTION_DYNAMIC_ENUM_HPP
Definition: canary_allocator.hpp:7
Stores dynamic reflection information of an enumeration type.
Definition: enum.hpp:18
Contains minimal information to execute the value semantics operations of a type. ...
Definition: typeinfo.hpp:115
Represents a C++ semantic entity (Class, function, namespace, etc) and manages its dynamic reflection...
Definition: entity.hpp:22