1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
#include "nexusdefs.h"
#include "nexustoken.h"
#include "nexus.h"
/**
* @class NexusBlock
* @file nexus.h
* @file nexusblock.cpp
* @author Paul O. Lewis
* @copyright Copyright 1999. All Rights Reserved.
* @variable isDisabled [bool:private] true if this block is currently disabled
* @variable isEmpty [bool:private] true if this object is currently storing data
* @variable next [NexusBlock*:protected] pointer to next block in list
* @variable id [nxsstring:protected] holds name of block (e.g., "DATA", "TREES", etc.)
* @see Nexus
* @see NexusReader
* @see NexusToken
*
* This is the base class from which all Nexus block classes are derived.
* The abstract virtual function Read must be overridden for each derived
* class to provide the ability to read everything following the block name
* (which is read by the Nexus object) to the end or endblock statement.
* Derived classes must provide their own data storage and access functions.
*/
/**
* @constructor
*
* Default constructor
* Initializes 'next' and 'nexus' data members to NULL, and 'isEmpty' and
* 'isEnabled' to true.
*/
NexusBlock::NexusBlock() : next(NULL), nexus(NULL), isEmpty(true), isEnabled(true)
{
}
/**
* @destructor
*
* Does nothing.
*/
NexusBlock::~NexusBlock()
{
}
/**
* @method CharLabelToNumber [int:protected]
* @param s [nxsstring] the character label to be translated to character number
*
* This base class version simply returns -1, but a derived class should
* override this function if it needs to construct and run a SetReader
* object to read a set involving characters. The SetReader object may
* need to use this function to look up a character label encountered in
* the set. A class that overrides this method should return the
* character index in the range [1..nchar]; i.e., add one to the 0-offset
* index.
*/
int NexusBlock::CharLabelToNumber( nxsstring /*s*/ )
{
return 0;
}
/**
* @method Disable [void:public]
*
* Sets the value of isEnabled to false. A NexusBlock
* can be disabled (by calling this method) if blocks of that type
* are to be skipped during execution of the nexus file.
* If a disabled block is encountered, the virtual
* Nexus::SkippingDisabledBlock function is called.
*/
void NexusBlock::Disable()
{
isEnabled = false;
}
/**
* @method Enable [void:public]
*
* Sets the value of isEnabled to true. A NexusBlock
* can be disabled (by calling Disable) if blocks of that type
* are to be skipped during execution of the nexus file.
* If a disabled block is encountered, the virtual
* Nexus::SkippingDisabledBlock function is called.
*/
void NexusBlock::Enable()
{
isEnabled = true;
}
/**
* @method IsEnabled [bool:public]
*
* Returns value of isEnabled, which can be controlled through
* use of the Enable and Disable member functions. A NexusBlock
* should be disabled if blocks of that type are to be skipped
* during execution of the nexus file. If a disabled block is
* encountered, the virtual Nexus::SkippingDisabledBlock function
* is called.
*/
bool NexusBlock::IsEnabled()
{
return isEnabled;
}
/**
* @method IsEmpty [bool:public]
*
* Returns true if Read function has not been called since the last Reset.
* This base class version simply returns the value of the data member
* isEmpty. If you derive a new block class from NexusBlock, be sure
* to set isEmpty to true in your Reset function and isEmpty to false in your
* Read function.
*/
bool NexusBlock::IsEmpty()
{
return isEmpty;
}
/**
* @method Read [virtual void:protected]
* @param token [NexusToken&] the NexusToken to use for reading block
* @param in [istream&] the input stream from which to read
*
* This abstract virtual function must be overridden for each derived
* class to provide the ability to read everything following the block name
* (which is read by the Nexus object) to the end or endblock statement.
* Characters are read from the input stream in. Note that to get output
* comments displayed, you must derive a class from NexusToken, override
* the member function OutputComment to display a supplied comment, and
* then pass a reference to an object of the derived class to this function.
*/
// virtual void Read( NexusToken& token, istream& in ) = 0;
/**
* @method Reset [virtual void:protected]
*
* This abstract virtual function must be overridden for each derived
* class to completely reset the block object in preparation for reading
* in another block of this type. This function is called by the Nexus
* object just prior to calling the block object's Read function.
*/
// virtual void Reset() = 0;
/**
* @method GetID [nxsstring:public]
*
* Returns the id nxsstring.
*/
nxsstring NexusBlock::GetID()
{
return id;
}
/**
* @method Report [virtual void:public]
* @param out [ostream&] the output stream to which the report is sent
*
* Provides a brief report of the contents of the block.
*/
// virtual void Report( ostream& out ) = 0;
/**
* @method SetNexus [virtual void:public]
* @param nxsptr [Nexus*] pointer to a Nexus object
*
* Sets the nexus data member of the NexusBlock object to
* nxsptr.
*/
void NexusBlock::SetNexus( Nexus* nxsptr )
{
nexus = nxsptr;
}
/**
* @method SkippingCommand [virtual void:public]
* @param commandName [nxsstring] the name of the command being skipped
*
* This function is called when an unknown command named commandName is
* about to be skipped. This version of the function does nothing (i.e.,
* no warning is issued that a command was unrecognized. Override this
* virtual function in a derived class to provide such warnings to the
* user.
*/
void NexusBlock::SkippingCommand( nxsstring /* commandName */ )
{
}
/**
* @method TaxonLabelToNumber [int:protected]
* @param s [nxsstring] the taxon label to be translated to a taxon number
*
* This base class version simply returns 0, but a derived class should
* override this function if it needs to construct and run a SetReader
* object to read a set involving taxa. The SetReader object may
* need to use this function to look up a taxon label encountered in
* the set. A class that overrides this method should return the
* taxon index in the range [1..ntax]; i.e., add one to the 0-offset
* index.
*/
int NexusBlock::TaxonLabelToNumber( nxsstring /*s*/ )
{
return 0;
}
|