eventObserver.cpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 #include "eventObserver.hpp"
22 #include "eventSubscriber.hpp"
23 
25  subscriber_(nullptr),
26  subscribed_(false)
27 {}
28 
30 (
31  const eventSubscriber& subscriber,
32  bool subscribe
33 )
34 :
35  subscriber_(&subscriber),
36  subscribed_(false)
37 {
38  if(subscribe && subscriber_)
39  {
40  subscribed_ = subscriber_->subscribe(this);
41  }
42 }
43 
45 {
46  if(subscribed_ && subscriber_)
47  subscriber_->unsubscribe(this);
48 }
49 
51 {
52  subscriber_ = &subscriber;
53  subscribed_ = subscriber_->subscribe(this);
54  return subscribed_;
55 }
56 
pFlow::eventSubscriber
Definition: eventSubscriber.hpp:34
pFlow::eventObserver::subscribe
bool subscribe(const eventSubscriber &subscriber)
Definition: eventObserver.cpp:50
pFlow::eventObserver::eventObserver
eventObserver()
Definition: eventObserver.cpp:24
eventObserver.hpp
pFlow::eventObserver::~eventObserver
virtual ~eventObserver()
Definition: eventObserver.cpp:44
pFlow::eventSubscriber::subscribe
virtual bool subscribe(eventObserver *observer) const
Definition: eventSubscriber.cpp:34
eventSubscriber.hpp