|
Carlos Lopez |
a09598 |
/* === S Y N F I G ========================================================= */
|
|
Carlos Lopez |
a09598 |
/*! \file value.h
|
|
Carlos Lopez |
a09598 |
** \brief Template Header
|
|
Carlos Lopez |
a09598 |
**
|
|
Carlos Lopez |
a09598 |
** $Id$
|
|
Carlos Lopez |
a09598 |
**
|
|
Carlos Lopez |
a09598 |
** \legal
|
|
Carlos Lopez |
a09598 |
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
|
|
Carlos Lopez |
a09598 |
** Copyright (c) 2007, 2008 Chris Moore
|
|
Carlos Lopez |
42fd7a |
** Copyright (c) 2011 Carlos Lรณpez
|
|
Carlos Lopez |
a09598 |
**
|
|
Carlos Lopez |
a09598 |
** This package is free software; you can redistribute it and/or
|
|
Carlos Lopez |
a09598 |
** modify it under the terms of the GNU General Public License as
|
|
Carlos Lopez |
a09598 |
** published by the Free Software Foundation; either version 2 of
|
|
Carlos Lopez |
a09598 |
** the License, or (at your option) any later version.
|
|
Carlos Lopez |
a09598 |
**
|
|
Carlos Lopez |
a09598 |
** This package is distributed in the hope that it will be useful,
|
|
Carlos Lopez |
a09598 |
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Carlos Lopez |
a09598 |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Carlos Lopez |
a09598 |
** General Public License for more details.
|
|
Carlos Lopez |
a09598 |
** \endlegal
|
|
Carlos Lopez |
a09598 |
*/
|
|
Carlos Lopez |
a09598 |
/* ========================================================================= */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === S T A R T =========================================================== */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
#ifndef __SYNFIG_VALUE_H
|
|
Carlos Lopez |
a09598 |
#define __SYNFIG_VALUE_H
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === H E A D E R S ======================================================= */
|
|
Carlos Lopez |
a09598 |
|
|
|
204555 |
#include "base_types.h"
|
|
|
204555 |
|
|
Carlos Lopez |
a09598 |
#include <vector></vector>
|
|
caryoscelus |
892c45 |
#include <list></list>
|
|
|
6dc75c |
#include "interpolation.h"
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
#include <etl ref_count=""></etl>
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === M A C R O S ========================================================= */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === T Y P E D E F S ===================================================== */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === C L A S S E S & S T R U C T S ======================================= */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
namespace synfig {
|
|
Carlos Lopez |
a09598 |
|
|
|
204555 |
// TODO: remove following predeclarations
|
|
Carlos Lopez |
a09598 |
class Canvas;
|
|
Carlos Lopez |
a09598 |
class Vector;
|
|
Carlos Lopez |
a09598 |
class Time;
|
|
Diego Barrios Romero |
a6f9bd |
struct Segment;
|
|
Carlos Lopez |
a09598 |
class Gradient;
|
|
Carlos Lopez |
a09598 |
class BLinePoint;
|
|
Carlos Lopez |
ecf316 |
class WidthPoint;
|
|
Carlos Lopez |
7cbd4c |
class DashItem;
|
|
Carlos Lopez |
a09598 |
class Color;
|
|
Nikita Kitaev |
dc5e35 |
class Bone;
|
|
Nikita Kitaev |
dc5e35 |
class ValueNode_Bone;
|
|
Nikita Kitaev |
dc5e35 |
class BoneWeightPair;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/*! \class ValueBase
|
|
Carlos Lopez |
1c1eea |
** \brief Base class for the Values of Synfig
|
|
Carlos Lopez |
a09598 |
*/
|
|
Carlos Lopez |
a09598 |
class ValueBase
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
a09598 |
/*
|
|
Carlos Lopez |
a09598 |
-- ** -- T Y P E S -----------------------------------------------------------
|
|
Carlos Lopez |
a09598 |
*/
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
public:
|
|
|
204555 |
typedef std::vector<valuebase> List;</valuebase>
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/*
|
|
Carlos Lopez |
a09598 |
-- ** -- D A T A -------------------------------------------------------------
|
|
Carlos Lopez |
a09598 |
*/
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
protected:
|
|
Carlos Lopez |
1c1eea |
//! The type of value
|
|
|
204555 |
Type *type;
|
|
Carlos Lopez |
1c1eea |
//! Pointer to hold the data of the value
|
|
Carlos Lopez |
a09598 |
void *data;
|
|
Carlos Lopez |
1c1eea |
//! Counter of Value Nodes that refers to this Value Base
|
|
Carlos Lopez |
1c1eea |
//! Value base can only be destructed if the ref_count is not greater than 0
|
|
Carlos Lopez |
1c1eea |
//!\see etl::reference_counter
|
|
Carlos Lopez |
a09598 |
etl::reference_counter ref_count;
|
|
Carlos Lopez |
1c1eea |
//! For Values with loop option like TYPE_LIST
|
|
Carlos Lopez |
a09598 |
bool loop_;
|
|
Carlos Lopez |
e6b894 |
//! For Values of Constant Value Nodes
|
|
Carlos Lopez |
ac1cb3 |
bool static_;
|
|
|
6dc75c |
//! Parameter interpolation
|
|
|
6dc75c |
Interpolation interpolation_;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/*
|
|
Carlos Lopez |
a09598 |
-- ** -- C O N S T R U C T O R S -----------------------------------
|
|
Carlos Lopez |
a09598 |
*/
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
public:
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
1c1eea |
//! Default constructor
|
|
Carlos Lopez |
a09598 |
ValueBase();
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
1c1eea |
//! Template constructor for any type
|
|
Carlos Lopez |
a09598 |
template <typename t=""></typename>
|
|
Carlos Lopez |
ac1cb3 |
ValueBase(const T &x, bool loop_=false, bool static_=false):
|
|
Rodolfo Ribeiro Gomes |
3b90f0 |
type(&type_nil),data(nullptr),ref_count(0),loop_(loop_), static_(static_),
|
|
|
6dc75c |
interpolation_(INTERPOLATION_UNDEFINED)
|
|
|
a255a5 |
{
|
|
|
9bfc3b |
#ifdef INITIALIZE_TYPE_BEFORE_USE
|
|
|
a255a5 |
type->initialize();
|
|
|
a255a5 |
#endif
|
|
|
a255a5 |
set(x);
|
|
|
a255a5 |
}
|
|
Carlos Lopez |
a09598 |
|
|
|
204555 |
template <typename t=""></typename>
|
|
|
204555 |
ValueBase(const std::vector<t> &x, bool loop_=false, bool static_=false):</t>
|
|
Rodolfo Ribeiro Gomes |
3b90f0 |
type(&type_nil),data(nullptr),ref_count(0),loop_(loop_), static_(static_),
|
|
|
204555 |
interpolation_(INTERPOLATION_UNDEFINED)
|
|
|
a255a5 |
{
|
|
|
9bfc3b |
#ifdef INITIALIZE_TYPE_BEFORE_USE
|
|
|
a255a5 |
type->initialize();
|
|
|
a255a5 |
#endif
|
|
|
a255a5 |
set_list_of(x);
|
|
|
a255a5 |
}
|
|
|
204555 |
|
|
Rodolfo Ribeiro Gomes |
288b11 |
//! Constructor with the type set.
|
|
|
204555 |
ValueBase(Type &x);
|
|
Carlos Lopez |
a09598 |
|
|
Rodolfo Ribeiro Gomes |
288b11 |
//! Copy constructor
|
|
Rodolfo Ribeiro Gomes |
288b11 |
ValueBase(const ValueBase &x);
|
|
Rodolfo Ribeiro Gomes |
288b11 |
|
|
Rodolfo Ribeiro Gomes |
288b11 |
//! Move constructor
|
|
Rodolfo Ribeiro Gomes |
288b11 |
ValueBase(ValueBase&& x);
|
|
Rodolfo Ribeiro Gomes |
288b11 |
|
|
Carlos Lopez |
1c1eea |
//! Default destructor
|
|
Rodolfo Ribeiro Gomes |
288b11 |
virtual ~ValueBase();
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/*
|
|
Carlos Lopez |
a09598 |
-- ** -- O P E R A T O R S ---------------------------------------------------
|
|
Carlos Lopez |
a09598 |
*/
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
public:
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
1c1eea |
//! Template for the operator assignation operator for non ValueBase classes
|
|
Carlos Lopez |
1c1eea |
//! \see set()
|
|
Carlos Lopez |
a09598 |
template <class t=""> ValueBase& operator=(const T& x)</class>
|
|
Carlos Lopez |
a09598 |
{ set(x); return *this; }
|
|
Carlos Lopez |
a09598 |
|
|
Rodolfo Ribeiro Gomes |
288b11 |
//!Copy/Move assignment operator for ValueBase classes
|
|
Rodolfo Ribeiro Gomes |
288b11 |
ValueBase& operator=(ValueBase x);
|
|
Carlos Lopez |
a09598 |
|
|
luz.paz |
99f3ef |
//! Equal than operator. Segment, Gradient and Bline Points cannot be compared.
|
|
Carlos Lopez |
a09598 |
bool operator==(const ValueBase& rhs)const;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
1c1eea |
//! Not equal than operator.
|
|
Carlos Lopez |
a09598 |
bool operator!=(const ValueBase& rhs)const { return !operator==(rhs); }
|
|
Carlos Lopez |
a09598 |
|
|
|
5ccd0a |
//! todo writeme
|
|
|
5ccd0a |
bool operator<(const ValueBase& rhs)const;
|
|
|
5ccd0a |
|
|
|
5ccd0a |
bool operator>(const ValueBase& rhs)const
|
|
|
5ccd0a |
{ return rhs < *this; }
|
|
|
5ccd0a |
bool operator<=(const ValueBase& rhs)const
|
|
|
5ccd0a |
{ return !(*this < rhs); }
|
|
|
5ccd0a |
bool operator>=(const ValueBase& rhs)const
|
|
|
5ccd0a |
{ return !(rhs < *this); }
|
|
|
5ccd0a |
|
|
Carlos Lopez |
a09598 |
//! Constant index operator for when value is of type TYPE_LIST
|
|
Carlos Lopez |
a09598 |
const ValueBase &operator[](int index)const
|
|
|
204555 |
{ assert(type==&type_list); assert(index>0); return get_list()[index]; }
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/*
|
|
Carlos Lopez |
a09598 |
-- ** -- M E M B E R F U N C T I O N S -------------------------------------
|
|
Carlos Lopez |
a09598 |
*/
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
public:
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
1c1eea |
//! Deletes the data only if the ref count is zero
|
|
Carlos Lopez |
a09598 |
void clear();
|
|
Carlos Lopez |
a09598 |
|
|
Rodolfo Ribeiro Gomes |
288b11 |
//! Swap object contents
|
|
Rodolfo Ribeiro Gomes |
288b11 |
friend void swap(ValueBase& first, ValueBase& second) {
|
|
Rodolfo Ribeiro Gomes |
288b11 |
std::swap(first.type, second.type);
|
|
Rodolfo Ribeiro Gomes |
288b11 |
std::swap(first.data, second.data);
|
|
Rodolfo Ribeiro Gomes |
288b11 |
std::swap(first.ref_count, second.ref_count);
|
|
Rodolfo Ribeiro Gomes |
288b11 |
std::swap(first.loop_, second.loop_);
|
|
Rodolfo Ribeiro Gomes |
288b11 |
std::swap(first.static_, second.static_);
|
|
Rodolfo Ribeiro Gomes |
288b11 |
std::swap(first.interpolation_, second.interpolation_);
|
|
Rodolfo Ribeiro Gomes |
288b11 |
}
|
|
Rodolfo Ribeiro Gomes |
288b11 |
|
|
Carlos Lopez |
1c1eea |
//! Gets the loop option.
|
|
Carlos Lopez |
a09598 |
bool get_loop()const { return loop_; }
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
1c1eea |
//! Sets the loop option.
|
|
Carlos Lopez |
a09598 |
void set_loop(bool x) { loop_=x; }
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
ac1cb3 |
//! Gets the static option.
|
|
Carlos Lopez |
ac1cb3 |
bool get_static()const { return static_; }
|
|
Carlos Lopez |
ac1cb3 |
|
|
Carlos Lopez |
ac1cb3 |
//! Sets the static option.
|
|
Carlos Lopez |
ac1cb3 |
void set_static(bool x) { static_=x; }
|
|
Carlos Lopez |
ac1cb3 |
|
|
|
6dc75c |
//! Gets the interpolation.
|
|
|
6dc75c |
Interpolation get_interpolation()const { return interpolation_; }
|
|
|
6dc75c |
|
|
|
6dc75c |
//! Sets the interpolation.
|
|
|
6dc75c |
void set_interpolation(Interpolation x) { interpolation_=x; }
|
|
|
4c1d21 |
|
|
|
4c1d21 |
//! Create independent copy from existing ValueBase object
|
|
|
4c1d21 |
void copy(const ValueBase& x);
|
|
|
6dc75c |
|
|
|
e0ed0c |
//! Copies properties (static, interpolation, etc) from other ValueBase object.
|
|
|
7f43d7 |
void copy_properties_of(const ValueBase& x);
|
|
|
7f43d7 |
|
|
Carlos Lopez |
1c1eea |
//! True if the Value is not valid or is type LIST and is empty
|
|
Carlos Lopez |
a09598 |
bool empty()const;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
1c1eea |
//! Gets the contained type in the Value Base
|
|
|
204555 |
Type& get_contained_type()const;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
//! Returns true if the contained value is defined and valid.
|
|
Carlos Lopez |
a09598 |
bool is_valid()const;
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
1c1eea |
//! Returns a string containing the name of the type. Used for sif files
|
|
|
204555 |
String type_name()const { return type->description.name; }
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
//! Returns the type of the contained value
|
|
|
204555 |
Type& get_type()const { return *type; }
|
|
|
204555 |
|
|
|
204555 |
template<typename t=""></typename>
|
|
|
204555 |
inline static bool can_get(const TypeId type, const T &x)
|
|
|
204555 |
{ return _can_get(type, types_namespace::get_type_alias(x)); }
|
|
|
204555 |
template<typename t=""></typename>
|
|
|
204555 |
inline static bool can_get(const Type& type, const T &x) { return can_get(type.identifier, x); }
|
|
|
204555 |
template<typename t=""></typename>
|
|
|
204555 |
inline static bool can_set(const TypeId type, const T &x)
|
|
|
204555 |
{ return _can_set(type, types_namespace::get_type_alias(x)); }
|
|
|
204555 |
template<typename t=""></typename>
|
|
|
204555 |
inline static bool can_set(const Type& type, const T &x) { return can_set(type.identifier, x); }
|
|
|
204555 |
template<typename t=""></typename>
|
|
|
204555 |
inline static bool can_put(const TypeId type, const T &x)
|
|
|
204555 |
{ return _can_put(type, types_namespace::get_type_alias(x)); }
|
|
|
204555 |
template<typename t=""></typename>
|
|
|
204555 |
inline static bool can_put(const Type& type, const T &x) { return can_put(type.identifier, x); }
|
|
|
204555 |
inline static bool can_copy(const TypeId dest, const TypeId src)
|
|
Rodolfo Ribeiro Gomes |
3b90f0 |
{ return Type::get_operation<operation::copyfunc>(Operation::Description::get_copy(dest, src)); }</operation::copyfunc>
|
|
|
204555 |
inline static bool can_copy(const Type& dest, const Type& src) { return can_copy(dest.identifier, src.identifier); }
|
|
|
204555 |
|
|
|
204555 |
template<typename t=""> inline bool can_get(const T &x) const { return is_valid() && can_get(*type, x); }</typename>
|
|
|
204555 |
template<typename t=""> inline bool can_set(const T &x) const { return can_set(*type, x); }</typename>
|
|
|
204555 |
template<typename t=""> inline bool can_put(const T &x) const { return is_valid() && can_put(*type, x); }</typename>
|
|
|
204555 |
bool can_copy_from(const TypeId type) const { return can_copy(this->type->identifier, type); }
|
|
|
204555 |
bool can_copy_from(const Type& type) const { return can_copy(*this->type, type); }
|
|
|
204555 |
bool can_copy_to(const TypeId type) const { return can_copy(type, this->type->identifier); }
|
|
|
204555 |
bool can_copy_to(const Type& type) const { return can_copy(type, *this->type); }
|
|
|
204555 |
|
|
|
204555 |
template<typename t=""> bool same_type_as(const T&x) const { return can_get(x) && can_set(x) && can_put(x); }</typename>
|
|
Carlos Lopez |
a09598 |
|
|
|
204555 |
// === GET MEMBERS ========================================================
|
|
|
204555 |
//! Template to get the ValueBase class data by casting the type
|
|
|
204555 |
template <typename t=""></typename>
|
|
|
204555 |
inline const T &get(const T &x)const { return (const T&)_get(types_namespace::get_type_alias(x)); }
|
|
Carlos Lopez |
a09598 |
|
|
|
204555 |
//! Gets the data as List Type
|
|
|
204555 |
const List& get_list()const { return get(List()); }
|
|
Carlos Lopez |
a09598 |
|
|
|
204555 |
template<typename t=""></typename>
|
|
|
204555 |
std::vector<t> get_list_of(const T &x)const</t>
|
|
Carlos Lopez |
a09598 |
{
|
|
|
204555 |
const List &list = get_list();
|
|
|
204555 |
std::vector<t> out_list;</t>
|
|
|
204555 |
out_list.reserve(list.size());
|
|
|
204555 |
for(List::const_iterator i = list.begin(); i != list.end(); ++i)
|
|
|
204555 |
if (i->can_get(x))
|
|
|
204555 |
out_list.push_back(i->get(x));
|
|
|
204555 |
return out_list;
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
|
204555 |
template<typename t=""></typename>
|
|
|
204555 |
void set_list_of(const std::vector<t> &list)</t>
|
|
Carlos Lopez |
a09598 |
{
|
|
|
204555 |
*this = List(list.begin(), list.end());
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
#ifdef _DEBUG
|
|
Carlos Lopez |
a09598 |
String get_string() const;
|
|
Carlos Lopez |
a09598 |
#endif // _DEBUG
|
|
Carlos Lopez |
a09598 |
// ========================================================================
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
1c1eea |
//! Put template for any class
|
|
Carlos Lopez |
a09598 |
template <typename t=""></typename>
|
|
|
204555 |
inline void put(T* x)const { _put(types_namespace::get_type_alias(*x), x); }
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
1c1eea |
//! Set template for any class
|
|
|
204555 |
template <typename t=""></typename>
|
|
|
204555 |
inline void set(const T& x) { _set(x); }
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/*
|
|
Carlos Lopez |
a09598 |
-- ** -- S T A T I C F U N C T I O N S -------------------------------------
|
|
Carlos Lopez |
a09598 |
*/
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
public:
|
|
Carlos Lopez |
1c1eea |
//! Returns a the corresponding Type of the described type.
|
|
Carlos Lopez |
1c1eea |
//! Notice that this is used in the loadcanvas. It should keep all
|
|
Carlos Lopez |
1c1eea |
//! all type names used in previous sif files
|
|
|
204555 |
static Type& ident_type(const String &str);
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
// === GET TYPE MEMBERS ===================================================
|
|
|
204555 |
template<typename t=""></typename>
|
|
|
204555 |
static Type& get_type(const T&) { return Type::get_type<t>(); }</t>
|
|
|
204555 |
|
|
|
204555 |
// TODO: remove this, when removed all references in code
|
|
|
204555 |
static Type& get_type(const List &)
|
|
|
204555 |
{ return Type::get_type<list>(); }</list>
|
|
|
204555 |
static Type& get_type(Canvas* const &)
|
|
|
204555 |
{ return Type::get_type<canvas*>(); }</canvas*>
|
|
|
204555 |
static Type& get_type(ValueNode_Bone* const &)
|
|
|
204555 |
{ return Type::get_type<valuenode_bone*>(); }</valuenode_bone*>
|
|
|
204555 |
template <typename t=""> static Type& get_type(const T* &)</typename>
|
|
|
204555 |
{ int i[(int)1 - (int)sizeof(T)]; return type_nil; }
|
|
|
204555 |
template <typename t=""> static Type& get_type(const std::vector<t> &)</t></typename>
|
|
|
204555 |
{ int i[(int)1 - (int)sizeof(T)]; return type_nil; }
|
|
|
204555 |
template <typename t=""> static Type& get_type(const std::list<t> &)</t></typename>
|
|
|
204555 |
{ int i[(int)1 - (int)sizeof(T)]; return type_nil; }
|
|
Carlos Lopez |
a09598 |
// ========================================================================
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/*
|
|
Carlos Lopez |
a09598 |
-- ** -- C A S T O P E R A T O R S -----------------------------------------
|
|
Carlos Lopez |
a09598 |
*/
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
public:
|
|
Carlos Lopez |
1c1eea |
//! I wonder why are those casting operators disabled...
|
|
|
204555 |
/*
|
|
|
204555 |
template<typename t=""></typename>
|
|
|
204555 |
operator const T&() const
|
|
|
204555 |
{
|
|
|
204555 |
Type &t = Type::get_type<t>();</t>
|
|
|
204555 |
Operation::GenericFuncs<t>::GetFunc func =</t>
|
|
|
204555 |
Type::get_operation<operation::genericfuncs<t>::GetFunc>(</operation::genericfuncs<t>
|
|
|
204555 |
Operation::Description::get_get(t.identifier) );
|
|
|
204555 |
assert(func != NULL);
|
|
|
204555 |
return func(data);
|
|
|
204555 |
}
|
|
|
204555 |
*/
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/*
|
|
Carlos Lopez |
a09598 |
-- ** -- O T H E R -----------------------------------------------------------
|
|
Carlos Lopez |
a09598 |
*/
|
|
Carlos Lopez |
a09598 |
|
|
|
204555 |
private:
|
|
|
204555 |
void create(Type &type);
|
|
|
204555 |
inline void create() { create(*type); }
|
|
Carlos Lopez |
a09598 |
|
|
|
204555 |
template <typename t=""></typename>
|
|
|
204555 |
inline static bool _can_get(const TypeId type, const T &)
|
|
Carlos Lopez |
a09598 |
{
|
|
|
204555 |
typedef typename T::AliasedType TT;
|
|
|
204555 |
return NULL !=
|
|
|
204555 |
Type::get_operation<typename operation::genericfuncs<tt="">::GetFunc>(</typename>
|
|
|
204555 |
Operation::Description::get_get(type) );
|
|
Carlos Lopez |
a09598 |
}
|
|
|
204555 |
|
|
|
204555 |
template <typename t=""></typename>
|
|
|
204555 |
inline static bool _can_put(const TypeId type, const T &)
|
|
Carlos Lopez |
a09598 |
{
|
|
|
204555 |
typedef typename T::AliasedType TT;
|
|
|
204555 |
return NULL !=
|
|
|
204555 |
Type::get_operation<typename operation::genericfuncs<tt="">::PutFunc>(</typename>
|
|
|
204555 |
Operation::Description::get_put(type) );
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
|
204555 |
template <typename t=""></typename>
|
|
|
204555 |
inline static bool _can_set(const TypeId type, const T &)
|
|
|
204555 |
{
|
|
|
204555 |
typedef typename T::AliasedType TT;
|
|
|
204555 |
return NULL !=
|
|
|
204555 |
Type::get_operation<typename operation::genericfuncs<tt="">::SetFunc>(</typename>
|
|
|
204555 |
Operation::Description::get_set(type) );
|
|
|
204555 |
}
|
|
Carlos Lopez |
a09598 |
|
|
|
204555 |
template <typename t=""></typename>
|
|
|
204555 |
const typename T::AliasedType& _get(const T &)const
|
|
Carlos Lopez |
a09598 |
{
|
|
|
204555 |
typedef typename T::AliasedType TT;
|
|
|
204555 |
#ifdef _DEBUG
|
|
|
204555 |
if (!is_valid())
|
|
|
204555 |
printf("%s:%d !is_valid()\n", __FILE__, __LINE__);
|
|
|
204555 |
#endif
|
|
|
204555 |
assert(is_valid());
|
|
|
204555 |
typename Operation::GenericFuncs<tt>::GetFunc func =</tt>
|
|
|
204555 |
Type::get_operation<typename operation::genericfuncs<tt="">::GetFunc>(</typename>
|
|
|
204555 |
Operation::Description::get_get(type->identifier) );
|
|
|
204555 |
#ifdef _DEBUG
|
|
|
204555 |
if (func == NULL)
|
|
|
204555 |
printf("%s:%d %s get_func == NULL\n", __FILE__, __LINE__, type->description.name.c_str());
|
|
|
204555 |
#endif
|
|
|
204555 |
assert(func != NULL);
|
|
|
204555 |
return func(data);
|
|
|
204555 |
}
|
|
Carlos Lopez |
a09598 |
|
|
|
204555 |
template <typename t=""></typename>
|
|
|
204555 |
void _put(const T &, typename T::AliasedType *x)const
|
|
|
204555 |
{
|
|
|
204555 |
assert(is_valid());
|
|
|
204555 |
typedef typename T::AliasedType TT;
|
|
|
204555 |
typename Operation::GenericFuncs<tt>::PutFunc func =</tt>
|
|
|
204555 |
Type::get_operation<typename operation::genericfuncs<tt="">::PutFunc>(</typename>
|
|
|
204555 |
Operation::Description::get_put(type->identifier) );
|
|
|
204555 |
assert(func != NULL);
|
|
|
204555 |
func(*x, data);
|
|
|
204555 |
}
|
|
Carlos Lopez |
a09598 |
|
|
|
204555 |
template<typename t=""></typename>
|
|
|
204555 |
void __set(const T &alias, const typename T::AliasedType &x)
|
|
|
204555 |
{
|
|
|
204555 |
typedef typename T::AliasedType TT;
|
|
|
9bfc3b |
#ifdef INITIALIZE_TYPE_BEFORE_USE
|
|
|
e00af6 |
alias.type.initialize();
|
|
|
a255a5 |
#endif
|
|
|
e00af6 |
|
|
|
204555 |
Type ¤t_type = *type;
|
|
|
204555 |
if (current_type != type_nil)
|
|
Carlos Lopez |
a09598 |
{
|
|
|
204555 |
typename Operation::GenericFuncs<tt>::SetFunc func =</tt>
|
|
|
204555 |
Type::get_operation<typename operation::genericfuncs<tt="">::SetFunc>(</typename>
|
|
|
204555 |
Operation::Description::get_set(current_type.identifier) );
|
|
|
204555 |
if (func != NULL)
|
|
Carlos Lopez |
a09598 |
{
|
|
|
204555 |
if (!ref_count.unique()) create(current_type);
|
|
|
204555 |
func(data, x);
|
|
Carlos Lopez |
a09598 |
return;
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
a09598 |
|
|
|
204555 |
Type &new_type = alias.type;
|
|
|
204555 |
assert(new_type != current_type);
|
|
|
204555 |
assert(new_type != type_nil);
|
|
Carlos Lopez |
a09598 |
|
|
|
204555 |
typename Operation::GenericFuncs<tt>::SetFunc func =</tt>
|
|
|
204555 |
Type::get_operation<typename operation::genericfuncs<tt="">::SetFunc>(</typename>
|
|
|
204555 |
Operation::Description::get_set(new_type.identifier) );
|
|
|
204555 |
assert(func != NULL);
|
|
Nikita Kitaev |
dc5e35 |
|
|
|
204555 |
create(new_type);
|
|
|
204555 |
assert(*type != type_nil);
|
|
|
204555 |
func(data, x);
|
|
Carlos Lopez |
a09598 |
}
|
|
Carlos Lopez |
1c1eea |
|
|
|
204555 |
//! Internal set template. Takes in consideration the reference counter
|
|
|
204555 |
template <typename t=""></typename>
|
|
|
204555 |
inline void _set(const T& x) { __set(types_namespace::get_type_alias(x), x); }
|
|
|
204555 |
|
|
Carlos Lopez |
a09598 |
}; // END of class ValueBase
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/*! \class Value
|
|
Carlos Lopez |
1c1eea |
** \brief Template for all the valid Value Types
|
|
Carlos Lopez |
a09598 |
*/
|
|
Carlos Lopez |
a09598 |
template <class t=""></class>
|
|
Carlos Lopez |
a09598 |
class Value : public ValueBase
|
|
Carlos Lopez |
a09598 |
{
|
|
Carlos Lopez |
a09598 |
public:
|
|
|
204555 |
Value(const T &x):ValueBase(x) { }
|
|
|
204555 |
Value(const ValueBase &x):ValueBase(x) { }
|
|
Carlos Lopez |
a09598 |
T get()const { return ValueBase::get(T()); }
|
|
Carlos Lopez |
a09598 |
void put(T* x)const { ValueBase::put(x); }
|
|
Carlos Lopez |
a09598 |
void set(const T& x) { ValueBase::operator=(x); }
|
|
Carlos Lopez |
a09598 |
Value<t>& operator=(const T& x) { set(x); return *this; }</t>
|
|
Carlos Lopez |
a09598 |
Value<t>& operator=(const Value<t>& x) { return ValueBase::operator=(x); }</t></t>
|
|
|
204555 |
Value<t>& operator=(const ValueBase& x) { return ValueBase::operator=(x); }</t>
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
}; // END of class Value
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
}; // END of namespace synfig
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
/* === E N D =============================================================== */
|
|
Carlos Lopez |
a09598 |
|
|
Carlos Lopez |
a09598 |
#endif
|