Use link_count from children vocabulary and return the stored vocabulary if already...
[synfig.git] / synfig-core / src / synfig / valuenode_not.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_not.cpp
3 **      \brief Implementation of the "Not" 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 **      Copyright (c) 2009 Nikita Kitaev
11 **
12 **      This package is free software; you can redistribute it and/or
13 **      modify it under the terms of the GNU General Public License as
14 **      published by the Free Software Foundation; either version 2 of
15 **      the License, or (at your option) any later version.
16 **
17 **      This package is distributed in the hope that it will be useful,
18 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
19 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 **      General Public License for more details.
21 **      \endlegal
22 */
23 /* ========================================================================= */
24
25 /* === H E A D E R S ======================================================= */
26
27 #ifdef USING_PCH
28 #       include "pch.h"
29 #else
30 #ifdef HAVE_CONFIG_H
31 #       include <config.h>
32 #endif
33
34 #include "valuenode_not.h"
35 #include "valuenode_const.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_Not::ValueNode_Not(const ValueBase &x):
55         LinkableValueNode(x.get_type())
56 {
57         Vocab ret(get_children_vocab());
58         set_children_vocab(ret);
59         bool value(x.get(bool()));
60
61         set_link("link",         ValueNode_Const::create(!value));
62 }
63
64 ValueNode_Not*
65 ValueNode_Not::create(const ValueBase &x)
66 {
67         return new ValueNode_Not(x);
68 }
69
70 LinkableValueNode*
71 ValueNode_Not::create_new()const
72 {
73         return new ValueNode_Not(get_type());
74 }
75
76 ValueNode_Not::~ValueNode_Not()
77 {
78         unlink_all();
79 }
80
81 bool
82 ValueNode_Not::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_,     ValueBase::TYPE_BOOL);
89         }
90         return false;
91 }
92
93 ValueNode::LooseHandle
94 ValueNode_Not::get_link_vfunc(int i)const
95 {
96         assert(i>=0 && i<link_count());
97
98         if(i==0) return link_;
99         return 0;
100 }
101
102 int
103 ValueNode_Not::link_count()const
104 {
105         return 1;
106 }
107
108 String
109 ValueNode_Not::link_local_name(int i)const
110 {
111         assert(i>=0 && i<link_count());
112
113         if(i==0) return _("Link");
114         return String();
115 }
116
117 String
118 ValueNode_Not::link_name(int i)const
119 {
120         assert(i>=0 && i<link_count());
121
122         if(i==0) return "link";
123         return String();
124 }
125
126 int
127 ValueNode_Not::get_link_index_from_name(const String &name)const
128 {
129         if(name=="link")     return 0;
130
131         throw Exception::BadLinkName(name);
132 }
133
134 ValueBase
135 ValueNode_Not::operator()(Time t)const
136 {
137         if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
138                 printf("%s:%d operator()\n", __FILE__, __LINE__);
139
140         bool link      = (*link_)    (t).get(bool());
141
142         return !link;
143 }
144
145 String
146 ValueNode_Not::get_name()const
147 {
148         return "not";
149 }
150
151 String
152 ValueNode_Not::get_local_name()const
153 {
154         return _("NOT");
155 }
156
157 bool
158 ValueNode_Not::check_type(ValueBase::Type type)
159 {
160         return type==ValueBase::TYPE_BOOL;
161 }
162
163 LinkableValueNode::Vocab
164 ValueNode_Not::get_children_vocab_vfunc()const
165 {
166         if(children_vocab.size())
167                 return children_vocab;
168
169         LinkableValueNode::Vocab ret;
170
171         ret.push_back(ParamDesc(ValueBase(),"link")
172                 .set_local_name(_("Link"))
173                 .set_description(_("Value node used to do the NOT operation"))
174         );
175
176         return ret;
177 }