bd80d375f33b2f91cac6b3f7b6f91579914791df
[synfig.git] / synfig-core / trunk / 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 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "valuenode_reference.h"
33 #include "valuenode_const.h"
34 #include "general.h"
35
36 #endif
37
38 /* === U S I N G =========================================================== */
39
40 using namespace std;
41 using namespace etl;
42 using namespace synfig;
43
44 /* === M A C R O S ========================================================= */
45
46 /* === G L O B A L S ======================================================= */
47
48 /* === P R O C E D U R E S ================================================= */
49
50 /* === M E T H O D S ======================================================= */
51
52 ValueNode_Reference::ValueNode_Reference(const ValueBase::Type &x):
53         LinkableValueNode(x)
54 {
55 }
56
57 ValueNode_Reference::ValueNode_Reference(const ValueNode::Handle &x):
58         LinkableValueNode(x->get_type())
59 {
60         set_link("link",x);
61 }
62
63 ValueNode_Reference*
64 ValueNode_Reference::create(const ValueBase &x)
65 {
66         return new ValueNode_Reference(ValueNode_Const::create(x));
67 }
68
69 LinkableValueNode*
70 ValueNode_Reference::create_new()const
71 {
72         return new ValueNode_Reference(get_type());
73 }
74
75 ValueNode_Reference::~ValueNode_Reference()
76 {
77         unlink_all();
78 }
79
80 bool
81 ValueNode_Reference::set_link_vfunc(int i,ValueNode::Handle value)
82 {
83         assert(i>=0 && i<link_count());
84
85         switch(i)
86         {
87         case 0: CHECK_TYPE_AND_SET_VALUE(link_, get_type());
88         }
89         return false;
90 }
91
92 ValueNode::LooseHandle
93 ValueNode_Reference::get_link_vfunc(int i __attribute__ ((unused)))const
94 {
95         assert(i>=0 && i<link_count());
96
97         return link_;
98 }
99
100 int
101 ValueNode_Reference::link_count()const
102 {
103         return 1;
104 }
105
106 String
107 ValueNode_Reference::link_local_name(int i)const
108 {
109         assert(i>=0 && i<link_count());
110
111         switch(i)
112         {
113         case 0: return _("Link");
114         }
115         return String();
116 }
117
118 String
119 ValueNode_Reference::link_name(int i)const
120 {
121         assert(i>=0 && i<link_count());
122
123         switch(i)
124         {
125         case 0: return "link";
126         }
127         return String();
128 }
129
130 int
131 ValueNode_Reference::get_link_index_from_name(const String &name)const
132 {
133         if(name=="link")
134                 return 0;
135
136         throw Exception::BadLinkName(name);
137 }
138
139 ValueBase
140 ValueNode_Reference::operator()(Time t)const
141 {
142         return (*link_)(t);
143 }
144
145
146 String
147 ValueNode_Reference::get_name()const
148 {
149         return "reference";
150 }
151
152 String
153 ValueNode_Reference::get_local_name()const
154 {
155         return _("Reference");
156 }
157
158 bool
159 ValueNode_Reference::check_type(ValueBase::Type type)
160 {
161         if(type)
162                 return true;
163         return false;
164 }