Exemplo n.º 1
0
/// Change number of rows, either by inserting or removing them
void c4_Sequence::Resize(int newSize_, int) {
  if (NumHandlers() > 0) {
    int diff = newSize_ - NumRows();

    if (diff > 0) {
      c4_Row empty; // make sure this doesn't recurse, see below
      InsertAt(NumRows(), &empty, diff);
    } else if (diff < 0)
      RemoveAt(newSize_,  - diff);
  } else
  // need special case to avoid recursion for c4_Row allocations
    SetNumRows(newSize_);
}
Exemplo n.º 2
0
 /*!
  * Remove all the elements from the map for which a predicate function returns
  * TRUE.
  *
  * This method is guaranteed to remove an element if the map contains a match at
  * the start of the remove operation and that matching element is not removed by
  * another client during this operation.  If a matching element is inserted during
  * this operation, it may or may not be removed.
  *
  *  @param[in] pred     An STL-like predicate functor.  A key is passed as the predicate's
  *                       only argument.  If it returns TRUE, that element is removed.
  */
 template<typename PRED> void RemoveIf(PRED pred)
 {
     FUND::UINT32 highWater = OPS::Load(&_highWaterMark);
     for (FUND::UINT32 i = 0;  i < highWater;  i++)
     {
         KEY key = OPS::Load(&_map[i]);
         if (key != KeyAvailable && key != KeyReserved)
         {
             if (pred(key))
                 RemoveAt(i, key);
         }
     }
 }
Exemplo n.º 3
0
    /*!
     * Attempt to remove an element in the map that has the given key.  If the map
     * contains more than one element with this key, one of them is chosen arbitrarily.
     *
     * This method is guaranteed to remove an element if the map contains a match at
     * the start of the remove operation and that matching element is not removed by
     * another client during this operation.  If a matching element is inserted during
     * this operation, it may or may not be removed.
     *
     *  @param[in] key  The key to search for.
     */
    void Remove(KEY key)
    {
        ATOMIC_CHECK_ASSERT(key != KeyAvailable && key != KeyReserved);

        FUND::UINT32 highWater = OPS::Load(&_highWaterMark);
        for (FUND::UINT32 i = 0;  i < highWater;  i++)
        {
            if (OPS::Load(&_map[i]) == key)
            {
                RemoveAt(i, key);
                return;
            }
        }
    }
Exemplo n.º 4
0
void DETOUR_CEffectList::DETOUR_TryDispel(
	CCreatureObject& creTarget,
	POSITION posSkip,
	BOOL bCheckDispellableFlag,
	BOOL bCheckProbability,
	char cRand,
	char cDispelLevel
) {
	BOOL bDispel = TRUE;
	int nDispelChance = 50;

	POSITION pos = GetHeadPosition();
	POSITION posCurr = pos;
	while (pos) {
		posCurr = pos;
		CEffect* pEff = (CEffect*)GetNext(pos);
		if (bCheckProbability) {
			nDispelChance = 50;
			if (pEff->effect.nSourceCreLevel > cDispelLevel) {
				//original code without proper brackets
				//nDispelChance += pEff->effect.nSourceCreLevel * 10 - nDispelLevel;
				nDispelChance += (pEff->effect.nSourceCreLevel - cDispelLevel) * 10;
			} else {
				nDispelChance -= (cDispelLevel - pEff->effect.nSourceCreLevel) * 5;
			}
			if (cRand == 0) {
				bDispel = FALSE;
			} else {
				//bDispel = (cRand > nDispelChance || cRand > 99) ? 1 : 0;
				bDispel = (cRand > nDispelChance || cRand > 98) ? 1 : 0; //roll is 0-99, allow 99 for always dispel
			}
		} else {
			bDispel = TRUE;
		}

		if (posCurr != posSkip && bDispel) {
			if (!bCheckDispellableFlag || pEff->effect.dwFlags & 1) {
				RemoveAt(posCurr);
				pEff->OnRemove(creTarget);
				delete pEff;
				pEff = NULL;
			}
		}

	} //while

	this->posCurrent = 0;

	return;
}
Exemplo n.º 5
0
void
SrcLineList::removeAt(const int idx) {
	POSITION pos;
	int lctr = 0;
	for(pos = GetHeadPosition() ; pos != NULL && lctr++ != idx ;
		GetNext(pos) ) {}

	if (pos) {
		SrcLine * sl = (SrcLine*)GetAt(pos);
		RemoveAt(pos);
		delete sl;
	}

}
Exemplo n.º 6
0
//------------------------------------------------------------------------------
//
// 	Function Name:	CMLListCtrlElements::Remove()
//
//	Parameters:		pCtrlElement  - pointer to the object to be removed
//					bDelete - TRUE to delete the object after removal
//
// 	Return Value:	None
//
// 	Description:	This function will remove the object from the list
//
//------------------------------------------------------------------------------
void CMLListCtrlElements::Remove(CMLListCtrlElement* pCtrlElement, BOOL bDelete)
{
	POSITION Pos = Find(pCtrlElement);

	//	Is this object in the list
	if(Pos != NULL)
	{
		RemoveAt(Pos);

		//	Do we need to delete the object?
		if(bDelete)
			delete pCtrlElement;
	}
}
Exemplo n.º 7
0
void ff::SmallDict::SetAt(size_t index, Value *value)
{
	assertRet(index < Size());
	if (value)
	{
		value->AddRef();
		_data->entries[index].value->Release();
		_data->entries[index].value = value;
	}
	else
	{
		RemoveAt(index);
	}
}
Exemplo n.º 8
0
//---------------------------------------------------------------------------
// Delete empty partitions.
//---------------------------------------------------------------------------
void CTDPartitions::deleteEmptyPartitions()
{    
    POSITION tempPos = NULL;
    CTDPartition* pPartition = NULL;
    for (POSITION pos = GetHeadPosition(); pos != NULL;) {
        tempPos = pos;
        pPartition = GetNext(pos);
        if (pPartition->getNumRecords() <= 0) {
            RemoveAt(tempPos);
            delete pPartition;
            pPartition = NULL;
        }
    }
}
void CZipExtraField::RemoveInternalHeaders()
{
	for (int i = GetCount() - 1; i >= 0; i--)
	{
		WORD headerID = GetAt(i)->GetHeaderID();
		if (headerID == ZIP_EXTRA_PKZIP 
			|| headerID == ZIP_EXTRA_WINZIP_AES
			|| headerID == ZIP_EXTRA_UNICODE_PATH
			|| headerID == ZIP_EXTRA_UNICODE_COMMENT
			|| headerID == ZIP_EXTRA_ZARCH_NAME
			|| headerID == ZIP_EXTRA_NTFS)
				RemoveAt(i);
	}
}
Exemplo n.º 10
0
void DeleteTask(Task* task)
{
    int i = 0;
    int j = 0;

    // delete from predecessors and successors
    for (i = 0; i < task->nbPredecessors; i++)
    {
        for (j = 0; j < task->predecessors[i]->nbSuccessors; j++)
        {
            if (task->predecessors[i]->successors[j]->id == task->id)
            {
                task->predecessors[i]->successors = (Task**)RemoveAt((void**)task->predecessors[i]->successors, task->predecessors[i]->nbSuccessors--, j);
                break;
            }
        }
    }
    free(task->predecessors);

    for (i = 0; i < task->nbSuccessors; i++)
    {
        for (j = 0; j < task->successors[i]->nbPredecessors; j++)
        {
            if (task->successors[i]->predecessors[j]->id == task->id)
            {
                task->successors[i]->predecessors = (Task**)RemoveAt((void**)task->successors[i]->predecessors, task->successors[i]->nbPredecessors--, j);
                break;
            }
        }
    }
    free(task->successors);

    free(task->assignedWorkers);
    free(task);

    _nbTasks--;
}
Exemplo n.º 11
0
CHXRingBuffer::Remove(IHXListIterator* pIter)
{
    HX_ASSERT_VALID_PTR(this);
    HX_ASSERT(pIter != NULL);

    IHXRingBufferIteratorPrivate* pIterPriv = NULL;
    pIter->QueryInterface(IID_IHXRingBufferIteratorPrivate, (void**)&pIterPriv);
    HX_ASSERT(pIterPriv != NULL);
    HX_ASSERT(pIterPriv->GetRingBuffer() == this && pIterPriv->GetPos() != INVALID_POS);
    UINT32 posIter = pIterPriv->GetPos();
    pIterPriv->Reset();
    pIterPriv->Release();

    return RemoveAt(posIter);
}
Exemplo n.º 12
0
BOOL CDomain::RemoveStock( LPCTSTR lpszStockCode )
{
	if( NULL == lpszStockCode || strlen(lpszStockCode) <= 0 )
		return FALSE;

	for( int k=0; k<GetSize(); k++ )
	{
		if( 0 == ElementAt(k).CompareNoCase(lpszStockCode) )
		{
			RemoveAt(k);
			return TRUE;
		}
	}
	return FALSE;
}
Exemplo n.º 13
0
Arquivo: persist.cpp Projeto: aosm/tcl
t4_i32 c4_Allocator::Allocate(t4_i32 len_) {
  // zero arg is ok, it simply returns first allocatable position   
  for (int i = 2; i < GetSize(); i += 2)
  if (GetAt(i + 1) >= GetAt(i) + len_) {
    t4_i32 pos = GetAt(i);
    if ((t4_i32)GetAt(i + 1) > pos + len_)
      ElementAt(i) += len_;
    else
      RemoveAt(i, 2);
    return pos;
  }

  d4_assert(0);
  return 0; // not reached
}
Exemplo n.º 14
0
void ff::SmallDict::Remove(ff::StringRef key)
{
	size_t size = Size();
	if (size)
	{
		hash_t hash = _data->atomizer->GetHash(key);

		for (size_t i = PreviousSize(size); i != INVALID_SIZE; i = PreviousSize(i))
		{
			if (_data->entries[i].hash == hash)
			{
				RemoveAt(i);
			}
		}
	}
}
Exemplo n.º 15
0
int UpdateGNplus(Task*** G, Task*** Nplus, int* GSize)
{
    int i = 0;
    int NplusSize = 0;
    for (i = 0; i < *GSize; i++)
    {
        if ((*G)[i]->nbPredecessors == (*G)[i]->nbPredecessorsDone)
        {
            *Nplus = (Task**)realloc(*Nplus, ++NplusSize * sizeof(Task*));
            (*Nplus)[NplusSize - 1] = (*G)[i];
            RemoveAt((void**)*G, (*GSize)--, i--);
        }
    }

    return NplusSize;
}
Exemplo n.º 16
0
void CXTPCalendarEvents::CloneEvents()
{
	int nCount = GetCount();
	for (int i = 0; i < nCount; i++)
	{
		CXTPCalendarEvent* pEvOrig = GetAt(i, FALSE);
		CXTPCalendarEventPtr ptrEvClone = pEvOrig ? pEvOrig->CloneEvent() : NULL;
		if (ptrEvClone)
		{
			SetAt(i, ptrEvClone);
		}
		else
		{
			RemoveAt(i);
		}
	}
}
Exemplo n.º 17
0
void CSongState::MergeDuplicateChords()
{
	int	nChords = m_Chord.GetSize();
	int iChord = 1;
	while (iChord < nChords) {	// for each chord
		const CSong::CChord&	chord = m_Chord[iChord];
		CSong::CChord&	PrevChord = m_Chord[iChord - 1];
		// if chord and previous chord are identical except for duration
		if (chord.EqualNoDuration(PrevChord)
		&& m_SectionMap[iChord] == m_SectionMap[iChord - 1]) {	// and belong to same section
			PrevChord.m_Duration += chord.m_Duration;	// sum durations
			RemoveAt(iChord);	// delete duplicate chord
			nChords--;
		} else	// chords differ
			iChord++;
	}
}
Exemplo n.º 18
0
BOOL CDomainContainer::RemoveDomain( LPCTSTR lpszDomainName )
{
	if( NULL == lpszDomainName || strlen(lpszDomainName) <= 0 )
		return FALSE;

	for( int i=0; i<GetSize(); i++ )
	{
		CDomain & domain = ElementAt(i);
		if( 0 == domain.m_strName.CompareNoCase( lpszDomainName ) )
		{
			RemoveAt( i );
			return TRUE;
		}
	}
	
	return FALSE;
}
void CXTPFlowGraphSelectedElements::Remove(CXTPFlowGraphElement* pElement)
{
	if (!pElement)
		return;

	if (!pElement->IsSelected())
		return;

	for (int i = 0; i < m_arrSelectedElements.GetSize(); i++)
	{
		if (m_arrSelectedElements[i] == pElement)
		{

			RemoveAt(i);
			return;
		}
	}
}
Exemplo n.º 20
0
bool CHotKeys::Remove(int clipId)
{
	INT_PTR count = GetSize();
	for(int i=0; i < count; i++)
	{
		if(ElementAt(i) != NULL && ElementAt(i)->m_clipId == clipId)
		{
			CHotKey *pKey = ElementAt(i);

			RemoveAt(i);

			delete pKey;

			return true;
		}
	}
	return false;
}
Exemplo n.º 21
0
/**
 * Delete any structures which are selected.
 * \return the number that were deleted.
 */
int vtStructureArray::DeleteSelected()
{
	int num_deleted = 0;
	for (uint i = 0; i < GetSize();)
	{
		vtStructure *str = GetAt(i);
		if (str->IsSelected())
		{
			DestroyStructure(i);
			delete str;
			RemoveAt(i);
			num_deleted++;
		}
		else
			i++;
	}
	return num_deleted;
}
Exemplo n.º 22
0
//
// Unify smaller clones to form larger clones
//
bool CCSClones::unifyToLargestClones(int windowSize, double minCoOccThreshold)
{
    CCSClone* pCloneX = NULL;
    CCSClone* pCloneY = NULL;
    for (int p = 0; p < GetSize(); ++p) {
#ifdef _CS_SHOW_PROGRESS
        _tprintf(_T("%c: pair #%d of %d.\r"), runningChars[p % CS_NUM_RUNNING_CHARS], p, GetSize() - 1);
#endif
        pCloneX = GetAt(p);

        for (int q = p + 1; q < GetSize(); ++q) {
            pCloneY = GetAt(q);
            if (pCloneX->overlap(*pCloneY, windowSize, minCoOccThreshold)) {
                // merge X and Y

                // join tarX and tarY
                if (pCloneX->m_tarStart > pCloneY->m_tarStart) {
                    pCloneX->m_tarStart = pCloneY->m_tarStart;
                    pCloneX->m_tarRawStart = pCloneY->m_tarRawStart;
                }
                if (pCloneX->m_tarEnd < pCloneY->m_tarEnd) {
                    pCloneX->m_tarEnd = pCloneY->m_tarEnd;
                    pCloneX->m_tarRawEnd = pCloneY->m_tarRawEnd;
                }

                // join srcX and srcY
                if (pCloneX->m_srcStart > pCloneY->m_srcStart) {
                    pCloneX->m_srcStart = pCloneY->m_srcStart;
                    pCloneX->m_srcRawStart = pCloneY->m_srcRawStart;
                }
                if (pCloneX->m_srcEnd < pCloneY->m_srcEnd) {
                    pCloneX->m_srcEnd = pCloneY->m_srcEnd;
                    pCloneX->m_srcRawEnd = pCloneY->m_srcRawEnd;
                }

                // Now delete clone pair CD
                RemoveAt(q--);     // decrement the index; otherwise, q will be off by one element.
                delete pCloneY;
                pCloneY = NULL;
            }
        }
    }
    return true;
}
Exemplo n.º 23
0
Arquivo: persist.cpp Projeto: aosm/tcl
void c4_Allocator::Release(t4_i32 pos, t4_i32 len) {
  int i = Locate(pos + len);
  d4_assert(0 < i && i < GetSize());
  d4_assert(i % 2 == 0); // don't release inside a free block

  if ((t4_i32)GetAt(i) == pos)
  // move start of next free down 
    ElementAt(i) -= len;
  else if ((t4_i32)GetAt(i - 1) == pos)
  // move end of previous free up
    ElementAt(i - 1) += len;
  else
  // insert a new entry
    InsertPair(i, pos, pos + len);

  if (GetAt(i - 1) == GetAt(i))
  // merge if adjacent free
    RemoveAt(i - 1, 2);
}
void CDiagramEntityContainer::RemoveAllSelected()
/* ============================================================
	Function :		CDiagramEntityContainer::RemoveAllSelected
	Description :	Removes all selected objects
					
	Return :		void
	Parameters :	none

	Usage :			Call to remove all selected objects from the 
					container. Releases allocated data

   ============================================================*/
{
	m_lastSelObj = NULL;
	int max = m_objs.GetSize() - 1;
	for( int t = max ; t >= 0 ; t-- )
		if( GetAt( t )->IsSelected() )
			RemoveAt( t );

}
Exemplo n.º 25
0
void CGXGridCellStylePtrArray::Move(int nIndex, int nCount, int nDest)
{
	if (nDest == nIndex || nCount == 0
		|| GetUpperBound() < nIndex && GetUpperBound() < nDest)
		return;
	else if (nDest < nIndex)
		nIndex += nCount;
	else if (nDest > nIndex)
		nDest += nCount;

	InsertAt(nDest, NULL, nCount);
	for (int n = 0; nIndex+n <= GetUpperBound() && n < nCount; n++)
	{
		if (GetAt(nIndex+n))
			SetAt(nDest+n, GetAt(nIndex+n));
	}

	if (nIndex <= GetUpperBound())
		RemoveAt(nIndex, min(nCount, GetUpperBound()-nIndex+1));
}
Exemplo n.º 26
0
void CLineCrossings::AddCrossing(CFixed lPosition, int nCount)
{
    int nCrossings = Crossings();
    int nCrossing;

    // Look for the crossing in the array.
    // This will also determine the place to insert if it is not found.
    for (nCrossing = 0; nCrossing < nCrossings; nCrossing++)
    {
        // Get the crossing to check where we are.
        CLineCrossing* pCrossing = Crossing(nCrossing);

        // If this crossing is at our position, merge the counts.
        if (pCrossing->m_lPosition == lPosition)
        {
            // Update the existing one.
            if ((pCrossing->m_nCount += nCount) == 0)
            {
                // The crossing went away! Get rid of it.
                delete pCrossing;
                RemoveAt(nCrossing);
            }
            return;
        }
        if (pCrossing->m_lPosition > lPosition)
        {
            // Insert here.
            break;
        }
    }

    // The crossing was not found. Create a new one.
    CLineCrossing* pCrossing = new CLineCrossing;

    // Fill in the values.
    pCrossing->m_lPosition = lPosition;
    pCrossing->m_nCount = nCount;

    // Insert it where we stopped searching.
    InsertAt(nCrossing, pCrossing);
}
Exemplo n.º 27
0
void CSongState::RemoveChords(CIntRange BeatRange)
{
	CIntRange	ChordRange, Offset;
	ChordRange = FindChordRange(BeatRange, Offset);
	if (Offset.Start) {	// if starting beat not on chord boundary
		m_Chord[ChordRange.Start].m_Duration = Offset.Start;
		ChordRange.Start++;
	}
	if (Offset.End) {	// if ending beat not on chord boundary
		if (ChordRange.Start > ChordRange.End)	// if beat range within one chord
			m_Chord[ChordRange.End].m_Duration += Offset.End;
		else {	// beat range spans at least two chords
			m_Chord[ChordRange.End].m_Duration = Offset.End;
			ChordRange.End--;
		}
	}
	int	nChords = ChordRange.LengthInclusive();
	if (nChords > 0)
		RemoveAt(ChordRange.Start, nChords);
	OnChordCountChange();
}
void CDiagramEntityContainer::Remove( CDiagramEntity* obj )
/* ============================================================
	Function :		CDiagramEntityContainer::Remove
	Description :	Removes the object.
					
	Return :		void
	Parameters :	CDiagramEntity* obj	-	The object to 
											remove.
					
	Usage :			Call to remove obj - if it exists - from the 
					container. Allocated memory is released.

   ============================================================*/
{
	if (obj == m_lastSelObj) m_lastSelObj = NULL;

	int index = Find( obj );
	if( index != -1 )
		RemoveAt( index );

}
void CDiagramEntityContainer::RemoveAll()
/* ============================================================
	Function :		CDiagramEntityContainer::RemoveAll
	Description :	Removes all data objects
					
	Return :		void
	Parameters :	none

	Usage :			Call to remove all data objects in the 
					container. Undo- and paste arrays are not 
					emptied.
					Allocated memory is released. Undo and 
					paste not deleted.

   ============================================================*/
{
	m_lastSelObj = NULL;
	int max = m_objs.GetSize() - 1;
	for( int t = max ; t >= 0 ; t-- )
		RemoveAt( t );

}
Exemplo n.º 30
0
// Remove inItem from the array.
//
void ArraySet::Remove( ID_TYPE inItem )
{
	ID_TYPE* p;

	/* At first try to find inItem */
	if( mIsSorted )
	{
		p = STD::lower_bound( mpStart, mpFinish, inItem );	
		if( p != mpFinish && *p > inItem )
			p = mpFinish;
	}
	else 
	{
		p = mpStart;
		while( p < mpFinish && *p != inItem )
			p++;
	}	

	/* If found remove it */
	if( p < mpFinish )
		 RemoveAt( (vuint32)(p - mpStart + 1 ) );
}