Ejemplo n.º 1
0
void ArrayInstanceImp::setLength(unsigned newLength, ExecState *exec)
{
    if(newLength <= storageLength)
    {
        resizeStorage(newLength);
    }

    if(newLength < length)
    {
        ReferenceList sparseProperties;

        _prop.addSparseArrayPropertiesToReferenceList(sparseProperties, Object(this));

        ReferenceListIterator it = sparseProperties.begin();
        while(it != sparseProperties.end())
        {
            Reference ref = it++;
            bool ok;
            unsigned index = ref.getPropertyName(exec).toArrayIndex(&ok);
            if(ok && index > newLength)
            {
                ref.deleteValue(exec);
            }
        }
    }

    length = newLength;
}
Ejemplo n.º 2
0
 ReferencePath getCommonPrefix(const ReferenceList& rl) {
     assert(rl.size() >= 2);
     ReferencePath prefix = getCommonPrefix(rl[0], rl[1]);
     for (size_t i = 2; i < rl.size(); ++i) {
         prefix = getCommonPrefix(prefix, rl[i]);
     }
     return prefix;
 }
Ejemplo n.º 3
0
ReferenceList StringInstanceImp::propList(ExecState *exec, bool recursive)
{
  ReferenceList properties = ObjectImp::propList(exec,recursive);

  UString str = internalValue().toString(exec);
  for (int i = 0; i < str.size(); i++)
    if (!ObjectImp::hasProperty(exec,Identifier::from(i)))
      properties.append(Reference(this, i));

  return properties;
}
ReferenceList ArrayInstanceImp::propList(ExecState *exec, bool recursive)
{
  ReferenceList properties = ObjectImp::propList(exec,recursive);

  // avoid fetching this every time through the loop
  ValueImp *undefined = UndefinedImp::staticUndefined;

  for (unsigned i = 0; i < storageLength; ++i) {
    ValueImp *imp = storage[i];
    if (imp && imp != undefined) {
      properties.append(Reference(this, i));
    }
  }
  return properties;
}
Ejemplo n.º 5
0
vector<NetworkID> GameFactory::GetIDObjectTypes(unsigned char type) noexcept
{
	vector<NetworkID> result;
	ReferenceList::iterator it;

	cs.StartSession();

	result.reserve(typecount[type]);
	ReferenceList copy = instances;

	cs.EndSession();

	for (it = copy.begin(); it != copy.end(); ++it)
		if (it->second & type)
			result.emplace_back(it->first->GetNetworkID());

	return result;
}
vector<FactoryObject> GameFactory::GetObjectTypes(unsigned char type) noexcept
{
	vector<FactoryObject> result;
	ReferenceList::iterator it;

	cs.StartSession();

	result.reserve(typecount[type]);
	ReferenceList copy = instances;

	cs.EndSession();

	for (it = copy.begin(); it != copy.end(); ++it)
		if (it->second & type)
			result.push_back(FactoryObject(it->first));

	return result;
}
Ejemplo n.º 7
0
unsigned ArrayInstanceImp::pushUndefinedObjectsToEnd(ExecState *exec)
{
    ValueImp *undefined = UndefinedImp::staticUndefined;

    unsigned o = 0;

    for(unsigned i = 0; i != storageLength; ++i)
    {
        ValueImp *v = storage[i];
        if(v && v != undefined)
        {
            if(o != i)
                storage[o] = v;
            o++;
        }
    }

    ReferenceList sparseProperties;
    _prop.addSparseArrayPropertiesToReferenceList(sparseProperties, Object(this));
    unsigned newLength = o + sparseProperties.length();

    if(newLength > storageLength)
    {
        resizeStorage(newLength);
    }

    ReferenceListIterator it = sparseProperties.begin();
    while(it != sparseProperties.end())
    {
        Reference ref = it++;
        storage[o] = ref.getValue(exec).imp();
        ObjectImp::deleteProperty(exec, ref.getPropertyName(exec));
        o++;
    }

    if(newLength != storageLength)
        memset(storage + o, 0, sizeof(ValueImp *) * (storageLength - o));

    return o;
}
Ejemplo n.º 8
0
vector<FactoryObject> GameFactory::GetObjectTypes(unsigned char type) noexcept
{
	vector<FactoryObject> result;
	ReferenceList::iterator it;

	cs.StartSession();

	result.reserve(typecount[type]);
	ReferenceList copy = instances;

	cs.EndSession();

	for (it = copy.begin(); it != copy.end(); ++it)
		if (it->second & type)
			try
			{
				result.emplace_back(FactoryObject(it->first.get(), it->second));
			}
			catch (...) { continue; }

	return result;
}
Ejemplo n.º 9
0
bool Alignment::init(const LcbList & lcbList, const VariantList & variantList, const ReferenceList & referenceList, const TrackList & trackList)
{
	totalLength = 0;
	filterFlags = 0;
	filterPass = true;
	filterPassScale = true;
	filterShow = false;
	trackReference = 0;
	destroyRegions();
	
	lcbs.resize(lcbList.getLcbCount());
	tracks.resize(trackList.getTrackCount());
	
	for ( int i = 0; i < tracks.size(); i++ )
	{
		tracks[i] = new QVector<Region *>(lcbList.getLcbCount());
	}
	
	for ( int i = 0; i < lcbList.getLcbCount(); i++ )
	{
		const LcbList::Lcb & lcb = lcbList.getLcb(i);
		
		int id = i;
		
		lcbs[id].concordance = 1 - lcb.concordance;
		//lcbs[id].number = atoi(lcb.name().c_str());
		
		QVector<Region *> * regions = new QVector<Region *>(lcb.regions.size());
		
		for ( int j = 0; j < lcb.regions.size(); j++ )
		{
			const LcbList::Region & lcbRegion = lcb.regions.at(j);
			
			int track = j;
			
			char * snps = 0;
			
			Region * region = new Region
			(
			 id,
			 lcbRegion.position,
			 lcbRegion.length,
			 lcbRegion.reverse,
			 snps
			 );
			
			(*regions)[track] = region;
			(*tracks[track])[id] = region;
			
			if ( track == 0 )
			{
				totalLength += region->getLength();
			}
		}
		
		lcbs[id].regions = regions;
	}
	
	for ( int i = 0; i < tracks.size(); i++ )
	{
		qSort(tracks[i]->begin(), tracks[i]->end(), Region::lessThan);
		
		// determine total length
		//
		unsigned int length = 0;
		//
		for ( int j = 0; j < tracks[i]->size(); j++ )
		{
			length += (*tracks[i])[j]->getLength();
		}
		
		// assigned scaled
		//
		unsigned int position = 0;
		//
		for ( int j = 0; j < tracks[i]->size(); j++ )
		{
			(*tracks[i])[j]->setScaled
			(
			 (float)position / length,
			 (float)(position + (*tracks[i])[j]->getLength()) / length
			 );
			
			position += (*tracks[i])[j]->getLength();
		}
	}
	
	snpMap.clear();
	filters.resize(variantList.getFilterCount());
	
	for ( int i = 0; i < variantList.getFilterCount(); i++ )
	{
		const VariantList::Filter & msgFilter = variantList.getFilter(i);
		
		Filter & filter = filters[i];
		filter.flag = msgFilter.flag;
		filter.name = QString::fromStdString(msgFilter.name);
		filter.description = QString::fromStdString(msgFilter.description);
	}
	
	snpCount = 0;
	char refLast = 0;
	int posLast;
	gapsTotal = 0;
	Gap gap;
	snpColumns.resize(0);
	gaps.resize(0);
	
	for ( int i = 0; i < variantList.getVariantCount(); i++ )
	{
		const VariantList::Variant & msgSnp = variantList.getVariant(i);
		
		long int refOffset = 0;
		int refIndex = 0;
		
		int position = msgSnp.position;
		char charRef = msgSnp.reference; // TODO: fixed?
		//char charRef = posLast == position ? '-' : referenceList.getReference(msgSnp.sequence).sequence[msgSnp.position];
		
		while ( msgSnp.sequence > refIndex ) // - 1 OLD )
		{
			refOffset += referenceList.getReference(refIndex).sequence.length();
			refIndex++;
		}
		
		position += refOffset;
		
		if ( refLast == '-' && ( charRef != '-' || posLast != position ) )
		{
			gap.end = gap.startAbs + gapsTotal;
			gap.offset = gapsTotal;
			gaps.push_back(gap);
			//gapsTotal += gap.end - gap.start + 1;
		}
		
		unsigned int filters = msgSnp.filters;
		
		if ( charRef == '-' )
		{
			if ( refLast != '-' || posLast != position )
			{
				gap.start = position + gapsTotal + 1;
				gap.startAbs = position;
			}
			
			gapsTotal++;
		}
		
		snpCount++;
		snpColumns.resize(snpColumns.size() + 1);
		snpMap.insert(snpMap.end(), std::pair<long long int, int>(position + gapsTotal, snpColumns.size() - 1));
		
		SnpColumn & snpColumn = snpColumns[snpColumns.size() - 1];
		
		snpColumn.position = position + gapsTotal;
		
		// HACK for vcf; (fixed?)
		//
		snpColumn.ref = charRef;
		snpColumn.filters = filters;
		
		for ( unsigned int i = 0; i < msgSnp.alleles.length(); i++ )
		{
			char charQry = msgSnp.alleles.c_str()[i];
			
			if ( charQry != snpColumn.ref )
			{
				Snp snp;
				snp.track = i;
				snp.snp = charQry;
				
				snpColumn.snps.push_back(snp);
			}
		}
		
		posLast = position;
		refLast = charRef;
	}
	
	//totalLength = (*tracks[0])[tracks[0]->size() - 1]->getStart() + (*tracks[0])[tracks[0]->size() - 1]->getLength() + gapsTotal;
	
	QString refSeq;
	
	for ( int i = 0; i < referenceList.getReferenceCount(); i++ )
	{
		refSeq.append(QString::fromStdString(referenceList.getReference(i).sequence));
	}
	
	int coreSize = 0;
	
	for ( int i = 0; i < lcbs.size(); i++ )
	{
		const Region * regionRef = (*lcbs[i].regions)[0];
		
		int startGapped = getPositionGapped(regionRef->getStart() - 1) + 1;
		int endGapped = getPositionGapped(regionRef->getStart() + regionRef->getLength()) - 1;
		
		lcbs[i].startGapped = startGapped;
		lcbs[i].lengthGapped = endGapped - startGapped + 1;
		
		coreSize += regionRef->getLength();
	}
	
	core = (float)coreSize / refSeq.length();
	
	qSort(lcbs.begin(), lcbs.end(), lcbLessThan);
	
	totalLength = refSeq.length() + gapsTotal;
	
	refSeqCount = referenceList.getReferenceCount();
	
	if ( refSeqStarts )
	{
		delete [] refSeqStarts;
	}
	
	refSeqStarts = new long long int[refSeqCount];
	
	long long int total = 0;
	
	for ( int i = 0; i < refSeqCount; i++ )
	{
		refSeqStarts[i] = getPositionGapped(total);
		total += referenceList.getReference(i).sequence.length();
	}
	
	if ( refSeqGapped )
	{
		delete [] refSeqGapped;
	}
	
	refSeqGapped = new char[totalLength];
	int gapId = 0;
	gapsTotal = 0;
	
	for ( int i = 0; i < totalLength; i++ )
	{
		if ( gaps.size() && i == gaps[gapId].start )
		{
			while( i <= gaps[gapId].end )
			{
				refSeqGapped[i] = '-';
				i++;
			}
			
			gapsTotal = gaps[gapId].offset;
			
			if ( gapId < gaps.size() - 1 )
			{
				gapId++;
			}
		}
		
		if ( i - gapsTotal < refSeq.length() )
		{
			refSeqGapped[i] = refSeq.at(i - gapsTotal).toLatin1(); // TODO: gap at pos 0?
		}
	}
	
	if ( trackList.getTrackReference() > 0 )
	{
		setTrackReference(trackList.getTrackReference());
	}
	
	setFilterScale();
	
	return true;
}