// This file is part of BULL, a program for phylogenetic simulations // most of the code was written by Mark T. Holder. // This program is for internal use by the lab of Dr. Tandy Warnow only. // Do not redistribute the code. It 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. // // Some of the code is from publically available source by Paul Lewis, Ziheng Yang, // John Huelsenbeck, David Swofford , and others (as noted in the code). // In fact the main structure of the program was created by modifying Paul Lewis' // basiccmdline.cpp from his NCL // // This code was used in Mark's dissertation, some changes were made in order to // get it to compile on gcc. It is possible that this porting introduced bugs (very // little debugging has been done on UNIX platforms). I would suggest checking // the simulator by generating data on trees with short branches, etc. // This file is part of BULL, a program for phylogenetic simulations // most of the code was written by Mark T. Holder. // This program is for internal use by the lab of Dr. Tandy Warnow only. // Do not redistribute the code. It 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. // // Some of the code is from publically available source by Paul Lewis, Ziheng Yang, // John Huelsenbeck, David Swofford , and others (as noted in the code). // In fact the main structure of the program was created by modifying Paul Lewis' // basiccmdline.cpp from his NCL // // This code was used in Mark's dissertation, some changes were made in order to // get it to compile on gcc. It is possible that this porting introduced bugs (very // little debugging has been done on UNIX platforms). I would suggest checking // the simulator by generating data on trees with short branches, etc. #include "nexus_defs.hpp" #include "nexus_token.hpp" #include "nexus.hpp" /** * @class NexusBlock * @file nexus.hpp * @file nexusblock.cpp * @author Paul O. Lewis * @copyright Copyright © 1999. All Rights Reserved. * @variable isEmpty [bool:private] true if this object is currently storing data * @variable next [NexusBlock*:protected] pointer to next block in list * @variable id [std::string: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 data member to NULL, and isEmpty to true. */ NexusBlock::NexusBlock() : next(NULL), nexus(NULL), isEmpty(true) { } /** * @destructor * * Does nothing. */ NexusBlock::~NexusBlock() { } /** * @method CharLabelToNumber [int:protected] * @param s [std::string] 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( std::string /*s*/ ) { return 0; } /** * @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 [std::string:public] * * Returns the id std::string. */ std::string 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 [std::string] 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( std::string /* commandName */ ) { } /** * @method TaxonLabelToNumber [int:protected] * @param s [std::string] 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( std::string /*s*/ ) { return 0; }