3de4642c81d126ccdd807221d3b868c42050feb2
[synfig.git] / synfig-core / src / synfig / valuenode_reference.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_reference.cpp
3 **      \brief Implementation of the "Reference" 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_reference.h"
34 #include "valuenode_const.h"
35 #include "general.h"
36
37 #endif
38
39 /* === U S I N G =========================================================== */
40
41 using namespace std;
42 using namespace etl;
43 using namespace synfig;
44
45 /* === M A C R O S ========================================================= */
46
47 /* === G L O B A L S ======================================================= */
48
49 /* === P R O C E D U R E S ================================================= */
50
51 /* === M E T H O D S ======================================================= */
52
53 ValueNode_Reference::ValueNode_Reference(const ValueBase::Type &x):
54         LinkableValueNode(x)
55 {
56 }
57
58 ValueNode_Reference::ValueNode_Reference(const ValueNode::Handle &x):
59         LinkableValueNode(x->get_type())
60 {
61         set_link("link",x);
62 }
63
64 ValueNode_Reference*
65 ValueNode_Reference::create(const ValueBase &x)
66 {
67         return new ValueNode_Reference(ValueNode_Const::create(x));
68 }
69
70 LinkableValueNode*
71 ValueNode_Reference::create_new()const
72 {
73         return new ValueNode_Reference(get_type());
74 }
75
76 ValueNode_Reference::~ValueNode_Reference()
77 {
78         unlink_all();
79 }
80
81 bool
82 ValueNode_Reference::set_link_vfunc(int i,ValueNode::Handle value)
83 {
84         assert(i>=0 && i<link_count());
85
86         switch(i)
87         {
88         case 0: CHECK_TYPE_AND_SET_VALUE(link_, get_type());
89         }
90         return false;
91 }
92
93 ValueNode::LooseHandle
94 ValueNode_Reference::get_link_vfunc(int i __attribute__ ((unused)))const
95 {
96         assert(i>=0 && i<link_count());
97
98         return link_;
99 }
100
101 int
102 ValueNode_Reference::link_count()const
103 {
104         return 1;
105 }
106
107 String
108 ValueNode_Reference::link_local_name(int i)const
109 {
110         assert(i>=0 && i<link_count());
111
112         switch(i)
113         {
114         case 0: return _("Link");
115         }
116         return String();
117 }
118
119 String
120 ValueNode_Reference::link_name(int i)const
121 {
122         assert(i>=0 && i<link_count());
123
124         switch(i)
125         {
126         case 0: return "link";
127         }
128         return String();
129 }
130
131 int
132 ValueNode_Reference::get_link_index_from_name(const String &name)const
133 {
134         if(name=="link")
135                 return 0;
136
137         throw Exception::BadLinkName(name);
138 }
139
140 ValueBase
141 ValueNode_Reference::operator()(Time t)const
142 {
143         if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
144                 printf("%s:%d operator()\n", __FILE__, __LINE__);
145
146         return (*link_)(t);
147 }
148
149
150 String
151 ValueNode_Reference::get_name()const
152 {
153         return "reference";
154 }
155
156 String
157 ValueNode_Reference::get_local_name()const
158 {
159         return _("Reference");
160 }
161
162 bool
163 ValueNode_Reference::check_type(ValueBase::Type type)
164 {
165         if(type)
166                 return true;
167         return false;
168 }
169
170 LinkableValueNode::Vocab
171 ValueNode_Reference::get_param_vocab()const
172 {
173         LinkableValueNode::Vocab ret;
174
175         ret.push_back(ParamDesc(ValueBase(),"link")
176                 .set_local_name(_("Link"))
177                 .set_description(_("The referenced value"))
178         );
179
180         return ret;
181 }