Exemple #1
0
void NormalizingReader::Clear()
	{
	writtenBlocks.clear();
	blockMapper.clear();
	for (VecBlockPtr::iterator it = blocksToDelete.begin(); it != blocksToDelete.end(); ++it)
		delete *it;
	}
Exemple #2
0
void NxsReader::BlockReadHook(const NxsString &currBlockName, NxsBlock *currentBlock, NxsToken * token)
	{
	VecBlockPtr implied = currentBlock->GetImpliedBlocks();
	for (VecBlockPtr::iterator impIt = implied.begin(); impIt != implied.end(); ++impIt)
		{
		NxsBlock * nb = *impIt;
		NCL_ASSERT(nb);
		NxsString impID = nb->GetID();
		bool storeBlock = true;
		if (destroyRepeatedTaxaBlocks && impID.EqualsCaseInsensitive("TAXA"))
			{
			NxsTaxaBlockAPI * oldTB = this->GetOriginalTaxaBlock((NxsTaxaBlockAPI *) nb);
			if (oldTB)
				{
				storeBlock = ! currentBlock->SwapEquivalentTaxaBlock(oldTB);
				const std::string altTitle = nb->GetTitle();
				this->RegisterAltTitle(oldTB, altTitle);
				if (!storeBlock)
					{
					delete nb;
					}
				
				}
			}
		if (storeBlock) 
			{
			std::cerr << "storing implied block: " << impID << std::endl;
			this->AddBlockToUsedBlockList(impID, nb, token);
			}
		}
	std::cerr << "storing read block: " << currentBlock->GetID() << std::endl;
	this->AddBlockToUsedBlockList(currBlockName, currentBlock, token);
	}
Exemple #3
0
void NormalizingReader::PostBlockReadingHook(NxsBlock & block)
	{
	//cerr << "PostBlockReadingHook for " << GetBlockIDTitleString(block) << endl;

	NxsBlock * toStore;
	if (this->storingBlocks)
		{
		try {
			toStore = block.CloneBlock(blockMapper);
			}
		catch (...)
			{
			cerr << "CloneBlock of " << GetBlockIDTitleString(block) << " failed with an exception.  Only Clonable blocks can be normalized." << endl;
			throw;
			}
		blocksToDelete.push_back(toStore);
		blockMapper[block.GetInstanceIdentifier()] = toStore;
		}
	else
		toStore = &block;
	VecBlockPtr impliedBlocks = toStore->GetImpliedBlocks();
	for (VecBlockPtr::const_iterator ibIt = impliedBlocks.begin(); ibIt != impliedBlocks.end(); ++ibIt)
		{
		const BlockUniqueID currBlockID = (*ibIt)->GetInstanceIdentifier();
		if ((!this->supportingSharedImpliedBlocks) || writtenBlocks.find(currBlockID) == writtenBlocks.end())
			{
			if (this->storingBlocks)
				blocksToDelete.push_back(*ibIt);
			try {
				if (outf != 0L)
					(*ibIt)->WriteAsNexus(*outf);
				}
			catch (...)
				{
				cerr << block.GetInstanceName() << "raised an exception when writing as NEXUS." << endl;
				throw;
				}
			if (this->supportingSharedImpliedBlocks) 
				writtenBlocks.insert(currBlockID);
			}
		}
	const BlockUniqueID toStoreBlockID = toStore->GetInstanceIdentifier();
	try {
		if (outf != 0L)
			toStore->WriteAsNexus(*outf);
		}
	catch (...)
		{
		cerr << GetBlockIDTitleString(block) << " raised an exception when writing as NEXUS." << endl;
		throw;
		}
	writtenBlocks.insert(toStoreBlockID);
	}