VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
testAssignUtil.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 2006 MaK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************/
5 /*********************************************************************
6 ** $RCSfile: testAssignUtil.h,v $ $Revision: 1.1 $ $State: Exp $
7 ********************************************************************/
8 #ifndef TD_TEST_ASSIGN_UTIL
9 #define TD_TEST_ASSIGN_UTIL
10 
11 //
12 // Utility class tests if data is changed while assigning it.
13 // If the data being tested has an operator = function, use set(old, new)
14 // If not then use if (set.test(old.<value>(), new.<value>())) and assign the value
15 // yourself inside the if statement.
16 //
17 
19 public:
20  TdTestAssignUtil(float tol = -1.0, double dTol = -1.0)
21  {
22  mTol = (tol < 0) ? 1.0e-6 : tol;
23  mDTol = (dTol < 0) ? 1.0e-9 : dTol;
24  myChanged = false;
25  }
26 
27  void operator() (float& oldVal, const float & newVal)
28  {
29  if (fabs(oldVal - newVal) > mTol)
30  {
31  myChanged = true;
32  oldVal = newVal;
33  }
34  }
35  bool test (const float& oldVal, const float & newVal)
36  {
37  myChanged = (fabs(oldVal - newVal) > mTol);
38  return myChanged;
39  }
40 
41  void operator() (double& oldVal, const double & newVal)
42  {
43  if (fabs(oldVal - newVal) > mDTol)
44  {
45  myChanged = true;
46  oldVal = newVal;
47  }
48  }
49  bool test (const double& oldVal, const double & newVal)
50  {
51  myChanged = (fabs(oldVal - newVal) > mDTol);
52  return myChanged;
53  }
54 
55  template <class _T>
56  void operator()(_T& oldVal, const _T& newVal)
57  {
58  // Note use of == instead of !=
59  if (!(oldVal == newVal))
60  {
61  myChanged = true;
62  oldVal = newVal;
63  }
64  }
65 
66  template <class _T>
67  bool test(const _T& oldVal, const _T& newVal)
68  {
69  // Note use of == instead of !=
70  if (!(oldVal == newVal))
71  {
72  myChanged = true;
73  return true;
74  }
75  return false;
76  }
77 
78  // Returns whether any of the preceeding assignments have changed
79  // a value.
80 
81  bool changed() const
82  {
83  return myChanged;
84  }
85 
86  // Reset the change flag to false
87  void reset()
88  {
89  myChanged = false;
90  }
91 
92 protected:
93  bool myChanged;
94  float mTol;
95  double mDTol;
96 };
97 
98 #endif
Definition: testAssignUtil.h:18
double mDTol
Definition: testAssignUtil.h:95
bool changed() const
Definition: testAssignUtil.h:81
float mTol
Definition: testAssignUtil.h:94
void operator()(float &oldVal, const float &newVal)
Definition: testAssignUtil.h:27
void operator()(_T &oldVal, const _T &newVal)
Definition: testAssignUtil.h:56
TdTestAssignUtil(float tol=-1.0, double dTol=-1.0)
Definition: testAssignUtil.h:20
bool test(const double &oldVal, const double &newVal)
Definition: testAssignUtil.h:49
void reset()
Definition: testAssignUtil.h:87
bool test(const _T &oldVal, const _T &newVal)
Definition: testAssignUtil.h:67
bool myChanged
Definition: testAssignUtil.h:93
bool test(const float &oldVal, const float &newVal)
Definition: testAssignUtil.h:35

Document ID: Generated on Tue Sep 24 19:28:17 EDT 2024 from SVN revision 269799
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)