eventSubscriber.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 
22 #include "eventSubscriber.hpp"
23 #include "Set.hpp"
24 
26 {
27  for(auto& observer:observerList_)
28  {
29  observer->invalidateSubscriber();
30  }
31 }
32 
34 (
35  eventObserver* observer
36 )const
37 {
38  if(observer)
39  {
40  observerList_.push_back(observer);
41  return true;
42  }
43  else
44  {
45  return false;
46  }
47 }
48 
50 (
51  eventObserver* observer
52 )const
53 {
54  if(observer)
55  {
56  observerList_.remove(observer);
57  }
58  return true;
59 }
60 
62 (
63  const eventMessage &msg
64 )
65 {
66  for ( auto& observer:observerList_ )
67  {
68  if(observer)
69  if( !observer->update(msg) ) return false;
70  }
71 
72  return true;
73 }
74 
76 (
77  const eventMessage& msg,
78  const List<eventObserver*>& exclutionList
79 )
80 {
81  Set<eventObserver*> sortedExcList(exclutionList.begin(),exclutionList.end());
82 
83  for(auto& observer:observerList_)
84  {
85  if( observer && sortedExcList.count(observer) == 0 )
86  {
87  if(!observer->update(msg)) return false;
88  }
89  }
90 
91  return true;
92 }
pFlow::List
Definition: List.hpp:39
pFlow::eventMessage
Definition: eventMessage.hpp:29
pFlow::eventSubscriber::notify
bool notify(const eventMessage &msg)
Definition: eventSubscriber.cpp:62
Set.hpp
pFlow::Set
std::set< Key, std::less< Key >, std::allocator< Key > > Set
Definition: Set.hpp:31
pFlow::eventSubscriber::observerList_
List< eventObserver * > observerList_
Definition: eventSubscriber.hpp:39
pFlow::eventObserver
Definition: eventObserver.hpp:33
pFlow::eventObserver::update
virtual bool update(const eventMessage &msg)=0
pFlow::eventSubscriber::subscribe
virtual bool subscribe(eventObserver *observer) const
Definition: eventSubscriber.cpp:34
pFlow::eventSubscriber::~eventSubscriber
virtual ~eventSubscriber()
Definition: eventSubscriber.cpp:25
pFlow::eventSubscriber::unsubscribe
virtual bool unsubscribe(eventObserver *observer) const
Definition: eventSubscriber.cpp:50
eventSubscriber.hpp