MetroCollect  2.3.4
Statistics.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 <array>
24 #include <string_view>
25 
26 using namespace std::literals;
27 
28 
29 namespace MetroCollect {
30  class MetricsController;
31 
35  class Statistics {
37  protected:
45  enum StatsIndex : uint8_t {
46  StatsIndexMin = 0,
47  StatsIndexMax = 1,
48  StatsIndexAverage = 2,
49  StatsIndexStdDev = 3,
50 
51  // Private intermediate statistics
52  StatsIndexIntermediateSum = 4,
53  StatsIndexIntermediateSumSquared = 5,
54  };
55 
56  public:
57  static constexpr size_t count = 4;
58  static constexpr std::array<std::string_view, count> names = {"min"sv, "max"sv, "average"sv, "stdDev"sv};
59  static constexpr std::string_view nameStatsAll = "*"sv;
60 
64  enum Stats : uint64_t {
65  StatsMin = 1 << StatsIndexMin,
66  StatsMax = 1 << StatsIndexMax,
67  StatsAverage = 1 << StatsIndexAverage,
68  StatsStdDev = 1 << StatsIndexStdDev,
69 
70  StatsNone = 0,
71  StatsAll = StatsMin | StatsMax | StatsAverage | StatsStdDev,
72  };
73  static constexpr std::array<Stats, count> allStats = {StatsMin, StatsMax, StatsAverage, StatsStdDev};
74 
75  static Stats statsFromName(const std::string_view& statName);
76  static Stats statsRequiredForStat(Stats stat);
77 
78  protected:
79  static constexpr size_t extraCount = count + 2;
80 
84  enum StatsDependency : uint64_t {
85  StatsDependencyMin = StatsMin,
86  StatsDependencyMax = StatsMax,
87  StatsDependencyStdDev = StatsStdDev,
88  StatsDependencyAverage = StatsAverage | StatsDependencyStdDev,
89  StatsDependencySum = StatsDependencyAverage,
90  StatsDependencySumSquared = StatsDependencyStdDev,
91  };
92  static constexpr std::array<StatsDependency, extraCount> StatsDependencies = {StatsDependencyMin, StatsDependencyMax, StatsDependencyAverage, StatsDependencyStdDev, StatsDependencySum, StatsDependencySumSquared};
93  };
94 
95 
104  template<typename T>
105  constexpr inline Statistics::Stats operator| (Statistics::Stats a, T b) {
106  return static_cast<Statistics::Stats>(static_cast<uint64_t>(a) | static_cast<uint64_t>(b));
107  }
108 
117  template<typename T>
118  constexpr inline Statistics::Stats& operator|= (Statistics::Stats& a, T b) {
119  a = a | b;
120  return a;
121  }
122 }
StatsIndex
Associates a unique index to each statistic.
Definition: Statistics.h:45
constexpr Statistics::Stats & operator|=(Statistics::Stats &a, T b)
Performs and assigns bitwise OR of two statistics.
Definition: Statistics.h:118
Stats
Bitwise type te select statistics.
Definition: Statistics.h:64
Class holding various statistics-related types and variables.
Definition: Statistics.h:35
constexpr Statistics::Stats operator|(Statistics::Stats a, T b)
Performs bitwise OR of two statistics.
Definition: Statistics.h:105
friend MetricsController
MetricsController can access to protected types and variables.
Definition: Statistics.h:36
StatsDependency
Dependency tree of each statistic.
Definition: Statistics.h:84