本文整理汇总了C++中NxsToken::GetFileLine方法的典型用法代码示例。如果您正苦于以下问题:C++ NxsToken::GetFileLine方法的具体用法?C++ NxsToken::GetFileLine怎么用?C++ NxsToken::GetFileLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NxsToken
的用法示例。
在下文中一共展示了NxsToken::GetFileLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Read
/*----------------------------------------------------------------------------------------------------------------------
| This function provides 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'. Overrides the pure
| virtual function in the base class.
*/
void NxsEmptyBlock::Read(
NxsToken &token) /* the token used to read from `in'*/
{
isEmpty = false;
// This should be the semicolon after the block name
//
token.GetNextToken();
if (!token.Equals(";"))
{
errormsg = "Expecting ';' after ";
errormsg += id;
errormsg += " block name, but found ";
errormsg += token.GetToken();
errormsg += " instead";
throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
}
for(;;)
{
token.GetNextToken();
if (token.Equals("END"))
{
HandleEndblock(token);
break;
}
else if(token.Equals("ENDBLOCK"))
{
HandleEndblock(token);
break;
}
else
{
SkippingCommand(token.GetToken());
do
{
token.GetNextToken();
}
while (!token.AtEOF() && !token.Equals(";"));
if (token.AtEOF())
{
errormsg = "Unexpected end of file encountered";
throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
}
}
}
}
示例2: HandleHelp
/*----------------------------------------------------------------------------------------------------------------------
| Called when the HELP command needs to be parsed from within the GarliReader block.
*/
void GarliReader::HandleHelp(
NxsToken &token) /* the token used to read from `in' */
{
// Retrieve all tokens for this command, stopping only in the event
// of a semicolon or an unrecognized keyword
//
for (;;)
{
token.GetNextToken();
if (token.Equals(";"))
{
break;
}
else
{
errormsg = "Unexpected keyword (";
errormsg += token.GetToken();
errormsg += ") encountered reading HELP command";
throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
}
}
message = "\nExamples of use of available commands:";
message += "\n help -> shows this message";
message += "\n log file=mylog.txt start -> opens log file named mylog.txt";
message += "\n log stop -> closes current log file";
message += "\n exe mydata.nex -> executes nexus file mydata.nex";
message += "\n show -> reports on blocks currently stored";
message += "\n quit -> terminates application";
message += "\n";
PrintMessage();
}
示例3: NxsException
*/void NxsBlock::DemandIsAtEquals(NxsToken &token, const char *contextString) const
{
if (!token.Equals("="))
{
errormsg = "Expecting '=' ";
if (contextString)
errormsg.append(contextString);
errormsg << " but found " << token.GetToken() << " instead";
throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
}
}
示例4: DemandEndSemicolon
/*!
Advances the token, and returns the unsigned int that the token represents
Sets errormsg and raises a NxsException on failure.
`contextString` is used in error messages:
"Expecting ';' to terminate the ${contextString} command"
*/
void NxsToken::DemandEndSemicolon(NxsToken &token, NxsString & errormsg, const char *contextString)
{
token.GetNextToken();
if (!token.Equals(";"))
{
errormsg = "Expecting ';' to terminate the ";
errormsg += contextString;
errormsg += " command, but found ";
errormsg += token.GetToken();
errormsg += " instead";
throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
}
}
示例5: HandleDimensions
/*!
Called when DIMENSIONS command needs to be parsed from within the UNALIGNED block. Deals with everything after the
token DIMENSIONS up to and including the semicolon that terminates the DIMENSIONS command.
*/
void NxsUnalignedBlock::HandleDimensions(
NxsToken & token) /* the token used to read from `in' */
{
unsigned ntaxRead = 0;
for (;;)
{
token.GetNextToken();
if (token.Equals("NEWTAXA"))
newtaxa = true;
else if (token.Equals("NTAX"))
{
DemandEquals(token, "after NTAX in DIMENSIONS command");
ntaxRead = DemandPositiveInt(token, "NTAX");
}
else if (token.Equals(";"))
break;
}
if (newtaxa)
{
if (ntaxRead == 0)
{
errormsg = "DIMENSIONS command must have an NTAX subcommand when the NEWTAXA option is in effect.";
throw NxsException(errormsg, token);
}
AssureTaxaBlock(createImpliedBlock, token, "Dimensions");
if (!createImpliedBlock)
{
taxa->Reset();
if (nexusReader)
nexusReader->RemoveBlockFromUsedBlockList(taxa);
}
taxa->SetNtax(ntaxRead);
nTaxWithData = ntaxRead;
}
else
{
AssureTaxaBlock(false, token, "Dimensions");
const unsigned ntaxinblock = taxa->GetNTax();
if (ntaxinblock == 0)
{
errormsg = "A TAXA block must be read before character data, or the DIMENSIONS command must use the NEWTAXA.";
throw NxsException(errormsg, token);
}
if (ntaxinblock < ntaxRead)
{
errormsg = "NTAX in UNALIGNED block must be less than or equal to NTAX in TAXA block\nNote: one circumstance that can cause this error is \nforgetting to specify NTAX in DIMENSIONS command when \na TAXA block has not been provided";
throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
}
nTaxWithData = (ntaxRead == 0 ? ntaxinblock : ntaxRead);
}
}
示例6: HandleEndblock
/*----------------------------------------------------------------------------------------------------------------------
Called when the END or ENDBLOCK command needs to be parsed from within the BASICCMDLINE block. Basically just
checks to make sure the next token in the data file is a semicolon.
*/
void BASICCMDLINE::HandleEndblock(
NxsToken & token) /* is the token used to read from `in' */
{
// Get the semicolon following END or ENDBLOCK token
token.GetNextToken();
if (!token.Equals(";"))
{
errormsg = "Expecting ';' to terminate the END or ENDBLOCK command, but found ";
errormsg += token.GetToken();
errormsg += " instead";
throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
}
}
示例7: DemandPositiveInt
/*----------------------------------------------------------------------------------------------------------------------
| Advances the token, and returns the unsigned int that the token represents
|
| Sets errormsg and raises a NxsException on failure.
| `contextString` is used in error messages:
| "${contextString} must be a number greater than 0"
*/
unsigned NxsToken::DemandPositiveInt(NxsToken &token, NxsString & errormsg, const char *contextString)
{
token.GetNextToken();
int i = atoi(token.GetToken().c_str());
if (i <= 0)
{
errormsg.assign(contextString);
errormsg += " must be a number greater than 0. Found";
errormsg += token.GetToken();
errormsg += " instead";
throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
}
return (unsigned) i;
}
示例8: GenerateUnexpectedTokenNxsException
/*----------------------------------------------------------------------------------------------------------------------
| throws a NxsException with the token info for `token`
| `expected` should fill in the phrase "Expecting ${expected}, but found..."
| expected can be NULL.
|
| Sets this->errormsg
*/
void NxsBlock::GenerateUnexpectedTokenNxsException(NxsToken &token, const char *expected) const
{
errormsg = "Unexpected token";
if (expected)
{
errormsg += ". Expecting ";
errormsg += expected;
errormsg += ", but found: ";
}
else
{
errormsg += ": ";
}
errormsg += token.GetToken();
throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
}
示例9: GetFileName
/*----------------------------------------------------------------------------------------------------------------------
Called whenever a file name needs to be read from either the command line or a file. Expects next token to be "="
followed by the token representing the file name. Call this function after, say, the keyword "file" has been read
in the following LOG command:
>
log file=doofus.txt start replace;
>
Note that this function will read only the "=doofus.txt " leaving "start replace;" in the stream for reading at
a later time.
*/
NxsString BASICCMDLINE::GetFileName(
NxsToken & token) /* is the token used to read from `in' */
{
// Eat the equals sign
token.GetNextToken();
if (!token.Equals("="))
{
errormsg = "Expecting an equals sign, but found ";
errormsg += token.GetToken();
errormsg += " instead";
throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
}
// Now get the filename itself
token.GetNextToken();
return token.GetToken();
}
示例10: ReadUntilEndblock
bool NxsReader::ReadUntilEndblock(NxsToken &token, const std::string & )
{
for (;;)
{
token.GetNextToken();
if (token.Equals("END") || token.Equals("ENDBLOCK"))
{
token.GetNextToken();
if (!token.Equals(";"))
{
std::string errormsg = "Expecting ';' after END or ENDBLOCK command, but found ";
errormsg += token.GetToken();
errormsg += " instead";
NexusError(NxsString(errormsg.c_str()), token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
return false;
}
return true;
}
}
}
示例11: Read
/*!
This function provides 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'. Overrides the abstract
virtual function in the base class.
*/
void NxsUnalignedBlock::Read(
NxsToken & token) /* is the token used to read from `in' */
{
isEmpty = false;
isUserSupplied = true;
// This should be the semicolon after the block name
token.GetNextToken();
if (!token.Equals(";"))
{
errormsg = "Expecting ';' after ";
errormsg += NCL_BLOCKTYPE_ATTR_NAME;
errormsg += " block name, but found ";
errormsg += token.GetToken();
errormsg += " instead";
throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
}
nTaxWithData = 0;
for (;;)
{
token.GetNextToken();
NxsBlock::NxsCommandResult res = HandleBasicBlockCommands(token);
if (res == NxsBlock::NxsCommandResult(STOP_PARSING_BLOCK))
return;
if (res != NxsBlock::NxsCommandResult(HANDLED_COMMAND))
{
if (token.Equals("DIMENSIONS"))
HandleDimensions(token);
else if (token.Equals("FORMAT"))
HandleFormat(token);
else if (token.Equals("TAXLABELS"))
HandleTaxLabels(token);
else if (token.Equals("MATRIX"))
HandleMatrix(token);
else
SkipCommand(token);
}
} // for (;;)
}
示例12: Read
/*! Other than the commands handled by NxsBlock::HandleBasicBlockCommands(), this
function will deal with Dimensions and call NxsTaxaBlock::HandleTaxLabels()
to parse the TaxLabels commands.
All other commands will be skipped
*/
void NxsTaxaBlock::Read(
NxsToken &token) /* the token used to read from in */
{
Reset();
isEmpty = false;
isUserSupplied = true;
DemandEndSemicolon(token, "BEGIN TAXA");
for (;;)
{
token.GetNextToken();
NxsBlock::NxsCommandResult res = HandleBasicBlockCommands(token);
if (res == NxsBlock::NxsCommandResult(STOP_PARSING_BLOCK))
return;
if (res != NxsBlock::NxsCommandResult(HANDLED_COMMAND))
{
if (token.Equals("DIMENSIONS"))
{
token.GetNextToken();
if (!token.Equals("NTAX"))
{
errormsg = "Expecting NTAX keyword, but found ";
errormsg += token.GetToken();
errormsg += " instead";
throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
}
DemandEquals(token, "after NTAX");
dimNTax = DemandPositiveInt(token, "NTAX");
taxLabels.reserve(dimNTax);
DemandEndSemicolon(token, "DIMENSIONS");
} // if (token.Equals("DIMENSIONS"))
else if (token.Equals("TAXLABELS"))
HandleTaxLabels(token);
else
SkipCommand(token);
}
} // GetNextToken loop
}
示例13: HandleTaxLabels
void NxsTaxaBlock::HandleTaxLabels(NxsToken &token)
{
if (dimNTax == 0)
{
errormsg = "NTAX must be specified before TAXLABELS command";
throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
}
taxLabels.clear();
labelToIndex.clear();
for (unsigned i = 0; i < dimNTax; i++)
{
token.GetNextToken();
try
{
NxsString t = token.GetToken();
AddTaxonLabel(t);
}
catch (const NxsException & x)
{
throw NxsException(x.msg, token);
}
}
DemandEndSemicolon(token, "TAXLABELS");
}
示例14: CoreExecutionTasks
/*! used internally to do most of the work of Execute() */
void NxsReader::CoreExecutionTasks(
NxsToken &token, /* the token object used to grab NxsReader tokens */
bool notifyStartStop) /* if true, ExecuteStarting and ExecuteStopping will be called */
{
unsigned numSigInts = NxsReader::getNumSignalIntsCaught();
const bool checkingSignals = NxsReader::getNCLCatchesSignals();
lastExecuteBlocksInOrder.clear();
currBlock = NULL;
NxsString errormsg;
token.SetEOFAllowed(true);
try
{
token.SetLabileFlagBit(NxsToken::saveCommandComments);
token.GetNextToken();
}
catch (NxsException x)
{
NexusError(token.errormsg, 0, 0, 0);
return;
}
if (token.Equals("#NEXUS"))
{
token.SetLabileFlagBit(NxsToken::saveCommandComments);
token.GetNextToken();
}
else
{
errormsg = "Expecting #NEXUS to be the first token in the file, but found ";
errormsg += token.GetToken();
errormsg += " instead";
/*mth changed this to a warning instead of an error because of the large number
of files that violate this requirement.
*/
NexusWarn(errormsg, NxsReader::AMBIGUOUS_CONTENT_WARNING, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
}
if (notifyStartStop)
{
ExecuteStarting();
}
bool keepReading = true;
for (; keepReading && !token.AtEOF(); )
{
if (checkingSignals && NxsReader::getNumSignalIntsCaught() != numSigInts)
{
throw NxsSignalCanceledParseException("Reading NEXUS content");
}
if (token.Equals("BEGIN"))
{
token.SetEOFAllowed(false); /*must exit the block before and EOF*/
token.GetNextToken();
token.SetBlockName(token.GetTokenReference().c_str());
for (currBlock = blockList; currBlock != NULL; currBlock = currBlock->next)
{
if (currBlock->CanReadBlockType(token))
{
break;
}
}
NxsString currBlockName = token.GetToken();
currBlockName.ToUpper();
NxsBlockFactory * sourceOfBlock = NULL;
if (currBlock == NULL)
{
try
{
currBlock = CreateBlockFromFactories(currBlockName, token, &sourceOfBlock);
}
catch (NxsException x)
{
NexusError(x.msg, x.pos, x.line, x.col);
token.SetBlockName(0L);
token.SetEOFAllowed(true);
return;
}
}
if (currBlock == NULL)
{
SkippingBlock(currBlockName);
if (!ReadUntilEndblock(token, currBlockName))
{
token.SetBlockName(0L);
token.SetEOFAllowed(true);
return;
}
}
else if (currBlock->IsEnabled())
{
keepReading = ExecuteBlock(token, currBlockName, currBlock, sourceOfBlock);
}
else
{
SkippingDisabledBlock(token.GetToken());
if (sourceOfBlock)
{
//.........这里部分代码省略.........
示例15: Read
/*----------------------------------------------------------------------------------------------------------------------
| This function provides 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. Overrides the abstract
| virtual function in the base class.
*/
void NxsTaxaBlock::Read(
NxsToken &token) /* the token used to read from in */
{
ntax = 0;
int nominal_ntax = 0;
isEmpty = false;
isUserSupplied = true;
// This should be the semicolon after the block name
//
token.GetNextToken();
if (!token.Equals(";"))
{
errormsg = "Expecting ';' after TAXA block name, but found ";
errormsg += token.GetToken();
errormsg += " instead";
throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
}
for (;;)
{
token.GetNextToken();
if (token.Equals("DIMENSIONS"))
{
// This should be the NTAX keyword
//
token.GetNextToken();
if (!token.Equals("NTAX"))
{
errormsg = "Expecting NTAX keyword, but found ";
errormsg += token.GetToken();
errormsg += " instead";
throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
}
// This should be the equals sign
//
token.GetNextToken();
if (!token.Equals("="))
{
errormsg = "Expecting '=', but found ";
errormsg += token.GetToken();
errormsg += " instead";
throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
}
// This should be the number of taxa
//
token.GetNextToken();
nominal_ntax = atoi(token.GetToken().c_str());
if (nominal_ntax <= 0)
{
errormsg = "NTAX should be greater than zero (";
errormsg += token.GetToken();
errormsg += " was specified)";
throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
}
// This should be the terminating semicolon
//
token.GetNextToken();
if (!token.Equals(";"))
{
errormsg = "Expecting ';' to terminate DIMENSIONS command, but found ";
errormsg += token.GetToken();
errormsg += " instead";
throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
}
} // if (token.Equals("DIMENSIONS"))
else if (token.Equals("TAXLABELS"))
{
if (nominal_ntax <= 0)
{
errormsg = "NTAX must be specified before TAXLABELS command";
throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
}
for (unsigned i = 0; (int)i < nominal_ntax; i++)
{
token.SetLabileFlagBit(NxsToken::hyphenNotPunctuation + NxsToken::preserveUnderscores);
token.GetNextToken();
//@pol should check to make sure this is not punctuation
AddTaxonLabel(token.GetToken());
}
// This should be terminating semicolon
//
token.GetNextToken();
//.........这里部分代码省略.........