From 556d3ae558f5072946218fe16c207d24592048c0 Mon Sep 17 00:00:00 2001 From: dooglus Date: Fri, 11 Jan 2008 10:43:49 +0000 Subject: [PATCH] Rearranged a bit, like for the Add ValueNode in r1299. Use type checking for the sub-parameters. git-svn-id: http://svn.voria.com/code@1330 1f10aa63-cdf2-0310-b900-c93c546f37ac --- .../trunk/src/synfig/valuenode_subtract.cpp | 65 ++-------------------- synfig-core/trunk/src/synfig/valuenode_subtract.h | 50 ++++------------- 2 files changed, 17 insertions(+), 98 deletions(-) diff --git a/synfig-core/trunk/src/synfig/valuenode_subtract.cpp b/synfig-core/trunk/src/synfig/valuenode_subtract.cpp index c018d43..50230e9 100644 --- a/synfig-core/trunk/src/synfig/valuenode_subtract.cpp +++ b/synfig-core/trunk/src/synfig/valuenode_subtract.cpp @@ -59,7 +59,7 @@ using namespace synfig; synfig::ValueNode_Subtract::ValueNode_Subtract(const ValueBase &value): LinkableValueNode(value.get_type()) { - set_scalar(1.0); + set_link("scalar",ValueNode_Const::create(Real(1.0))); ValueBase::Type id(value.get_type()); switch(id) @@ -93,8 +93,8 @@ synfig::ValueNode_Subtract::ValueNode_Subtract(const ValueBase &value): throw runtime_error(get_local_name()+_(":Bad type ")+ValueBase::type_local_name(id)); } - assert(get_lhs()->get_type()==id); - assert(get_rhs()->get_type()==id); + assert(ref_a->get_type()==id); + assert(ref_b->get_type()==id); assert(get_type()==id); DCAST_HACK_ENABLE(); @@ -117,51 +117,6 @@ synfig::ValueNode_Subtract::~ValueNode_Subtract() unlink_all(); } -void -ValueNode_Subtract::set_scalar(Real value) -{ - set_link("scalar",ValueNode_Const::create(value)); -} - -bool -synfig::ValueNode_Subtract::set_scalar(ValueNode::Handle value) -{ - if(value->get_type()!=ValueBase::TYPE_REAL&& !PlaceholderValueNode::Handle::cast_dynamic(value)) - return false; - scalar=value; - return true; -} - -bool -synfig::ValueNode_Subtract::set_lhs(ValueNode::Handle x) -{ - assert(get_type()); - - if(!x || - (get_type()==ValueBase::TYPE_NIL && !check_type(x->get_type())) || - (get_type()!=ValueBase::TYPE_NIL && x->get_type()!=get_type() && !PlaceholderValueNode::Handle::cast_dynamic(x))) - return false; - - ref_a=x; - - return true; -} - -bool -synfig::ValueNode_Subtract::set_rhs(ValueNode::Handle x) -{ - assert(get_type()); - - if(!x || - (get_type()==ValueBase::TYPE_NIL && !check_type(x->get_type())) || - (get_type()!=ValueBase::TYPE_NIL && x->get_type()!=get_type() && !PlaceholderValueNode::Handle::cast_dynamic(x))) - return false; - - ref_b=x; - - return true; -} - synfig::ValueBase synfig::ValueNode_Subtract::operator()(Time t)const { @@ -195,18 +150,10 @@ ValueNode_Subtract::set_link_vfunc(int i,ValueNode::Handle value) switch(i) { - case 0: - if(set_lhs(value)) { signal_child_changed()(i);signal_value_changed()(); return true; } - return false; - case 1: - if(set_rhs(value)) { signal_child_changed()(i);signal_value_changed()(); return true; } - return false; - case 2: - scalar=value; - signal_child_changed()(i);signal_value_changed()(); - return true; + case 0: CHECK_TYPE_AND_SET_VALUE(ref_a, get_type()); + case 1: CHECK_TYPE_AND_SET_VALUE(ref_b, get_type()); + case 2: CHECK_TYPE_AND_SET_VALUE(scalar, ValueBase::TYPE_REAL); } - return false; } diff --git a/synfig-core/trunk/src/synfig/valuenode_subtract.h b/synfig-core/trunk/src/synfig/valuenode_subtract.h index 5a73497..08ba9d6 100644 --- a/synfig-core/trunk/src/synfig/valuenode_subtract.h +++ b/synfig-core/trunk/src/synfig/valuenode_subtract.h @@ -42,65 +42,37 @@ struct ValueNode_Subtract : public LinkableValueNode typedef etl::handle ConstHandle; protected: - ValueNode_Subtract(const ValueBase &value); private: - ValueNode::RHandle ref_a; ValueNode::RHandle ref_b; ValueNode::RHandle scalar; public: - + LinkableValueNode* create_new()const; + static ValueNode_Subtract* create(const ValueBase &value=ValueBase()); virtual ~ValueNode_Subtract(); - -// static Handle create(ValueBase::Type id=ValueBase::TYPE_NIL); - - //! Sets the left-hand-side value_node - bool set_lhs(ValueNode::Handle a); - - //! Gets the left-hand-side value_node - ValueNode::Handle get_lhs()const { return ref_a; } - - //! Sets the right-hand-side value_node - bool set_rhs(ValueNode::Handle b); - - //! Gets the right-hand-side value_node - ValueNode::Handle get_rhs()const { return ref_b; } - - //! Sets the scalar value_node - bool set_scalar(ValueNode::Handle x); - - //! Gets the scalar value_node - ValueNode::Handle get_scalar()const { return scalar; } - - void set_scalar(Real x); - + virtual ValueBase operator()(Time t)const; virtual bool set_link_vfunc(int i,ValueNode::Handle x); - virtual ValueNode::LooseHandle get_link_vfunc(int i)const; - virtual int link_count()const; - virtual String link_local_name(int i)const; virtual String link_name(int i)const; virtual int get_link_index_from_name(const String &name)const; - - virtual ValueBase operator()(Time t)const; - virtual String get_name()const; virtual String get_local_name()const; + static bool check_type(ValueBase::Type type); -// static bool check_type(const ValueBase::Type &type); + //! Gets the left-hand-side value_node + ValueNode::Handle get_lhs()const { return ref_a; } - LinkableValueNode* create_new()const; + //! Gets the right-hand-side value_node + ValueNode::Handle get_rhs()const { return ref_b; } + + //! Gets the scalar value_node + ValueNode::Handle get_scalar()const { return scalar; } -public: - using synfig::LinkableValueNode::get_link_vfunc; - using synfig::LinkableValueNode::set_link_vfunc; - static bool check_type(ValueBase::Type type); - static ValueNode_Subtract* create(const ValueBase &value=ValueBase()); }; // END of class ValueNode_Subtract }; // END of namespace synfig -- 2.7.4