Use link_count from children vocabulary and return the stored vocabulary if already...
[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 int
104 ValueNode_Reference::link_count()const
105 {
106         return 1;
107 }
108
109 String
110 ValueNode_Reference::link_local_name(int i)const
111 {
112         assert(i>=0 && i<link_count());
113
114         switch(i)
115         {
116         case 0: return _("Link");
117         }
118         return String();
119 }
120
121 String
122 ValueNode_Reference::link_name(int i)const
123 {
124         assert(i>=0 && i<link_count());
125
126         switch(i)
127         {
128         case 0: return "link";
129         }
130         return String();
131 }
132
133 int
134 ValueNode_Reference::get_link_index_from_name(const String &name)const
135 {
136         if(name=="link")
137                 return 0;
138
139         throw Exception::BadLinkName(name);
140 }
141
142 ValueBase
143 ValueNode_Reference::operator()(Time t)const
144 {
145         if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
146                 printf("%s:%d operator()\n", __FILE__, __LINE__);
147
148         return (*link_)(t);
149 }
150
151
152 String
153 ValueNode_Reference::get_name()const
154 {
155         return "reference";
156 }
157
158 String
159 ValueNode_Reference::get_local_name()const
160 {
161         return _("Reference");
162 }
163
164 bool
165 ValueNode_Reference::check_type(ValueBase::Type type)
166 {
167         if(type)
168                 return true;
169         return false;
170 }
171
172 LinkableValueNode::Vocab
173 ValueNode_Reference::get_children_vocab_vfunc()const
174 {
175         if(children_vocab.size())
176                 return children_vocab;
177
178         LinkableValueNode::Vocab ret;
179
180         ret.push_back(ParamDesc(ValueBase(),"link")
181                 .set_local_name(_("Link"))
182                 .set_description(_("The referenced value"))
183         );
184
185         return ret;
186 }