From 6f8559ddcb82636029d07776700d51b0e0c35e92 Mon Sep 17 00:00:00 2001 From: dooglus Date: Fri, 11 Jan 2008 09:43:34 +0000 Subject: [PATCH] Add type checking to almost all the linkable ValueNodes. git-svn-id: http://svn.voria.com/code@1326 1f10aa63-cdf2-0310-b900-c93c546f37ac --- synfig-core/trunk/src/synfig/valuenode_add.cpp | 4 + synfig-core/trunk/src/synfig/valuenode_atan2.cpp | 15 +--- synfig-core/trunk/src/synfig/valuenode_bline.cpp | 3 +- .../src/synfig/valuenode_blinecalctangent.cpp | 21 ++--- .../trunk/src/synfig/valuenode_blinecalcvertex.cpp | 21 ++--- .../src/synfig/valuenode_blinereversetangent.cpp | 16 ++-- synfig-core/trunk/src/synfig/valuenode_cos.cpp | 15 +--- .../trunk/src/synfig/valuenode_duplicate.cpp | 14 ++-- synfig-core/trunk/src/synfig/valuenode_exp.cpp | 15 +--- .../trunk/src/synfig/valuenode_gradientrotate.cpp | 31 +------ .../trunk/src/synfig/valuenode_gradientrotate.h | 12 --- synfig-core/trunk/src/synfig/valuenode_integer.cpp | 10 +-- synfig-core/trunk/src/synfig/valuenode_linear.cpp | 15 +--- synfig-core/trunk/src/synfig/valuenode_range.cpp | 16 +--- .../trunk/src/synfig/valuenode_reciprocal.cpp | 14 ++-- .../trunk/src/synfig/valuenode_reference.cpp | 12 +-- .../trunk/src/synfig/valuenode_repeat_gradient.cpp | 98 ++-------------------- .../trunk/src/synfig/valuenode_repeat_gradient.h | 8 -- synfig-core/trunk/src/synfig/valuenode_scale.cpp | 71 ++-------------- synfig-core/trunk/src/synfig/valuenode_scale.h | 15 ---- .../trunk/src/synfig/valuenode_segcalctangent.cpp | 15 +--- .../trunk/src/synfig/valuenode_segcalcvertex.cpp | 15 +--- synfig-core/trunk/src/synfig/valuenode_sine.cpp | 15 +--- synfig-core/trunk/src/synfig/valuenode_stripes.cpp | 61 ++------------ synfig-core/trunk/src/synfig/valuenode_stripes.h | 14 ---- synfig-core/trunk/src/synfig/valuenode_switch.cpp | 23 ++--- .../trunk/src/synfig/valuenode_timedswap.cpp | 98 ++-------------------- synfig-core/trunk/src/synfig/valuenode_timedswap.h | 12 --- .../trunk/src/synfig/valuenode_timeloop.cpp | 16 ++-- synfig-core/trunk/src/synfig/valuenode_twotone.cpp | 31 +------ synfig-core/trunk/src/synfig/valuenode_twotone.h | 15 ---- 31 files changed, 127 insertions(+), 614 deletions(-) diff --git a/synfig-core/trunk/src/synfig/valuenode_add.cpp b/synfig-core/trunk/src/synfig/valuenode_add.cpp index 93dd3c3..3843598 100644 --- a/synfig-core/trunk/src/synfig/valuenode_add.cpp +++ b/synfig-core/trunk/src/synfig/valuenode_add.cpp @@ -141,6 +141,7 @@ bool ValueNode_Add::set_link_vfunc(int i,ValueNode::Handle value) { assert(i>=0 && i=0 && i=0 && i=0 && i=0 && i=0 && (unsigned)i=0 && i=0 && i=0 && i=0 && i=0 && i=0 && i=0 && i=0 && i=0 && i=0 && i=0 && i=0 && i=0 && i=0 && i=0 && i=0 && iget_type()!=ValueBase::TYPE_GRADIENT&& !PlaceholderValueNode::Handle::cast_dynamic(a)) - return false; - - ref_gradient=a; - - return true; -} - -bool -synfig::ValueNode_GradientRotate::set_offset(ValueNode::Handle b) -{ - if(b->get_type()!=ValueBase::TYPE_REAL&& !PlaceholderValueNode::Handle::cast_dynamic(b)) - return false; - ref_offset=b; - return true; -} - synfig::ValueBase synfig::ValueNode_GradientRotate::operator()(Time t)const { @@ -122,20 +102,15 @@ synfig::ValueNode_GradientRotate::operator()(Time t)const } bool -ValueNode_GradientRotate::set_link_vfunc(int i,ValueNode::Handle x) +ValueNode_GradientRotate::set_link_vfunc(int i,ValueNode::Handle value) { assert(i>=0 && i=0 && i=0 && i=0 && i=0 && iget_type()!=get_type() && !PlaceholderValueNode::Handle::cast_dynamic(x)) - return false; - link_=x; - signal_child_changed()(i);signal_value_changed()(); - return true; + switch(i) + { + case 0: CHECK_TYPE_AND_SET_VALUE(link_, get_type()); + } + return false; } ValueNode::LooseHandle diff --git a/synfig-core/trunk/src/synfig/valuenode_repeat_gradient.cpp b/synfig-core/trunk/src/synfig/valuenode_repeat_gradient.cpp index 0ea3f12..fbac822 100644 --- a/synfig-core/trunk/src/synfig/valuenode_repeat_gradient.cpp +++ b/synfig-core/trunk/src/synfig/valuenode_repeat_gradient.cpp @@ -93,73 +93,6 @@ synfig::ValueNode_Repeat_Gradient::~ValueNode_Repeat_Gradient() unlink_all(); } -bool -synfig::ValueNode_Repeat_Gradient::set_gradient(ValueNode::Handle a) -{ - if(a->get_type()!=ValueBase::TYPE_GRADIENT) - return false; - - gradient_=a; - - return true; -} - -bool -synfig::ValueNode_Repeat_Gradient::set_width(ValueNode::Handle x) -{ - if(x->get_type()!=ValueBase::TYPE_REAL) - return false; - - width_=x; - - return true; -} - -bool -synfig::ValueNode_Repeat_Gradient::set_count(ValueNode::Handle b) -{ - if(b->get_type()!=ValueBase::TYPE_INTEGER) - return false; - count_=b; - return true; -} - -bool -synfig::ValueNode_Repeat_Gradient::set_specify_start(ValueNode::Handle a) -{ - if(a->get_type()!=ValueBase::TYPE_BOOL) - return false; - specify_start_=a; - return true; -} - -bool -synfig::ValueNode_Repeat_Gradient::set_specify_end(ValueNode::Handle a) -{ - if(a->get_type()!=ValueBase::TYPE_BOOL) - return false; - specify_end_=a; - return true; -} - -bool -synfig::ValueNode_Repeat_Gradient::set_start_color(ValueNode::Handle a) -{ - if(a->get_type()!=ValueBase::TYPE_COLOR) - return false; - start_color_=a; - return true; -} - -bool -synfig::ValueNode_Repeat_Gradient::set_end_color(ValueNode::Handle a) -{ - if(a->get_type()!=ValueBase::TYPE_COLOR) - return false; - end_color_=a; - return true; -} - synfig::ValueBase synfig::ValueNode_Repeat_Gradient::operator()(Time t)const { @@ -199,35 +132,20 @@ synfig::ValueNode_Repeat_Gradient::operator()(Time t)const } bool -ValueNode_Repeat_Gradient::set_link_vfunc(int i,ValueNode::Handle x) +ValueNode_Repeat_Gradient::set_link_vfunc(int i,ValueNode::Handle value) { assert(i>=0 && iget_type()==id); + assert(value_node->get_type()==id); assert(get_type()==id); } @@ -109,56 +109,6 @@ synfig::ValueNode_Scale::~ValueNode_Scale() unlink_all(); } -void -ValueNode_Scale::set_scalar(Real x) -{ - set_link("scalar",ValueNode::Handle(ValueNode_Const::create(x))); -} - -bool -ValueNode_Scale::set_scalar(const ValueNode::Handle &x) -{ - if(!x - || x->get_type()!=ValueBase::TYPE_REAL - && !PlaceholderValueNode::Handle::cast_dynamic(x) - ) - return false; - scalar=x; - return true; -} - -ValueNode::Handle -ValueNode_Scale::get_scalar()const -{ - return scalar; -} - -bool -ValueNode_Scale::set_value_node(const ValueNode::Handle &x) -{ - assert(get_type()); - - // if this isn't a proper value - if(!x || - // or we don't have a type, and this value isn't one of the types we accept - (get_type()==ValueBase::TYPE_NIL && !check_type(x->get_type())) || - // or we have a type and this value is a different type and (placeholder?) - (get_type()!=ValueBase::TYPE_NIL && x->get_type()!=get_type() && !PlaceholderValueNode::Handle::cast_dynamic(x))) - // then fail to set the value - return false; - - value_node=x; - - return true; -} - -ValueNode::Handle -ValueNode_Scale::get_value_node()const -{ - return value_node; -} - - synfig::ValueBase synfig::ValueNode_Scale::operator()(Time t)const { @@ -190,19 +140,16 @@ synfig::ValueNode_Scale::operator()(Time t)const bool -ValueNode_Scale::set_link_vfunc(int i,ValueNode::Handle x) +ValueNode_Scale::set_link_vfunc(int i,ValueNode::Handle value) { assert(i>=0 && i=0 && i=0 && i=0 && iget_type()!=ValueBase::TYPE_COLOR) - return false; - - color1_=a; - - return true; -} - -bool -synfig::ValueNode_Stripes::set_color2(ValueNode::Handle a) -{ - if(a->get_type()!=ValueBase::TYPE_COLOR) - return false; - - color2_=a; - - return true; -} - -bool -synfig::ValueNode_Stripes::set_width(ValueNode::Handle x) -{ - if(x->get_type()!=ValueBase::TYPE_REAL) - return false; - - width_=x; - - return true; -} - -bool -synfig::ValueNode_Stripes::set_stripes(ValueNode::Handle b) -{ - if(b->get_type()!=ValueBase::TYPE_INTEGER) - return false; - stripes_=b; - return true; -} - synfig::ValueBase synfig::ValueNode_Stripes::operator()(Time t)const { @@ -161,26 +119,17 @@ synfig::ValueNode_Stripes::operator()(Time t)const } bool -ValueNode_Stripes::set_link_vfunc(int i,ValueNode::Handle x) +ValueNode_Stripes::set_link_vfunc(int i,ValueNode::Handle value) { assert(i>=0 && i=0 && iget_type()!=get_type() && !PlaceholderValueNode::Handle::cast_dynamic(x)) - return false; - link_off_=x; - signal_child_changed()(i);signal_value_changed()(); - return true; - case 1: - if(x->get_type()!=get_type() && !PlaceholderValueNode::Handle::cast_dynamic(x)) - return false; - link_on_=x; - signal_child_changed()(i);signal_value_changed()(); - return true; - case 2: - switch_=x; - signal_child_changed()(i);signal_value_changed()(); - return true; + case 0: CHECK_TYPE_AND_SET_VALUE(link_off_, get_type()); + case 1: CHECK_TYPE_AND_SET_VALUE(link_on_, get_type()); + case 2: CHECK_TYPE_AND_SET_VALUE(switch_, ValueBase::TYPE_BOOL); } - return true; + return false; } ValueNode::LooseHandle diff --git a/synfig-core/trunk/src/synfig/valuenode_timedswap.cpp b/synfig-core/trunk/src/synfig/valuenode_timedswap.cpp index c444fda..1f369a1 100644 --- a/synfig-core/trunk/src/synfig/valuenode_timedswap.cpp +++ b/synfig-core/trunk/src/synfig/valuenode_timedswap.cpp @@ -98,95 +98,17 @@ ValueNode_TimedSwap::create(const ValueBase& x) return new ValueNode_TimedSwap(x); } - LinkableValueNode* ValueNode_TimedSwap::create_new()const { return new ValueNode_TimedSwap(get_type()); } - synfig::ValueNode_TimedSwap::~ValueNode_TimedSwap() { unlink_all(); } - - -bool -ValueNode_TimedSwap::set_before(const ValueNode::Handle &x) -{ - if(!x || x->get_type()!=get_type() - && !PlaceholderValueNode::Handle::cast_dynamic(x)) - return false; - - before=x; - - return true; -} - -ValueNode::Handle -ValueNode_TimedSwap::get_before()const -{ - return before; -} - - -bool -ValueNode_TimedSwap::set_after(const ValueNode::Handle &x) -{ - if(!x || x->get_type()!=get_type() - && !PlaceholderValueNode::Handle::cast_dynamic(x)) - return false; - - after=x; - - return true; -} - -ValueNode::Handle -ValueNode_TimedSwap::get_after()const -{ - return after; -} - - -bool -ValueNode_TimedSwap::set_swap_time(const ValueNode::Handle &x) -{ - if(!x || (!ValueBase(x->get_type()).same_type_as(ValueBase::TYPE_TIME) && - !PlaceholderValueNode::Handle::cast_dynamic(x))) - return false; - - swap_time=x; - return true; -} - -ValueNode::Handle -ValueNode_TimedSwap::get_swap_time()const -{ - return swap_time; -} - -bool -ValueNode_TimedSwap::set_swap_length(const ValueNode::Handle &x) -{ - if(!x || (!ValueBase(x->get_type()).same_type_as(ValueBase::TYPE_TIME) && - !PlaceholderValueNode::Handle::cast_dynamic(x))) - return false; - - swap_length=x; - return true; -} - -ValueNode::Handle -ValueNode_TimedSwap::get_swap_length()const -{ - return swap_length; -} - - - synfig::ValueBase synfig::ValueNode_TimedSwap::operator()(Time t)const { @@ -246,7 +168,6 @@ synfig::ValueNode_TimedSwap::operator()(Time t)const } } - /*! \todo this should interpolate from ** before to after over the period defined ** by swap_length */ @@ -254,18 +175,17 @@ synfig::ValueNode_TimedSwap::operator()(Time t)const return (*before)(t); } - bool -ValueNode_TimedSwap::set_link_vfunc(int i,ValueNode::Handle x) +ValueNode_TimedSwap::set_link_vfunc(int i,ValueNode::Handle value) { assert(i>=0 && i=0 && iget_type()!=ValueBase::TYPE_COLOR) - return false; - - ref_a=a; - - return true; -} - -bool -synfig::ValueNode_TwoTone::set_rhs(ValueNode::Handle b) -{ - if(b->get_type()!=ValueBase::TYPE_COLOR) - return false; - ref_b=b; - return true; -} - synfig::ValueBase synfig::ValueNode_TwoTone::operator()(Time t)const { @@ -114,20 +94,15 @@ synfig::ValueNode_TwoTone::operator()(Time t)const } bool -ValueNode_TwoTone::set_link_vfunc(int i,ValueNode::Handle x) +ValueNode_TwoTone::set_link_vfunc(int i,ValueNode::Handle value) { assert(i>=0 && i