~verifypn-maintainers/verifypn/emptyTracePrint

« back to all changes in this revision

Viewing changes to PetriEngine/Colored/Colors.h

  • Committer: Jiri Srba
  • Date: 2018-04-18 10:58:36 UTC
  • mfrom: (197.3.78 cpn_ctlss)
  • Revision ID: srba.jiri@gmail.com-20180418105836-a5rha272u0om4u77
merged in branch lp:~verifypn-cpn/verifypn/cpn_ctlss/

CPN unfolding
CPN linear overapproximation
Export of reduced queries and model
parallel query simplification
TAR for P/T nets
Improved structural reduction rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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.
 
5
 */
 
6
 
 
7
/* 
 
8
 * File:   Colors.h
 
9
 * Author: andreas
 
10
 *
 
11
 * Created on February 19, 2018, 8:22 PM
 
12
 */
 
13
 
 
14
#ifndef COLORS_H
 
15
#define COLORS_H
 
16
 
 
17
#include <stdint.h>
 
18
#include <stddef.h>
 
19
#include <string>
 
20
#include <string.h>
 
21
#include <vector>
 
22
 
 
23
namespace PetriEngine {
 
24
    namespace Colored {
 
25
        class ColorType;
 
26
        
 
27
        // Should make constructor protected, and make ColorType Friendly
 
28
        class Color {
 
29
        public:
 
30
            friend std::ostream& operator<< (std::ostream& stream, const Color& color);
 
31
            
 
32
        protected:
 
33
            const std::vector<const Color*> _tuple;
 
34
            ColorType* _colorType;
 
35
            std::string _colorName;
 
36
            uint32_t _id;
 
37
            
 
38
        public:
 
39
            Color(ColorType* colorType, uint32_t id, std::vector<const Color*>& colors);
 
40
            Color(ColorType* colorType, uint32_t id, const char* color);
 
41
            
 
42
            bool isTuple() const {
 
43
                return _tuple.size() > 1;
 
44
            }
 
45
            
 
46
            const std::string& getColorName() const {
 
47
                if (this->isTuple()) {
 
48
                    throw "Cannot get color from a tuple color.";
 
49
                }
 
50
                return _colorName;
 
51
            }
 
52
            
 
53
            ColorType* getColorType() const {
 
54
                return _colorType;
 
55
            }
 
56
            
 
57
            uint32_t getId() const {
 
58
                return _id;
 
59
            }
 
60
            
 
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;
 
66
            
 
67
            bool operator== (const Color& other) const {
 
68
                return _colorType == other._colorType && _id == other._id;
 
69
            }
 
70
            bool operator!= (const Color& other) const {
 
71
                return !((*this) == other);
 
72
            }
 
73
            
 
74
            const Color& operator++ () const;
 
75
            const Color& operator-- () const;
 
76
            
 
77
            std::string toString() const;
 
78
            static std::string toString(const Color* color);
 
79
            static std::string toString(const std::vector<const Color*>& colors);
 
80
        };
 
81
        
 
82
        /*
 
83
         *  Singleton pattern from: 
 
84
         * https://stackoverflow.com/questions/1008019/c-singleton-design-pattern
 
85
         */
 
86
        class DotConstant : public Color {
 
87
        private:
 
88
            DotConstant();
 
89
            
 
90
        public:
 
91
            static const Color* dotConstant() {
 
92
                static DotConstant _instance;
 
93
                
 
94
                return &_instance;
 
95
            }
 
96
            
 
97
            DotConstant(DotConstant const&) = delete;
 
98
            void operator=(DotConstant const&) = delete;
 
99
 
 
100
            bool operator== (const DotConstant& other) {
 
101
                return true;
 
102
            }
 
103
        };
 
104
        
 
105
        class ColorType {
 
106
        public:
 
107
            typedef std::vector<Color>::iterator iterator;
 
108
            typedef std::vector<Color>::const_iterator const_iterator;
 
109
            
 
110
        private:
 
111
            std::vector<Color> _colors;
 
112
            uintptr_t _id;
 
113
            
 
114
        public:
 
115
            ColorType(std::vector<ColorType*> elements);
 
116
            ColorType() : _colors() {
 
117
                _id = (uintptr_t)this;
 
118
            }
 
119
            
 
120
            void addColor(const char* colorName);
 
121
            void addColor(std::vector<const Color*>& colors);
 
122
            void addDot() {
 
123
                _colors.push_back(*DotConstant::dotConstant());
 
124
            }
 
125
            
 
126
            size_t size() const {
 
127
                return _colors.size();
 
128
            }
 
129
            
 
130
            const Color& operator[] (size_t index) const {
 
131
                return _colors[index];
 
132
            }
 
133
            
 
134
            const Color& operator[] (int index) const {
 
135
                return _colors[index];
 
136
            }
 
137
            
 
138
            const Color& operator[] (uint32_t index) const {
 
139
                return _colors[index];
 
140
            }
 
141
            
 
142
            const Color& operator[] (const char* index) const;
 
143
            
 
144
            const Color& operator[] (std::string index) const {
 
145
                return (*this)[index.c_str()];
 
146
            }
 
147
            
 
148
            bool operator== (const ColorType& other) const {
 
149
                return _id == other._id;
 
150
            }
 
151
 
 
152
            uintptr_t getId() {
 
153
                return _id;
 
154
            }
 
155
            
 
156
            iterator begin() {
 
157
                return _colors.begin();
 
158
            }
 
159
            
 
160
            const_iterator begin() const {
 
161
                return _colors.begin();
 
162
            }
 
163
            
 
164
            iterator end() {
 
165
                return _colors.end();
 
166
            }
 
167
            
 
168
            const_iterator end() const {
 
169
                return _colors.end();
 
170
            }
 
171
        };
 
172
        
 
173
        struct Variable {
 
174
            std::string name;
 
175
            ColorType* colorType;
 
176
        };
 
177
        
 
178
        struct Binding {
 
179
            Variable* var;
 
180
            const Color* color;
 
181
            
 
182
            bool operator==(Binding& other) {
 
183
                return var->name.compare(other.var->name);
 
184
            }
 
185
        };
 
186
    }
 
187
}
 
188
 
 
189
#endif /* COLORS_H */
 
190