1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_compare.cpp
3 ** \brief Implementation of the "Compare" valuenode conversion.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
10 ** Copyright (c) 2009 Nikita Kitaev
12 ** This package is free software; you can redistribute it and/or
13 ** modify it under the terms of the GNU General Public License as
14 ** published by the Free Software Foundation; either version 2 of
15 ** the License, or (at your option) any later version.
17 ** This package is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ** General Public License for more details.
23 /* ========================================================================= */
25 /* === H E A D E R S ======================================================= */
34 #include "valuenode_compare.h"
35 #include "valuenode_const.h"
40 /* === U S I N G =========================================================== */
44 using namespace synfig;
46 /* === M A C R O S ========================================================= */
48 /* === G L O B A L S ======================================================= */
50 /* === P R O C E D U R E S ================================================= */
52 /* === M E T H O D S ======================================================= */
54 ValueNode_Compare::ValueNode_Compare(const ValueBase &x):
55 LinkableValueNode(x.get_type())
57 Vocab ret(get_children_vocab());
58 set_children_vocab(ret);
59 bool value(x.get(bool()));
61 set_link("lhs", ValueNode_Const::create(Real(0)));
62 set_link("rhs", ValueNode_Const::create(Real(0)));
63 set_link("greater", ValueNode_Const::create(bool(false)));
65 set_link("equal",ValueNode_Const::create(bool(true)));
67 set_link("equal",ValueNode_Const::create(bool(false)));
68 set_link("less", ValueNode_Const::create(bool(false)));
72 ValueNode_Compare::create(const ValueBase &x)
74 return new ValueNode_Compare(x);
78 ValueNode_Compare::create_new()const
80 return new ValueNode_Compare(get_type());
83 ValueNode_Compare::~ValueNode_Compare()
89 ValueNode_Compare::set_link_vfunc(int i,ValueNode::Handle value)
91 assert(i>=0 && i<link_count());
95 case 0: CHECK_TYPE_AND_SET_VALUE(lhs_, ValueBase::TYPE_REAL);
96 case 1: CHECK_TYPE_AND_SET_VALUE(rhs_, ValueBase::TYPE_REAL);
97 case 2: CHECK_TYPE_AND_SET_VALUE(greater_, ValueBase::TYPE_BOOL);
98 case 3: CHECK_TYPE_AND_SET_VALUE(equal_, ValueBase::TYPE_BOOL);
99 case 4: CHECK_TYPE_AND_SET_VALUE(less_, ValueBase::TYPE_BOOL);
104 ValueNode::LooseHandle
105 ValueNode_Compare::get_link_vfunc(int i)const
107 assert(i>=0 && i<link_count());
109 if(i==0) return lhs_;
110 if(i==1) return rhs_;
111 if(i==2) return greater_;
112 if(i==3) return equal_;
113 if(i==4) return less_;
118 ValueNode_Compare::operator()(Time t)const
120 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
121 printf("%s:%d operator()\n", __FILE__, __LINE__);
123 Real lhs = (*lhs_) (t).get(Real());
124 Real rhs = (*rhs_) (t).get(Real());
125 Real greater = (*greater_) (t).get(bool());
126 Real equal = (*equal_) (t).get(bool());
127 Real less = (*less_) (t).get(bool());
129 if (greater && lhs > rhs)
131 if (equal && lhs == rhs)
133 if (less && lhs < rhs)
140 ValueNode_Compare::get_name()const
146 ValueNode_Compare::get_local_name()const
152 ValueNode_Compare::check_type(ValueBase::Type type)
154 return type==ValueBase::TYPE_BOOL;
157 LinkableValueNode::Vocab
158 ValueNode_Compare::get_children_vocab_vfunc()const
160 if(children_vocab.size())
161 return children_vocab;
163 LinkableValueNode::Vocab ret;
165 ret.push_back(ParamDesc(ValueBase(),"lhs")
166 .set_local_name(_("LHS"))
167 .set_description(_("The left side of the comparison"))
170 ret.push_back(ParamDesc(ValueBase(),"rhs")
171 .set_local_name(_("RHS"))
172 .set_description(_("The right side of the comparison"))
175 ret.push_back(ParamDesc(ValueBase(),"greater")
176 .set_local_name(_("Greater"))
177 .set_description(_("When checked, returns true if LHS > RHS"))
180 ret.push_back(ParamDesc(ValueBase(),"equal")
181 .set_local_name(_("Equal"))
182 .set_description(_("When checked, returns true if LHS = RHS"))
185 ret.push_back(ParamDesc(ValueBase(),"less")
186 .set_local_name(_("Less"))
187 .set_description(_("When checked, returns true if LHS < RHS"))