1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_realstring.cpp
3 ** \brief Implementation of the "RealString" 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_realstring.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_RealString::ValueNode_RealString(const ValueBase &value):
55 LinkableValueNode(value.get_type())
57 switch(value.get_type())
59 case ValueBase::TYPE_STRING:
60 set_link("real",ValueNode_Const::create(Real(0)));
61 set_link("width",ValueNode_Const::create(int(0)));
62 set_link("precision",ValueNode_Const::create(int(3)));
63 set_link("zero_pad",ValueNode_Const::create(bool(false)));
66 throw Exception::BadType(ValueBase::type_local_name(value.get_type()));
73 ValueNode_RealString::create_new()const
75 return new ValueNode_RealString(get_type());
79 ValueNode_RealString::create(const ValueBase &x)
81 return new ValueNode_RealString(x);
84 ValueNode_RealString::~ValueNode_RealString()
90 ValueNode_RealString::operator()(Time t)const
92 Real real((*real_)(t).get(Real()));
93 int width((*width_)(t).get(int()));
94 int precision((*precision_)(t).get(int()));
95 int zero_pad((*zero_pad_)(t).get(bool()));
99 case ValueBase::TYPE_STRING:
100 return strprintf(strprintf("%%%s%d.%df",
103 precision).c_str(), real);
113 ValueNode_RealString::get_name()const
119 ValueNode_RealString::get_local_name()const
121 return _("Real String");
125 ValueNode_RealString::set_link_vfunc(int i,ValueNode::Handle value)
127 assert(i>=0 && i<link_count());
131 case 0: CHECK_TYPE_AND_SET_VALUE(real_, ValueBase::TYPE_REAL);
132 case 1: CHECK_TYPE_AND_SET_VALUE(width_, ValueBase::TYPE_INTEGER);
133 case 2: CHECK_TYPE_AND_SET_VALUE(precision_, ValueBase::TYPE_INTEGER);
134 case 3: CHECK_TYPE_AND_SET_VALUE(zero_pad_, ValueBase::TYPE_BOOL);
139 ValueNode::LooseHandle
140 ValueNode_RealString::get_link_vfunc(int i)const
142 assert(i>=0 && i<link_count());
146 case 0: return real_;
147 case 1: return width_;
148 case 2: return precision_;
149 case 3: return zero_pad_;
156 ValueNode_RealString::link_count()const
162 ValueNode_RealString::link_name(int i)const
164 assert(i>=0 && i<link_count());
168 case 0: return "real";
169 case 1: return "width";
170 case 2: return "precision";
171 case 3: return "zero_pad";
177 ValueNode_RealString::link_local_name(int i)const
179 assert(i>=0 && i<link_count());
183 case 0: return _("Real");
184 case 1: return _("Width");
185 case 2: return _("Precision");
186 case 3: return _("Zero Padded");
192 ValueNode_RealString::get_link_index_from_name(const String &name)const
194 if (name=="real") return 0;
195 if (name=="width") return 1;
196 if (name=="precision") return 2;
197 if (name=="zero_pad") return 3;
199 throw Exception::BadLinkName(name);
203 ValueNode_RealString::check_type(ValueBase::Type type)
206 type==ValueBase::TYPE_STRING;