Chaste  Release::3.4
FileComparison Class Reference

#include <FileComparison.hpp>

+ Inheritance diagram for FileComparison:
+ Collaboration diagram for FileComparison:

Public Member Functions

 FileComparison (std::string fileName1, std::string fileName2, bool calledCollectively=true, bool suppressOutput=false)
 
 FileComparison (const FileFinder &rFileName1, const FileFinder &rFileName2, bool calledCollectively=true, bool suppressOutput=false)
 
void SetupCommentLines ()
 
void SetIgnoreCommentLines (bool ignore=true)
 
void IgnoreBlankLines (bool ignore=true)
 
void SetIgnoreLinesBeginningWith (std::string lineStart)
 
void IgnoreLinesContaining (const std::string &rIgnorableText)
 
bool CompareFiles (unsigned ignoreFirstFewLines=0, bool doTsAssert=true)
 
- Public Member Functions inherited from AbstractFileComparison
 AbstractFileComparison (const FileFinder &rFileFinder1, const FileFinder &rFileFinder2, bool calledCollectively, bool suppressOutput)
 
 AbstractFileComparison (std::string fileName1, std::string fileName2, bool calledCollectively, bool suppressOutput)
 
virtual ~AbstractFileComparison ()
 

Private Attributes

bool mIgnoreCommentLines
 
bool mIgnoreBlankLines
 
std::vector< std::string > mCommentLineStarts
 
std::vector< std::string > mIgnorableContent
 

Additional Inherited Members

- Protected Member Functions inherited from AbstractFileComparison
void ResetFiles ()
 
void SkipHeaderLines (unsigned numLinesToSkip)
 
- Protected Attributes inherited from AbstractFileComparison
std::string mFilename1
 
std::string mFilename2
 
std::ifstream * mpFile1
 
std::ifstream * mpFile2
 
unsigned mLineNum
 
bool mCalledCollectively
 
bool mSuppressOutput
 

Detailed Description

Compare files to check for any differences (in numeric and/or string values).

By default this class ignores all lines which (in both files) start with '#' or '!'.

Definition at line 47 of file FileComparison.hpp.

Constructor & Destructor Documentation

FileComparison::FileComparison ( std::string  fileName1,
std::string  fileName2,
bool  calledCollectively = true,
bool  suppressOutput = false 
)
inline

Specify two files to compare, and open them for reading. Actual comparison is done by calling CompareFiles.

Parameters
fileName1first file
fileName2second file
calledCollectivelyif true there will be a barrier before opening files, and only master compares contents.
suppressOutputif true then no errors will go to TS_TRACE(). Should only be set for the test of this class.

Definition at line 75 of file FileComparison.hpp.

References SetupCommentLines().

FileComparison::FileComparison ( const FileFinder rFileName1,
const FileFinder rFileName2,
bool  calledCollectively = true,
bool  suppressOutput = false 
)
inline

Specify two files to compare, and open them for reading. Actual comparison is done by calling CompareFiles.

Parameters
rFileName1first file finder
rFileName2second file finder
calledCollectivelyif true there will be a barrier before opening files, and only master compares contents.
suppressOutputif true then no errors will go to TS_TRACE(). Should only be set for the test of this class.

Definition at line 92 of file FileComparison.hpp.

References SetupCommentLines().

Member Function Documentation

bool FileComparison::CompareFiles ( unsigned  ignoreFirstFewLines = 0,
bool  doTsAssert = true 
)
inline
Returns
true if the files are identical, barring ignored content.
Parameters
ignoreFirstFewLineshow many lines to ignore from the comparison
doTsAssertwhether to throw a TS_ASSERT internally (switched off for testing only)

Definition at line 169 of file FileComparison.hpp.

References PetscTools::AmMaster(), AbstractFileComparison::mCalledCollectively, mCommentLineStarts, AbstractFileComparison::mFilename1, AbstractFileComparison::mFilename2, mIgnorableContent, mIgnoreBlankLines, mIgnoreCommentLines, AbstractFileComparison::mLineNum, AbstractFileComparison::mpFile1, AbstractFileComparison::mpFile2, AbstractFileComparison::mSuppressOutput, AbstractFileComparison::ResetFiles(), and AbstractFileComparison::SkipHeaderLines().

void FileComparison::IgnoreBlankLines ( bool  ignore = true)
inline

Set whether or not we should ignore blank lines. If only one of the files being compared has a blank line, if this mode is on we just skip that line and see if the next content line matches the other file.

Parameters
ignorewhether to ignore blank lines appearing only in one file

Definition at line 135 of file FileComparison.hpp.

References mIgnoreBlankLines.

void FileComparison::IgnoreLinesContaining ( const std::string &  rIgnorableText)
inline

Add the given string to mIgnorableContent, and hence ignore differences in lines which contain that text in both files.

Parameters
rIgnorableTextthe text indicating lines to ignore

Definition at line 158 of file FileComparison.hpp.

References mIgnorableContent.

void FileComparison::SetIgnoreCommentLines ( bool  ignore = true)
inline

Whether or not we should ignore lines starting with a comment symbol (the default symbols are '#' and '!', set by SetupCommentLines).

Parameters
ignorewhether to ignore these lines. If set to false, existing defined comment symbols are also cleared, so that an entirely new set may be defined with SetIgnoreLinesBeginningWith.

Definition at line 120 of file FileComparison.hpp.

References mCommentLineStarts, and mIgnoreCommentLines.

void FileComparison::SetIgnoreLinesBeginningWith ( std::string  lineStart)
inline

Set an additional line start which should be treated as a comment and ignored (and therefore switch on mIgnoreCommentLines = true).

Parameters
lineStartthe beginning of a line which should be treated as a comment

Definition at line 146 of file FileComparison.hpp.

References mCommentLineStarts, and mIgnoreCommentLines.

void FileComparison::SetupCommentLines ( )
inline

Set some line starts that define comments in the files.

These are ignored by default and when mIgnoreCommentLines is explicitly set to true.

Definition at line 105 of file FileComparison.hpp.

References mCommentLineStarts.

Referenced by FileComparison().

Member Data Documentation

std::vector<std::string> FileComparison::mCommentLineStarts
private

A list of strings, which if found at the beginning of lines when mIgnoreCommentLines is true, differences in these lines are ignored.

Definition at line 60 of file FileComparison.hpp.

Referenced by CompareFiles(), SetIgnoreCommentLines(), SetIgnoreLinesBeginningWith(), and SetupCommentLines().

std::vector<std::string> FileComparison::mIgnorableContent
private

Any lines which (in both files) contain one of these strings will be ignored.

Definition at line 63 of file FileComparison.hpp.

Referenced by CompareFiles(), and IgnoreLinesContaining().

bool FileComparison::mIgnoreBlankLines
private

Whether or not we should ignore blank lines. False by default.

Definition at line 54 of file FileComparison.hpp.

Referenced by CompareFiles(), and IgnoreBlankLines().

bool FileComparison::mIgnoreCommentLines
private

Whether or not we should ignore comment lines. True by default.

Definition at line 51 of file FileComparison.hpp.

Referenced by CompareFiles(), SetIgnoreCommentLines(), and SetIgnoreLinesBeginningWith().


The documentation for this class was generated from the following file: