1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_join.cpp
3 ** \brief Implementation of the "Join" valuenode conversion.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 Chris Moore
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.
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.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "valuenode_join.h"
34 #include "valuenode_const.h"
35 #include "valuenode_dynamiclist.h"
41 /* === U S I N G =========================================================== */
45 using namespace synfig;
47 /* === M A C R O S ========================================================= */
49 /* === G L O B A L S ======================================================= */
51 /* === P R O C E D U R E S ================================================= */
53 /* === M E T H O D S ======================================================= */
55 ValueNode_Join::ValueNode_Join(const ValueBase &value):
56 LinkableValueNode(value.get_type())
58 switch(value.get_type())
60 case ValueBase::TYPE_STRING:
62 vector<ValueBase> v(1, value.get(String()));
64 // "insert item (smart)" inserts before the selected entry, making it hard to append to the end
65 // add an extra element at the end to allow the easy insertion of text after the given value's string
68 set_link("strings",ValueNode_DynamicList::create_from(v));
69 set_link("before",ValueNode_Const::create(String("")));
70 set_link("separator",ValueNode_Const::create(String(" ")));
71 set_link("after",ValueNode_Const::create(String("")));
75 throw Exception::BadType(ValueBase::type_local_name(value.get_type()));
80 ValueNode_Join::create_new()const
82 return new ValueNode_Join(get_type());
86 ValueNode_Join::create(const ValueBase &x)
88 return new ValueNode_Join(x);
91 ValueNode_Join::~ValueNode_Join()
97 ValueNode_Join::operator()(Time t)const
99 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
100 printf("%s:%d operator()\n", __FILE__, __LINE__);
102 const std::vector<ValueBase> strings((*strings_)(t).get_list());
103 const String before((*before_)(t).get(String()));
104 const String separator((*separator_)(t).get(String()));
105 const String after((*after_)(t).get(String()));
109 case ValueBase::TYPE_STRING:
113 for (std::vector<ValueBase>::const_iterator iter = strings.begin(); iter != strings.end(); iter++)
119 ret += iter->get(String());
133 ValueNode_Join::get_name()const
139 ValueNode_Join::get_local_name()const
141 return _("Joined List");
145 ValueNode_Join::set_link_vfunc(int i,ValueNode::Handle value)
147 assert(i>=0 && i<link_count());
151 case 0: CHECK_TYPE_AND_SET_VALUE(strings_, ValueBase::TYPE_LIST);
152 case 1: CHECK_TYPE_AND_SET_VALUE(before_, ValueBase::TYPE_STRING);
153 case 2: CHECK_TYPE_AND_SET_VALUE(separator_, ValueBase::TYPE_STRING);
154 case 3: CHECK_TYPE_AND_SET_VALUE(after_, ValueBase::TYPE_STRING);
159 ValueNode::LooseHandle
160 ValueNode_Join::get_link_vfunc(int i)const
162 assert(i>=0 && i<link_count());
166 case 0: return strings_;
167 case 1: return before_;
168 case 2: return separator_;
169 case 3: return after_;
176 ValueNode_Join::link_count()const
182 ValueNode_Join::link_name(int i)const
184 assert(i>=0 && i<link_count());
188 case 0: return "strings";
189 case 1: return "before";
190 case 2: return "separator";
191 case 3: return "after";
197 ValueNode_Join::link_local_name(int i)const
199 assert(i>=0 && i<link_count());
203 case 0: return _("Strings");
204 case 1: return _("Before");
205 case 2: return _("Separator");
206 case 3: return _("After");
212 ValueNode_Join::get_link_index_from_name(const String &name)const
214 if (name=="strings") return 0;
215 if (name=="before") return 1;
216 if (name=="separator") return 2;
217 if (name=="after") return 3;
219 throw Exception::BadLinkName(name);
223 ValueNode_Join::check_type(ValueBase::Type type)
226 type==ValueBase::TYPE_STRING;