Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / stable / src / synfig / valuenode_timestring.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_timestring.cpp
3 **      \brief Implementation of the "TimeString" valuenode conversion.
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2008 Chris Moore
10 **
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.
15 **
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.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "valuenode_timestring.h"
34 #include "valuenode_const.h"
35 #include "canvas.h"
36 #include "general.h"
37
38 #endif
39
40 /* === U S I N G =========================================================== */
41
42 using namespace std;
43 using namespace etl;
44 using namespace synfig;
45
46 /* === M A C R O S ========================================================= */
47
48 /* === G L O B A L S ======================================================= */
49
50 /* === P R O C E D U R E S ================================================= */
51
52 /* === M E T H O D S ======================================================= */
53
54 ValueNode_TimeString::ValueNode_TimeString(const ValueBase &value):
55         LinkableValueNode(value.get_type())
56 {
57         switch(value.get_type())
58         {
59         case ValueBase::TYPE_STRING:
60                 set_link("time",ValueNode_Const::create(Time(0)));
61                 break;
62         default:
63                 throw Exception::BadType(ValueBase::type_local_name(value.get_type()));
64         }
65
66         DCAST_HACK_ENABLE();
67 }
68
69 LinkableValueNode*
70 ValueNode_TimeString::create_new()const
71 {
72         return new ValueNode_TimeString(get_type());
73 }
74
75 ValueNode_TimeString*
76 ValueNode_TimeString::create(const ValueBase &x)
77 {
78         return new ValueNode_TimeString(x);
79 }
80
81 ValueNode_TimeString::~ValueNode_TimeString()
82 {
83         unlink_all();
84 }
85
86 ValueBase
87 ValueNode_TimeString::operator()(Time t)const
88 {
89         Time time((*time_)(t).get(Time()));
90
91         switch (get_type())
92         {
93         case ValueBase::TYPE_STRING:
94                 if (get_root_canvas())
95                         return time.get_string(get_root_canvas()->rend_desc().get_frame_rate());
96                 else
97                         return time.get_string();
98         default:
99                 break;
100         }
101
102         assert(0);
103         return ValueBase();
104 }
105
106 String
107 ValueNode_TimeString::get_name()const
108 {
109         return "timestring";
110 }
111
112 String
113 ValueNode_TimeString::get_local_name()const
114 {
115         return _("Time String");
116 }
117
118 bool
119 ValueNode_TimeString::set_link_vfunc(int i,ValueNode::Handle value)
120 {
121         assert(i>=0 && i<link_count());
122
123         switch(i)
124         {
125         case 0: CHECK_TYPE_AND_SET_VALUE(time_, ValueBase::TYPE_TIME);
126         }
127         return false;
128 }
129
130 ValueNode::LooseHandle
131 ValueNode_TimeString::get_link_vfunc(int i)const
132 {
133         assert(i>=0 && i<link_count());
134
135         switch(i)
136         {
137         case 0: return time_;
138         }
139
140         return 0;
141 }
142
143 int
144 ValueNode_TimeString::link_count()const
145 {
146         return 1;
147 }
148
149 String
150 ValueNode_TimeString::link_name(int i)const
151 {
152         assert(i>=0 && i<link_count());
153
154         switch(i)
155         {
156                 case 0: return "time";
157         }
158         return String();
159 }
160
161 String
162 ValueNode_TimeString::link_local_name(int i)const
163 {
164         assert(i>=0 && i<link_count());
165
166         switch(i)
167         {
168                 case 0: return _("Time");
169         }
170         return String();
171 }
172
173 int
174 ValueNode_TimeString::get_link_index_from_name(const String &name)const
175 {
176         if (name=="time") return 0;
177
178         throw Exception::BadLinkName(name);
179 }
180
181 bool
182 ValueNode_TimeString::check_type(ValueBase::Type type)
183 {
184         return
185                 type==ValueBase::TYPE_STRING;
186 }