MetroCollect  2.3.4
SourceInterests.h
Go to the documentation of this file.
1 //
2 // SourceInterests.h
3 //
4 // Created on August 27th 2018
5 //
6 // Copyright 2018 CFM (www.cfm.fr)
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 // See the License for the specific language governing permissions and
18 // limitations under the License.
19 //
20 
21 #pragma once
22 
23 #include <memory>
24 #include <vector>
25 
26 
33  struct Interests {
34  uint64_t value;
35 
36 
41  inline Interests() : value(0) { }
42 
49  template<typename T>
50  inline Interests(T v) : value(v) { }
51 
52 
60  template<typename T>
61  inline Interests& operator=(const T v) {
62  value = v;
63  return *this;
64  }
65 
66 
73  inline bool any() const {
74  return value != 0;
75  }
76 
77 
84  inline bool none() const {
85  return value == 0;
86  }
87 
88 
96  template<typename T>
97  inline bool isSet(T index) const {
98  return (value & (static_cast<size_t>(1) << (index % (8 * sizeof(size_t))))) != 0;
99  }
100 
101 
108  template<typename T>
109  inline void set(T index) {
110  value |= (static_cast<size_t>(1) << (index % (8 * sizeof(size_t))));
111  }
112 
113 
120  template<typename T>
121  inline void unSet(T index) {
122  value &= ~(static_cast<size_t>(1) << (index % (8 * sizeof(size_t))));
123  }
124  };
125 
126 
132  template<>
133  inline Interests::Interests(bool v) : value(v ? ~0 : 0) { }
134 
135 
142  template<>
143  inline Interests& Interests::operator=(const bool v) {
144  value = (v ? ~0 : 0);
145  return *this;
146  }
147 
148 
149  using SourceInterests = std::shared_ptr<std::vector<MetricsSource::Interests>>;
150 
157  SourceInterests makeSourceInterests(bool value = false);
158 }
Interests(T v)
Construct a new Interests object.
std::shared_ptr< std::vector< MetricsSource::Interests > > SourceInterests
Type used to store and share interests of multiple sources.
Namespace for sources of metrics objects and operations.
Interests & operator=(const T v)
Assigns values to the boolean array.
uint64_t value
Boolean array underlying storage.
Interests()
Construct a new Interests object (each value defaults to false)
void unSet(T index)
Set a specific bit&#39;s value to false.
SourceInterests makeSourceInterests(bool value)
Construct a new shared pointer to a SourceInterests object.
bool none() const
Checks wether all bit are false.
Boolean array to keep track of which fields a source has to fetch metrics for.
bool any() const
Checks wether any bit is true.
bool isSet(T index) const
Checks if a specific bit is true.