BioDynaMo  v1.05.120-25dc9790
new_agent_event.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #ifndef CORE_AGENT_NEW_AGENT_EVENT_H_
16 #define CORE_AGENT_NEW_AGENT_EVENT_H_
17 
18 #include <limits>
19 #include <mutex>
21 #include "core/util/log.h"
22 
23 namespace bdm {
24 
29 using NewAgentEventUid = uint64_t;
30 
31 class Agent;
32 class Behavior;
33 
37  public:
40  delete;
41 
43 
45  std::lock_guard<std::recursive_mutex> lock(mutex_);
46  constexpr uint64_t kOne = 1;
47  if (counter_ == 64) {
48  Log::Fatal("NewAgentEventUidGenerator",
49  "BioDynaMo only supports 64 unique NewAgentEventUids."
50  " You requested a 65th one.");
51  }
52  return kOne << counter_++;
53  }
54 
55  private:
56  NewAgentEventUidGenerator() = default;
57  std::recursive_mutex mutex_;
58  uint64_t counter_ = 0;
59 };
60 
61 struct NewAgentEvent {
62  virtual ~NewAgentEvent() = default;
63 
64  virtual NewAgentEventUid GetUid() const = 0;
65 
83 };
84 
85 } // namespace bdm
86 
87 #endif // CORE_AGENT_NEW_AGENT_EVENT_H_
bdm::NewAgentEvent
Definition: new_agent_event.h:61
inline_vector.h
bdm
Definition: agent.cc:39
bdm::NewAgentEvent::existing_behavior
Behavior * existing_behavior
Definition: new_agent_event.h:77
bdm::NewAgentEventUidGenerator
Definition: new_agent_event.h:36
bdm::Behavior
Definition: behavior.h:29
bdm::NewAgentEvent::existing_agent
Agent * existing_agent
Definition: new_agent_event.h:69
bdm::Agent
Contains code required by all agents.
Definition: agent.h:79
bdm::NewAgentEventUidGenerator::counter_
uint64_t counter_
Definition: new_agent_event.h:58
bdm::NewAgentEventUidGenerator::GenerateUid
NewAgentEventUid GenerateUid()
Definition: new_agent_event.h:44
bdm::NewAgentEvent::new_behaviors
InlineVector< Behavior *, 3 > new_behaviors
Definition: new_agent_event.h:82
bdm::NewAgentEventUid
uint64_t NewAgentEventUid
Definition: new_agent_event.h:29
bdm::NewAgentEvent::new_agents
InlineVector< Agent *, 3 > new_agents
Definition: new_agent_event.h:73
bdm::Log::Fatal
static void Fatal(const std::string &location, const Args &... parts)
Prints fatal error message.
Definition: log.h:115
bdm::NewAgentEventUidGenerator::GetInstance
static NewAgentEventUidGenerator * GetInstance()
Definition: new_agent_event.cc:23
log.h
bdm::NewAgentEvent::~NewAgentEvent
virtual ~NewAgentEvent()=default
bdm::NewAgentEventUidGenerator::mutex_
std::recursive_mutex mutex_
Definition: new_agent_event.h:57
bdm::NewAgentEvent::GetUid
virtual NewAgentEventUid GetUid() const =0
bdm::NewAgentEventUidGenerator::operator=
NewAgentEventUidGenerator & operator=(const NewAgentEventUidGenerator &)=delete
bdm::InlineVector
Definition: inline_vector.h:49
bdm::NewAgentEventUidGenerator::NewAgentEventUidGenerator
NewAgentEventUidGenerator()=default