BioDynaMo  v1.05.159-3be850bb
agent_handle.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_AGENT_HANDLE_H_
16 #define CORE_AGENT_AGENT_HANDLE_H_
17 
18 #include <limits>
19 #include "core/util/root.h"
20 
21 namespace bdm {
22 
29 class AgentHandle {
30  public:
31  using NumaNode_t = uint16_t;
32  using ElementIdx_t = uint32_t;
33 
34  constexpr AgentHandle() noexcept
35  : numa_node_(std::numeric_limits<NumaNode_t>::max()),
36  element_idx_(std::numeric_limits<ElementIdx_t>::max()) {}
37 
38  explicit AgentHandle(ElementIdx_t element_idx)
39  : numa_node_(0), element_idx_(element_idx) {}
40 
41  AgentHandle(NumaNode_t numa_node, ElementIdx_t element_idx)
42  : numa_node_(numa_node), element_idx_(element_idx) {}
43 
44  NumaNode_t GetNumaNode() const { return numa_node_; }
46  void SetElementIdx(ElementIdx_t element_idx) { element_idx_ = element_idx; }
47 
48  bool operator==(const AgentHandle& other) const {
49  return numa_node_ == other.numa_node_ && element_idx_ == other.element_idx_;
50  }
51 
52  bool operator!=(const AgentHandle& other) const { return !(*this == other); }
53 
54  bool operator<(const AgentHandle& other) const {
55  if (numa_node_ == other.numa_node_) {
56  return element_idx_ < other.element_idx_;
57  } else {
58  return numa_node_ < other.numa_node_;
59  }
60  }
61 
62  friend std::ostream& operator<<(std::ostream& stream,
63  const AgentHandle& handle) {
64  stream << "Numa node: " << handle.numa_node_
65  << " element idx: " << handle.element_idx_;
66  return stream;
67  }
68 
69  private:
71 
75 
77 };
78 
79 } // namespace bdm
80 
81 #endif // CORE_AGENT_AGENT_HANDLE_H_
constexpr AgentHandle() noexcept
Definition: agent_handle.h:34
friend std::ostream & operator<<(std::ostream &stream, const AgentHandle &handle)
Definition: agent_handle.h:62
bool operator==(const AgentHandle &other) const
Definition: agent_handle.h:48
ElementIdx_t element_idx_
Definition: agent_handle.h:74
bool operator!=(const AgentHandle &other) const
Definition: agent_handle.h:52
NumaNode_t numa_node_
Definition: agent_handle.h:70
void SetElementIdx(ElementIdx_t element_idx)
Definition: agent_handle.h:46
uint16_t NumaNode_t
Definition: agent_handle.h:31
ElementIdx_t GetElementIdx() const
Definition: agent_handle.h:45
NumaNode_t GetNumaNode() const
Definition: agent_handle.h:44
AgentHandle(NumaNode_t numa_node, ElementIdx_t element_idx)
Definition: agent_handle.h:41
bool operator<(const AgentHandle &other) const
Definition: agent_handle.h:54
AgentHandle(ElementIdx_t element_idx)
Definition: agent_handle.h:38
uint32_t ElementIdx_t
Definition: agent_handle.h:32
BDM_CLASS_DEF_NV(AgentHandle, 1)
Definition: agent.cc:39
Definition: agent_uid.h:117