2
* To change this license header, choose License Headers in Project Properties.
3
* To change this template file, choose Tools | Templates
4
* and open the template in the editor.
11
* Created on February 19, 2018, 8:22 PM
23
namespace PetriEngine {
27
// Should make constructor protected, and make ColorType Friendly
30
friend std::ostream& operator<< (std::ostream& stream, const Color& color);
33
const std::vector<const Color*> _tuple;
34
ColorType* _colorType;
35
std::string _colorName;
39
Color(ColorType* colorType, uint32_t id, std::vector<const Color*>& colors);
40
Color(ColorType* colorType, uint32_t id, const char* color);
42
bool isTuple() const {
43
return _tuple.size() > 1;
46
const std::string& getColorName() const {
47
if (this->isTuple()) {
48
throw "Cannot get color from a tuple color.";
53
ColorType* getColorType() const {
57
uint32_t getId() const {
61
const Color* operator[] (size_t index) const;
62
bool operator< (const Color& other) const;
63
bool operator> (const Color& other) const;
64
bool operator<= (const Color& other) const;
65
bool operator>= (const Color& other) const;
67
bool operator== (const Color& other) const {
68
return _colorType == other._colorType && _id == other._id;
70
bool operator!= (const Color& other) const {
71
return !((*this) == other);
74
const Color& operator++ () const;
75
const Color& operator-- () const;
77
std::string toString() const;
78
static std::string toString(const Color* color);
79
static std::string toString(const std::vector<const Color*>& colors);
83
* Singleton pattern from:
84
* https://stackoverflow.com/questions/1008019/c-singleton-design-pattern
86
class DotConstant : public Color {
91
static const Color* dotConstant() {
92
static DotConstant _instance;
97
DotConstant(DotConstant const&) = delete;
98
void operator=(DotConstant const&) = delete;
100
bool operator== (const DotConstant& other) {
107
typedef std::vector<Color>::iterator iterator;
108
typedef std::vector<Color>::const_iterator const_iterator;
111
std::vector<Color> _colors;
115
ColorType(std::vector<ColorType*> elements);
116
ColorType() : _colors() {
117
_id = (uintptr_t)this;
120
void addColor(const char* colorName);
121
void addColor(std::vector<const Color*>& colors);
123
_colors.push_back(*DotConstant::dotConstant());
126
size_t size() const {
127
return _colors.size();
130
const Color& operator[] (size_t index) const {
131
return _colors[index];
134
const Color& operator[] (int index) const {
135
return _colors[index];
138
const Color& operator[] (uint32_t index) const {
139
return _colors[index];
142
const Color& operator[] (const char* index) const;
144
const Color& operator[] (std::string index) const {
145
return (*this)[index.c_str()];
148
bool operator== (const ColorType& other) const {
149
return _id == other._id;
157
return _colors.begin();
160
const_iterator begin() const {
161
return _colors.begin();
165
return _colors.end();
168
const_iterator end() const {
169
return _colors.end();
175
ColorType* colorType;
182
bool operator==(Binding& other) {
183
return var->name.compare(other.var->name);
189
#endif /* COLORS_H */