NEXUS CLASS LIBRARY home | classes | functions

Class MyNexusFileReader

Data Members

inf, infile_exists, outf

Member Functions

DebugReportBlock, EnteringBlock, ExitingBlock, FileExists, MyNexusFileReader, ~MyNexusFileReader, NexusError, OutputComment, SkippingBlock, SkippingDisabledBlock

Class Description

This class represents a NEXUS file reader that supervises the interpretation of a NEXUS-formatted data file. It overloads several important virtual base class functions, including EnteringBlock and ExitingBlock (which allow it to inform the user when particular blocks are being entered or exited), ExecuteStarting and ExecuteStopping (which allow any initialization before a NEXUS file is read or cleanup afterwards, respectively), SkippingBlock and SkippingDisabledBlock (which allow user to be informed when unknown NEXUS blocks are encountered in the data file or when NEXUS blocks are encountered that are known to this application but are being skipped because these blocks were temporarily disabled), OutputComment (which determines how user-specified printable comments in NEXUS files are displayed), and NexusError (which determines how errors encountered in the NEXUS data file are to be reported).

Key to symbols and colors

public, protected, private, A = abstract, C = constructor, D = destructor, I = inline, S = static, V = virtual, F = friend

 

Data Members
     ifstream   inf
       
input file stream used for reading NEXUS file
     bool   infile_exists
       
true if input file is determined to exist, false otherwise
     ofstream   outf
       
output file stream used for reporting progress

 

Member Functions
    void   DebugReportBlock(NxsBlock &nexusBlock)
       
Override of base class virtual function. If a block of the type referenced by 'nexusBlock' has been read (i.e. the IsEmpty member function returns false), this function calls the Report member function of 'nexusBlock' to dump the contents of the block object to the output file stream outf.
    bool   EnteringBlock(NxsString blockName)
       
Override of base class virtual function. Simply reports to both standard output and the output file stream outf that a block named 'blockName' was just entered by the NEXUS file reader. Always returns true.
    void   ExitingBlock(NxsString blockName)
       
Override of base class virtual function. Simply reports to both standard output and the output file stream outf that the NEXUS file reader just finished with a block named 'blockName'.
    bool   FileExists(char *fn)
       
A simple function to test for the existance of a file named 'fn'. Returns true if an attempt to open the file succeeds, and false otherwise. No attempt is made to diagnose failure to open the file, so this function may return false even when the file exists if the file could not be opened for some other reason (e.g. user does not have read permissions for that file).
C     MyNexusFileReader(char *infname, char *outfname)
       
Initializes infile_exists to true if a file by the name 'infname' exists and to false otherwise. If a file named 'infname' exists, proceeds to open the ifstream data member inf to that file and the ofstream data member outf to the file specified by the 'outfname' argument. Does not check for the existance of the output file beforehand, so will overwrite a file if one by than name already exists. In a real application, use the FileExists member function to check for the existance of the output file as well and warn the user before opening it.
D     ~MyNexusFileReader()
       
Destructor simply closes the input file stream inf and the output file stream outf.
    void   NexusError(NxsString msg, file_pos pos, unsigned line, unsigned col)
       
Override of base class virtual function. This function simply reports the error message contained in the string 'msg' and the file position, line and column (contained in 'pos', 'line' and 'col', respectively) to both the standard error stream and the output file stream outf. It then aborts the application by invoking exit(0).
    void   OutputComment(const NxsString &s)
       
Override of base class virtual function. Simply outputs the string 's' to both the standard output and the output stream outf. This function will be called when a printable NEXUS comment is found in a NEXUS file. The contents of the comment are provided in the string argument 's'.
    void   SkippingBlock(NxsString blockName)
       
Override of base class virtual function. Simply reports to both the standard output and to the output stream outf that a block named 'blockName' is being skipped because this NEXUS file reader does not know how to interpret blocks by this name. This situation is common if the NEXUS file has private blocks, e.g. a PAUP block containing commands understood only by the program PAUP.
    void   SkippingDisabledBlock(NxsString blockName)
       
Override of base class virtual function. Simply reports to both the standard output and to the output stream outf that a block named 'blockName' is being skipped because this block, though known to the NEXUS reader, is currently disabled. This situation arises when reading a treefile for instance (the application may disable all blocks except NxsTreesBlock because only TREES blocks expected in a treefile. Overriding this function gives the application a chance to report to the user that NEXUS blocks were found in the file that were unexpected under the circumstances.