retdec
enum_type.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_CTYPES_ENUM_TYPE_H
8 #define RETDEC_CTYPES_ENUM_TYPE_H
9 
10 #include <memory>
11 #include <string>
12 #include <vector>
13 
14 #include "retdec/ctypes/type.h"
15 
16 namespace retdec {
17 namespace ctypes {
18 
19 class Context;
20 
24 class EnumType: public Type
25 {
26  public:
30  class Value {
31  public:
33  using ValueType = std::int64_t;
34 
35  public:
36  Value(const std::string &name, ValueType value);
37 
38  const std::string &getName() const;
39  ValueType getValue() const;
40 
41  bool operator==(const Value &other) const;
42  bool operator!=(const Value &other) const;
43 
44  private:
45  std::string name;
47  };
48 
49  public:
52 
53  public:
54  using Values = std::vector<Value>;
55  using iterator = Values::iterator;
56  using const_iterator = Values::const_iterator;
57 
58  public:
59  static std::shared_ptr<EnumType> create(const std::shared_ptr<Context> &context,
60  const std::string &name, const Values &values);
61 
67  const_iterator value_end() const;
68  Values::size_type getValueCount() const;
69  const Value &getValue(Values::size_type index) const;
71 
72  virtual bool isEnum() const override;
73 
76  virtual void accept(Visitor *v) override;
78 
79  private:
80  EnumType(const std::string &name, const Values &values);
81 
82  private:
84 };
85 
86 } // namespace ctypes
87 } // namespace retdec
88 
89 #endif
A representation of enum value.
Definition: enum_type.h:30
std::string name
Definition: enum_type.h:45
ValueType value
Definition: enum_type.h:46
bool operator==(const Value &other) const
Definition: enum_type.cpp:49
std::int64_t ValueType
Type of enum value.
Definition: enum_type.h:33
const std::string & getName() const
Returns enum value's name.
Definition: enum_type.cpp:36
Value(const std::string &name, ValueType value)
Constructs a new enum value.
Definition: enum_type.cpp:26
bool operator!=(const Value &other) const
Definition: enum_type.cpp:54
ValueType getValue() const
Returns enum value's value.
Definition: enum_type.cpp:44
A representation of enum type.
Definition: enum_type.h:25
static std::shared_ptr< EnumType > create(const std::shared_ptr< Context > &context, const std::string &name, const Values &values)
Creates enum type.
Definition: enum_type.cpp:123
virtual void accept(Visitor *v) override
Visitor pattern implementation.
Definition: enum_type.cpp:148
std::vector< Value > Values
Definition: enum_type.h:54
Values values
Definition: enum_type.h:83
iterator value_end()
Returns an iterator past the last enum value.
Definition: enum_type.cpp:78
iterator value_begin()
Returns an iterator to the enum value.
Definition: enum_type.cpp:62
Values::iterator iterator
Definition: enum_type.h:55
Values::const_iterator const_iterator
Definition: enum_type.h:56
Values::size_type getValueCount() const
Returns number of enum's values.
Definition: enum_type.cpp:94
static const Value::ValueType DEFAULT_VALUE
Value used for unknown values.
Definition: enum_type.h:51
EnumType(const std::string &name, const Values &values)
Constructs a new enum type.
Definition: enum_type.cpp:20
virtual bool isEnum() const override
Definition: enum_type.cpp:143
const Value & getValue(Values::size_type index) const
Returns n-th value.
Definition: enum_type.cpp:105
A base class of all C types.
Definition: type.h:22
std::string name
Definition: type.h:48
A base class of all C-types' visitors.
Definition: visitor.h:33
A base class of all C types.
Definition: archive_wrapper.h:19