Skip to content

Commit

Permalink
fix: "rule of two" : copy constructor and copy assignment operator
Browse files Browse the repository at this point in the history
And copy assignment operator returns reference, not a copy.
  • Loading branch information
rodolforg committed Sep 9, 2022
1 parent 1ce65b6 commit 7dc2288
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions synfig-core/src/synfig/base_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class TypeReal: public Type
mutable Time t;
Real r;
Inner(): f(0.f), t(0.0), r(0.0) { }
Inner(const Inner& other) { r = other.r; }

bool operator== (const Inner &other) const { return r == other.r; }
Inner& operator= (const Inner &other) { return *this = other.r; }
Expand Down Expand Up @@ -416,6 +417,8 @@ class TypeCanvas: public Type
#else
Inner(): p(nullptr) { }
#endif
Inner(const Inner& other) { *this = other; }

Inner& operator= (const etl::loose_handle<Canvas> &other)
{
#ifdef TRY_FIX_FOR_BUG_27
Expand Down Expand Up @@ -542,6 +545,7 @@ class TypeBoneValueNode: public Type
mutable ValueNode_BonePtr p;

Inner(): p(nullptr) { }
Inner(const Inner& other) { h = other.h; }
Inner& operator= (const etl::handle<ValueNode_Bone> &other) { h = other; return *this; }
Inner& operator= (const etl::loose_handle<ValueNode_Bone> &other) { h = other; return *this; }
Inner& operator= (const ValueNode_BonePtr &other) { h = other; return *this; }
Expand Down
9 changes: 6 additions & 3 deletions synfig-core/src/synfig/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ class IndependentContext: public CanvasBase::const_iterator
//! Constructor based on other CanvasBase iterator
IndependentContext(const CanvasBase::const_iterator &x):CanvasBase::const_iterator(x) { }

//! Assignation operator
IndependentContext operator=(const CanvasBase::const_iterator &x)
{ return CanvasBase::const_iterator::operator=(x); }
//! Assignment operator
IndependentContext& operator=(const CanvasBase::const_iterator &x)
{
CanvasBase::const_iterator::operator=(x);
return *this;
}

//! Sets the context to the Time \time. It is done recursively.
void set_time(Time time, bool force = false) const;
Expand Down
8 changes: 8 additions & 0 deletions synfig-core/src/synfig/rect.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ class rect
minx(o.minx), miny(o.miny), maxx(o.maxx), maxy(o.maxy) { }
rect(const rect<T> &o):
minx(o.minx), miny(o.miny), maxx(o.maxx), maxy(o.maxy) { }
rect<T>& operator=(const rect<T>& o)
{
minx = o.minx;
maxx = o.maxx;
miny = o.miny;
maxy = o.maxy;
return *this;
}

template<typename F>
rect(
Expand Down
6 changes: 6 additions & 0 deletions synfig-studio/src/gui/_smach.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ class smach

//! Copy constructor
event_def_internal(const event_def_internal &x):id(x.id),handler(x.handler) { }
event_def_internal& operator=(const event_def_internal& x)
{
id = x.id;
handler = x.handler;
return *this;
}

};

Expand Down

0 comments on commit 7dc2288

Please sign in to comment.