ChecksumLogValueT.cc 2.69 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
// (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.

#ifdef TEST_ON

#include "ChecksumLogValueT.hh"
14
#include "ReadValuesT.hh"
15
#include "StreamContainerT.hh"
16
17
18
#include "TestStream.hh"

#include "Base/Debug/DebOut.hh"
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

#include <boost/filesystem.hpp>

#include <vector>

namespace Test {
namespace Checksum {

// class ChecksumLog implementation
  
namespace { // ChecksumLog locals

template <typename ValueT>
std::ostream& operator<<(std::ostream& _out_str, const std::vector<ValueT>& _vals)
{
  return write_container(_out_str, _vals);
}

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
#define ARITHMETICTYPE(ValueT) \
  typename std::enable_if<std::is_arithmetic<ValueT>::value, ValueT>::type

#define NOTARITHMETICTYPE(ValueT) \
  typename std::enable_if<!std::is_arithmetic<ValueT>::value, ValueT>::type

// Arithmetic types prints the value difference.
template <typename ValueT> void print_values(OStream& _os, 
                                             const ARITHMETICTYPE(ValueT)& _a,
                                             const ARITHMETICTYPE(ValueT)& _b)
{
  _os << "Diff: " << double(_b) - double(_a) << ", L = " << _a << ", R = " <<  _b;
}

// Not arithmetic types prints the two value.
template <typename ValueT> void print_values(OStream& _os, 
                                             const NOTARITHMETICTYPE(ValueT)& _a, 
                                             const NOTARITHMETICTYPE(ValueT)& _b)
{
  _os << _a << " , " << _b;
}

#undef NOTARITHMETICTYPE
#undef ARITHMETICTYPE

62
}//namespace
63
64
65
66

// Class LogValueT

template <typename ValueT, class CompareT> 
67
68
LogValueT<ValueT, CompareT>::LogValueT(const char* _name, const CompareT& _comp)
  : IChecksum(_name), comp_(_comp)
69
70
71
{}

template <typename ValueT, class CompareT>
72
73
74
Severity LogValueT<ValueT, CompareT>::compare(IStream& _str0, IStream& _str1,
                                              OStream& _os, 
                                              const Path*, const Path*) const
75
{
76
77
78
79
  ValueT val[2];
  _str0 >> val[0];
  _str1 >> val[1];
  if (val[0] == val[1])
80
    return 0;
81
82
83

  print_values<ValueT>(_os, val[0], val[1]);
  return 1;
84
85
86
}

template <typename ValueT, class CompareT>
87
void LogValueT<ValueT, CompareT>::record(const Result& _rep_res, const ValueT& _val)
88
{
89
  stream_out() << _rep_res << "  " << name() << ": " << _val << std::endl;
90
91
92
}

}//namespace Checksum
93
}//namespace Test
94
95

#endif//TEST_ON