Add a macro to check the type of value before using it. This will be used by each...
authordooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Wed, 9 Jan 2008 13:09:19 +0000 (13:09 +0000)
committerdooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Wed, 9 Jan 2008 13:09:19 +0000 (13:09 +0000)
git-svn-id: http://svn.voria.com/code@1298 1f10aa63-cdf2-0310-b900-c93c546f37ac

synfig-core/trunk/src/synfig/valuenode.h

index 99280b8..4f91873 100644 (file)
 # define DCAST_HACK_ENABLE()
 #endif
 
+#define CHECK_TYPE_AND_SET_VALUE(variable, type)                                               \
+       /* I don't think this ever happens - maybe remove this code? */         \
+       if (get_type() == ValueBase::TYPE_NIL) {                                                        \
+               warning("%s:%d get_type() IS nil sometimes!",                                   \
+                               __FILE__, __LINE__);                                                                    \
+               return false;                                                                                                   \
+       }                                                                                                                                       \
+       if (get_type() != ValueBase::TYPE_NIL &&                                                        \
+               !(ValueBase::same_type_as(value->get_type(), type)) &&                  \
+               !PlaceholderValueNode::Handle::cast_dynamic(value)) {                   \
+               error("%s:%d wrong type for %s: need %s but got %s",                    \
+                         __FILE__, __LINE__,                                                                           \
+                         link_local_name(i).c_str(),                                                           \
+                         ValueBase::type_name(type).c_str(),                                           \
+                         ValueBase::type_name(value->get_type()).c_str());             \
+               return false;                                                                                                   \
+       }                                                                                                                                       \
+       variable = value;                                                                                                       \
+       signal_child_changed()(i);                                                                                      \
+       signal_value_changed()();                                                                                       \
+       return true
+
 /* === T Y P E D E F S ===================================================== */
 
 /* === C L A S S E S & S T R U C T S ======================================= */