DP3
Fields.h
Go to the documentation of this file.
1 // Copyright (C) 2022 ASTRON (Netherlands Institute for Radio Astronomy)
2 // SPDX-License-Identifier: GPL-3.0-or-later
3 
4 #ifndef DP3_COMMON_FIELDS_H_
5 #define DP3_COMMON_FIELDS_H_
6 
7 #include <bitset>
8 #include <iosfwd>
9 
10 namespace dp3 {
11 namespace common {
12 
16 class Fields {
17  public:
21  enum class Single {
22  kData,
23  kFlags,
24  kWeights,
25  kUvw,
26  kCount
27  };
28 
32  constexpr Fields() : value_() {}
33 
38  constexpr explicit Fields(Single field)
39  : value_(1 << static_cast<int>(field)) {}
40 
44  constexpr bool Data() const {
45  return value_[static_cast<int>(Single::kData)];
46  }
47 
51  constexpr bool Flags() const {
52  return value_[static_cast<int>(Single::kFlags)];
53  }
54 
58  constexpr bool Weights() const {
59  return value_[static_cast<int>(Single::kWeights)];
60  }
61 
65  constexpr bool Uvw() const { return value_[static_cast<int>(Single::kUvw)]; }
66 
72  Fields& operator|=(const Fields& other) {
73  value_ |= other.value_;
74  return *this;
75  }
76 
85  Fields& UpdateRequirements(const Fields& required, const Fields& provided) {
86  std::bitset<static_cast<int>(Single::kCount)> to_reset =
87  provided.value_ & ~required.value_;
88  value_ |= required.value_;
89  value_ &= ~to_reset;
90  return *this;
91  }
92 
97  friend Fields operator|(const Fields& left, const Fields& right) {
98  Fields fields(left);
99  fields |= right;
100  return fields;
101  }
102 
107  friend bool operator==(const Fields& left, const Fields& right) {
108  return left.value_ == right.value_;
109  }
110 
115  friend bool operator!=(const Fields& left, const Fields& right) {
116  return left.value_ != right.value_;
117  }
118 
122  friend std::ostream& operator<<(std::ostream&, const Fields& fields);
123 
124  private:
125  // Using a bitset instead of individual booleans simplifies adding more
126  // fields in the future.
127  std::bitset<static_cast<int>(Single::kCount)> value_;
128 };
129 
130 } // namespace common
131 } // namespace dp3
132 
133 #endif // DP3_COMMON_FIELDS_H_
Definition: Fields.h:16
constexpr bool Data() const
Definition: Fields.h:44
Single
Definition: Fields.h:21
@ kData
Is the visibility data needed?
@ kUvw
Are the uvw needed?
@ kCount
Number of fields. Must be last.
@ kWeights
Are the weights needed?
@ kFlags
Are the flags needed?
friend bool operator==(const Fields &left, const Fields &right)
Definition: Fields.h:107
constexpr bool Weights() const
Definition: Fields.h:58
Fields & operator|=(const Fields &other)
Definition: Fields.h:72
friend Fields operator|(const Fields &left, const Fields &right)
Definition: Fields.h:97
friend std::ostream & operator<<(std::ostream &, const Fields &fields)
constexpr Fields(Single field)
Definition: Fields.h:38
friend bool operator!=(const Fields &left, const Fields &right)
Definition: Fields.h:115
constexpr bool Flags() const
Definition: Fields.h:51
constexpr bool Uvw() const
Definition: Fields.h:65
Fields & UpdateRequirements(const Fields &required, const Fields &provided)
Definition: Fields.h:85
constexpr Fields()
Definition: Fields.h:32
This file has generic helper routines for testing steps.
Definition: AntennaConfig.h:53