~verifypn-cpn/verifypn/unitTest

« back to all changes in this revision

Viewing changes to PetriEngine/Colored/TimeInvariant.h

  • Committer: Mark Glavind
  • Date: 2019-04-03 12:35:47 UTC
  • mfrom: (215.1.16 TACPNParser)
  • Revision ID: mglavi14@student.aau.dk-20190403123547-6sqbnfo1xeg3gq81
 merge from TACPNParser, feature finished

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Created by niels on 3/20/19.
 
3
//
 
4
 
 
5
#ifndef VERIFYPN_TIMEINVARIANT_H
 
6
#define VERIFYPN_TIMEINVARIANT_H
 
7
 
 
8
#include <string>
 
9
#include <map>
 
10
#include <limits>
 
11
#include <algorithm>
 
12
#include <cctype>
 
13
#include <locale>
 
14
#include "Colors.h"
 
15
 
 
16
namespace PetriEngine {
 
17
    namespace Colored{
 
18
        class TimeInvariant{
 
19
 
 
20
        public:
 
21
            TimeInvariant(Colored::Color color) : strictComparison(true), bound(std::numeric_limits<int>::max()), color(color) {};
 
22
            TimeInvariant(bool strictComparison, int bound, PetriEngine::Colored::Color color) : strictComparison(strictComparison), bound(bound), color(color) { };
 
23
            TimeInvariant(const TimeInvariant& ti) : strictComparison(ti.strictComparison), bound(ti.bound), color(ti.color) { };
 
24
            TimeInvariant& operator=(const TimeInvariant& ti)
 
25
            {
 
26
                strictComparison = ti.strictComparison;
 
27
                bound = ti.bound;
 
28
                return *this;
 
29
            }
 
30
 
 
31
            virtual ~TimeInvariant(){ /*Left empty*/  };
 
32
 
 
33
        public: // inspectors
 
34
            void print(std::ostream& out) const;
 
35
            inline const int getBound() const { return bound; }
 
36
            inline const bool isBoundStrict() const { return strictComparison; }
 
37
 
 
38
        public: // statics
 
39
            static TimeInvariant createFor(const std::string& invariant, std::vector<const Colored::Color*> colors);
 
40
            static Colored::Color createColor(std::vector<const Colored::Color*> colors);
 
41
 
 
42
        private: // data
 
43
            bool strictComparison;
 
44
            int bound;
 
45
            Colored::Color color;
 
46
        };
 
47
 
 
48
        inline bool operator==(const TimeInvariant& a, const TimeInvariant& b)
 
49
        {
 
50
            return a.getBound() == b.getBound() && a.isBoundStrict() == b.isBoundStrict();
 
51
        }
 
52
 
 
53
        inline bool operator!=(const TimeInvariant& a, const TimeInvariant& b)
 
54
        {
 
55
            return !(a == b);
 
56
        }
 
57
 
 
58
        inline std::ostream& operator<<(std::ostream& out, const TimeInvariant& invariant)
 
59
        {
 
60
            invariant.print(out);
 
61
            return out;
 
62
        }
 
63
        /*
 
64
        *  Singleton pattern from:
 
65
        * https://stackoverflow.com/questions/1008019/c-singleton-design-pattern
 
66
        */
 
67
        class TimeInvariantConstant : public TimeInvariant {
 
68
        private:
 
69
            TimeInvariantConstant();
 
70
 
 
71
        public:
 
72
            static const TimeInvariant* starColorDotConstant() {
 
73
                static TimeInvariantConstant _instance;
 
74
                return &_instance;
 
75
            }
 
76
            TimeInvariantConstant(TimeInvariant const&) = delete;
 
77
            void operator=(TimeInvariant const&) = delete;
 
78
            bool operator==(const TimeInvariant other) {
 
79
                return true;
 
80
            }
 
81
        };
 
82
    }
 
83
}
 
84
 
 
85
#endif //VERIFYPN_TIMEINVARIANT_H