1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_or.cpp
3 ** \brief Implementation of the "Or" valuenode conversion.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 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_or.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_Or::ValueNode_Or(const ValueBase &x):
55 LinkableValueNode(x.get_type())
57 bool value(x.get(bool()));
59 set_link("link1", ValueNode_Const::create(bool(false)));
60 set_link("link2", ValueNode_Const::create(bool(false)));
62 set_link("link1",ValueNode_Const::create(bool(true)));
66 ValueNode_Or::create(const ValueBase &x)
68 return new ValueNode_Or(x);
72 ValueNode_Or::create_new()const
74 return new ValueNode_Or(get_type());
77 ValueNode_Or::~ValueNode_Or()
83 ValueNode_Or::set_link_vfunc(int i,ValueNode::Handle value)
85 assert(i>=0 && i<link_count());
89 case 0: CHECK_TYPE_AND_SET_VALUE(link1_, ValueBase::TYPE_BOOL);
90 case 1: CHECK_TYPE_AND_SET_VALUE(link2_, ValueBase::TYPE_BOOL);
95 ValueNode::LooseHandle
96 ValueNode_Or::get_link_vfunc(int i)const
98 assert(i>=0 && i<link_count());
100 if(i==0) return link1_;
101 if(i==1) return link2_;
106 ValueNode_Or::link_count()const
112 ValueNode_Or::link_local_name(int i)const
114 assert(i>=0 && i<link_count());
116 if(i==0) return _("Link1");
117 if(i==1) return _("Link2");
122 ValueNode_Or::link_name(int i)const
124 assert(i>=0 && i<link_count());
126 if(i==0) return "link1";
127 if(i==1) return "link2";
132 ValueNode_Or::get_link_index_from_name(const String &name)const
134 if(name=="link1") return 0;
135 if(name=="link2") return 1;
137 throw Exception::BadLinkName(name);
141 ValueNode_Or::operator()(Time t)const
143 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
144 printf("%s:%d operator()\n", __FILE__, __LINE__);
146 bool link1 = (*link1_) (t).get(bool());
147 bool link2 = (*link2_) (t).get(bool());
149 return (link1 || link2);
153 ValueNode_Or::get_name()const
159 ValueNode_Or::get_local_name()const
165 ValueNode_Or::check_type(ValueBase::Type type)
167 return type==ValueBase::TYPE_BOOL;