Commit 9602f27e authored by Marco Amagliani's avatar Marco Amagliani

Added report enumeration output.

[git-p4: depot-paths = "//ReForm/ReForm/main/Base/": change = 13850]
parent 6d050fa9
......@@ -18,7 +18,7 @@ namespace Checksum {
// Template instantiations.
template LogValueT<int>;
template LogValueT<unsigned>;
template LogValueT<double>;
template LogValueT<double, DoubleCompare>;
template LogValueT<size_t>;
template LogValueT<std::string>;
......@@ -27,9 +27,24 @@ template LogValueT<std::string>;
// Check on the debug errors.
LogValueT<Count> chk_error(2, "Debug_errors", "ERROR: ");
struct TimeCompare : public DoubleCompare
{
TimeCompare(double _sec) : DoubleCompare(_sec) {}
ReportOutcome check(const std::vector<double>& _times) const
{
if (_times.size() != 1)
return RO_ERRORS; // Error: time not found.
if (_times[0] < 180)
return RO_OK;
if (_times[0] < 600)
return RO_WARNINGS;
return RO_ERRORS; // Time too long.
}
};
// Check the time.
LogValueT<double, DoubleEqual>
chk_time(2, "Time", "Test time =", DoubleEqual(2), "out.log");
LogValueT<double, TimeCompare>
chk_time(2, "Time", "Test time =", TimeCompare(2), "out.log");
}//namespace Test
}//namespace Checksum
......
......@@ -64,7 +64,7 @@ Severity LogValueT<ValueT, CompareT>::compare(const Path& _dir0,
}
for (auto i = list0.size(); i-- > 0; )
{
if (comp_(list0[i], list1[i]))
if (comp_.same(list0[i], list1[i]))
{
list0.erase(list0.begin() + i);
list1.erase(list1.begin() + i);
......@@ -76,15 +76,14 @@ Severity LogValueT<ValueT, CompareT>::compare(const Path& _dir0,
return 0.5;
}
// Reads and check the values using the compare object.
template <typename ValueT, class CompareT>
Severity LogValueT<ValueT, CompareT>::report(const Path& _dir,
ReportOutcome LogValueT<ValueT, CompareT>::report(const Path& _dir,
std::stringstream& _os) const
{
auto list = read_values<ValueT>(key_, flnm_, _dir);
if (list.empty())
return 0;
_os << list;
return 1;
auto vals = read_values<ValueT>(key_, flnm_, _dir);
_os << vals;
return comp_.check(vals);
}
}//namespace Test
......
......@@ -15,19 +15,53 @@
#include "IChecksum.hh"
#include "Base/Debug/DebDefault.hh"
#include <functional>
#include <vector>
namespace Test {
namespace Checksum {
/*! Default implementation of a comparison class for LogValueT.
*/
template <typename ValueT>
struct DefaultCompareT
{
bool same(const ValueT& _a, const ValueT& _b) const { return _a == _b; }
ReportOutcome check(const std::vector<ValueT>& _vals) const
{
return _vals.empty() ? RO_OK : RO_ERRORS;
}
};
/*! Comparison class for LogValueT for checksums that MUST be present in the log.
*/
template <typename ValueT>
struct RequiredCompareT : public DefaultCompareT<ValueT>
{
ReportOutcome check(const std::vector<ValueT>& _vals) const
{
return _vals.empty() ? RO_ERRORS : RO_OK;
}
};
/*! Comparison class for checksums that MUST only be logged.
*/
template <typename ValueT>
struct NoCompareT
{
bool same(const ValueT& _a, const ValueT& _b) const { return true; }
ReportOutcome check(const std::vector<ValueT>& _vals) const { return RO_OK; }
};
/*!
Utility class to compare double with a tolerance. Can be used to redefine the
default compare class in class LogValueT.
*/
struct DoubleEqual
struct DoubleCompare : public DefaultCompareT<double>
{
DoubleEqual(double _tol = 1e-12) : tol_(_tol) {}
bool operator()(const double& _a, const double& _b) const
DoubleCompare(double _tol = 1e-12) : tol_(_tol) {}
bool same(const double& _a, const double& _b) const
{
return std::fabs(_a - _b) <= tol_;
}
......@@ -54,7 +88,7 @@ Generic Checksum class to compare data that can be read from a output file
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>>
template <typename ValueT, class CompareT = DefaultCompareT<ValueT>>
class LogValueT : public IChecksum
{
public:
......@@ -70,7 +104,7 @@ public:
//*!<[in] File to parse to get the information.
);
virtual Severity report(const Path& _dir, std::stringstream& _os) const;
virtual ReportOutcome report(const Path& _dir, std::stringstream& _os) const;
virtual Severity compare(const Path& _dir0, const Path& _dir1,
std::stringstream& _os) const;
......@@ -78,7 +112,7 @@ public:
private:
CompareT comp_; // Compare class.
LogValueT<ValueT>& operator=(const LogValueT<ValueT>&);
// LogValueT<ValueT, CompareT>& operator=(const LogValueT<ValueT, CompareT>&) { return *this;}
};
......
......@@ -16,10 +16,7 @@
#else
#include "types.hh"
#include <functional>
#include <list>
#include <map>
#include <set>
#include <sstream>
namespace Test {
......@@ -39,9 +36,9 @@ public:
/*!
Override report to log any "interesting value" that the check has in
directory _dir. For example a number of face defects greater that 0.
Return an estimation of the severity.
Returns a simple ReportOutcome.
*/
virtual Severity report(
virtual ReportOutcome report(
const Path& _dir, //!< [in] Directory with the date to report.
std::stringstream& _os //!< [out] Description of the retrieved information.
) const = 0;
......
......@@ -21,6 +21,10 @@ namespace Test {
typedef boost::filesystem::path Path;
typedef double Severity;
enum ReportOutcome {
RO_OK, // Checksum is valid.
RO_WARNINGS, // Checksum is valid but suspicios.
RO_ERRORS }; // Checksum is not valid.
}//namespace Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment