-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTypeDescriptor.hpp
More file actions
69 lines (56 loc) · 1.63 KB
/
TypeDescriptor.hpp
File metadata and controls
69 lines (56 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef EXPRINTER_TYPEDESCRIPTOR_HPP
#define EXPRINTER_TYPEDESCRIPTOR_HPP
#include <string>
#include <iostream>
#include <vector>
class TypeDescriptor {
public:
enum types {INTEGER, DOUBLE, STRING, ARRAY, NOT_SPECIFIED};
TypeDescriptor(): _type{NOT_SPECIFIED} {}
TypeDescriptor(types type): _type{type} {}
types &type() { return _type; }
virtual ~TypeDescriptor() {}
virtual void print() = 0;
private:
types _type;
};
class IntegerDescriptor : public TypeDescriptor {
public:
IntegerDescriptor(int value): TypeDescriptor(INTEGER), _value(value) {}
int value() { return _value; }
void print() { std::cout << value(); }
private:
int _value;
};
class DoubleDescriptor : public TypeDescriptor {
public:
DoubleDescriptor(double value): TypeDescriptor(DOUBLE), _value(value) {}
double value() { return _value; }
void print() { std::cout << value(); }
private:
double _value;
};
class StringDescriptor : public TypeDescriptor {
public:
StringDescriptor(std::string value): TypeDescriptor(STRING), _value(value) {}
std::string value() { return _value; }
void print() { std::cout << value(); }
private:
std::string _value;
};
class ArrayDescriptor : public TypeDescriptor {
public:
ArrayDescriptor();
ArrayDescriptor(std::vector<TypeDescriptor*> values, types elType);
std::vector<TypeDescriptor*> value() const;
std::vector<TypeDescriptor*> &value();
types &elType();
int numElements() const;
int &numElements();
void print();
private:
types _elType;
int _numElements;
std::vector<TypeDescriptor*> _values;
};
#endif //EXPRINTER_TYPEDESCRIPTOR_HPP