ChecksumLogValueT.cc 2.66 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// (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"
#include "StreamContainerT.hh"

#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);
}

template <typename ValueT> std::vector<ValueT>
get_values(const std::string& _key, const char* const _flnm,
  const boost::filesystem::path& _dir)
{
  std::ifstream istr((_dir / _flnm).string());
  std::string line;
  std::vector<ValueT> defcts;
  while (std::getline(istr, line))
  {
    auto pos = line.find(_key);
    if (pos == std::string::npos)
      continue;

    pos += _key.length();
    std::stringstream str_dat(line.substr(pos));
    defcts.push_back(ValueT());
    str_dat >> defcts.back();
  }
  return defcts;
}

}

// Class LogValueT

template <typename ValueT, class CompareT> 
LogValueT<ValueT, CompareT>::LogValueT
  (
  unsigned _order, const char* _name,
  const char* _key,
  const CompareT& _comp,
  const char* _flnm
  )
  : IChecksum(_order, _name), comp_(_comp), key_(_key),  flnm_(_flnm)
{}

template <typename ValueT, class CompareT>
Severity LogValueT<ValueT, CompareT>::compare(
  const boost::filesystem::path& _dir0, 
  const boost::filesystem::path& _dir1,
  std::stringstream& _os) const
{
  auto list0 = get_values<ValueT>(key_, flnm_, _dir0);
  auto list1 = get_values<ValueT>(key_, flnm_, _dir1);
  if (list0.size() != list1.size())
  {
    _os << '#' << list0.size() << " #" << list1.size();
    return 1;
  }
  for (auto i = list0.size(); i-- > 0; )
  {
    if (comp_(list0[i], list1[i]))
    {
      list0.erase(list0.begin() + i);
      list1.erase(list1.begin() + i);
    }
  }
  if (list0.empty() && list1.empty())
    return 0;
  _os << list0 << " " << list1;
  return 0.5;
}

template <typename ValueT, class CompareT>
Severity LogValueT<ValueT, CompareT>::report(
  const boost::filesystem::path& _dir,
  std::stringstream& _os) const
{
  auto list = get_values<ValueT>(name(), flnm_, _dir);
  if (list.empty())
    return 0;
  _os << list;
  return 1;
}

}//namespace Test
}//namespace Checksum

#endif//TEST_ON