# PhasicFlow: src/phasicFlow/eventManagement/subscriber.cpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

subscriber.cpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#include "subscriber.hpp"
#include "anyList.hpp"
#include "observer.hpp"
#include "message.hpp"
pFlow::subscriber::subscriber(const subscriber & src)
:
subName_(src.subName_)
{
}
pFlow::subscriber::subscriber(subscriber && src)
:
observerList_(std::move(src.observerList_)),
subName_(std::move(src.subName_))
{
for(size_t i=0; i<observerList_.size(); i++)
{
for( auto obsvr: observerList_[i] )
{
if(obsvr) obsvr->changeSubscriber(this);
}
}
}
pFlow::subscriber &pFlow::subscriber::operator=(const subscriber & rhs)
{
this->subName_ = rhs.subName_;
return *this;
}
pFlow::subscriber &pFlow::subscriber::operator=(subscriber && rhs)
{
this->subName_ = std::move(rhs.subName_);
this->observerList_ = std::move(rhs.observerList_);
for(size_t i=0; i<observerList_.size(); i++)
{
for( auto obsvr: observerList_[i] )
{
if(obsvr) obsvr->changeSubscriber(this);
}
}
return *this;
}
pFlow::subscriber::~subscriber()
{
for(size_t i=0; i<observerList_.size(); i++)
{
for( auto obsvr: observerList_[i] )
{
if(obsvr)
{
obsvr->invalidateSubscriber();
}
}
}
}
bool pFlow::subscriber::subscribe
(
message msg,
observer* obsevr
)const
{
// do not subscribe nullptr
if(!obsevr)return false;
for(size_t i=0; i<msg.size(); i++)
{
if(msg.equivalentTo(i))
{
if(!observerList_[i].search(obsevr))
{
observerList_[i].push_back(obsevr);
}
}
}
return true;
}
bool pFlow::subscriber::unsubscribe
(
observer* obsrvr
)const
{
if(obsrvr)
{
for(size_t i=0; i<observerList_.size(); i++)
{
if( auto iter = observerList_[i].find(obsrvr); iter!= observerList_[i].end())
{
(*iter)->invalidateSubscriber();
observerList_[i].erase(iter);
}
}
}
return true;
}
bool pFlow::subscriber::notify
(
uint32 iter,
real t,
real dt,
const message msg,
const anyList& varList
)
{
for(size_t i=0; i<msg.size(); i++)
{
if(msg.equivalentTo(i))
{
for( auto obsvr: observerList_[i] )
{
obsvr->hearChanges
(
t,
dt,
iter,
message(i),
varList
);
}
}
}
return true;
}
bool pFlow::subscriber::notify(const timeInfo &ti, const message msg, const anyList &varList)
{
return notify(ti.iter(), ti.t(), ti.dt(), msg, varList);
}
pFlow::message::equivalentTo
bool equivalentTo(EVENT evnt) const
Definition: message.hpp:131
pFlow::observer
Definition: observer.hpp:33
pFlow::subscriber::notify
bool notify(uint32 iter, real t, real dt, const message msg, const anyList &varList)
Definition: subscriber.cpp:126
subscriber.hpp
anyList.hpp
pFlow::message
Definition: message.hpp:33
pFlow::subscriber::unsubscribe
virtual bool unsubscribe(observer *obsevr) const
Definition: subscriber.cpp:107
pFlow::real
float real
Definition: builtinTypes.hpp:45
message.hpp
pFlow::subscriber::subscriber
subscriber(const word &name)
Definition: subscriber.hpp:48
pFlow::find
int64 find(Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:69
observer.hpp
pFlow::subscriber::observerList_
std::array< List< observer * >, message::numEvents()> observerList_
Definition: subscriber.hpp:42
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::message::size
auto size() const
Definition: message.hpp:146
pFlow::subscriber::subName_
word subName_
Definition: subscriber.hpp:44
pFlow::subscriber
Definition: subscriber.hpp:37
pFlow::timeInfo
Definition: timeInfo.hpp:28
pFlow::subscriber::subscribe
virtual bool subscribe(message msg, observer *obsevr) const
Definition: subscriber.cpp:85
pFlow::anyList
Definition: anyList.hpp:35
pFlow::timeInfo::dt
const real & dt() const
Definition: timeInfo.hpp:51
pFlow::subscriber::~subscriber
virtual ~subscriber()
Definition: subscriber.cpp:70
pFlow::subscriber::operator=
subscriber & operator=(const subscriber &)
Copy assignemnt, only assign the name, do not assign the list.
Definition: subscriber.cpp:48
pFlow::timeInfo::t
const real & t() const
Definition: timeInfo.hpp:47
pFlow::timeInfo::iter
const uint32 & iter() const
Definition: timeInfo.hpp:55