NeoPZ
TPZAssert.h
Go to the documentation of this file.
1 /*
2  * File: TPZAssert.h
3  * Author: thiago
4  *
5  * Created on 26 de Fevereiro de 2018, 13:49
6  */
7 
8 #ifndef TPZASSERT_H
9 #define TPZASSERT_H
10 
11 #include "pzerror.h"
12 #include "pzextractval.h"
13 
14 class TPZAssert {
15 public:
16 
17  template<typename T>
18  static T& NonNegative(T &value) {
19  //Note that IsZero uses a tolerance.
20  if (value < T(0) && TPZExtractVal::IsZero(value)){
21  SetValue(value, 0);
22  }
23  return value;
24  }
25 
26  template<typename T>
27  static T NonNegative(const T &value) {
28  T copy(value);
29  return NonNegative(copy);
30  }
31 
32 private:
33 
34  template<typename T, typename TValue>
35  static void SetValue(T &var, const TValue value) {
36  TPZExtractVal::ref(var) = value;
37  }
38 
39 };
40 
41 #endif /* TPZASSERT_H */
42 
static int & ref(int &number)
Definition: pzextractval.h:58
Defines PZError.
static bool IsZero(const T &a)
Definition: pzextractval.h:88
static T NonNegative(const T &value)
Definition: TPZAssert.h:27
static T & NonNegative(T &value)
Definition: TPZAssert.h:18
static void SetValue(T &var, const TValue value)
Definition: TPZAssert.h:35