1
/* PeTe - Petri Engine exTremE
2
* Copyright (C) 2011 Jonas Finnemann Jensen <jopsen@gmail.com>,
3
* Thomas Søndersø Nielsen <primogens@gmail.com>,
4
* Lars Kærlund Østergaard <larsko@gmail.com>,
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#ifndef VALIDATIONBUILDER_H
20
#define VALIDATIONBUILDER_H
22
#include "AbstractPetriNetBuilder.h"
28
namespace PetriEngine{
30
class ValidationBuilder;
32
/** Error experienced during Validation */
33
class ValidationError{
34
/** Create error for an arc */
35
ValidationError(const std::string& startId,
36
const std::string& endId,
37
const std::string& text)
38
: _startId(startId), _endId(endId), _text(text) {
39
_hasExprError = false;
40
_isConditionError = false;
43
/** Create error for a PQL expression */
44
ValidationError(const std::string& id,
45
const PQL::ExprError& error,
46
bool isConditionError)
47
: _startId(id), _exprError(error) {
49
_isConditionError = isConditionError;
52
/** Create error for an entity */
53
ValidationError(const std::string& id,
54
const std::string& text)
55
: _startId(id), _text(text) {
56
_hasExprError = false;
57
_isConditionError = false;
60
/** Identifier related to the error, start identifier if related to an arc */
61
const std::string& startIdentifier() const { return _startId; }
63
/** End identifier to the error if related to an arc, otherwise empty */
64
const std::string& endIdentifier() const { return _endId; }
66
/** True, if this error carries and non-empty PQL::ExprError */
67
bool hasExprError() const { return _hasExprError; }
69
/** True, if this error carries an non-empty PQL::ExprError
70
* related to a condition, false if it's related to AssignmentExpression
71
* or carries an empty PQL::ExprError. See also hasExprError().
73
bool isConditionError() const {return _isConditionError; }
75
/** Expression error, found in an expression */
76
const PQL::ExprError& exprError() const { return _exprError; }
78
/** Explanation of the error, empty of it's carries an PQL::ExprError */
79
const std::string& text() const { return _text; }
81
std::string _startId, _endId;
83
bool _isConditionError;
84
PQL::ExprError _exprError;
86
friend class ValidationBuilder;
89
/** Builder for validating the consistency of Petri Nets
90
* @remarks This builder ensures the following properties:
91
* - Identifiers are unique
92
* - Conditions can be parsed and analysed without problems
93
* - Assignments can be parsed and analysed without problems
94
* - Initial value of variables is within range
95
* - The inital marking isn't negative
96
* - No weights are negative
97
* - Arcs goes between existing start and end points of correct type
99
class ValidationBuilder : public AbstractPetriNetBuilder
101
/** Arc, just internal stuff */
103
Arc(const std::string& start,
104
const std::string& end){
113
void addVariable(const std::string& name,
116
void addPlace(const std::string& name,
120
void addTransition(const std::string& name,
121
const std::string& conditions,
122
const std::string& assignments,
125
void addInputArc(const std::string& place,
126
const std::string& transition,
128
void addOutputArc(const std::string& transition,
129
const std::string& place,
131
/** Stop accepting stuff, and start validating
132
* @return true, if no errors were found
136
/** Get errors found during evaluation */
137
const std::vector<ValidationError>& errors() const { return _errors; }
139
/** Get the number of matching identifiers */
140
int countMatchingIds(const std::string& id);
141
std::vector<ValidationError> _errors;
142
std::vector<std::string> _varNames;
143
std::vector<std::string> _placeNames;
144
std::vector<std::string> _transitionNames;
145
std::vector<std::string> _conditions;
146
std::vector<std::string> _assignments;
147
std::vector<Arc> _inputArcs;
148
std::vector<Arc> _outputArcs;
153
#endif // VALIDATIONBUILDER_H