Add a macro to check the type of value before using it. This will be used by each...
[synfig.git] / synfig-core / trunk / src / synfig / value.h
index 53dc12a..db2cbf3 100644 (file)
@@ -6,6 +6,7 @@
 **
 **     \legal
 **     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2007 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
@@ -204,9 +205,20 @@ public:
        {
                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;
        }
@@ -289,9 +301,9 @@ public:
        static const Type get_type(const etl::loose_handle<Canvas>&)
                { return TYPE_CANVAS; }
        static const Type get_type(const list_type&) { return TYPE_LIST; }
-       template <class T> static const Type get_type(const std::vector<T> &x)
+       template <class T> static const Type get_type(const std::vector<T> &/*x*/)
                { return TYPE_LIST; }
-       template <class T> static const Type get_type(const std::list<T> &x)
+       template <class T> static const Type get_type(const std::list<T> &/*x*/)
                { return TYPE_LIST; }
        // ========================================================================