StructurePool.hpp 3.63 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

#ifndef StructurePool_hpp_
#define StructurePool_hpp_
#include "NFAStructure.hpp"
#include "util/ValueIDMultimap.hpp"
#include "NFAController.hpp"
/**
 * @brief A structures pool to keep all lived structures (sequences) inside. It is responsible
 * for creating the sequences and put them inside a multi-map to retrieve them as fast as possible. In other words, It is a multi-map container with a partition pointer key and
 * sequence pointer as value. Partitioning technique is used to speed up the lookup to all current
 * lived structures. To detect the complex event, then engine should go through this pool (or a partition "part") and process these sequences.
 */
namespace pfabric {
32
template<class TinPtr, class ToutPtr, class TdepPtr>
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
33
class StructurePool: public ValueIDMultimap<
34
35
		typename NFAStructure<TinPtr, ToutPtr, TdepPtr>::NFAStructurePtr, TinPtr> {
	typedef boost::shared_ptr<StructurePool<TinPtr, ToutPtr, TdepPtr>> StructurePoolPtr;
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
public:
	/**
	 * A default constructor
	 * Nothing to do
	 */
	StructurePool() {}
	/**
	 * A virtual destructor
	 * Nothing to do
	 */
	virtual ~StructurePool() {}
	/**
	 * Get a structure from this pool after creating it. It receive its partition and a pointer to the original
	 * NFA. Once this function creates a new sequence, it puts the sequence inside a multi-map
	 * by using appendValue. It also lets the sequence to know its partition in this pool.
	 * @param nfa the original NFA for the system which is shared among all running sequences
	 * @param p the partition of this sequence in the pool
	 * @return a created sequence from this pool
	 */
55
56
	const typename NFAStructure<TinPtr, ToutPtr, TdepPtr>::NFAStructurePtr getStructure(
			const typename NFAController<TinPtr, ToutPtr, TdepPtr>::NFAControllerPtr& nfa,
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
57
			Partition<TinPtr>* p) {
58
59
		typename NFAStructure<TinPtr, ToutPtr, TdepPtr>::NFAStructurePtr str(
				new NFAStructure<TinPtr, ToutPtr, TdepPtr>(nfa));
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
60
61
62
63
64
65
66
67
		str->setEqualityValue(p);
		this->appendValue(p, str);
		return str;
	}
	/**
	 * Output the information  into ostream object
	 * @param out The output stream handle.
	 */
aliahmadbutt4's avatar
aliahmadbutt4 committed
68
	void print(std::ostream& out = std::cout) const {
Kai-Uwe Sattler's avatar
Kai-Uwe Sattler committed
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
		/*
		 os << std::endl;
		 for (value_id_multimap<
		 structure_ptr>::multimap_iterator it =
		 this->value_id.begin(); it != this->value_id.end(); it++) {
		 //os << " [" << it->first << ", ";
		 //it->second->print(os);
		 os << "]";
		 }
		 os << std::endl;*/
	}

	/**
	 * Remove all structure except the structures which have this id or more
	 * @param str the structure id to remove all structure above it
	 */
	void removeAllExceptMore(long str) {
		/*
		 for (value_id_map<structure_ptr>::map_const_iterator it =
		 this->value_id.begin(); it != this->value_id.end();) {
		 if (it->first < str) {
		 this->value_id.erase(it++);
		 } else {
		 ++it;
		 }
		 }
		 */
	}

};

}
#endif /* StructurePool_hpp_ */