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
|
// Copyright (C) 1999-2003 Paul O. Lewis
//
// This file is part of NCL (Nexus Class Library) version 2.0.
//
// NCL is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// NCL is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with NCL; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#include "ncl.h"
/*----------------------------------------------------------------------------------------------------------------------
| Initializes all pointer data members to NULL, and all bool data members to true except isUserSupplied, which is
| initialized to false.
*/
NxsBlock::NxsBlock()
{
next = NULL;
nexus = NULL;
isEmpty = true;
isEnabled = true;
isUserSupplied = false;
id.clear();
errormsg.clear();
}
/*----------------------------------------------------------------------------------------------------------------------
| Nothing to be done.
*/
NxsBlock::~NxsBlock()
{
}
/*----------------------------------------------------------------------------------------------------------------------
| This base class version simply returns 0 but a derived class should override this function if it needs to construct
| and run a NxsSetReader object to read a set involving characters. The NxsSetReader 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].
*/
unsigned NxsBlock::CharLabelToNumber(
NxsString s) /* the character label to be translated to the character's number */
{
# if defined(HAVE_PRAGMA_UNUSED)
# pragma unused(s)
# endif
return 0;
}
/*----------------------------------------------------------------------------------------------------------------------
| Sets the value of isEnabled to false. A NxsBlock 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
| NxsReader::SkippingDisabledBlock function is called, giving your application the opportunity to inform the user
| that a block was skipped.
*/
void NxsBlock::Disable()
{
isEnabled = false;
}
/*----------------------------------------------------------------------------------------------------------------------
| Sets the value of isEnabled to true. A NxsBlock 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
| NxsReader::SkippingDisabledBlock function is called, giving your application the opportunity to inform the user
| that a block was skipped.
*/
void NxsBlock::Enable()
{
isEnabled = true;
}
/*----------------------------------------------------------------------------------------------------------------------
| Returns value of isEnabled, which can be controlled through use of the Enable and Disable member functions. A
| NxsBlock 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 NxsReader::SkippingDisabledBlock function is called, giving your
| application the opportunity to inform the user that a block was skipped.
*/
bool NxsBlock::IsEnabled()
{
return isEnabled;
}
/*----------------------------------------------------------------------------------------------------------------------
| Returns value of isUserSupplied, which is true if and only if this block's Read function is called to process a
| block of this type appearing in a data file. This is useful because in some cases, a block object may be created
| internally (e.g. a NxsTaxaBlock may be populated using taxon names provided in a DATA block), and such blocks do
| not require permission from the user to delete data stored therein.
*/
bool NxsBlock::IsUserSupplied()
{
return isUserSupplied;
}
/*----------------------------------------------------------------------------------------------------------------------
| 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 NxsBlock, be sure to set isEmpty to true in
| your Reset function and isEmpty to false in your Read function.
*/
bool NxsBlock::IsEmpty()
{
return isEmpty;
}
/*----------------------------------------------------------------------------------------------------------------------
| Returns the id NxsString.
*/
NxsString NxsBlock::GetID()
{
return id;
}
/*----------------------------------------------------------------------------------------------------------------------
| This 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 NxsReader 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 NxsToken, 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.
*/
void NxsBlock::Read(
NxsToken &token) /* the NxsToken to use for reading block */
{
# if defined(HAVE_PRAGMA_UNUSED)
# pragma unused(token)
# endif
}
/*----------------------------------------------------------------------------------------------------------------------
| This virtual function should 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 NxsReader object just prior to
| calling the block object's Read function.
*/
void NxsBlock::Reset()
{
}
/*----------------------------------------------------------------------------------------------------------------------
| This virtual function provides a brief report of the contents of the block.
*/
void NxsBlock::Report(
ostream &out) /* the output stream to which the report is sent */
{
# if defined(HAVE_PRAGMA_UNUSED)
# pragma unused(out)
# endif
}
/*----------------------------------------------------------------------------------------------------------------------
| Sets the nexus data member of the NxsBlock object to 'nxsptr'.
*/
void NxsBlock::SetNexus(
NxsReader *nxsptr) /* pointer to a NxsReader object */
{
nexus = nxsptr;
}
/*----------------------------------------------------------------------------------------------------------------------
| 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 NxsBlock::SkippingCommand(
NxsString commandName) /* the name of the command being skipped */
{
# if defined(HAVE_PRAGMA_UNUSED)
# pragma unused(commandName)
# endif
}
/*----------------------------------------------------------------------------------------------------------------------
| This base class version simply returns 0, but a derived class should override this function if it needs to construct
| and run a NxsSetReader object to read a set involving taxa. The NxsSetReader 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].
*/
unsigned NxsBlock::TaxonLabelToNumber(
NxsString s) /* the taxon label to be translated to a taxon number */
{
# if defined(HAVE_PRAGMA_UNUSED)
# pragma unused(s)
# endif
return 0;
}
|