LoopEdge.hpp 3.21 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*
 * Copyright (C) 2014-2021 DBIS Group - TU Ilmenau, All Rights Reserved.
 *
 * This file is part of the PipeFabric package.
 *
 * PipeFabric 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.
 *
 * PipeFabric 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 PipeFabric. If not,
 * see <http://www.gnu.org/licenses/>.
 */

aliahmadbutt4's avatar
aliahmadbutt4 committed
18

Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
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

#ifndef _LoopEdge_hpp
#define _LoopEdge_hpp

#include "NFAEdge.hpp"

namespace pfabric {
/**
 * @brief  an object represents a loop edge in our engine. the system will stay in this
 * loop until some condition should be satisfied such as reaching the limit of
 * allowed loop
 */
template<class Tin, class Tout, class Tdep>
class LoopEdge;
template<class Tin, class Tout, class Tdep>
class LoopEdge: public NFAEdge<Tin, Tout, Tdep> {

private:
	/**
	 * specify a limit for the number of loop
	 */
	short numOfLoop;
public:
	typedef ns_types::SharedPtr<LoopEdge<Tin, Tout, Tdep>> LoopEdgePtr;
	/**
	 * default constructor to set the edge id and its predicate
	 * @param NFAEdge_id the ID assigned to this edge
	 * @param predicate a condition to check by this edge to stay in
	 */
	LoopEdge(int edgeID, typename NFAEdge<Tin, Tout, Tdep>::EdgePredicate predicate) :
			NFAEdge<Tin, Tout, Tdep>(edgeID, predicate) {
		numOfLoop = std::numeric_limits<short>::max();
	}
	/**
	 * virtual destructor
	 */
	virtual ~LoopEdge() {}
	/**
	 * output member variable information.
	 * @param out the output stream handle.
	 */
aliahmadbutt4's avatar
aliahmadbutt4 committed
60
	virtual void write(std::ostream& out = std::cout) const {
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
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
		out << "This is a loop edge with ID(" << this->edgeID << ") with loop number "
				<< numOfLoop;
	}
	/**
	 * equality comparison operator.
	 * @param rhs The input edge for this edge to compare to
	 * @return True iff this edge has the same predicate as that of rhs
	 */
	bool operator ==(const LoopEdge& rhs) const {
		return NFAEdge<Tin, Tout, Tdep>::operator ==(rhs) && numOfLoop == rhs.getNumOfLoop();
	}

	/**
	 * inequality comparison operator.
	 * @param rhs The input edge for this edge to compare to
	 * @return True iff this edge does not have the same predicate as that of rhs
	 */
	bool operator !=(const LoopEdge& rhs) const {
		return !(this->operator ==(rhs));
	}

	/**
	 * get the edge type (forward edge)
	 * @return as above
	 */
	const typename NFAEdge<Tin, Tout, Tdep>::EdgeType getEdgeType() const {
		return NFAEdge<Tin, Tout, Tdep>::Loop;
	}
	/**
	 * get the number of loops for this edge
	 * @return as above
	 */
	int getNumOfLoop() const {
		return numOfLoop;
	}
	/**
	 * set the number of loops for this edge
	 * @param  num_loop the number of loops for this edge to set
	 */
	void setNumOfLoop(int numLoop) {
		assert(numLoop >= 0);
		numOfLoop = numLoop;
	}

};
//class LoopEdge
}//namespace pfabric

#endif //_LoopEdge_hpp