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()));
82 ValueNode_Join::create_new()const
84 return new ValueNode_Join(get_type());
88 ValueNode_Join::create(const ValueBase &x)
90 return new ValueNode_Join(x);
93 ValueNode_Join::~ValueNode_Join()
99 ValueNode_Join::operator()(Time t)const
101 const std::vector<ValueBase> strings((*strings_)(t).get_list());
102 const String before((*before_)(t).get(String()));
103 const String separator((*separator_)(t).get(String()));
104 const String after((*after_)(t).get(String()));
108 case ValueBase::TYPE_STRING:
112 for (std::vector<ValueBase>::const_iterator iter = strings.begin(); iter != strings.end(); iter++)
118 ret += iter->get(String());
132 ValueNode_Join::get_name()const
138 ValueNode_Join::get_local_name()const
140 return _("Joined List");
144 ValueNode_Join::set_link_vfunc(int i,ValueNode::Handle value)
146 assert(i>=0 && i<link_count());
150 case 0: CHECK_TYPE_AND_SET_VALUE(strings_, ValueBase::TYPE_LIST);
151 case 1: CHECK_TYPE_AND_SET_VALUE(before_, ValueBase::TYPE_STRING);
152 case 2: CHECK_TYPE_AND_SET_VALUE(separator_, ValueBase::TYPE_STRING);
153 case 3: CHECK_TYPE_AND_SET_VALUE(after_, ValueBase::TYPE_STRING);
158 ValueNode::LooseHandle
159 ValueNode_Join::get_link_vfunc(int i)const
161 assert(i>=0 && i<link_count());
165 case 0: return strings_;
166 case 1: return before_;
167 case 2: return separator_;
168 case 3: return after_;
175 ValueNode_Join::link_count()const
181 ValueNode_Join::link_name(int i)const
183 assert(i>=0 && i<link_count());
187 case 0: return "strings";
188 case 1: return "before";
189 case 2: return "separator";
190 case 3: return "after";
196 ValueNode_Join::link_local_name(int i)const
198 assert(i>=0 && i<link_count());
202 case 0: return _("Strings");
203 case 1: return _("Before");
204 case 2: return _("Separator");
205 case 3: return _("After");
211 ValueNode_Join::get_link_index_from_name(const String &name)const
213 if (name=="strings") return 0;
214 if (name=="before") return 1;
215 if (name=="separator") return 2;
216 if (name=="after") return 3;
218 throw Exception::BadLinkName(name);
222 ValueNode_Join::check_type(ValueBase::Type type)
225 type==ValueBase::TYPE_STRING;