1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_intstring.cpp
3 ** \brief Implementation of the "IntString" valuenode conversion.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 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_intstring.h"
34 #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_IntString::ValueNode_IntString(const ValueBase &value):
55 LinkableValueNode(value.get_type())
57 switch(value.get_type())
59 case ValueBase::TYPE_STRING:
60 set_link("int",ValueNode_Const::create(int(0)));
61 set_link("width",ValueNode_Const::create(int(0)));
62 set_link("zero_pad",ValueNode_Const::create(bool(false)));
65 throw Exception::BadType(ValueBase::type_local_name(value.get_type()));
70 ValueNode_IntString::create_new()const
72 return new ValueNode_IntString(get_type());
76 ValueNode_IntString::create(const ValueBase &x)
78 return new ValueNode_IntString(x);
81 ValueNode_IntString::~ValueNode_IntString()
87 ValueNode_IntString::operator()(Time t)const
89 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
90 printf("%s:%d operator()\n", __FILE__, __LINE__);
92 int integer((*int_)(t).get(int()));
93 int width((*width_)(t).get(int()));
94 int zero_pad((*zero_pad_)(t).get(bool()));
98 case ValueBase::TYPE_STRING:
99 return strprintf(strprintf("%%%s%dd",
101 width).c_str(), integer);
111 ValueNode_IntString::get_name()const
117 ValueNode_IntString::get_local_name()const
119 return _("Int String");
123 ValueNode_IntString::set_link_vfunc(int i,ValueNode::Handle value)
125 assert(i>=0 && i<link_count());
129 case 0: CHECK_TYPE_AND_SET_VALUE(int_, ValueBase::TYPE_INTEGER);
130 case 1: CHECK_TYPE_AND_SET_VALUE(width_, ValueBase::TYPE_INTEGER);
131 case 2: CHECK_TYPE_AND_SET_VALUE(zero_pad_, ValueBase::TYPE_BOOL);
136 ValueNode::LooseHandle
137 ValueNode_IntString::get_link_vfunc(int i)const
139 assert(i>=0 && i<link_count());
144 case 1: return width_;
145 case 2: return zero_pad_;
152 ValueNode_IntString::link_count()const
158 ValueNode_IntString::link_name(int i)const
160 assert(i>=0 && i<link_count());
164 case 0: return "int";
165 case 1: return "width";
166 case 2: return "zero_pad";
172 ValueNode_IntString::link_local_name(int i)const
174 assert(i>=0 && i<link_count());
178 case 0: return _("Int");
179 case 1: return _("Width");
180 case 2: return _("Zero Padded");
186 ValueNode_IntString::get_link_index_from_name(const String &name)const
188 if (name=="int") return 0;
189 if (name=="width") return 1;
190 if (name=="zero_pad") return 2;
192 throw Exception::BadLinkName(name);
196 ValueNode_IntString::check_type(ValueBase::Type type)
199 type==ValueBase::TYPE_STRING;