ICG 2
Electric Boogaloo
EnumDataType.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 #include <stdexcept>
5 
6 #include "Type/DataType.hpp"
7 
8 #include "Enumerator.hpp"
10 
11 
12 
18 class EnumDataType : public DataType {
19 
20 public:
21 
29  EnumDataType( EnumDictionary* enumDictionary,
30  std::string name,
31  size_t sizeof_element);
32 
33  /* ================================================================================= */
34  /* RULE OF THREE (and a half) INTERFACE */
35  /* ================================================================================= */
36 
37  EnumDataType ( const EnumDataType & original ) = delete;
38  ~EnumDataType ();
39  EnumDataType & operator=( EnumDataType rhs ) = delete;
40 
41  /* ==================================================================== */
42  /* VIRTUAL INTERFACE */
43  /* ==================================================================== */
44 
45 
48  bool validate(DataTypeInator* dataTypeInator = NULL) override;
49 
50  bool isValid() const override;
51 
55  size_t getSize() const override;
56 
59  void* createInstance(unsigned int num) const override;
60 
63  void deleteInstance(void* address) const override;
64 
67  std::string toString() const override;
68 
72  std::string getTypeSpecName() const override;
73 
74  bool accept (DataTypeVisitor* visitor) const override;
75 
76 
77  /* ==================================================================== */
78  /* CLASS SPECIFIC INTERFACE */
79  /* ==================================================================== */
80 
86  void clearValue(void * address) const;
87 
94  bool assignValue(void * address, int value) const;
95 
102  int getValue(void *address) const;
103 
109  void addEnumerator( std::string val_name, int value);
110 
117  std::string lookupEnumeratorName(int value) const;
118 
125  bool containsValue(int value) const;
126 
127  static const std::string invalid_str;
128 
129 private:
130  EnumDataType() {};
131  std::vector<Enumerator*> enum_list;
132  size_t enumSize;
133  std::string name;
134 
135  // Pointer to EnumDictionary that this belongs to
136  // TODO: does this belong here?
137  EnumDictionary * enumDictionary;
138 };
139 
140 
Register and manage datatypes at runtime.
Definition: DataTypeInator.hpp:16
Abstract base class for a DataTypeVisitor.
Definition: DataTypeVisitor.hpp:20
Abstract base class for DataTypes.
Definition: DataType.hpp:11
Enum represents an Enumerated data type.
Definition: EnumDataType.hpp:18
void clearValue(void *address) const
Set the instance of this type at the given address to 0.
Definition: EnumDataType.cpp:56
std::string toString() const override
Definition: EnumDataType.cpp:101
bool validate(DataTypeInator *dataTypeInator=NULL) override
Verify that all of the types that are named by this DataType or subordinate DataTypes are resolvable ...
Definition: EnumDataType.cpp:35
bool containsValue(int value) const
Determine if this enum type has something defined to this value.
Definition: EnumDataType.cpp:142
bool accept(DataTypeVisitor *visitor) const override
Definition: EnumDataType.cpp:120
EnumDataType(const EnumDataType &original)=delete
static const std::string invalid_str
Definition: EnumDataType.hpp:127
EnumDataType & operator=(EnumDataType rhs)=delete
void deleteInstance(void *address) const override
Delete this instance.
Definition: EnumDataType.cpp:52
void * createInstance(unsigned int num) const override
Create one or more instances of this type.
Definition: EnumDataType.cpp:47
bool assignValue(void *address, int value) const
Assign the value to the instance of this data member.
Definition: EnumDataType.cpp:66
std::string getTypeSpecName() const override
Definition: EnumDataType.cpp:116
int getValue(void *address) const
Get the Value of an instance of this type with the given address.
Definition: EnumDataType.cpp:86
~EnumDataType()
Definition: EnumDataType.cpp:24
bool isValid() const override
Determine whether this type has already been successfully validated.
Definition: EnumDataType.cpp:39
size_t getSize() const override
Definition: EnumDataType.cpp:43
std::string lookupEnumeratorName(int value) const
Get the string name that corresponds to the integer for this type.
Definition: EnumDataType.cpp:132
void addEnumerator(std::string val_name, int value)
Add a name-value pair to this enum data type.
Definition: EnumDataType.cpp:124
Definition: EnumDictionary.hpp:11