PLearn 0.1
|
#include <DiffCommand.h>
Public Member Functions | |
DiffCommand () | |
virtual void | run (const std::vector< std::string > &args) |
The actual implementation of the 'DiffCommand' command. | |
Static Protected Attributes | |
static PLearnCommandRegistry | reg_ |
This allows to register the 'DiffCommand' command in the command registry. |
Definition at line 56 of file DiffCommand.h.
PLearn::DiffCommand::DiffCommand | ( | ) |
Definition at line 56 of file DiffCommand.cc.
: PLearnCommand("diff", "Compare PLearn objects", prgname() + " diff <reference.psave> <other_1.psave> ..." "<other_n.psave> " "[ <tolerance> [ <relative_tolerance> ] ]\n" "The files with the objects' specifications are given in argument,\n" "the first one being the reference object.\n" "If 'tolerance' is specified, it is taken as the absolute tolerance\n" "(when two numbers are less than 1), and as the relative tolerance\n" "(when one of two numbers is more than 1) unless " "'relative_tolerance'\n" "is also specified.\n" ) {}
void PLearn::DiffCommand::run | ( | const std::vector< std::string > & | args | ) | [virtual] |
The actual implementation of the 'DiffCommand' command.
Implements PLearn::PLearnCommand.
Definition at line 73 of file DiffCommand.cc.
References PLearn::TVec< T >::append(), PLearn::diff(), PLearn::endl(), i, n, PLearn::pl_isnumber(), PLERROR, PLearn::pout, and PLearn::smartLoadObject().
{ const char* error_msg = "In DiffCommand::run - You need to provide at " "least two file names"; if (args.size() < 2) PLERROR(error_msg); // Parse arguments. // First check whether some tolerance is given. real absolute_tolerance = ABSOLUTE_TOLERANCE; real relative_tolerance = RELATIVE_TOLERANCE; real tol; string tol_str = args[args.size() - 1]; int to_ignore = 0; // Number of arguments to ignore at end of 'args'. if (pl_isnumber(tol_str, &tol)) { relative_tolerance = tol; tol_str = args[args.size() - 2]; to_ignore++; if (pl_isnumber(tol_str, &tol)) { to_ignore++; absolute_tolerance = tol; } else absolute_tolerance = relative_tolerance; } // Then read the object specifications paths. TVec<PPath> obj_spec; int n = int(args.size()) - to_ignore; if (n < 2) PLERROR(error_msg); for (vector<string>::size_type i = 0; i<vector<string>::size_type(n); i++) obj_spec.append(args[i]); // Load objects. TVec< PP<Object> > obj; for (int i = 0; i < n; i++) { PP<Object> new_object = smartLoadObject(obj_spec[i]); if (!new_object) PLERROR("In DiffCommand::run - Unable to serialize file %s as an Object", obj_spec[i].absolute().c_str()); obj.append(new_object); } // Compare objects. PStream& out = pout; PP<Object> refer = obj[0]; PP<PLearnDiff> diffs = new PLearnDiff(); diffs->absolute_tolerance = absolute_tolerance; diffs->relative_tolerance = relative_tolerance; for (int i = 1; i < n; i++) { PP<Object> other = obj[i]; diffs->forget(); int n_diffs = diff(refer, other, diffs); if (n_diffs > 0) { out << "Reference (" << obj_spec[0] << ") and object " << i << " (" << obj_spec[i] << ") differ:" << endl; diffs->printDiffs(out); } /* if (!diffs.empty()) { for (vector<string>::size_type j = 0; j < diffs.size(); j += 3) out << " " << diffs[j] << " = " << diffs[j+1] << " != " << diffs[j+2] << endl; } */ } }
PLearnCommandRegistry PLearn::DiffCommand::reg_ [static, protected] |
This allows to register the 'DiffCommand' command in the command registry.
Definition at line 66 of file DiffCommand.h.