]> git.jsancho.org Git - guile-irrlicht.git/blobdiff - src/wrapped.h
reference counted refactor
[guile-irrlicht.git] / src / wrapped.h
index 2412d7eab0907ab46d02c098457d8eeedf73fb93..5ffafb6745c10f3ece617a9d4dd7fe3c527774c4 100644 (file)
@@ -19,6 +19,9 @@
    <http://www.gnu.org/licenses/>.
 */
 
+#ifndef __GUILE_IRRLICHT_WRAPPED_H_INCLUDED__
+#define __GUILE_IRRLICHT_WRAPPED_H_INCLUDED__
+
 #include <libguile.h>
 
 #define DECLARE_WRAPPED_TYPE(TYPE, INIT, PRED, WRAP, UNWRAP)            \
   WRAP (TYPE foreign_obj);                                              \
                                                                         \
   TYPE                                                                  \
-  UNWRAP (SCM wrapped_obj);                                             \
+  UNWRAP (SCM wrapped_obj, bool assert_type = true);                    \
                                                                         \
   bool                                                                  \
   PRED (SCM wrapped_obj);
 
 
 #define DEFINE_WRAPPED_TYPE(TYPE, PRINT_NAME, INIT, PRED, WRAP, UNWRAP) \
-  static SCM wrapped_type;                                              \
+  static SCM wrapped_##INIT;                                            \
                                                                         \
   void                                                                  \
   INIT (void)                                                           \
     slots = scm_list_1 (scm_from_utf8_symbol ("data"));                 \
     finalizer = NULL;                                                   \
                                                                         \
-    wrapped_type =                                                      \
+    wrapped_##INIT =                                                    \
       scm_make_foreign_object_type (name, slots, finalizer);            \
   }                                                                     \
                                                                         \
   SCM                                                                   \
   WRAP (TYPE foreign_obj)                                               \
   {                                                                     \
-    return scm_make_foreign_object_1 (wrapped_type, foreign_obj);       \
+    return scm_make_foreign_object_1 (wrapped_##INIT, foreign_obj);     \
   }                                                                     \
                                                                         \
   TYPE                                                                  \
-  UNWRAP (SCM wrapped_obj)                                              \
+  UNWRAP (SCM wrapped_obj, bool assert_type)                            \
   {                                                                     \
-    scm_assert_foreign_object_type (wrapped_type, wrapped_obj);         \
+    if (assert_type)                                                    \
+      {                                                                 \
+        scm_assert_foreign_object_type (wrapped_##INIT, wrapped_obj);   \
+      }                                                                 \
     return (TYPE)scm_foreign_object_ref (wrapped_obj, 0);               \
   }                                                                     \
                                                                         \
   bool                                                                  \
   PRED (SCM wrapped_obj)                                                \
   {                                                                     \
-    return SCM_IS_A_P (wrapped_obj, wrapped_type);                      \
+    return SCM_IS_A_P (wrapped_obj, wrapped_##INIT);                    \
   }
+
+#endif