BioDynaMo
v1.05.120-25dc9790
|
Go to the documentation of this file.
15 #ifndef CORE_AGENT_AGENT_POINTER_H_
16 #define CORE_AGENT_AGENT_POINTER_H_
21 #include <type_traits>
57 template <
typename TAgent = Agent>
69 d_.
agent = Cast<Agent, TAgent>(ctxt->GetAgent(uid));
77 d_.
uid = agent->GetUid();
92 if (*
this ==
nullptr) {
103 if (*
this ==
nullptr) {
143 template <
typename TOtherAgent>
147 return d_.
uid == other->GetUid();
152 if (
d_.
agent !=
nullptr && other !=
nullptr) {
153 return d_.
agent->GetUid() == other->GetUid();
154 }
else if (
d_.
agent ==
nullptr && other ==
nullptr) {
162 template <
typename TOtherAgent>
179 assert(*
this !=
nullptr);
185 return Cast<Agent, TAgent>(ctxt->GetAgent(
d_.
uid));
192 assert(*
this !=
nullptr);
198 return Cast<const Agent, const TAgent>(ctxt->GetConstAgent(
d_.
uid));
206 str <<
"{ uid: " << agent_ptr.
GetUid() <<
"}";
214 operator bool()
const {
return *
this !=
nullptr; }
245 template <
typename TFrom,
typename TTo>
246 typename std::enable_if<std::is_base_of<TFrom, TTo>::value, TTo*>::type
Cast(
247 TFrom* agent)
const {
248 return static_cast<TTo*
>(agent);
251 template <
typename TFrom,
typename TTo>
252 typename std::enable_if<!std::is_base_of<TFrom, TTo>::value, TTo*>::type
Cast(
253 TFrom* agent)
const {
254 return dynamic_cast<TTo*
>(agent);
262 #if (!defined(__CLING__) || defined(__ROOTCLING__)) && defined(USE_DICT)
264 template <
typename TAgent>
265 inline void AgentPointer<TAgent>::Streamer(TBuffer& R__b) {
266 if (R__b.IsReading()) {
267 R__b.ReadClassBuffer(AgentPointer::Class(),
this);
268 AgentUid restored_uid;
269 R__b.ReadClassBuffer(AgentUid::Class(), &restored_uid);
271 d_.uid = restored_uid;
272 }
else if (restored_uid != AgentUid()) {
274 d_.agent = Cast<Agent, TAgent>(ctxt->GetAgent(restored_uid));
279 R__b.WriteClassBuffer(AgentPointer::Class(),
this);
283 R__b.WriteClassBuffer(AgentUid::Class(), &d_.uid);
284 }
else if (d_.agent !=
nullptr) {
285 uid = d_.agent->GetUid();
287 R__b.WriteClassBuffer(AgentUid::Class(), &uid);
291 #endif // !defined(__CLING__) || defined(__ROOTCLING__)
293 template <
typename T>
295 static constexpr
bool value =
false;
298 template <
typename T>
306 template <
typename T>
307 static typename std::enable_if<is_agent_ptr<T>::value, uint64_t>::type
GetUid(
312 template <
typename T>
313 static typename std::enable_if<!is_agent_ptr<T>::value, uint64_t>::type
323 #endif // CORE_AGENT_AGENT_POINTER_H_
std::enable_if< std::is_base_of< TFrom, TTo >::value, TTo * >::type Cast(TFrom *agent) const
BDM_CLASS_DEF_NV(AgentPointer, 3)
uint64_t GetUidAsUint64() const
std::enable_if<!std::is_base_of< TFrom, TTo >::value, TTo * >::type Cast(TFrom *agent) const
friend std::ostream & operator<<(std::ostream &str, const AgentPointer &agent_ptr)
bool operator==(std::nullptr_t) const
AgentPointer(std::nullptr_t)
Allow AgentPointer<> ap = nullptr definitions.
const TAgent * operator->() const
TODO. Replace with std::variant once we move to >= c++17.
AgentPointer()
constructs an AgentPointer object representing a nullptr
const TAgent * Get() const
bool operator<(const AgentPointer &other) const
bool operator!=(const AgentPointer &other) const
bool operator!=(std::nullptr_t) const
static constexpr bool value
AgentPointerMode gAgentPointerMode
AgentPointer(TAgent *agent)
bool operator==(const TOtherAgent *other) const
AgentPointer & operator=(std::nullptr_t)
const TAgent & operator*() const
ExecutionContext * GetExecutionContext()
Returns a thread local execution context.
bool operator!=(const TOtherAgent *other) const
static Simulation * GetActive()
This function returns the currently active Simulation simulation.
AgentPointer(const AgentUid &uid)
bool operator==(const AgentPointer &other) const