~verifypn-cpn/verifypn/unitTest

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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* PeTe - Petri Engine exTremE
 * Copyright (C) 2011  Jonas Finnemann Jensen <jopsen@gmail.com>,
 *                     Thomas Søndersø Nielsen <primogens@gmail.com>,
 *                     Lars Kærlund Østergaard <larsko@gmail.com>,
 *                     Peter Gjøl Jensen <root@petergjoel.dk>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef ABSTRACTPETRINETBUILDER_H
#define ABSTRACTPETRINETBUILDER_H

#include <string>

#include "PQL/PQL.h"
#include "Colored/Multiset.h"
#include "Colored/Expressions.h"

namespace PetriEngine {

    /** Abstract builder for petri nets */
    class AbstractPetriNetBuilder {
    protected:
        bool _isColored = false;
        
    public:
        /** Add a new place with a unique name */
        virtual void addPlace(const std::string& name,
                int tokens,
                double x = 0,
                double y = 0) = 0;
        /** Add a new colored place with a unique name */
        virtual void addPlace(const std::string& name,
                Colored::ColorType* type,
                Colored::Multiset&& tokens,
                double x = 0,
                double y = 0)
        {
            std::cerr << "Colored places are not supported in standard P/T nets" << std::endl;
            exit(ErrorCode);
        }
        /** Add a new transition with a unique name */
        virtual void addTransition(const std::string& name,
                double x = 0,
                double y = 0) = 0;
        /** Add a new colored transition with a unique name */
        virtual void addTransition(const std::string& name,
                const Colored::GuardExpression_ptr& guard,
                double x = 0,
                double y = 0)
        {
            std::cerr << "Colored transitions are not supported in standard P/T nets" << std::endl;
            exit(ErrorCode);
        }
        /** Add input arc with given weight */
        virtual void addInputArc(const std::string& place,
                const std::string& transition,
                bool inhibitor,
                int) = 0;
        /** Add colored input arc with given arc expression */
        virtual void addInputArc(const std::string& place,
                const std::string& transition,
                const Colored::ArcExpression_ptr& expr)
        {
            std::cerr << "Colored input arcs are not supported in standard P/T nets" << std::endl;
            exit(ErrorCode);
        }
        /** Add output arc with given weight */
        virtual void addOutputArc(const std::string& transition,
                const std::string& place,
                int weight = 1) = 0;
        /** Add output arc with given arc expression */
        virtual void addOutputArc(const std::string& transition,
                const std::string& place,
                const Colored::ArcExpression_ptr& expr)
        {
            std::cerr << "Colored output arcs are not supported in standard P/T nets" << std::endl;
            exit(ErrorCode);
        }
        /** Add color types with id */
        virtual void addColorType(const std::string& id,
                Colored::ColorType* type)
        {
            std::cerr << "Color types are not supported in standard P/T nets" << std::endl;
            exit(ErrorCode);
        }
        
        virtual void enableColors() {
            _isColored = true;
        }

        virtual bool isColored() const {
            return _isColored;
        }

        virtual void sort() = 0;
        
        virtual ~AbstractPetriNetBuilder() {
        }
    };

}

#endif // ABSTRACTPETRINETBUILDER_H