PLearn 0.1
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Static Protected Member Functions | Protected Attributes | Private Types | Private Member Functions
PLearn::PLearnDiff Class Reference

#include <PLearnDiff.h>

Inheritance diagram for PLearn::PLearnDiff:
Inheritance graph
[legend]
Collaboration diagram for PLearn::PLearnDiff:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 PLearnDiff ()
 Default constructor.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual PLearnDiffdeepCopy (CopiesMap &copies) const
virtual void build ()
 Post-constructor.
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.
int diff (const string &refer, const string &other, const string &name)
 If 'refer' != 'other' return 1 and add the difference 'name' with the corresponding reference and other values.
void forget ()
 Empty the 'diffs' matrix.
void addDiffPrefix (const string &prefix, int n)
 Add 'prefix' in front of the last 'n' difference names in 'diffs'.
void printDiffs (PStream &out=pout, unsigned int indent=2, unsigned int tab_step=20, unsigned int max_width=120)
 Display the differences that were found.
int nDiffs ()
 Return the number of differences found.
void setSaveDiffs (bool save_diffs, bool *save_diffs_backup=0)
 Set 'save_diffs' option.

Static Public Member Functions

static string _classname_ ()
static OptionList_getOptionList_ ()
static RemoteMethodMap_getRemoteMethodMap_ ()
static Object_new_instance_for_typemap_ ()
static bool _isa_ (const Object *o)
static void _static_initialize_ ()
static const PPathdeclaringFile ()

Public Attributes

real absolute_tolerance
real relative_tolerance
bool save_diffs

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

static void declareOptions (OptionList &ol)
 Declares this class' options.

Protected Attributes

TMat< string > diffs

Private Types

typedef Object inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Definition at line 54 of file PLearnDiff.h.


Member Typedef Documentation

Reimplemented from PLearn::Object.

Definition at line 59 of file PLearnDiff.h.


Constructor & Destructor Documentation

PLearn::PLearnDiff::PLearnDiff ( )

Default constructor.

Definition at line 50 of file PLearnDiff.cc.

References build_(), and forget().

                      :
    absolute_tolerance(ABSOLUTE_TOLERANCE),
    relative_tolerance(RELATIVE_TOLERANCE),
    save_diffs(true)
{
    build_();
    forget();
}

Here is the call graph for this function:


Member Function Documentation

string PLearn::PLearnDiff::_classname_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 62 of file PLearnDiff.cc.

OptionList & PLearn::PLearnDiff::_getOptionList_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 62 of file PLearnDiff.cc.

RemoteMethodMap & PLearn::PLearnDiff::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 62 of file PLearnDiff.cc.

bool PLearn::PLearnDiff::_isa_ ( const Object o) [static]

Reimplemented from PLearn::Object.

Definition at line 62 of file PLearnDiff.cc.

Object * PLearn::PLearnDiff::_new_instance_for_typemap_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 62 of file PLearnDiff.cc.

StaticInitializer PLearnDiff::_static_initializer_ & PLearn::PLearnDiff::_static_initialize_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 62 of file PLearnDiff.cc.

void PLearn::PLearnDiff::addDiffPrefix ( const string &  prefix,
int  n 
)

Add 'prefix' in front of the last 'n' difference names in 'diffs'.

Definition at line 100 of file PLearnDiff.cc.

References diffs, j, PLearn::TMat< T >::length(), n, and PLASSERT.

Referenced by PLearn::addDiffPrefix().

{
    PLASSERT( n >= 0 && n <= diffs.length() );
    int l = diffs.length() - 1;
    for (int j = 0; j < n; j++)
        diffs(l - j, 0) = prefix + diffs(l - j, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::PLearnDiff::build ( ) [virtual]

Post-constructor.

The normal implementation should call simply inherited::build(), then this class's build_(). This method should be callable again at later times, after modifying some option fields to change the "architecture" of the object.

Reimplemented from PLearn::Object.

Definition at line 91 of file PLearnDiff.cc.

References PLearn::Object::build(), and build_().

Here is the call graph for this function:

void PLearn::PLearnDiff::build_ ( ) [private]

This does the actual building.

Reimplemented from PLearn::Object.

Definition at line 83 of file PLearnDiff.cc.

References diffs, PLearn::TMat< T >::length(), and PLearn::TMat< T >::resize().

Referenced by build(), and PLearnDiff().

{
    diffs.resize(diffs.length(), 3);
}

Here is the call graph for this function:

Here is the caller graph for this function:

string PLearn::PLearnDiff::classname ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 62 of file PLearnDiff.cc.

void PLearn::PLearnDiff::declareOptions ( OptionList ol) [static, protected]

Declares this class' options.

Reimplemented from PLearn::Object.

Definition at line 64 of file PLearnDiff.cc.

References absolute_tolerance, PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::Object::declareOptions(), relative_tolerance, and save_diffs.

{
    declareOption(ol, "absolute_tolerance", &PLearnDiff::absolute_tolerance, OptionBase::buildoption,
            "The absolute tolerance used when comparing real numbers less than 1.");

    declareOption(ol, "relative_tolerance", &PLearnDiff::relative_tolerance, OptionBase::buildoption,
            "The relative tolerance used when comparing real numbers and one is more than 1.");

    declareOption(ol, "save_diffs", &PLearnDiff::save_diffs, OptionBase::buildoption,
            "If set to 1, each call to 'diff' will save any difference found.\n"
            "Otherwise, differences will not be saved.");

    // Now call the parent class' declareOptions
    inherited::declareOptions(ol);
}

Here is the call graph for this function:

static const PPath& PLearn::PLearnDiff::declaringFile ( ) [inline, static]

Reimplemented from PLearn::Object.

Definition at line 100 of file PLearnDiff.h.

{ return diffs.length(); }
PLearnDiff * PLearn::PLearnDiff::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 62 of file PLearnDiff.cc.

int PLearn::PLearnDiff::diff ( const string &  refer,
const string &  other,
const string &  name 
)

If 'refer' != 'other' return 1 and add the difference 'name' with the corresponding reference and other values.

Otherwise, do nothing and just return 0.

Definition at line 117 of file PLearnDiff.cc.

References PLearn::TMat< T >::appendRow(), diffs, PLearn::TVec< T >::resize(), and save_diffs.

Referenced by PLearn::diff().

{
    static TVec<string> diff_row;
    diff_row.resize(3);
    if (refer != other) {
        if (save_diffs) {
            diff_row[0] = name;
            diff_row[1] = refer;
            diff_row[2] = other;
            diffs.appendRow(diff_row);
        }
        return 1;
    } else
        return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::PLearnDiff::forget ( )

Empty the 'diffs' matrix.

Definition at line 142 of file PLearnDiff.cc.

References diffs, PLearn::TMat< T >::resize(), and PLearn::TMat< T >::width().

Referenced by PLearnDiff().

{
    diffs.resize(0, diffs.width());
}

Here is the call graph for this function:

Here is the caller graph for this function:

OptionList & PLearn::PLearnDiff::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 62 of file PLearnDiff.cc.

OptionMap & PLearn::PLearnDiff::getOptionMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 62 of file PLearnDiff.cc.

RemoteMethodMap & PLearn::PLearnDiff::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 62 of file PLearnDiff.cc.

void PLearn::PLearnDiff::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::Object.

Definition at line 168 of file PLearnDiff.cc.

References PLearn::Object::makeDeepCopyFromShallowCopy(), and PLERROR.

{
    inherited::makeDeepCopyFromShallowCopy(copies);

    // ### Call deepCopyField on all "pointer-like" fields 
    // ### that you wish to be deepCopied rather than 
    // ### shallow-copied.
    // ### ex:
    // deepCopyField(trainvec, copies);

    // ### Remove this line when you have fully implemented this method.
    PLERROR("PLearnDiff::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
}

Here is the call graph for this function:

int PLearn::PLearnDiff::nDiffs ( ) [inline]

Return the number of differences found.

Definition at line 130 of file PLearnDiff.h.

References diffs, and PLearn::TMat< T >::length().

Referenced by printDiffs().

{ return diffs.length(); }

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::PLearnDiff::printDiffs ( PStream out = pout,
unsigned int  indent = 2,
unsigned int  tab_step = 20,
unsigned int  max_width = 120 
)

Display the differences that were found.

'indent' specifies the number of whitespaces to add before each line. 'tab_step' specifies the canonical length of each element (name and values for each difference), in order to obtain a fancy output. 'max_width' specifies the maximum number of characters printed on each line (note that a long option value or name that exceeds this number will still be printed unchanged).

Definition at line 185 of file PLearnDiff.cc.

References diffs, PLearn::endl(), i, n, and nDiffs().

{
    int n = nDiffs();
    for (int i = 0; i < n; i++) {
        const string& diff_name = diffs(i, 0);
        const string& diff_val1 = diffs(i, 1);
        const string& diff_val2 = diffs(i, 2);
        unsigned int n_blanks_after_name =
            tab_step - (unsigned int)(diff_name.size()) % tab_step;
        unsigned int n_blanks_after_val1 =
            tab_step - (unsigned int)(diff_val1.size()) % tab_step;
        if (indent + diff_name.size() + n_blanks_after_name + 3 
            + diff_val1.size() + n_blanks_after_val1 + 7 + diff_val2.size()
            < max_width) {
            out << string(indent, ' ')
                << diff_name << string(n_blanks_after_name, ' ')
                << ":  "
                << diff_val1 << string(n_blanks_after_val1, ' ')
                << "  -->  "
                << diff_val2 << endl;
        } else {
            out << string(indent, ' ')
                << diff_name << ":" << endl
                << diff_val1 << endl
                << "  -->  " << endl
                << diff_val2 << endl;
        }
    }
}

Here is the call graph for this function:

void PLearn::PLearnDiff::setSaveDiffs ( bool  save_diffs,
bool save_diffs_backup = 0 
)

Set 'save_diffs' option.

If 'save_diffs_backup' is provided, copy the old value of 'save_diffs' in it.

Definition at line 220 of file PLearnDiff.cc.

References save_diffs.

Referenced by PLearn::setSaveDiffs().

{
    if (save_diffs_backup)
        *save_diffs_backup = this->save_diffs;
    this->save_diffs = save_diffs;
}

Here is the caller graph for this function:


Member Data Documentation

Reimplemented from PLearn::Object.

Definition at line 100 of file PLearnDiff.h.

Definition at line 75 of file PLearnDiff.h.

Referenced by declareOptions(), and PLearn::get_absolute_tolerance().

TMat<string> PLearn::PLearnDiff::diffs [protected]

Definition at line 67 of file PLearnDiff.h.

Referenced by addDiffPrefix(), build_(), diff(), forget(), nDiffs(), and printDiffs().

Definition at line 76 of file PLearnDiff.h.

Referenced by declareOptions(), and PLearn::get_relative_tolerance().

Definition at line 77 of file PLearnDiff.h.

Referenced by declareOptions(), diff(), and setSaveDiffs().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines