AutoPas  3.0.0
Loading...
Searching...
No Matches
OwnershipState.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <bitset>
11#include <iostream>
12#include <string>
13
14namespace autopas {
20enum class OwnershipState : int64_t {
24 dummy = 0b0000, // 0
26 owned = 0b0001, // 1
28 halo = 0b0010, // 2
29};
30
38 return static_cast<OwnershipState>(static_cast<int64_t>(a) & static_cast<int64_t>(b));
39}
40
48 return static_cast<OwnershipState>(static_cast<int64_t>(a) | static_cast<int64_t>(b));
49}
50
57constexpr int64_t toInt64(const OwnershipState a) { return static_cast<int64_t>(a); }
58
64inline std::string format_as(const OwnershipState &state) {
65 switch (state) {
67 return "dummy";
69 return "owned";
71 return "halo";
72 default:
73 return "unknown state: 0b" + std::bitset<4>(static_cast<int64_t>(state)).to_string();
74 }
75}
76
84inline std::ostream &operator<<(std::ostream &os, const OwnershipState &ownershipState) {
85 // Reuse format_as to prevent duplicated logic
86 return os << format_as(ownershipState);
87}
88} // namespace autopas
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:34
std::string format_as(const OwnershipState &state)
This function is needed to pass an ownership state to spdlog/fmt.
Definition: OwnershipState.h:64
constexpr int64_t toInt64(const OwnershipState a)
Returns the int64_t value of a given OwnershipState.
Definition: OwnershipState.h:57
constexpr OwnershipState operator|(const OwnershipState a, const OwnershipState b)
Bitwise OR operator for OwnershipState.
Definition: OwnershipState.h:47
OwnershipState
Enum that specifies the state of ownership.
Definition: OwnershipState.h:20
@ dummy
Dummy or deleted state, a particle with this state is not an actual particle!
@ halo
Halo state, a particle with this state is an actual particle, but not owned by the current AutoPas ob...
@ owned
Owned state, a particle with this state is an actual particle and owned by the current AutoPas object...
std::ostream & operator<<(std::ostream &os, const OwnershipState &ownershipState)
Insertion operator for OwnershipState.
Definition: OwnershipState.h:84
constexpr OwnershipState operator&(const OwnershipState a, const OwnershipState b)
Bitwise AND operator for OwnershipState.
Definition: OwnershipState.h:37