ICG 2
Electric Boogaloo
SequenceDataType.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Type/DataType.hpp"
4 #include "DataTypeInator.hpp"
5 
6 #include <stddef.h>
7 #include <string>
8 #include <stdexcept>
9 #include <vector>
10 
15 class SequenceDataType : public DataType {
16 
17  public:
18 
25  SequenceDataType( std::string typeSpecifierName, int typeSize, void *(*allocator)(int), void (*deAllocator)(void*) ) ;
26 
27  /* ================================================================================= */
28  /* RULE OF THREE (and a half) INTERFACE */
29  /* ================================================================================= */
30 
34  SequenceDataType ( const SequenceDataType & original ) = delete;
35 
40 
41  /* ==================================================================== */
42  /* VIRTUAL INTERFACE */
43  /* ==================================================================== */
44 
47  bool validate(DataTypeInator* dataTypeInator) override;
48 
49  bool isValid() const override;
50 
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 getTypeSpecName() const override;
68 
71  std::string makeDeclaration(std::string declarator) const override;
72 
73  bool accept(DataTypeVisitor * visitor) const override;
74 
75 
76 
77  /* ==================================================================== */
78  /* CLASS SPECIFIC INTERFACE */
79  /* ==================================================================== */
80 
86  std::shared_ptr<const DataType> getSubType() const;
87 
94  virtual std::vector<void *> getElementAddresses (void * address) const = 0;
95 
102  virtual int getNumElements (void * address) const = 0;
103 
111  virtual bool resize (void * address, int n_elems) const = 0;
112 
119  virtual bool clear (void * address) const = 0;
120 
121 
122  private:
123  bool initSequenceDataType( const DataTypeInator* dataTypeInator, std::string typeSpecName, unsigned int n_elems );
124 
125  size_t typeSize;
126  bool is_valid;
127  std::string typeSpecName;
128  std::string elemTypeName;
129  std::shared_ptr<const DataType> subType;
130  void* (*allocator)(int);
131  void (*deAllocator)(void*);
132 };
133 
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
Represents an STL sequence type - vector, list, deque, array.
Definition: SequenceDataType.hpp:15
std::string getTypeSpecName() const override
Get the Type Spec Name object.
Definition: SequenceDataType.cpp:72
void * createInstance(unsigned int num) const override
Create one or more instances of this type.
Definition: SequenceDataType.cpp:63
SequenceDataType(std::string typeSpecifierName, int typeSize, void *(*allocator)(int), void(*deAllocator)(void *))
Construct an SequenceDataType.
Definition: SequenceDataType.cpp:10
std::shared_ptr< const DataType > getSubType() const
Get the type of the elements of this sequence.
Definition: SequenceDataType.cpp:76
std::string makeDeclaration(std::string declarator) const override
Definition: SequenceDataType.cpp:81
bool validate(DataTypeInator *dataTypeInator) override
Verify that all of the types that are named by this DataType or subordinate DataTypes are resolvable ...
Definition: SequenceDataType.cpp:23
bool accept(DataTypeVisitor *visitor) const override
Definition: SequenceDataType.cpp:85
virtual bool resize(void *address, int n_elems) const =0
resize the underlying container
~SequenceDataType()
Definition: SequenceDataType.cpp:19
void deleteInstance(void *address) const override
Delete this instance.
Definition: SequenceDataType.cpp:67
virtual int getNumElements(void *address) const =0
Given the address of a sequence of this type, get the number of elements in this sequence.
virtual bool clear(void *address) const =0
clear the underlying container
SequenceDataType(const SequenceDataType &original)=delete
bool isValid() const override
Determine whether this type has already been successfully validated.
Definition: SequenceDataType.cpp:48
size_t getSize() const override
Definition: SequenceDataType.cpp:53
virtual std::vector< void * > getElementAddresses(void *address) const =0
Given the address of a sequence of this type, get a list of all the addresses of the elements within.