1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
5 ** $Id: value.cpp,v 1.1.1.1 2005/01/04 01:23:15 darco Exp $
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
34 #include <ETL/stringf>
47 using namespace synfig;
51 /* === M A C R O S ========================================================= */
53 /* === G L O B A L S ======================================================= */
55 /* === P R O C E D U R E S ================================================= */
57 /* === M E T H O D S ======================================================= */
59 ValueBase::ValueBase():type(TYPE_NIL),data(0),ref_count(0),loop_(0)
63 ValueBase::ValueBase(Type x):
72 data=static_cast<void*>(new bool());
75 data=static_cast<void*>(new int());
78 data=static_cast<void*>(new Angle());
81 data=static_cast<void*>(new Vector());
84 data=static_cast<void*>(new Time());
87 data=static_cast<void*>(new Real());
90 data=static_cast<void*>(new Color());
93 data=static_cast<void*>(new Segment());
96 data=static_cast<void*>(new BLinePoint());
99 data=static_cast<void*>(new list_type());
102 data=static_cast<void*>(new String());
105 data=static_cast<void*>(new Gradient());
108 data=static_cast<void*>(new etl::handle<Canvas>());
115 ValueBase::~ValueBase()
121 ValueBase::get(const char*)const
123 return get(String()).c_str();
130 ValueBase::set(Canvas* x)
133 if(x && x->is_inline())
135 _set(etl::handle<Canvas>(x));
139 _set(etl::loose_handle<Canvas>(x));
145 ValueBase::set(etl::loose_handle<Canvas> x)
148 if(x && x->is_inline())
150 _set(etl::handle<Canvas>(x));
154 _set(etl::loose_handle<Canvas>(x));
160 ValueBase::set(etl::handle<Canvas> x)
163 if(x && x->is_inline())
165 _set(etl::handle<Canvas>(x));
169 _set(etl::loose_handle<Canvas>(x));
175 ValueBase::set(const list_type &x)
181 ValueBase::set(const char* x)
187 ValueBase::is_valid()const
189 return type>TYPE_NIL && type<TYPE_END && ref_count;
193 ValueBase::empty()const
195 return !is_valid() || ((type==TYPE_LIST)?get_list().empty():false);
199 ValueBase::get_contained_type()const
201 if(type!=TYPE_LIST || empty())
203 return get_list().front().get_type();
207 ValueBase::operator=(const ValueBase& x)
214 ref_count=x.ref_count;
223 if(ref_count.unique() && data)
228 delete static_cast<bool*>(data);
231 delete static_cast<int*>(data);
234 delete static_cast<Angle*>(data);
237 delete static_cast<Vector*>(data);
240 delete static_cast<Time*>(data);
243 delete static_cast<Real*>(data);
246 delete static_cast<Color*>(data);
249 delete static_cast<Segment*>(data);
251 case TYPE_BLINEPOINT:
252 delete static_cast<BLinePoint*>(data);
255 delete static_cast<list_type*>(data);
258 delete static_cast<String*>(data);
261 delete static_cast<Gradient*>(data);
267 etl::handle<Canvas> canvas(get(etl::loose_handle<Canvas>()));
268 if(canvas && canvas->is_inline())
270 delete static_cast<etl::handle<Canvas>*>(data);
274 delete static_cast<etl::loose_handle<Canvas>*>(data);
290 ValueBase::type_name(Type id)
318 case TYPE_BLINEPOINT:
319 return "bline_point";
325 synfig::warning("Encountered unknown ValueBase with an Type of %d",id);
331 ValueBase::ident_type(const String &str)
333 if(str=="nil" || str=="null")
335 else if(str=="time" || str==_("time"))
337 else if(str=="real" || str=="float" || str==_("real"))
339 else if(str=="integer" || str=="int" || str==_("integer"))
341 else if(str=="bool" || str==_("bool"))
343 else if(str=="angle" || str=="degrees" || str=="radians" || str=="rotations")
345 else if(str=="vector" || str=="point")
347 else if(str=="color")
349 else if(str=="string")
351 else if(str=="canvas")
355 else if(str=="segment")
357 else if(str=="gradient")
358 return TYPE_GRADIENT;
359 else if(str=="bline_point" || str=="blinepoint")
360 return TYPE_BLINEPOINT;
366 ValueBase::operator==(const ValueBase& rhs)const
368 if(get_type()!=rhs.get_type())
376 return get(Time()).is_equal(rhs.get(Time()));
378 return abs(get(Real())-rhs.get(Real()))<=0.00000000000001;
380 return get(int())==rhs.get(int());
382 return get(bool())==rhs.get(bool());
384 return get(Angle())==rhs.get(Angle());
386 return get(Vector()).is_equal_to(rhs.get(Vector()));
388 return get(Color())==rhs.get(Color());
390 return get(String())==rhs.get(String());
392 return get(Canvas::LooseHandle())==rhs.get(Canvas::LooseHandle());
394 return get_list()==rhs.get_list();
396 // return get(Segment())==rhs.get(Segment());
398 // return get(Gradient())==rhs.get(Gradient());
399 case TYPE_BLINEPOINT:
400 // return get(BLinePoint())==rhs.get(BLinePoint());