From cf1a6e2a6f015914a56e5f539da2e14146ce4c20 Mon Sep 17 00:00:00 2001 From: dooglus Date: Sat, 15 Sep 2007 07:56:41 +0000 Subject: [PATCH] I'm told that it's a bad idea to inherit from std::vector (because it has no virtual destructor), so use a vector member variable instead. git-svn-id: http://svn.voria.com/code@673 1f10aa63-cdf2-0310-b900-c93c546f37ac --- synfig-core/trunk/src/synfig/gradient.cpp | 10 +++++----- synfig-core/trunk/src/synfig/gradient.h | 23 +++++++++++++++++++++-- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/synfig-core/trunk/src/synfig/gradient.cpp b/synfig-core/trunk/src/synfig/gradient.cpp index 21ea107..11b2295 100644 --- a/synfig-core/trunk/src/synfig/gradient.cpp +++ b/synfig-core/trunk/src/synfig/gradient.cpp @@ -143,7 +143,7 @@ supersample_helper(const synfig::Gradient::CPoint &color1, const synfig::Gradien Color synfig::Gradient::operator()(const Real &x,float supersample)const { - if(empty()) + if(cpoints.empty()) return Color(0,0,0,0); if(supersample<0) supersample=-supersample; @@ -153,11 +153,11 @@ synfig::Gradient::operator()(const Real &x,float supersample)const float begin_sample(x-supersample*0.5); float end_sample(x+supersample*0.5); - if(size()==1 || end_sample<=front().pos || isnan(x)) - return front().color; + if(cpoints.size()==1 || end_sample<=cpoints.front().pos || isnan(x)) + return cpoints.front().color; - if(begin_sample>=back().pos) - return back().color; + if(begin_sample>=cpoints.back().pos) + return cpoints.back().color; /* if(end_sample>=back().pos) diff --git a/synfig-core/trunk/src/synfig/gradient.h b/synfig-core/trunk/src/synfig/gradient.h index 25a9dbf..bc4c1e8 100644 --- a/synfig-core/trunk/src/synfig/gradient.h +++ b/synfig-core/trunk/src/synfig/gradient.h @@ -60,12 +60,17 @@ struct GradientCPoint : public UniqueID /*! \class Gradient ** \brief Color Gradient Class */ -class Gradient : public std::vector +using namespace std; +class Gradient { public: typedef GradientCPoint CPoint; + typedef vector::const_iterator const_iterator; + typedef vector::iterator iterator; + typedef vector::const_reverse_iterator const_reverse_iterator; + typedef vector::reverse_iterator reverse_iterator; private: - + vector cpoints; public: Gradient() { } @@ -81,6 +86,20 @@ public: //! You should call this function after changing stuff. void sort(); + void push_back(const GradientCPoint cpoint) { cpoints.push_back(cpoint); } + iterator erase(iterator iter) { return cpoints.erase(iter); } + bool empty()const { return cpoints.empty(); } + size_t size()const { return cpoints.size(); } + + iterator begin() { return cpoints.begin(); } + iterator end() { return cpoints.end(); } + reverse_iterator rbegin() { return cpoints.rbegin(); } + reverse_iterator rend() { return cpoints.rend(); } + const_iterator begin()const { return cpoints.begin(); } + const_iterator end()const { return cpoints.end(); } + const_reverse_iterator rbegin()const { return cpoints.rbegin(); } + const_reverse_iterator rend()const { return cpoints.rend(); } + Color operator()(const Real &x, float supersample=0)const; //! Returns the iterator of the CPoint closest to \a x -- 2.7.4