BlockId.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <ostream>
8 #include <pup.h>
9 
10 /// \cond
11 namespace PUP {
12 class er;
13 } // namespace PUP
14 /// \endcond
15 
16 namespace domain {
17 /*!
18  * \ingroup ComputationalDomainGroup
19  * \brief Index a block of the computational domain.
20  */
21 class BlockId {
22  public:
23  BlockId() = default;
24  explicit BlockId(size_t id) noexcept : id_(id) {}
25 
26  // NOLINTNEXTLINE(google-runtime-references)
27  void pup(PUP::er& p) noexcept { p | id_; }
28 
29  size_t get_index() const noexcept { return id_; }
30 
31  BlockId& operator++() noexcept {
32  ++id_;
33  return *this;
34  }
35 
36  BlockId& operator--() noexcept {
37  --id_;
38  return *this;
39  }
40 
41  // NOLINTNEXTLINE(cert-dcl21-cpp) returned object doesn't need to be const
42  BlockId operator++(int) noexcept {
43  BlockId temp = *this;
44  id_++;
45  return temp;
46  }
47 
48  // NOLINTNEXTLINE(cert-dcl21-cpp) returned object doesn't need to be const
49  BlockId operator--(int) noexcept {
50  BlockId temp = *this;
51  id_--;
52  return temp;
53  }
54 
55  private:
56 
57  size_t id_{0};
58 };
59 
60 inline bool operator==(const BlockId& lhs, const BlockId& rhs) noexcept {
61  return lhs.get_index() == rhs.get_index();
62 }
63 
64 inline bool operator!=(const BlockId& lhs, const BlockId& rhs) noexcept {
65  return not(lhs == rhs);
66 }
67 
68 inline std::ostream& operator<<(std::ostream& os, const BlockId& block_id) {
69  return os << '[' << block_id.get_index() << ']';
70 }
71 
72 } // namespace domain
Definition: Strahlkorper.hpp:14
Index a block of the computational domain.
Definition: BlockId.hpp:21
Definition: BlockId.hpp:16