Use LinkableValueNode members functions when possible in the derived valuenodes.
[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         Vocab ret(get_children_vocab());
62         set_children_vocab(ret);
63         set_link("link",x);
64 }
65
66 ValueNode_Reference*
67 ValueNode_Reference::create(const ValueBase &x)
68 {
69         return new ValueNode_Reference(ValueNode_Const::create(x));
70 }
71
72 LinkableValueNode*
73 ValueNode_Reference::create_new()const
74 {
75         return new ValueNode_Reference(get_type());
76 }
77
78 ValueNode_Reference::~ValueNode_Reference()
79 {
80         unlink_all();
81 }
82
83 bool
84 ValueNode_Reference::set_link_vfunc(int i,ValueNode::Handle value)
85 {
86         assert(i>=0 && i<link_count());
87
88         switch(i)
89         {
90         case 0: CHECK_TYPE_AND_SET_VALUE(link_, get_type());
91         }
92         return false;
93 }
94
95 ValueNode::LooseHandle
96 ValueNode_Reference::get_link_vfunc(int i __attribute__ ((unused)))const
97 {
98         assert(i>=0 && i<link_count());
99
100         return link_;
101 }
102
103 ValueBase
104 ValueNode_Reference::operator()(Time t)const
105 {
106         if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
107                 printf("%s:%d operator()\n", __FILE__, __LINE__);
108
109         return (*link_)(t);
110 }
111
112
113 String
114 ValueNode_Reference::get_name()const
115 {
116         return "reference";
117 }
118
119 String
120 ValueNode_Reference::get_local_name()const
121 {
122         return _("Reference");
123 }
124
125 bool
126 ValueNode_Reference::check_type(ValueBase::Type type)
127 {
128         if(type)
129                 return true;
130         return false;
131 }
132
133 LinkableValueNode::Vocab
134 ValueNode_Reference::get_children_vocab_vfunc()const
135 {
136         if(children_vocab.size())
137                 return children_vocab;
138
139         LinkableValueNode::Vocab ret;
140
141         ret.push_back(ParamDesc(ValueBase(),"link")
142                 .set_local_name(_("Link"))
143                 .set_description(_("The referenced value"))
144         );
145
146         return ret;
147 }