From db068ff16aa689c180037af831d9ba6fca7594d7 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Sat, 28 Jan 2012 21:59:34 +0100 Subject: Removed inheritance from std::vector by CompoundSprite In my opinion, the code is clearer when using aggregation. For performance it makes no difference. This also fixes a memory leak in CompountSprite::clear, which forgot to delete any existing sprites. Reviewed-by: Erik Schilling Conflicts: src/compoundsprite.cpp src/compoundsprite.h --- src/compoundsprite.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/compoundsprite.h') diff --git a/src/compoundsprite.h b/src/compoundsprite.h index 1c04e44d2..1b9eeca34 100644 --- a/src/compoundsprite.h +++ b/src/compoundsprite.h @@ -44,11 +44,11 @@ class CompoundItem Image *alphaImage; }; -class CompoundSprite : public Sprite, private std::vector +class CompoundSprite : public Sprite { public: - typedef CompoundSprite::iterator SpriteIterator; - typedef CompoundSprite::const_iterator SpriteConstIterator; + typedef std::vector::iterator SpriteIterator; + typedef std::vector::const_iterator SpriteConstIterator; CompoundSprite(); @@ -60,7 +60,7 @@ public: virtual bool update(int time); - virtual bool draw(Graphics* graphics, int posX, int posY) const; + virtual bool draw(Graphics *graphics, int posX, int posY) const; /** * Gets the width in pixels of the first sprite in the list. @@ -72,7 +72,7 @@ public: */ virtual int getHeight() const; - virtual const Image* getImage() const; + virtual const Image *getImage() const; virtual bool setSpriteDirection(SpriteDirection direction); @@ -83,17 +83,17 @@ public: unsigned int getFrameCount() const; size_t size() const - { return std::vector::size(); } + { return mSprites.size(); } bool empty() const - { return std::vector::empty(); } + { return mSprites.empty(); } - void addSprite(Sprite* sprite); + void addSprite(Sprite *sprite); - void setSprite(int layer, Sprite* sprite); + void setSprite(int layer, Sprite *sprite); Sprite *getSprite(int layer) const - { return at(layer); } + { return mSprites.at(layer); } void removeSprite(int layer); @@ -144,6 +144,7 @@ private: bool mEnableAlphaFix; bool mDisableAdvBeingCaching; bool mDisableBeingCaching; + std::vector mSprites; }; #endif // COMPOUNDSPRITE_H -- cgit v1.2.3-70-g09d2