OpenASIP
2.0
src
tools
Informer.cc
Go to the documentation of this file.
1
/*
2
Copyright (c) 2002-2009 Tampere University.
3
4
This file is part of TTA-Based Codesign Environment (TCE).
5
6
Permission is hereby granted, free of charge, to any person obtaining a
7
copy of this software and associated documentation files (the "Software"),
8
to deal in the Software without restriction, including without limitation
9
the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
and/or sell copies of the Software, and to permit persons to whom the
11
Software is furnished to do so, subject to the following conditions:
12
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
15
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
DEALINGS IN THE SOFTWARE.
23
*/
24
/**
25
* @file Informer.cc
26
*
27
* Implementation of Informer class.
28
*
29
* @author Atte Oksman 2005 (oksman-no.spam-cs.tut.fi)
30
* @author Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
31
* @note rating: red
32
*/
33
34
#include <utility>
35
36
#include "
Informer.hh
"
37
#include "
Listener.hh
"
38
#include "
Application.hh
"
39
40
41
/**
42
* Constructor.
43
*/
44
Informer::Informer
() {
45
}
46
47
48
/**
49
* Destructor.
50
*/
51
Informer::~Informer
() {
52
}
53
54
/**
55
* Finds the event slot for the given listener listening to the given event.
56
*
57
* In case the listener is not found, it's added to the list and index of
58
* it is returned.
59
*
60
* @param event Event the listener is listening to.
61
* @param listener The listener.
62
* @return The index of the event slot.
63
*/
64
inline
std::size_t
65
Informer::findListenerSlot
(
int
event,
Listener
* listener) {
66
for
(std::size_t i = 0; i <
eventListeners_
.size(); ++i) {
67
if
(
eventListeners_
.at(i).first == event &&
68
eventListeners_
.at(i).second == listener) {
69
return
i;
70
}
71
}
72
eventListeners_
.push_back(std::make_pair(event, listener));
73
return
eventListeners_
.size() - 1;
74
}
75
76
/**
77
* Adds the given Listener to the list of listeners of the given event.
78
*
79
* After this function has been called, the listener will be notified every
80
* time the event occurs.
81
*
82
* @param event The code identifying the event.
83
* @param listener The Listener that should be added.
84
* @return 'True' if adding of the listener succeeds, 'false' otherwise.
85
*/
86
bool
87
Informer::registerListener
(
int
event,
Listener
* listener) {
88
findListenerSlot
(event, listener);
89
return
true
;
90
}
91
92
93
/**
94
* Removes the given Listener from the list of listeners of the given event.
95
*
96
* After this function has been called, the listener will not be notified
97
* that the event has occurred.
98
*
99
* @param event The code identifying the event.
100
* @param listener The Listener that should be removed.
101
* @return 'True' if removing the listener succeeds, 'false' otherwise.
102
*/
103
bool
104
Informer::unregisterListener
(
int
event,
Listener
* listener) {
105
std::size_t index =
findListenerSlot
(event, listener);
106
ListenerList::iterator i =
eventListeners_
.begin() + index;
107
eventListeners_
.erase(i);
108
return
true
;
109
}
Listener
Definition:
Listener.hh:40
Informer.hh
Informer::unregisterListener
virtual bool unregisterListener(int event, Listener *listener)
Definition:
Informer.cc:104
Application.hh
Informer::registerListener
virtual bool registerListener(int event, Listener *listener)
Definition:
Informer.cc:87
Informer::~Informer
virtual ~Informer()
Definition:
Informer.cc:51
Informer::Informer
Informer()
Definition:
Informer.cc:44
Informer::eventListeners_
ListenerList eventListeners_
Definition:
Informer.hh:65
Informer::findListenerSlot
std::size_t findListenerSlot(int event, Listener *listener)
Definition:
Informer.cc:65
Listener.hh
Generated by
1.8.17