Parcourir la source

core: implement Array::Resize() to forcibly set the size of an array.

legacy
Sam Hocevar sam il y a 12 ans
Parent
révision
518942d4ca
1 fichiers modifiés avec 17 ajouts et 0 suppressions
  1. +17
    -0
      src/array.h

+ 17
- 0
src/array.h Voir le fichier

@@ -157,6 +157,8 @@ public:

void Remove(int pos, int todelete = 1)
{
/* FIXME: we need to call dtors for the first
* todelete elements here */
for (int i = pos; i + todelete < m_count; i++)
m_data[i] = m_data[i + todelete];
for (int i = m_count - todelete; i < m_count; i++)
@@ -164,6 +166,21 @@ public:
m_count -= todelete;
}

void Resize(int count, Element e = Element())
{
Reserve(count);

/* Too many elements? Remove them. */
for (int i = count; i < m_count; ++i)
m_data[i].~Element();

/* Not enough elements? Add some. */
for (int i = m_count; i < count; ++i)
m_data[i] = e;

m_count = count;
}

inline void Empty()
{
Remove(0, m_count);


Chargement…
Annuler
Enregistrer