1 //
2 // This file is part of libyacurs.
3 // Copyright (C) 2013 Rafael Ostertag
4 //
5 // This program is free software: you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation, either version 3 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see
17 // <http://www.gnu.org/licenses/>.
18 //
19 //
20 // $Id$
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include "eventconnector.h"
27
28 using namespace YACURS;
29
30 ////////////////////////////////////////////////////////
31 //
32 // class EventConnectorBase
33 //
34 ////////////////////////////////////////////////////////
35
36 //
37 // Protected
38 //
39
40 //
41 // Public
42 //
EventConnectorBase(const EventType e,bool s)43 EventConnectorBase::EventConnectorBase(const EventType e, bool s)
44 : evt(e), _suspended(s) {}
45
~EventConnectorBase()46 EventConnectorBase::~EventConnectorBase() {}
47
operator ==(const EventConnectorBase & ec) const48 bool EventConnectorBase::operator==(const EventConnectorBase& ec) const {
49 return (evt == ec.evt) && (id() == ec.id());
50 }
51
operator !=(const EventConnectorBase & ec) const52 bool EventConnectorBase::operator!=(const EventConnectorBase& ec) const {
53 return !operator==(ec);
54 }
55
operator ==(const Event & eb) const56 bool EventConnectorBase::operator==(const Event& eb) const {
57 return eb.type() == evt;
58 }
59
operator !=(const Event & eb) const60 bool EventConnectorBase::operator!=(const Event& eb) const {
61 return !operator==(eb);
62 }
63
operator ==(const EventType et) const64 bool EventConnectorBase::operator==(const EventType et) const {
65 return et == evt;
66 }
67
operator !=(const EventType et) const68 bool EventConnectorBase::operator!=(const EventType et) const {
69 return !operator==(et);
70 }
71
type() const72 const EventType EventConnectorBase::type() const { return evt; }
73
suspended(bool s)74 void EventConnectorBase::suspended(bool s) { _suspended = s; }
75
suspended() const76 bool EventConnectorBase::suspended() const { return _suspended; }
77
operator const EventType() const78 EventConnectorBase::operator const EventType() const { return evt; }
79
80 ////////////////////////////////////////////////////////
81 //
82 // class EventConnectorFunction1
83 //
84 ////////////////////////////////////////////////////////
85
86 //
87 // Protected
88 //
id() const89 uintptr_t EventConnectorFunction1::id() const { return (uintptr_t)_func; }
90
91 //
92 // Public
93 //
EventConnectorFunction1(const EventType e,fptr_t func)94 EventConnectorFunction1::EventConnectorFunction1(const EventType e, fptr_t func)
95 : EventConnectorBase(e), _func(func) {
96 assert(_func != 0);
97 }
98
call(Event & e) const99 void EventConnectorFunction1::call(Event& e) const {
100 assert(_func != 0);
101
102 if (suspended()) return;
103
104 _func(e);
105 }
106
clone() const107 EventConnectorBase* EventConnectorFunction1::clone() const {
108 return new EventConnectorFunction1(*this);
109 }
110