/*******************************************************************
 * Destructor
 *******************************************************************/
IArrestClientMgr :: ~IArrestClientMgr()
{
  ISequence<IArrest *> tempList;
  IArrest *            arrest;

// if (dResultWrapper)
//    delete dResultWrapper;
  if (dResultListWrapper)
  {
     IVSequence<IArrest*>::Cursor cursor(*dResultListWrapper);
     forCursor( cursor )
       tempList.addAsFirst( dResultListWrapper->elementAt( cursor ) );

     dResultListWrapper->removeAll( );

     ISequence<IArrest*>::Cursor tempCursor( tempList );
     forCursor( cursor )
     {
       arrest = tempList.elementAt ( tempCursor );
       delete arrest;
     }
     tempList.removeAll( );

     delete dResultListWrapper;
  }
}
Example #2
0
seqio_status seqio_read_all(seqio_sequence sequence,
                            char **buffer,
                            uint64_t *buffer_length,
                            uint64_t *read_length) {
    check_null(sequence);
    check_null(buffer);
    check_null(buffer_length);
    check_null(read_length);

    ISequence *iseq = (ISequence *)sequence;

    try {
        if(*buffer == nullptr) {
            *buffer_length = INITIAL_READ_ALL_BUFFER_LENGTH;
            *buffer = (char *)malloc(*buffer_length);
            if(*buffer == nullptr)
                raise_oom("Cannot allocate %zu bytes", size_t(*buffer_length));
        }

        auto grow_to = [=] (uint64_t new_length) {
            char *buffer_ = (char *)realloc(*buffer, new_length);
            if(buffer_ == nullptr) {
                raise_oom("Cannot allocate %zu bytes", size_t(new_length));
            }
            *buffer = buffer_;
            *buffer_length = new_length;
        };

        uint64_t nread;
        uint64_t nread_total = 0;

        while( (nread = iseq->read(*buffer + nread_total, *buffer_length - nread_total)) != 0) {
            nread_total += nread;
            if(nread_total == *buffer_length) {
                grow_to(*buffer_length * 2);
            }
        }

        if(nread_total == *buffer_length) {
            grow_to(*buffer_length + 1);
        }
        (*buffer)[nread_total] = '\0';

        *read_length = nread_total;
    } catch(Exception x) {
        *read_length = 0;
        return err_handler(x.err_info);
    }
    
    return SEQIO_SUCCESS;    
}
Example #3
0
seqio_status seqio_get_metadata(seqio_sequence sequence,
                                seqio_const_dictionary *dict) {
    check_null(sequence);
    check_null(dict);

    try {
        ISequence *iseq = (ISequence *)sequence;
        *dict = (seqio_const_dictionary)&iseq->getMetadata();
    } catch(Exception x) {
        return err_handler(x.err_info);
    }

    return SEQIO_SUCCESS;
}
Example #4
0
ISequence*
collapseIntoSequence( const char* path )
{
    ISequence* seq = StdADTFactory_createSequence();
    int now  =  0;
    int last = -1;

    bool loop = 1;

    while ( loop )
    {
        switch ( path[now] )
        {
        case '\0':
            loop = 0;
        /* Intentional fall through */
        case '/':
            if ( (now != last) && (now != (last + 1) ) )
            {
                char* token = CharString_substring( path, last + 1, now - 1 );
                if ( 0 == CharString_compare( token, "." ) )
                {
                    free_CharString( token );
                }
                else if ( 0 == CharString_compare( token, ".." ) )
                {
                    char* popped = (char*) seq->removeLast( seq );
                    if ( popped )
                    {
                        free_CharString( popped );
                        free_CharString( token );
                    } else {
                        seq->addLast( seq, token );
                    }
                }
                else
                {
                    seq->addLast( seq, token );
                }
            }
            last = now;
        /* Intentional fall through */
        default:
            now++;
        }
    }

    return seq;
}
Example #5
0
char* Path_condensePath( const char* location )
{
    char* canonical_path = NULL;
    char* path = new_CharString( location );
    {
        CharString_replace( path, '\\', '/' );

        /*
        //	Add each directory onto a stack removing '.' and also
        //	parent if '..' is encountred.
        */

        ISequence* seq = collapseIntoSequence( (const char*) path );
        {
            /*
            //	Extract directories from sequence and form into path
            */

            canonical_path = ( '/' == path[0] ) ? new_CharString( "/" ) : new_CharString( "" );

            while ( ! seq->isEmpty( seq ) )
            {
                char* tmp   = canonical_path;
                char* token = (char*) seq->removeFirst( seq );
                if ( seq->isEmpty( seq ) )
                {
                    canonical_path = CharString_cat2( canonical_path, token );
                } else {
                    canonical_path = CharString_cat3( canonical_path, token, "/" );
                }
                free_CharString( tmp );
                free_CharString( token );
            }
        }
        seq->free( seq );
    }
    free_CharString( path );

    return canonical_path;
}
Example #6
0
void Lilith3D::Draw()
{
	//TimeClock* timeClock = TimeClock::Instance();
	const SunMoon& sunMoon = timeClock.GetSunMoon();
	unsigned j;

	// --- Lights --- //
	/*
	InnerCircle<PointLight>* lightNode = pointLightSentinel.Next();
	while( lightNode != &pointLightSentinel )
	{
		PointLight* light = lightNode->Container();
		if ( light->Done() ) {
			InnerCircle<PointLight>* temp = lightNode->Next();
			delete light;
			lightNode = temp;
		}
		else {
			light->DoTick();
			lightNode = lightNode->Next();
		}
	}
	*/

	// --- Morphs --- //
	for(	SequenceListIterator sequenceIt  = sequenceList.begin(); 
			sequenceIt != sequenceList.end();
			// no increment. handled in loop.
	    )
		{
		ISequence* sequence = *sequenceIt;
		if ( sequence->DoSequence( &timeClock ) )
		{
			SequenceListIterator tempIt = sequenceIt;
			++sequenceIt;

			// It's complete.
			sequenceList.erase( tempIt );
			delete sequence;
		}
		else
		{
			++sequenceIt;
		}
	}

	// --- Particle systems --- //
	for( unsigned i=0; i<particleSystems.size(); ++i )
	{
		GLASSERT( particleSystems[i] );
		particleSystems[i]->DoTick();
	}

	// --- Mobs --- //
	mobGroup.UpdateAll( &timeClock );

	// --- Stream out & Culling --- //
	DoCulling();

	CurrentWeather().SmartEnableFog();
	StateManager::SetLightProperties( sunMoon.vector, sunMoon.ambientColorL4, sunMoon.diffuseColorL4 );

	// -- Opaque pass --
	{
		terrainMesh->StreamOut();

		TreeMesh::StreamAllTreesVBO( this, quadTree->GetTreeRoot() );

		Mesh* root = quadTree->GetMeshRoot();
		while ( root )
		{
			GLASSERT( root->Type() != FOLIAGEMESH );
			GLASSERT( root->Type() != TREEMESH );
			root->StreamOutMesh( BRIGHT_PASS, OPAQUE_PASS );
			root = root->nextRender;
		}

		FoliageMesh::StreamAllFoliage( quadTree->GetFoliageRoot() );

		for( j=0; j<meshSystems.size(); ++j )
		{
			meshSystems[j]->StreamOut( 0, BRIGHT_PASS, OPAQUE_PASS );
		}
	}
	
	#ifdef SHADOW_VOLUME
	if ( RenderShadows() ) 
	{ 
		DrawShadowVolumes();

		// Render the shadows on the RECEIVERS
		glStencilFunc( GL_NOTEQUAL, 0, ~0 );
		glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
		GLASSERT( glGetError() == GL_NO_ERROR );

		// First pass, the terrain:
		terrainMesh->StreamOutShadowed();
		GLASSERT( glGetError() == GL_NO_ERROR );

		// And the opaque pass for shadow receivers.
		glColor3f( 1.0f, 1.0f, 1.0f );
		for( Mesh* mesh = quadTree->GetMeshRoot(); mesh; mesh=mesh->nextRender )
		{
			if ( mesh->IsShadowReceiver() )	{
				mesh->StreamOutMesh( SHADOW_PASS, OPAQUE_PASS );
			}
		}
		glDisable( GL_STENCIL_TEST );
		GLASSERT( glGetError() == GL_NO_ERROR );
	}
	#endif

	
	// -- Blend pass --
	{
		// Water
		terrainMesh->StreamOutWater();

		// General mesh
		Mesh* root = quadTree->GetMeshRoot();
		while ( root )
		{
			root->StreamOutMesh( BRIGHT_PASS, BLEND_PASS );
			root = root->nextRender;
		}

		// Translucent particles
		for( j=0; j<meshSystems.size(); ++j ) {
			meshSystems[j]->StreamOut( 0, BRIGHT_PASS, BLEND_PASS );
		}
	}
	glDisable( GL_FOG );

	StateManager::Reset();	// play well with the host app
}
SequenceContainer * SequenceApplicationTools::getSequenceContainer(
  const Alphabet * alpha,
  map<string, string> & params,
  const string & suffix,
  bool suffixIsOptional,
  bool verbose)
{
  string sequenceFilePath = ApplicationTools::getAFilePath("sequence.file",params, true, true, suffix, suffixIsOptional);
  string sequenceFormat = ApplicationTools::getStringParameter("sequence.format", params, "Fasta", suffix, suffixIsOptional);
  if(verbose) ApplicationTools::displayResult("Sequence format " + suffix, sequenceFormat);
  ISequence * iSeq = NULL;
  if(sequenceFormat == "Mase")
  {
    iSeq = new Mase();
  }
  else if(sequenceFormat == "Phylip")
  {
    bool sequential = true, extended = true;
    string split = "  ";
    if(params.find("sequence.format_phylip.order") != params.end())
    {
           if(params["sequence.format_phylip.order"] == "sequential" ) sequential = true;
      else if(params["sequence.format_phylip.order"] == "interleaved") sequential = false;
      else ApplicationTools::displayWarning("Argument '" +
             params["sequence.format_phylip.order"] +
             "' for parameter 'sequence.format_phylip.order' is unknown. " +
             "Default used instead: sequential.");
    }
    else ApplicationTools::displayWarning("Argument 'sequence.format_phylip.order' not found. Default used instead: sequential.");
    if(params.find("sequence.format_phylip.ext") != params.end())
    {
           if(params["sequence.format_phylip.ext"] == "extended")
      {
        extended = true;
        split = ApplicationTools::getStringParameter("sequence.format_phylip.extended.split", params, "spaces", suffix, suffixIsOptional);
        if(split == "spaces") split = "  ";
        else if(split == "tab") split = "\t";
        else throw Exception("Unknown option for sequence.format_phylip.extended.split: " + split);
      }
      else if(params["sequence.format_phylip.ext"] == "classic" ) extended = false;
      else ApplicationTools::displayWarning("Argument '" +
             params["sequence.format_phylip.ext"] +
             "' for parameter 'sequence.format_phylip.ext' is unknown. " +
             "Default used instead: extended.");
    }
    else ApplicationTools::displayWarning("Argument 'sequence.format_phylip.ext' not found. Default used instead: extended.");
    iSeq = new Phylip(extended, sequential, 100, true, split);
  }
  else if(sequenceFormat == "Fasta") iSeq = new Fasta();
  else if(sequenceFormat == "Clustal") iSeq = new Clustal();
  else
  {
    ApplicationTools::displayError("Unknown sequence format.");
    exit(-1);
  }
  SequenceContainer * sequences = iSeq->read(sequenceFilePath, alpha);
  delete iSeq;
  
  if(verbose) ApplicationTools::displayResult("Sequence file " + suffix, sequenceFilePath);

  return sequences;
}
VectorSiteContainer * SequenceApplicationTools::getSiteContainer(
  const Alphabet * alpha,
  map<string, string> & params,
  const string & suffix,
  bool suffixIsOptional,
  bool verbose)
{
  string sequenceFilePath = ApplicationTools::getAFilePath("sequence.file",params, true, true, suffix, suffixIsOptional);
  string sequenceFormat = ApplicationTools::getStringParameter("sequence.format", params, "Fasta", suffix, suffixIsOptional);
  if(verbose) ApplicationTools::displayResult("Sequence format " + suffix, sequenceFormat);
  ISequence * iSeq = NULL;
  if(sequenceFormat == "Mase")
  {
    iSeq = new Mase();
  }
  else if(sequenceFormat == "Phylip")
  {
    bool sequential = true, extended = true;
    string split = "  ";
    if(params.find("sequence.format_phylip.order") != params.end())
    {
           if(params["sequence.format_phylip.order"] == "sequential" ) sequential = true;
      else if(params["sequence.format_phylip.order"] == "interleaved") sequential = false;
      else ApplicationTools::displayWarning("Argument '" +
             params["sequence.format_phylip.order"] +
             "' for parameter 'sequence.format_phylip.order' is unknown. " +
             "Default used instead: sequential.");
    }
    else ApplicationTools::displayWarning("Argument 'sequence.format_phylip.order' not found. Default used instead: sequential.");
    if(params.find("sequence.format_phylip.ext") != params.end())
    {
      if(params["sequence.format_phylip.ext"] == "extended")
      {
        extended = true;
        split = ApplicationTools::getStringParameter("sequence.format_phylip.extended.split", params, "spaces", suffix, suffixIsOptional);
        if(split == "spaces") split = "  ";
        else if(split == "tab") split = "\t";
        else throw Exception("Unknown option for sequence.format_phylip.extended.split: " + split);
      }
      else if(params["sequence.format_phylip.ext"] == "classic" ) extended = false;
      else ApplicationTools::displayWarning("Argument '" +
             params["sequence.format_phylip.ext"] +
             "' for parameter 'sequence.format_phylip.ext' is unknown. " +
             "Default used instead: extended.");
    }
    else ApplicationTools::displayWarning("Argument 'sequence.format_phylip.ext' not found. Default used instead: extended.");
    iSeq = new Phylip(extended, sequential, 100, true, split);
  }
  else if(sequenceFormat == "Fasta") iSeq = new Fasta();
  else if(sequenceFormat == "Clustal") iSeq = new Clustal();
  else
  {
    ApplicationTools::displayError("Unknown sequence format.");
    exit(-1);
  }
  const SequenceContainer * seqCont = iSeq->read(sequenceFilePath, alpha);
  VectorSiteContainer * sites = new VectorSiteContainer(* dynamic_cast<const OrderedSequenceContainer *>(seqCont));
  delete seqCont;
  delete iSeq;
  
  if(verbose) ApplicationTools::displayResult("Sequence file " + suffix, sequenceFilePath);

  // Look for site selection:
  if(sequenceFormat == "Mase")
  {
    //getting site set:
    string siteSet = ApplicationTools::getStringParameter("sequence.format_mase.site_selection", params, "none", suffix, suffixIsOptional, false);
    if(siteSet != "none")
    {
      VectorSiteContainer * selectedSites;
      try
      {
        selectedSites = dynamic_cast<VectorSiteContainer *>(MaseTools::getSelectedSites(* sites, siteSet));
        if(verbose) ApplicationTools::displayResult("Set found", TextTools::toString(siteSet) + " sites.");
      }
      catch(IOException ioe)
      {
        ApplicationTools::displayError("Site Set '" + siteSet + "' not found.");
        exit(-1);
      }
      if(selectedSites->getNumberOfSites() == 0)
      {
        ApplicationTools::displayError("Site Set '" + siteSet + "' is empty.");
        exit(-1);
      }
      delete sites;
      sites = selectedSites;
    }
  }
  return sites;
}