EMANE  1.0.1
statisticnumeric.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 - Adjacent Link LLC, Bridgewater, New Jersey
3  * Copyright (c) 2010 - DRS CenGen, LLC, Columbia, Maryland
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of DRS CenGen, LLC nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef EMANESTATISTICNUMERIC_HEADER_
35 #define EMANESTATISTICNUMERIC_HEADER_
36 
37 #include "emane/statistic.h"
38 
39 #include <mutex>
40 
41 namespace EMANE
42 {
43  class StatisticRegistrar;
44 
52  template<typename T>
53  class StatisticNumeric : public Statistic
54  {
55  public:
57 
59 
60  const T operator++(int);
61 
63 
64  const T operator--(int);
65 
67 
68  const T operator+(const StatisticNumeric<T> & rhs) const;
69 
70  const T operator-(const StatisticNumeric<T> & rhs) const;
71 
73 
74  const T operator*(const StatisticNumeric<T> & rhs) const;
75 
77 
78  const T operator/(const StatisticNumeric<T> & rhs) const;
79 
81 
83 
84  StatisticNumeric<T> & operator+=(const T & rhs);
85 
86  T operator+(const T & rhs) const;
87 
88  T operator-(const T & rhs) const;
89 
90  StatisticNumeric<T> & operator-=(const T & rhs);
91 
92  T operator*(const T & rhs) const;
93 
94  StatisticNumeric<T> & operator*=(const T & rhs);
95 
96  T operator/(const T & rhs) const;
97 
98  StatisticNumeric<T> & operator/=(const T & rhs);
99 
100  StatisticNumeric<T> & operator=(const T & rhs);
101 
102  bool operator==(const StatisticNumeric<T> & rhs) const;
103 
104  bool operator!=(const StatisticNumeric<T> & rhs) const;
105 
106  bool operator<(const StatisticNumeric<T> & rhs) const;
107 
108  bool operator<=(const StatisticNumeric<T> & rhs) const;
109 
110  bool operator>(const StatisticNumeric<T> & rhs) const;
111 
112  bool operator>=(const StatisticNumeric<T> & rhs) const;
113 
114  bool operator==(const T & rhs) const;
115 
116  bool operator!=(const T & rhs) const;
117 
118  bool operator<(const T & rhs) const;
119 
120  bool operator<=(const T & rhs) const;
121 
122  bool operator>(const T & rhs) const;
123 
124  bool operator>=(const T & rhs) const;
125 
131  T get() const;
132 
133  Any asAny() const override;
134 
135  void clear() override;
136 
137  template<typename Compare = std::equal_to<T>>
138  bool compareExchange(const T & expected, const T & desired);
139 
140  template<typename Compare = std::equal_to<T>>
141  bool compareExchange(const T & expected,
142  const T & desired,
143  const T & alternate);
144 
145  private:
146  T value_;
147  mutable std::mutex mutex_;
148 
150 
151  friend StatisticRegistrar;
152  };
153 }
154 
155 template <typename T>
156 bool operator<=(const T & val, const EMANE::StatisticNumeric<T> & stat);
157 
158 template <typename T>
159 bool operator>=(const T & val, const EMANE::StatisticNumeric<T> & stat);
160 
161 template <typename T>
162 bool operator>(const T & val, const EMANE::StatisticNumeric<T> & stat);
163 
164 template <typename T>
165 bool operator<(const T & val, const EMANE::StatisticNumeric<T> & stat);
166 
167 template <typename T>
168 bool operator==(const T & val, const EMANE::StatisticNumeric<T> & stat);
169 
170 template <typename T>
171 bool operator!=(const T & val, const EMANE::StatisticNumeric<T> & stat);
172 
173 template <typename T>
174 T operator+(const T & val, const EMANE::StatisticNumeric<T> & stat);
175 
176 template <typename T>
177 T operator-(const T & val, const EMANE::StatisticNumeric<T> & stat);
178 
179 template <typename T>
180 T operator*(const T & val, const EMANE::StatisticNumeric<T> & stat);
181 
182 template <typename T>
183 T operator/(const T & val, const EMANE::StatisticNumeric<T> & stat);
184 
185 template <typename T>
186 T & operator+=(T & val, const EMANE::StatisticNumeric<T> & stat);
187 
188 template <typename T>
189 T & operator-=(T & val, const EMANE::StatisticNumeric<T> & stat);
190 
191 template <typename T>
192 T & operator*=(T & val, const EMANE::StatisticNumeric<T> & stat);
193 
194 template <typename T>
195 T & operator/=(T & val, const EMANE::StatisticNumeric<T> & stat);
196 
198 
199 #endif // EMANESTATISTICNUMERIC_T_HEADER_
StatisticNumeric< T > & operator--()
StatisticNumeric< T > & operator++()
bool operator<=(const StatisticNumeric< T > &rhs) const
Any asAny() const override
bool operator>(const StatisticNumeric< T > &rhs) const
StatisticNumeric< T > & operator-=(const StatisticNumeric< T > &rhs)
The StatisticRegistrar allows NEM layers to register statistics and statistic tables. Statistics and Statistic tables are owned by the emulator framework and a borrowed reference is returned to the registering NEM layer.
StatisticNumeric< T > & operator/=(const StatisticNumeric< T > &rhs)
const T operator+(const StatisticNumeric< T > &rhs) const
bool operator>=(const StatisticNumeric< T > &rhs) const
StatisticNumeric< T > & operator*=(const StatisticNumeric< T > &rhs)
The Statistic interface is the base class of all statistics. It provided methods to access and clear ...
Definition: statistic.h:48
bool compareExchange(const T &expected, const T &desired)
const T operator-(const StatisticNumeric< T > &rhs) const
The Any class can contain an instance of one of any type in its support type set. ...
Definition: any.h:49
bool operator<(const StatisticNumeric< T > &rhs) const
Definition: agent.h:43
StatisticNumeric< T > & operator+=(const StatisticNumeric< T > &rhs)
bool operator!=(const StatisticNumeric< T > &rhs) const
const T operator/(const StatisticNumeric< T > &rhs) const
const T operator*(const StatisticNumeric< T > &rhs) const
StatisticNumeric< T > & operator=(const StatisticNumeric< T > &rhs)
bool operator==(const StatisticNumeric< T > &rhs) const
Defines a numeric statistic and its operations.