EMANE  1.2.1
statisticnumeric.inl
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 - 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 template<typename T>
36  value_{}{}
37 
38 template<typename T>
40 
41 template<typename T>
43 {
44  std::lock_guard<std::mutex> m(mutex_);
45 
46  ++value_;
47 
48  return *this;
49 }
50 
51 template<typename T>
53 {
54  std::lock_guard<std::mutex> m(mutex_);
55 
56  T tmp{value_};
57 
58  ++value_;
59 
60  return tmp;
61 }
62 
63 template<typename T>
65 {
66  std::lock_guard<std::mutex> m(mutex_);
67 
68  value_ += rhs.value_;
69 
70  return *this;
71 }
72 
73 template<typename T>
75 {
76  std::lock_guard<std::mutex> m(mutex_);
77 
78  T tmp{value_};
79 
80  tmp += rhs;
81 
82  return tmp;
83 }
84 
85 template<typename T>
87 {
88  std::lock_guard<std::mutex> m(mutex_);
89 
90  --value_;
91 
92  return *this;
93 }
94 
95 template<typename T>
97 {
98  std::lock_guard<std::mutex> m(mutex_);
99 
100  T tmp{value_};
101 
102  --value_;
103 
104  return tmp;
105 }
106 
107 template<typename T>
109 {
110  std::lock_guard<std::mutex> m(mutex_);
111 
112  T tmp{value_};
113 
114  tmp -= rhs;
115 
116  return tmp;
117 }
118 
119 template<typename T>
121 {
122  std::lock_guard<std::mutex> m(mutex_);
123 
124  value_ -= rhs.value_;
125 
126  return *this;
127 }
128 
129 template<typename T>
131 {
132  std::lock_guard<std::mutex> m(mutex_);
133 
134  T tmp{value_};
135 
136  tmp *= rhs;
137 
138  return tmp;
139 }
140 
141 template<typename T>
143 {
144  std::lock_guard<std::mutex> m(mutex_);
145 
146  value_ *= rhs.value_;
147 
148  return *this;
149 }
150 
151 template<typename T>
153 {
154  std::lock_guard<std::mutex> m(mutex_);
155 
156  T tmp{value_};
157 
158  tmp /= rhs;
159 
160  return tmp;
161 }
162 
163 template<typename T>
165 {
166  std::lock_guard<std::mutex> m(mutex_);
167 
168  value_ /= rhs.value_;
169 
170  return *this;
171 }
172 
173 template<typename T>
175 {
176  std::lock_guard<std::mutex> m(mutex_);
177 
178  value_ = rhs.value_;
179 
180  return *this;
181 }
182 
183 template<typename T>
185 {
186  std::lock_guard<std::mutex> m(mutex_);
187 
188  value_ += rhs;
189 
190  return *this;
191 }
192 
193 template<typename T>
195 {
196  std::lock_guard<std::mutex> m(mutex_);
197 
198  return value_ + rhs;
199 }
200 
201 
202 template<typename T>
204 {
205  std::lock_guard<std::mutex> m(mutex_);
206 
207  return value_ - rhs;
208 }
209 
210 template<typename T>
212 {
213  std::lock_guard<std::mutex> m(mutex_);
214 
215  value_-= rhs;
216 
217  return *this;
218 }
219 
220 template<typename T>
222 {
223  std::lock_guard<std::mutex> m(mutex_);
224 
225  return value_ * rhs;
226 }
227 
228 template<typename T>
230 {
231  std::lock_guard<std::mutex> m(mutex_);
232 
233  value_ *= rhs;
234 
235  return *this;
236 }
237 
238 template<typename T>
240 {
241  std::lock_guard<std::mutex> m(mutex_);
242 
243  return value_ / rhs;
244 }
245 
246 template<typename T>
248 {
249  std::lock_guard<std::mutex> m(mutex_);
250 
251  value_ /= rhs;
252 
253  return *this;
254 }
255 
256 
257 template<typename T>
259 {
260  std::lock_guard<std::mutex> m(mutex_);
261 
262  value_ = rhs;
263 
264  return *this;
265 }
266 
267 
268 template<typename T>
270 {
271  std::lock_guard<std::mutex> m(mutex_);
272 
273  return value_ == rhs.value_;
274 }
275 
276 template<typename T>
278 {
279  return !operator==(rhs);
280 }
281 
282 template<typename T>
284 {
285  std::lock_guard<std::mutex> m(mutex_);
286 
287  return value_ < rhs.value_;
288 }
289 
290 template<typename T>
292 {
293  std::lock_guard<std::mutex> m(mutex_);
294 
295  return value_ <= rhs.value_;
296 }
297 
298 template<typename T>
300 {
301  std::lock_guard<std::mutex> m(mutex_);
302 
303  return value_ > rhs.value_;
304 }
305 
306 template<typename T>
308 {
309  std::lock_guard<std::mutex> m(mutex_);
310 
311  return value_ >= rhs.value_;
312 }
313 
314 template<typename T>
315 bool EMANE::StatisticNumeric<T>::operator==(const T & rhs) const
316 {
317  std::lock_guard<std::mutex> m(mutex_);
318 
319  return value_ == rhs;
320 }
321 
322 template<typename T>
323 bool EMANE::StatisticNumeric<T>::operator!=(const T & rhs) const
324 {
325  return value_ != rhs;
326 }
327 
328 template<typename T>
329 bool EMANE::StatisticNumeric<T>::operator<(const T & rhs) const
330 {
331  std::lock_guard<std::mutex> m(mutex_);
332 
333  return value_ < rhs;
334 }
335 
336 template<typename T>
337 bool EMANE::StatisticNumeric<T>::operator<=(const T & rhs) const
338 {
339  std::lock_guard<std::mutex> m(mutex_);
340 
341  return value_ <= rhs;
342 }
343 
344 template<typename T>
345 bool EMANE::StatisticNumeric<T>::operator>(const T & rhs) const
346 {
347  std::lock_guard<std::mutex> m(mutex_);
348 
349  return value_ > rhs;
350 }
351 
352 template<typename T>
353 bool EMANE::StatisticNumeric<T>::operator>=(const T & rhs) const
354 {
355  std::lock_guard<std::mutex> m(mutex_);
356 
357  return value_ >= rhs;
358 }
359 
360 template<typename T>
362 {
363  std::lock_guard<std::mutex> m(mutex_);
364 
365  return value_;
366 }
367 
368 template<typename T>
370 {
371  std::lock_guard<std::mutex> m(mutex_);
372 
373  return Any{value_};
374 }
375 
376 template<typename T>
378 {
379  std::lock_guard<std::mutex> m(mutex_);
380 
381  value_ = 0;
382 }
383 
384 template<typename T>
385 template<typename Compare>
386 bool EMANE::StatisticNumeric<T>::compareExchange(const T & expected, const T & desired)
387 {
388  Compare cmp{};
389 
390  std::lock_guard<std::mutex> m(mutex_);
391 
392  if(cmp(value_,expected))
393  {
394  value_ = desired;
395 
396  return true;
397  }
398 
399  return false;
400 }
401 
402 template<typename T>
403 template<typename Compare>
405  const T & desired,
406  const T & alternate)
407 {
408  Compare cmp{};
409 
410  std::lock_guard<std::mutex> m(mutex_);
411 
412  if(cmp(value_,expected))
413  {
414  value_ = desired;
415 
416  return true;
417  }
418  else
419  {
420  value_ = alternate;
421  }
422 
423  return false;
424 }
425 
426 template <typename T>
427 bool operator<=(const T & val, const EMANE::StatisticNumeric<T> & stat)
428 {
429  return EMANE::StatisticNumeric<T>(val)<=stat;
430 }
431 
432 template <typename T>
433 bool operator>=(const T & val, const EMANE::StatisticNumeric<T> & stat)
434 {
435  return EMANE::StatisticNumeric<T>(val)>=stat;
436 }
437 
438 template <typename T>
439 bool operator>(const T & val, const EMANE::StatisticNumeric<T> & stat)
440 {
441  return val > stat.get();
442 }
443 
444 template <typename T>
445 bool operator<(const T & val, const EMANE::StatisticNumeric<T> & stat)
446 {
447  return val > stat.getValue();
448 }
449 
450 template <typename T>
451 bool operator==(const T & val, const EMANE::StatisticNumeric<T> & stat)
452 {
453  return val == stat.getValue();
454 }
455 
456 template <typename T>
457 bool operator!=(const T & val, const EMANE::StatisticNumeric<T> & stat)
458 {
459  return val != stat.getValue();
460 }
461 
462 template <typename T>
463 T operator+(const T & val, const EMANE::StatisticNumeric<T> & stat)
464 {
465  return val + stat.getValue();
466 }
467 
468 template <typename T>
469 T operator-(const T & val, const EMANE::StatisticNumeric<T> & stat)
470 {
471  return val - stat.getValue();
472 }
473 
474 template <typename T>
475 T operator*(const T & val, const EMANE::StatisticNumeric<T> & stat)
476 {
477  return val * stat.getValue();
478 }
479 
480 template <typename T>
481 T operator/(const T & val, const EMANE::StatisticNumeric<T> & stat)
482 {
483  return val / stat.getValue();
484 }
485 
486 template <typename T>
487 T & operator+=(T & val, const EMANE::StatisticNumeric<T> & stat)
488 {
489  return val += stat.getValue();
490 }
491 
492 template <typename T>
493 T & operator-=(T & val, const EMANE::StatisticNumeric<T> & stat)
494 {
495  return val -= stat.getValue();
496 }
497 
498 template <typename T>
499 T & operator*=(T & val, const EMANE::StatisticNumeric<T> & stat)
500 {
501  return val *= stat.getValue();
502 }
503 
504 template <typename T>
505 T & operator/=(T & val, const EMANE::StatisticNumeric<T> & stat)
506 {
507  return val /= stat.getValue();
508 }
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)
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)
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
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.