Renamed ptr_vector to PtrVector so that is follows

our naming convention, also changed contentsVector
to m_contents_vector, and removed unused add method
(which is using an iterator, which would not work
when using aligned_arrays on windows anyway).


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7602 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2011-02-03 22:20:53 +00:00
parent 9c56bd4781
commit 4d8b8e5dea
32 changed files with 268 additions and 240 deletions

View File

@ -79,7 +79,10 @@ const irr::core::stringw UnlockableFeature::getUnlockedMessage() const
}
//-----------------------------------------------------------------------------
/** Sets that the given track will be unlocked if this challenge
* is unlocked.
* \param track_name Name of the track to unlock.
*/
void Challenge::addUnlockTrackReward(const std::string &track_name)
{
@ -169,8 +172,9 @@ void Challenge::load(const XMLNode* challengesNode)
bool finished=false;
node->get("solved", &finished);
m_state = finished ? CH_SOLVED : CH_INACTIVE;
m_version = 0;
node->get("version", &m_version);
if(!finished) loadAdditionalInfo(node);
} // load

View File

@ -59,18 +59,30 @@ private:
enum {CH_INACTIVE, // challenge not yet possible
CH_ACTIVE, // challenge possible, but not yet solved
CH_SOLVED} m_state; // challenge was solved
std::string m_Id; // short, internal name for this challenge
irr::core::stringw m_Name; // name used in menu for this challenge
irr::core::stringw m_challenge_description; // Message the user gets when the feature is not yet unlocked
std::vector<UnlockableFeature> m_feature; // Features to unlock
std::vector<std::string> m_prerequisites; // what needs to be done before accessing this challenge
/** Short, internal name for this challenge. */
std::string m_Id;
/** Name used in menu for this challenge. */
irr::core::stringw m_Name;
/** Message the user gets when the feature is not yet unlocked. */
irr::core::stringw m_challenge_description;
/** Features to unlock. */
std::vector<UnlockableFeature> m_feature;
/** What needs to be done before accessing this challenge. */
std::vector<std::string> m_prerequisites;
/** Version number of the challenge. */
int m_version;
public:
Challenge(const std::string &id, const std::string &name);
Challenge() {m_Id=""; m_Name="";m_state=CH_INACTIVE;}
virtual ~Challenge() {};
/** Returns the id of the challenge. */
const std::string &getId() const { return m_Id; }
/** Returns the name of the challenge. */
const irr::core::stringw &getName() const { return m_Name; }
/** Sets the name of the challenge. */
void setName(const irr::core::stringw & s) { m_Name = s; }
/** Sets the id of this challenge. */
void setId(const std::string& s) { m_Id = s; }
void addUnlockTrackReward(const std::string &track_name);
void addUnlockModeReward(const std::string &internal_mode_name,

View File

@ -44,8 +44,6 @@ private:
std::string m_gp_id;
std::string m_track_name;
int m_energy;
//std::vector<std::string> m_depends_on;
//std::vector<UnlockableFeature> m_unlock;
std::string m_filename;
void getUnlocks(const XMLNode *root, const std:: string type, REWARD_TYPE reward);

View File

@ -31,7 +31,7 @@
#include "utils/ptr_vector.hpp"
class UserConfigParam;
static ptr_vector<UserConfigParam, REF> all_params;
static PtrVector<UserConfigParam, REF> all_params;
// X-macros

View File

@ -377,7 +377,7 @@ namespace UserConfigParams
// TODO? implement blacklist for new irrlicht device and GUI
PARAM_PREFIX std::vector<std::string> m_blacklist_res;
PARAM_PREFIX ptr_vector<PlayerProfile> m_all_players;
PARAM_PREFIX PtrVector<PlayerProfile> m_all_players;
}
#undef PARAM_PREFIX

View File

@ -1006,7 +1006,7 @@ IrrDriver::RTTProvider::~RTTProvider()
* to be the root, and all following meshes will have their locations relative to
* the location of the first mesh.
*/
void IrrDriver::RTTProvider::setupRTTScene(ptr_vector<scene::IMesh, REF>& mesh,
void IrrDriver::RTTProvider::setupRTTScene(PtrVector<scene::IMesh, REF>& mesh,
AlignedArray<Vec3>& mesh_location,
AlignedArray<Vec3>& mesh_scale,
const std::vector<int>& model_frames)

View File

@ -205,7 +205,7 @@ public:
* When frame is not -1, the corresponding IMesh must be an IAnimatedMesh.
* \precondition The 3 vectors have the same size.
*/
void setupRTTScene(ptr_vector<scene::IMesh, REF>& mesh,
void setupRTTScene(PtrVector<scene::IMesh, REF>& mesh,
AlignedArray<Vec3>& mesh_location,
AlignedArray<Vec3>& mesh_scale,
const std::vector<int>& model_frames);

View File

@ -40,7 +40,7 @@ AbstractTopLevelContainer::AbstractTopLevelContainer()
m_last_widget = NULL;
}
void AbstractTopLevelContainer::addWidgetsRecursively(ptr_vector<Widget>& widgets, Widget* parent)
void AbstractTopLevelContainer::addWidgetsRecursively(PtrVector<Widget>& widgets, Widget* parent)
{
const unsigned short widgets_amount = widgets.size();
@ -77,7 +77,7 @@ void AbstractTopLevelContainer::addWidgetsRecursively(ptr_vector<Widget>& widget
// ----------------------------------------------------------------------------
bool isMyChildHelperFunc(const ptr_vector<Widget>* within, const Widget* widget)
bool isMyChildHelperFunc(const PtrVector<Widget>* within, const Widget* widget)
{
if (within->size() == 0) return false;
@ -120,7 +120,7 @@ Widget* AbstractTopLevelContainer::getWidget(const int id)
// -----------------------------------------------------------------------------
Widget* AbstractTopLevelContainer::getWidget(const char* name,
ptr_vector<Widget>* within_vector)
PtrVector<Widget>* within_vector)
{
const unsigned short widgets_amount = within_vector->size();
@ -143,7 +143,7 @@ Widget* AbstractTopLevelContainer::getWidget(const char* name,
// -----------------------------------------------------------------------------
Widget* AbstractTopLevelContainer::getWidget(const int id,
ptr_vector<Widget>* within_vector)
PtrVector<Widget>* within_vector)
{
const unsigned short widgets_amount = within_vector->size();
@ -167,7 +167,7 @@ Widget* AbstractTopLevelContainer::getWidget(const int id,
// -----------------------------------------------------------------------------
Widget* AbstractTopLevelContainer::getFirstWidget(ptr_vector<Widget>* within_vector)
Widget* AbstractTopLevelContainer::getFirstWidget(PtrVector<Widget>* within_vector)
{
if (m_first_widget != NULL) return m_first_widget;
if (within_vector == NULL) within_vector = &m_widgets;
@ -201,7 +201,7 @@ Widget* AbstractTopLevelContainer::getFirstWidget(ptr_vector<Widget>* within_vec
// -----------------------------------------------------------------------------
Widget* AbstractTopLevelContainer::getLastWidget(ptr_vector<Widget>* within_vector)
Widget* AbstractTopLevelContainer::getLastWidget(PtrVector<Widget>* within_vector)
{
if (m_last_widget != NULL) return m_last_widget;
if (within_vector == NULL) within_vector = &m_widgets;

View File

@ -32,7 +32,7 @@ namespace GUIEngine
{
protected:
/** the widgets in this screen */
ptr_vector<Widget, HOLD> m_widgets;
PtrVector<Widget, HOLD> m_widgets;
/**
* AbstractTopLevelContainer is generally able to determine its first widget just fine,
@ -48,7 +48,7 @@ namespace GUIEngine
*/
Widget* m_last_widget;
void addWidgetsRecursively(ptr_vector<Widget>& widgets, Widget* parent=NULL);
void addWidgetsRecursively(PtrVector<Widget>& widgets, Widget* parent=NULL);
public:
@ -78,11 +78,11 @@ namespace GUIEngine
return outCasted;
}
static Widget* getWidget(const char* name, ptr_vector<Widget>* within_vector);
static Widget* getWidget(const int id, ptr_vector<Widget>* within_vector);
static Widget* getWidget(const char* name, PtrVector<Widget>* within_vector);
static Widget* getWidget(const int id, PtrVector<Widget>* within_vector);
Widget* getFirstWidget(ptr_vector<Widget>* within_vector=NULL);
Widget* getLastWidget(ptr_vector<Widget>* within_vector=NULL);
Widget* getFirstWidget(PtrVector<Widget>* within_vector=NULL);
Widget* getLastWidget(PtrVector<Widget>* within_vector=NULL);
bool isMyChild(Widget* widget) const;
};

View File

@ -588,10 +588,10 @@ namespace GUIEngine
}
using namespace Private;
ptr_vector<Widget, REF> needsUpdate;
PtrVector<Widget, REF> needsUpdate;
//FIXME: the contents of this vector are never ever freed
ptr_vector<Screen, REF> g_loaded_screens;
PtrVector<Screen, REF> g_loaded_screens;
float dt = 0;

View File

@ -91,7 +91,7 @@ namespace GUIEngine
}
/** Widgets that need to be notified at every frame can add themselves there (FIXME: unclean) */
extern ptr_vector<Widget, REF> needsUpdate;
extern PtrVector<Widget, REF> needsUpdate;
/**
* \brief Call this method to init the GUI engine.

View File

@ -239,7 +239,7 @@ void LayoutManager::readCoords(Widget* self, AbstractTopLevelContainer* topLevel
// ----------------------------------------------------------------------------
void LayoutManager::calculateLayout(ptr_vector<Widget>& widgets, AbstractTopLevelContainer* topLevelContainer,
void LayoutManager::calculateLayout(PtrVector<Widget>& widgets, AbstractTopLevelContainer* topLevelContainer,
Widget* parent)
{
const unsigned short widgets_amount = widgets.size();

View File

@ -52,7 +52,7 @@ namespace GUIEngine
* Manages 'horizontal-row' and 'vertical-row' layouts, along with the proportions
* of the remaining children, as well as absolute sizes and locations.
*/
static void calculateLayout(ptr_vector<Widget>& widgets, AbstractTopLevelContainer* topLevelContainer,
static void calculateLayout(PtrVector<Widget>& widgets, AbstractTopLevelContainer* topLevelContainer,
Widget* parent=NULL);
};

View File

@ -184,7 +184,7 @@ void Screen::addWidgets()
* Called when screen is removed. This means all irrlicht widgets this object has pointers
* to are now gone. Set all references to NULL to avoid problems.
*/
void Screen::elementsWereDeleted(ptr_vector<Widget>* within_vector)
void Screen::elementsWereDeleted(PtrVector<Widget>* within_vector)
{
assert(m_magic_number == 0xCAFEC001);
if (within_vector == NULL) within_vector = &m_widgets;

View File

@ -114,7 +114,7 @@ namespace GUIEngine
* Builds a hierarchy of Widget objects whose contents are a direct transcription of the XML file,
* with little analysis or layout performed on them.
*/
static void parseScreenFileDiv(irr::io::IrrXMLReader* xml, ptr_vector<Widget>& append_to,
static void parseScreenFileDiv(irr::io::IrrXMLReader* xml, PtrVector<Widget>& append_to,
irr::gui::IGUIElement* parent = NULL);
@ -159,7 +159,7 @@ namespace GUIEngine
* \brief invoked when irrlicht widgets added to the screen have been deleted
* so that we can drop any pointer to them we had (they are now dangling pointers)
*/
void elementsWereDeleted(ptr_vector<Widget>* within_vector = NULL);
void elementsWereDeleted(PtrVector<Widget>* within_vector = NULL);
/** Next time this menu needs to be shown, don't use cached values, re-calculate everything.
(useful e.g. on reschange, when sizes have changed and must be re-calculated) */

View File

@ -34,7 +34,7 @@ using namespace io;
using namespace gui;
using namespace GUIEngine;
void Screen::parseScreenFileDiv(irr::io::IrrXMLReader* xml, ptr_vector<Widget>& append_to,
void Screen::parseScreenFileDiv(irr::io::IrrXMLReader* xml, PtrVector<Widget>& append_to,
irr::gui::IGUIElement* parent)
{
// parse XML file

View File

@ -1231,7 +1231,7 @@ void Skin::drawListSelection(const core::rect< s32 > &rect, Widget* widget, bool
/** recursive function to render all sections (recursion allows to easily traverse the tree of children
* and sub-children)
*/
void Skin::renderSections(ptr_vector<Widget>* within_vector)
void Skin::renderSections(PtrVector<Widget>* within_vector)
{
if (within_vector == NULL) within_vector = &getCurrentScreen()->m_widgets;

View File

@ -284,7 +284,7 @@ namespace GUIEngine
irr::gui::IGUISkin* getFallbackSkin() { return m_fallback_skin; }
void renderSections(ptr_vector<Widget>* within_vector=NULL);
void renderSections(PtrVector<Widget>* within_vector=NULL);
void drawBgImage();
void drawBGFadeColor();
void drawBadgeOn(const Widget* widget, const irr::core::rect<irr::s32>& rect);

View File

@ -214,7 +214,7 @@ namespace GUIEngine
* be created automatically for logical widgets built with more than
* one irrlicht widgets (e.g. Spinner)
*/
ptr_vector<Widget> m_children;
PtrVector<Widget> m_children;
/** A bitmask of which badges to show, if any; choices are *_BADGE, defined above */
int m_badges;
@ -488,7 +488,7 @@ namespace GUIEngine
/**
* \return a read-only view of the childrens of this widget, if any
*/
const ptr_vector<Widget>& getChildren() const { return m_children; }
const PtrVector<Widget>& getChildren() const { return m_children; }
/**
* \brief removes and deletes the child with the given PROP_ID

View File

@ -70,7 +70,7 @@ namespace GUIEngine
friend class RibbonWidget;
/** A list of all listeners that registered to be notified on hover/selection */
ptr_vector<DynamicRibbonHoverListener> m_hover_listeners;
PtrVector<DynamicRibbonHoverListener> m_hover_listeners;
virtual ~DynamicRibbonWidget();
@ -177,7 +177,7 @@ namespace GUIEngine
/** Reference pointers only, the actual instances are owned by m_children. Used to create mtultiple-row
ribbons (what appears to be a grid of icons is actually a vector of stacked basic ribbons) */
ptr_vector<RibbonWidget, REF> m_rows;
PtrVector<RibbonWidget, REF> m_rows;
/** Dynamically add an item to the ribbon's list of items (will not be visible until you
* call 'updateItemDisplay' or 'add').

View File

@ -44,7 +44,7 @@ namespace GUIEngine
float m_rotation_speed;
float m_rotation_target;
ptr_vector<scene::IMesh, REF> m_models;
PtrVector<scene::IMesh, REF> m_models;
AlignedArray<Vec3> m_model_location;
AlignedArray<Vec3> m_model_scale;
std::vector<int> m_model_frames;

View File

@ -75,7 +75,7 @@ namespace GUIEngine
virtual EventPropagation transmitEvent(Widget* w, std::string& originator, const int playerID=0);
virtual EventPropagation focused(const int playerID);
ptr_vector<irr::gui::IGUIStaticText, REF> m_labels;
PtrVector<irr::gui::IGUIStaticText, REF> m_labels;
IRibbonListener* m_listener;

View File

@ -51,10 +51,10 @@ class DeviceManager: public NoCopy
{
private:
ptr_vector<KeyboardDevice, HOLD> m_keyboards;
ptr_vector<GamePadDevice, HOLD> m_gamepads;
ptr_vector<KeyboardConfig, HOLD> m_keyboard_configs;
ptr_vector<GamepadConfig, HOLD> m_gamepad_configs;
PtrVector<KeyboardDevice, HOLD> m_keyboards;
PtrVector<GamePadDevice, HOLD> m_gamepads;
PtrVector<KeyboardConfig, HOLD> m_keyboard_configs;
PtrVector<GamepadConfig, HOLD> m_gamepad_configs;
core::array<SJoystickInfo> m_irrlicht_gamepads;
InputDevice* m_latest_used_device;
PlayerAssignMode m_assign_mode;

View File

@ -353,7 +353,7 @@ void RaceManager::computeGPRanks()
{
// calculate the rank of each kart
const unsigned int NUM_KARTS = getNumberOfKarts();
ptr_vector<computeGPRanksData::SortData> sort_data;
PtrVector<computeGPRanksData::SortData> sort_data;
// Ignore the first kart if it's a follow-the-leader race.
int start=(race_manager->getMinorMode()==RaceManager::MINOR_MODE_FOLLOW_LEADER);

View File

@ -34,7 +34,7 @@ class CreditsScreen : public GUIEngine::Screen, public GUIEngine::ScreenSingleto
{
float m_time_element;
ptr_vector<CreditsSection, HOLD> m_sections;
PtrVector<CreditsSection, HOLD> m_sections;
CreditsSection* getCurrentSection();
int x, y, w, h;

View File

@ -78,10 +78,10 @@ class FeatureUnlockedCutScene : public GUIEngine::Screen, public GUIEngine::Scre
};
/** The list of all unlocked things. */
ptr_vector<UnlockedThing, HOLD> m_unlocked_stuff;
PtrVector<UnlockedThing, HOLD> m_unlocked_stuff;
/** To store the copy of the KartModel for each unlocked kart. */
ptr_vector<KartModel> m_all_kart_models;
PtrVector<KartModel> m_all_kart_models;
/** sky angle, 0-360 */
float m_sky_angle;

View File

@ -1437,7 +1437,7 @@ void KartSelectionScreen::allPlayersDone()
DynamicRibbonWidget* w = getWidget<DynamicRibbonWidget>("karts");
assert( w != NULL );
const ptr_vector< StateManager::ActivePlayer, HOLD >& players = StateManager::get()->getActivePlayers();
const PtrVector< StateManager::ActivePlayer, HOLD >& players = StateManager::get()->getActivePlayers();
// ---- Print selection (for debugging purposes)
if(UserConfigParams::m_verbosity>=4)

View File

@ -43,7 +43,7 @@ class KartSelectionScreen : public GUIEngine::Screen, public GUIEngine::ScreenSi
/** Contains the custom widget shown for every player. (ref only since we're adding them to a
* Screen, and the Screen will take ownership of these widgets)
*/
ptr_vector<PlayerKartWidget, REF> m_kart_widgets;
PtrVector<PlayerKartWidget, REF> m_kart_widgets;
friend class GUIEngine::ScreenSingleton<KartSelectionScreen>;
friend class PlayerKartWidget;

View File

@ -144,7 +144,7 @@ public:
};
const ptr_vector<ActivePlayer, HOLD>& getActivePlayers()
const PtrVector<ActivePlayer, HOLD>& getActivePlayers()
{ return m_active_players; }
ActivePlayer* getActivePlayer(const int id);
@ -185,7 +185,7 @@ private:
/**
* A list of all currently playing players.
*/
ptr_vector<ActivePlayer, HOLD> m_active_players;
PtrVector<ActivePlayer, HOLD> m_active_players;
};
#endif

View File

@ -20,7 +20,6 @@
#include "irrlicht.h"
#include "guiengine/screen.hpp"
#include "utils/ptr_vector.hpp"
#include "guiengine/CGUISpriteBank.h"
using namespace irr::core;

View File

@ -73,7 +73,7 @@ private:
std::vector<std::string> m_groups;
std::vector<scene::ISceneNode*> m_all_nodes;
std::vector<scene::IMesh*> m_all_meshes;
ptr_vector<ParticleEmitter> m_all_emitters;
PtrVector<ParticleEmitter> m_all_emitters;
scene::ILightSceneNode *m_sun;
TriangleMesh* m_track_mesh;
/** Minimum coordinates of this track. */

View File

@ -15,12 +15,12 @@
*/
/*
* I made this class to work like a regular vector, except that contentsVector are placed
* one the heap so third-party contentsVector can keep pointers to them.
* I made this class to work like a regular vector, except that m_contents_vector are placed
* one the heap so third-party m_contents_vector can keep pointers to them.
*/
#ifndef HEADER_PTR_VECTOR_HPP
#define HEADER_PTR_VECTOR_HPP
#ifndef HEADER_PtrVector_HPP
#define HEADER_PtrVector_HPP
#include <vector>
#include <iostream>
@ -34,226 +34,241 @@ enum VECTOR_TYPE
HOLD
};
template<typename TYPE, VECTOR_TYPE type=HOLD>
class ptr_vector
class PtrVector
{
public:
AlignedArray<TYPE*> contentsVector;
AlignedArray<TYPE*> m_contents_vector;
ptr_vector()
{
}
PtrVector()
{
}
~ptr_vector()
{
if(type == HOLD) clearAndDeleteAll();
}
// ------------------------------------------------------------------------
~PtrVector()
{
if(type == HOLD) clearAndDeleteAll();
}
void push_back(TYPE* t)
{
contentsVector.push_back(t);
}
// ------------------------------------------------------------------------
void push_back(TYPE* t)
{
m_contents_vector.push_back(t);
}
void add(TYPE* t, int index)
{
contentsVector.insert(contentsVector.begin()+index, t);
}
void swap(int ID1, int ID2)
{
assert(ID1 > -1);
assert((unsigned int)ID1 < contentsVector.size());
assert(ID2 > -1);
assert((unsigned int)ID2 < contentsVector.size());
// ------------------------------------------------------------------------
void swap(int ID1, int ID2)
{
assert(ID1 > -1);
assert((unsigned int)ID1 < m_contents_vector.size());
assert(ID2 > -1);
assert((unsigned int)ID2 < m_contents_vector.size());
TYPE* temp = contentsVector[ID2];
TYPE* temp = m_contents_vector[ID2];
contentsVector[ID2] = contentsVector[ID1];
contentsVector[ID1] = temp;
}
m_contents_vector[ID2] = m_contents_vector[ID1];
m_contents_vector[ID1] = temp;
}
TYPE* get(const int ID)
{
// ------------------------------------------------------------------------
TYPE* get(const int ID)
{
assert(ID > -1);
assert((unsigned int)ID < (unsigned int)contentsVector.size());
assert(ID > -1);
assert((unsigned int)ID < (unsigned int)m_contents_vector.size());
return contentsVector[ID];
}
return m_contents_vector[ID];
}
const TYPE* getConst(const int ID) const
{
assert(ID > -1);
assert((unsigned int)ID < (unsigned int)contentsVector.size());
return contentsVector[ID];
}
// ------------------------------------------------------------------------
const TYPE* getConst(const int ID) const
{
int size() const
{
return contentsVector.size();
}
assert(ID > -1);
assert((unsigned int)ID < (unsigned int)m_contents_vector.size());
void erase(const int ID)
{
assert(ID > -1);
assert((unsigned int)ID < (unsigned int)contentsVector.size());
return m_contents_vector[ID];
}
delete ( TYPE *) contentsVector[ID];
// ------------------------------------------------------------------------
int size() const
{
return m_contents_vector.size();
}
// ------------------------------------------------------------------------
void erase(const int ID)
{
assert(ID > -1);
assert((unsigned int)ID < (unsigned int)m_contents_vector.size());
delete ( TYPE *) m_contents_vector[ID];
#ifdef USE_ALIGNED
const unsigned int amount = (unsigned int)contentsVector.size();
for(unsigned int i=ID; i<amount-1; i++)
{
contentsVector[i]=contentsVector[i+1];
}
contentsVector.pop_back();
#else
contentsVector.erase(contentsVector.begin()+ID);
#endif
}
TYPE* remove(const int ID)
{
assert(ID > -1);
assert((unsigned int)ID < (unsigned int)contentsVector.size());
TYPE* out = contentsVector[ID];
#ifdef USE_ALIGNED
const unsigned int amount = (unsigned int)contentsVector.size();
for(unsigned int i=ID; i<amount-1; i++)
{
contentsVector[i]=contentsVector[i+1];
}
contentsVector.pop_back();
#else
contentsVector.erase(contentsVector.begin()+ID);
#endif
return out;
}
bool contains( const TYPE* instance ) const
{
const unsigned int amount = (unsigned int)contentsVector.size();
for (unsigned int n=0; n<amount; n++)
{
const TYPE * pointer = contentsVector[n];
if (pointer == instance) return true;
}
return false;
}
void clearAndDeleteAll()
{
for (unsigned int n=0; n<(unsigned int)contentsVector.size(); n++)
{
TYPE * pointer = contentsVector[n];
delete pointer;
contentsVector[n] = (TYPE*)0xDEADBEEF;
// When deleting, it's important that the same pointer cannot be
// twice in the vector, resulting in a double delete
assert( !contains(pointer) );
}
contentsVector.clear();
}
TYPE& operator[](const unsigned int ID)
{
assert((unsigned int)ID < (unsigned int)contentsVector.size());
return *(contentsVector[ID]);
}
const TYPE& operator[](const unsigned int ID) const
{
assert((unsigned int)ID < (unsigned int)contentsVector.size());
return *(contentsVector[ID]);
}
void clearWithoutDeleting()
{
contentsVector.clear();
}
/**
* Removes without deleting
*/
void remove(TYPE* obj)
{
for(unsigned int n=0; n<(unsigned int)contentsVector.size(); n++)
{
TYPE * pointer = contentsVector[n];
if(pointer == obj)
const unsigned int amount = (unsigned int)m_contents_vector.size();
for(unsigned int i=ID; i<amount-1; i++)
{
#ifdef USE_ALIGNED
const unsigned int amount = (unsigned int)contentsVector.size();
for(unsigned int i=n; i<amount-1; i++)
{
contentsVector[i]=contentsVector[i+1];
}
contentsVector.pop_back();
#else
contentsVector.erase(contentsVector.begin()+n);
#endif
return;
m_contents_vector[i]=m_contents_vector[i+1];
}
m_contents_vector.pop_back();
#else
m_contents_vector.erase(m_contents_vector.begin()+ID);
#endif
}
}
/**
* \brief Removes and deletes the given object.
* \return whether this object was found in the vector and deleted
*/
bool erase(void* obj)
{
for(unsigned int n=0; n<(unsigned int)contentsVector.size(); n++)
// ------------------------------------------------------------------------
TYPE* remove(const int ID)
{
TYPE * pointer = contentsVector[n];
if((void*)pointer == obj)
{
assert(ID > -1);
assert((unsigned int)ID < (unsigned int)m_contents_vector.size());
TYPE* out = m_contents_vector[ID];
#ifdef USE_ALIGNED
const unsigned int amount = (unsigned int)contentsVector.size();
for(unsigned int i=n; i<amount-1; i++)
{
contentsVector[i]=contentsVector[i+1];
}
contentsVector.pop_back();
const unsigned int amount = (unsigned int)m_contents_vector.size();
for(unsigned int i=ID; i<amount-1; i++)
{
m_contents_vector[i]=m_contents_vector[i+1];
}
m_contents_vector.pop_back();
#else
contentsVector.erase(contentsVector.begin()+n);
m_contents_vector.erase(m_contents_vector.begin()+ID);
#endif
return out;
}
// ------------------------------------------------------------------------
bool contains( const TYPE* instance ) const
{
const unsigned int amount = (unsigned int)m_contents_vector.size();
for (unsigned int n=0; n<amount; n++)
{
const TYPE * pointer = m_contents_vector[n];
if (pointer == instance) return true;
}
return false;
}
// ------------------------------------------------------------------------
void clearAndDeleteAll()
{
for (unsigned int n=0; n<(unsigned int)m_contents_vector.size(); n++)
{
TYPE * pointer = m_contents_vector[n];
delete pointer;
return true;
}
}
return false;
}
m_contents_vector[n] = (TYPE*)0xDEADBEEF;
// When deleting, it's important that the same pointer cannot be
// twice in the vector, resulting in a double delete
assert( !contains(pointer) );
}
m_contents_vector.clear();
}
// ------------------------------------------------------------------------
TYPE& operator[](const unsigned int ID)
{
assert((unsigned int)ID < (unsigned int)m_contents_vector.size());
return *(m_contents_vector[ID]);
}
// ------------------------------------------------------------------------
const TYPE& operator[](const unsigned int ID) const
{
assert((unsigned int)ID < (unsigned int)m_contents_vector.size());
return *(m_contents_vector[ID]);
}
// ------------------------------------------------------------------------
void clearWithoutDeleting()
{
m_contents_vector.clear();
}
// ------------------------------------------------------------------------
/**
* Removes without deleting
*/
void remove(TYPE* obj)
{
for(unsigned int n=0; n<(unsigned int)m_contents_vector.size(); n++)
{
TYPE * pointer = m_contents_vector[n];
if(pointer == obj)
{
#ifdef USE_ALIGNED
const unsigned int amount =
(unsigned int)m_contents_vector.size();
for(unsigned int i=n; i<amount-1; i++)
{
m_contents_vector[i]=m_contents_vector[i+1];
}
m_contents_vector.pop_back();
#else
m_contents_vector.erase(m_contents_vector.begin()+n);
#endif
return;
}
}
}
// ------------------------------------------------------------------------
/**
* \brief Removes and deletes the given object.
* \return whether this object was found in the vector and deleted
*/
bool erase(void* obj)
{
for(unsigned int n=0; n<(unsigned int)m_contents_vector.size(); n++)
{
TYPE * pointer = m_contents_vector[n];
if((void*)pointer == obj)
{
#ifdef USE_ALIGNED
const unsigned int amount =
(unsigned int)m_contents_vector.size();
for(unsigned int i=n; i<amount-1; i++)
{
m_contents_vector[i]=m_contents_vector[i+1];
}
m_contents_vector.pop_back();
#else
m_contents_vector.erase(m_contents_vector.begin()+n);
#endif
delete pointer;
return true;
}
}
return false;
}
// ------------------------------------------------------------------------
void insertionSort(unsigned int start=0)
{
for(unsigned int j=start; j<(unsigned)contentsVector.size()-1; j++)
for(unsigned int j=start; j<(unsigned)m_contents_vector.size()-1; j++)
{
if(*(contentsVector[j])<*(contentsVector[j+1])) continue;
// Now search the proper place for contentsVector[j+1]
if(*(m_contents_vector[j])<*(m_contents_vector[j+1])) continue;
// Now search the proper place for m_contents_vector[j+1]
// in the sorted section contentsVectot[start:j]
TYPE* t=contentsVector[j+1];
TYPE* t=m_contents_vector[j+1];
unsigned int i = j+1;
do
{
contentsVector[i] = contentsVector[i-1];
m_contents_vector[i] = m_contents_vector[i-1];
i--;
} while (i>0 && *t<*(contentsVector[i-1]));
contentsVector[i]=t;
} while (i>0 && *t<*(m_contents_vector[i-1]));
m_contents_vector[i]=t;
}
} // insertionSort
};
}; // class ptrVector
#endif