RSB  0.17.0
CauseFilter.cpp
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is part of the RSB project.
4  *
5  * Copyright (C) 2016 Jan Moringen <jmoringe@techfak.uni-bielefeld.de>
6  *
7  * This file may be licensed under the terms of the
8  * GNU Lesser General Public License Version 3 (the ``LGPL''),
9  * or (at your option) any later version.
10  *
11  * Software distributed under the License is distributed
12  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13  * express or implied. See the LGPL for the specific language
14  * governing rights and limitations.
15  *
16  * You should have received a copy of the LGPL along with this
17  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
18  * or write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  * The development of this software was supported by:
22  * CoR-Lab, Research Institute for Cognition and Robotics
23  * Bielefeld University
24  *
25  * ============================================================ */
26 
27 #include "CauseFilter.h"
28 
29 #include "FilterObserver.h"
30 
31 using namespace rsc::misc;
32 
33 namespace rsb {
34 namespace filter {
35 
36 CauseFilter::CauseFilter(const UUID& cause,
37  bool invert):
38  causeAsUUID(cause), invert(invert) {
39 }
40 
41 CauseFilter::CauseFilter(const EventId& cause,
42  bool invert):
43  causeAsEventId(new EventId(cause)), invert(invert) {
44 }
45 
46 UUID CauseFilter::getCause() const {
47  if (this->causeAsEventId) {
48  return this->causeAsEventId->getAsUUID();
49  } else {
50  return this->causeAsUUID;
51  }
52 }
53 
55  return this->invert;
56 }
57 
59  bool result = false;
60  if (this->causeAsEventId) {
61  result = e->isCause(*this->causeAsEventId);
62  } else {
63  std::set<EventId> causes = e->getCauses();
64  for (std::set<EventId>::const_iterator it = causes.begin();
65  it != causes.end(); ++it) {
66  if (it->getAsUUID() == this->causeAsUUID) {
67  result = true;
68  break;
69  }
70  }
71  }
72  return this->invert ? !result : result;
73 }
74 
77  fo->notify(this, at);
78 }
79 
80 }
81 }
rsc::misc::UUID causeAsUUID
Definition: CauseFilter.h:92
bool isInverted() const
Indicates whether the filter is inverted.
Definition: CauseFilter.cpp:54
rsc::misc::UUID getCause() const
Return the cause that has to be present in events matched by this filter.
Definition: CauseFilter.cpp:46
void notifyObserver(FilterObserverPtr fo, FilterAction::Types at)
Double-dispatch method to notfify a FilterObserver about changes for this filter with a more specific...
Definition: CauseFilter.cpp:75
bool match(EventPtr e)
Matches the given event against the constraints specified by this filter.
Definition: CauseFilter.cpp:58
Types
Possible actions with filters.
boost::shared_ptr< FilterObserver > FilterObserverPtr
Definition: Filter.h:38
A unique ID for events in RSB.
Definition: EventId.h:48
boost::shared_ptr< Event > EventPtr
Definition: Event.h:264