X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftags%2Fstable%2Fsrc%2Fsynfig%2Fvalue.h;h=cc6cab9337fd7942af7e557a9962d60a1524a961;hb=47fce282611fbba1044921d22ca887f9b53ad91a;hp=228eab19b0f92fd6470e7e4af34d9dc7bb33af1b;hpb=d3408370fc3297609b3aa8d4ff7edf1f238df251;p=synfig.git diff --git a/synfig-core/tags/stable/src/synfig/value.h b/synfig-core/tags/stable/src/synfig/value.h index 228eab1..cc6cab9 100644 --- a/synfig-core/tags/stable/src/synfig/value.h +++ b/synfig-core/tags/stable/src/synfig/value.h @@ -6,6 +6,7 @@ ** ** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2007, 2008 Chris Moore ** ** This package is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License as @@ -200,13 +201,24 @@ public: //! Checks the type of the parameter against itself. Returns true if they are of the same type. template bool - same_as(const T &x)const + same_type_as(const T &x)const { const Type testtype(get_type(x)); - if(testtype==type)return true; - if( (type==TYPE_REAL || type==TYPE_TIME) && - (testtype==TYPE_REAL || testtype==TYPE_TIME) ) + return same_type_as(type, testtype); + } + + bool same_type_as(const Type testtype)const + { + return same_type_as(type, testtype); + } + + //! Compares two types. Returns true if they are the same type. + static bool same_type_as(const Type type1, const Type type2) + { + if (type1 == type2) return true; + if ((type1 == TYPE_REAL || type1 == TYPE_TIME) && + (type2 == TYPE_REAL || type2 == TYPE_TIME)) return true; return false; } @@ -214,9 +226,9 @@ public: // === GET MEMBERS ======================================================== template - const T &get(const T& x)const + const T &get(const T& x __attribute__ ((unused)))const { - assert(is_valid() && same_as(x)); + assert(is_valid() && same_type_as(x)); return *static_cast(data); } float get(const float &)const { return get(Real()); } @@ -234,7 +246,7 @@ public: template void put(T* x)const { - assert(same_as(*x)); + assert(same_type_as(*x)); *x=*static_cast(data); } void put(float* x)const { *x=get(Real()); } @@ -248,6 +260,7 @@ public: void set(const float &x) { _set(Real(x)); } void set(const list_type &x); void set(const char* x); + void set(char* x); void set(Canvas*x); void set(etl::loose_handle x); void set(etl::handle x); @@ -267,31 +280,34 @@ public: //! Returns a string containing the name of the given Type static String type_name(Type id); + //! Returns a string containing the translated name of the given Type + static String type_local_name(Type id); + //! Returns a the corresponding Type of the described type static Type ident_type(const String &str); // === GET TYPE MEMBERS =================================================== - static const Type get_type(bool) { return TYPE_BOOL; } - static const Type get_type(int) { return TYPE_INTEGER; } - static const Type get_type(const Time&) { return TYPE_TIME; } - static const Type get_type(const Real&) { return TYPE_REAL; } - static const Type get_type(const float&) { return TYPE_REAL; } - static const Type get_type(const Vector&) { return TYPE_VECTOR; } - static const Type get_type(const Color&) { return TYPE_COLOR; } - static const Type get_type(const Segment&) { return TYPE_SEGMENT; } - static const Type get_type(const BLinePoint&) { return TYPE_BLINEPOINT; } - static const Type get_type(const String&) { return TYPE_STRING; } - static const Type get_type(const Gradient&) { return TYPE_GRADIENT; } - static const Type get_type(Canvas*) { return TYPE_CANVAS; } - static const Type get_type(const etl::handle&) + static Type get_type(bool) { return TYPE_BOOL; } + static Type get_type(int) { return TYPE_INTEGER; } + static Type get_type(const Time&) { return TYPE_TIME; } + static Type get_type(const Real&) { return TYPE_REAL; } + static Type get_type(const float&) { return TYPE_REAL; } + static Type get_type(const Vector&) { return TYPE_VECTOR; } + static Type get_type(const Color&) { return TYPE_COLOR; } + static Type get_type(const Segment&) { return TYPE_SEGMENT; } + static Type get_type(const BLinePoint&) { return TYPE_BLINEPOINT; } + static Type get_type(const String&) { return TYPE_STRING; } + static Type get_type(const Gradient&) { return TYPE_GRADIENT; } + static Type get_type(Canvas*) { return TYPE_CANVAS; } + static Type get_type(const etl::handle&) { return TYPE_CANVAS; } - static const Type get_type(const etl::loose_handle&) + static Type get_type(const etl::loose_handle&) { return TYPE_CANVAS; } - static const Type get_type(const list_type&) { return TYPE_LIST; } - template static const Type get_type(const std::vector &x) + static Type get_type(const list_type&) { return TYPE_LIST; } + template static Type get_type(const std::vector &/*x*/) { return TYPE_LIST; } - template static const Type get_type(const std::list &x) + template static Type get_type(const std::list &/*x*/) { return TYPE_LIST; } // ======================================================================== @@ -325,13 +341,13 @@ public: half get(const half &)const { return get(Real()); } void put(half*x)const { *x=get(Real()); } void set(const half &x) { _set(Real(x)); } - static const Type get_type(const half&) { return TYPE_REAL; } + static Type get_type(const half&) { return TYPE_REAL; } operator half()const { return get(Real()); } #endif #ifndef SYNFIG_NO_ANGLE operator const Angle&()const { return get(Angle()); } - static const Type get_type(const Angle&) { return TYPE_ANGLE; } + static Type get_type(const Angle&) { return TYPE_ANGLE; } #endif template @@ -390,7 +406,7 @@ public: Value(const ValueBase &x):ValueBase(x) { - if(!x.same_as(T())) + if(!x.same_type_as(T())) throw Exception::BadType("Value(ValueBase): Type Mismatch"); } @@ -410,7 +426,7 @@ public: Value& operator=(const ValueBase& x) { - if(!x.same_as(T())) + if(!x.same_type_as(T())) throw Exception::BadType("Value(ValueBase): Type Mismatch"); return ValueBase::operator=(x); } @@ -427,7 +443,7 @@ public: } Value(const ValueBase &x):ValueBase(x) { - if(!x.same_as(T())) + if(!x.same_type_as(T())) throw Exception::BadType("Value(ValueBase): Type Mismatch"); } Value() @@ -446,7 +462,7 @@ public: Value& operator=(const ValueBase& x) { - if(!x.same_as(T())) + if(!x.same_type_as(T())) throw Exception::BadType("Value(ValueBase): Type Mismatch"); return ValueBase::operator=(x); }