1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_switch.cpp
3 ** \brief Implementation of the "Switch" valuenode conversion.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "valuenode_switch.h"
34 #include "valuenode_const.h"
39 /* === U S I N G =========================================================== */
43 using namespace synfig;
45 /* === M A C R O S ========================================================= */
47 /* === G L O B A L S ======================================================= */
49 /* === P R O C E D U R E S ================================================= */
51 /* === M E T H O D S ======================================================= */
53 ValueNode_Switch::ValueNode_Switch(const ValueBase::Type &x):
58 ValueNode_Switch::ValueNode_Switch(const ValueNode::Handle &x):
59 LinkableValueNode(x->get_type())
61 set_link("link_off",x);
62 set_link("link_on",x);
63 set_link("switch",ValueNode_Const::create(bool(false)));
67 ValueNode_Switch::create(const ValueBase &x)
69 return new ValueNode_Switch(ValueNode_Const::create(x));
73 ValueNode_Switch::create_new()const
75 return new ValueNode_Switch(get_type());
78 ValueNode_Switch::~ValueNode_Switch()
84 ValueNode_Switch::set_link_vfunc(int i,ValueNode::Handle value)
86 assert(i>=0 && i<link_count());
90 case 0: CHECK_TYPE_AND_SET_VALUE(link_off_, get_type());
91 case 1: CHECK_TYPE_AND_SET_VALUE(link_on_, get_type());
92 case 2: CHECK_TYPE_AND_SET_VALUE(switch_, ValueBase::TYPE_BOOL);
97 ValueNode::LooseHandle
98 ValueNode_Switch::get_link_vfunc(int i)const
100 assert(i>=0 && i<link_count());
104 case 0: return link_off_;
105 case 1: return link_on_;
106 case 2: return switch_;
112 ValueNode_Switch::link_count()const
118 ValueNode_Switch::link_name(int i)const
120 assert(i>=0 && i<link_count());
124 case 0: return "link_off";
125 case 1: return "link_on";
126 case 2: return "switch";
132 ValueNode_Switch::link_local_name(int i)const
134 assert(i>=0 && i<link_count());
138 case 0: return "Link Off";
139 case 1: return "Link On";
140 case 2: return "Switch";
146 ValueNode_Switch::get_link_index_from_name(const String &name)const
148 if(name=="link_off") return 0;
149 if(name=="link_on" ) return 1;
150 if(name=="switch" ) return 2;
151 throw Exception::BadLinkName(name);
155 ValueNode_Switch::operator()(Time t)const
157 return (*switch_)(t).get(bool()) ? (*link_on_)(t) : (*link_off_)(t);
162 ValueNode_Switch::get_name()const
168 ValueNode_Switch::get_local_name()const
174 ValueNode_Switch::check_type(ValueBase::Type type)