ChecksumLogValueT.hh 2.65 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// (C) Copyright 2016 by Autodesk, Inc.
//
// The information contained herein is confidential, proprietary
// to Autodesk,  Inc.,  and considered a trade secret as defined
// in section 499C of the penal code of the State of California.
// Use of  this information  by  anyone  other  than  authorized
// employees of Autodesk, Inc.  is granted  only under a written
// non-disclosure agreement,  expressly  prescribing  the  scope
// and manner of such use.
#ifndef BASE_CHECKSUMLOGVALUET_HH_INCLUDE
#define BASE_CHECKSUMLOGVALUET_HH_INCLUDE

#ifdef TEST_ON

#include "IChecksum.hh"
#include "Base/Debug/DebDefault.hh"

#include <functional>

namespace Test {
namespace Checksum {

/*!
Utility class to compare double with a tolerance. Can be used to redefine the
default compare class in class LogValueT.
*/
struct DoubleEqual
{
  DoubleEqual(double _tol = 1e-12) : tol_(_tol) {}
  bool operator()(const double& _a, const double& _b) const
  {
    return std::fabs(_a - _b) <= tol_;
  }
private:
  double tol_;
};

/*!
Class that can be used to specialize the behavior of LogValueT in such a way
that it only checks the number of occurrences.
*/
struct Count
{
  bool operator==(const Count&) const { return true; }

  friend std::istream& operator >> (std::istream& _is, Count&) { return _is; }

  friend std::ostream& operator << (std::ostream& _os, const Count&) { return _os; }
};

/*!
Generic Checksum class to compare data that can be read from a output file 
(default Debug::Default::LOG_FILENAME). It searches all occurrences of a string
in the file and reads the next field to get the checksum value. 
If ValueT == Count it simply counts the number of occurrences of the search string.
*/
template <typename ValueT, class CompareT = std::equal_to<ValueT>>
class LogValueT : public IChecksum
{
public:
  const char* flnm_; // File to parse
  const char* key_;  // String to search as information key.

  LogValueT(
    unsigned _order,   //!<[in] Execution order. Low order means high priority.
    const char* _name, //!<[in] Checksum name.
    const char* _key,  //!<[in] String to search in the output file.
    const CompareT& _comp = CompareT(), //!<[in] Comparison function.
    const char* _flnm = Debug::Default::LOG_FILENAME
                       //*!<[in] File to parse to get the information.
    );

73
  virtual Severity report(const Path& _dir, std::stringstream& _os) const;
74

75
76
  virtual Severity compare(const Path& _dir0, const Path& _dir1, 
    std::stringstream& _os) const;
77
78
79
80
81
82
83
84
85
86
87
88
89
90

private:
  CompareT comp_; // Compare class.

  LogValueT<ValueT>& operator=(const LogValueT<ValueT>&);
};



}//namespace Checksum
}//namespace Test

#endif//TEST_ON
#endif//BASE_CHECKSUMLOGVALUET_HH_INCLUDE