List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:May 7 2007 7:54am
Subject:Rev 109: Fixed set_datetime multimethod dispatch problem by adding a typecheck typemap. (Thanks to Gonzalo Garramuño from the swig-user list) in ht...
View as plain text  
------------------------------------------------------------
revno: 109
revision-id: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: ndbjmerge
timestamp: Mon 2007-05-07 00:52:53 -0700
message:
  Fixed set_datetime multimethod dispatch problem by adding a typecheck typemap. (Thanks
to Gonzalo Garramuño from the swig-user list)
modified:
  ruby/ndbapi.i                  ndb.i-20070228212451-7arjxk90dkwcn5xr-3
=== modified file 'ruby/ndbapi.i'
--- a/ruby/ndbapi.i	2007-05-06 04:28:40 +0000
+++ b/ruby/ndbapi.i	2007-05-07 07:52:53 +0000
@@ -29,11 +29,26 @@
   $2 = (size_t)RSTRING($input)->len;
  }
 
-%typemap(in) (MYSQL_TIME * anInputDateTime) { 
+%typecheck(SWIG_TYPECHECK_POINTER) MYSQL_TIME* (const char* klass) {
+        // do typecheck using kind_of? DateTime
+//        static VALUE rb_cDateTime = rb_const_get( rb_cObject,
+//						  "DateTime" );
+//	$1 = rb_obj_is_kind_of( $input, rb_cDateTime );
+
+	// or... better yet, do it with duck typing... any class
+        // will work, as long as these are defined...
+	$1 = ( rb_respond_to( $input, rb_intern("day") ) &&
+	       rb_respond_to( $input, rb_intern("month") ) &&
+	       rb_respond_to( $input, rb_intern("year") ) &&
+               rb_respond_to( $input, rb_intern("hour") ) &&
+               rb_respond_to( $input, rb_intern("min") ) &&
+               rb_respond_to( $input, rb_intern("sec") ) );
+}
+
+%typemap(in,numinputs=1) (MYSQL_TIME * anInputDateTime) { 
 
   // How do I check that we're getting a Ruby DateTime?!!?
 
-  printf("whee!\n");
     MYSQL_TIME * dt = (MYSQL_TIME *)malloc(sizeof(MYSQL_TIME));
     if (dt==NULL) 
       NDB_exception(NdbApiException,"Failed to allocate a MYSQL_TIME");
@@ -46,7 +61,6 @@
 
     $1 = dt;      
 
-
  }
 
 %{ 

Thread
Rev 109: Fixed set_datetime multimethod dispatch problem by adding a typecheck typemap. (Thanks to Gonzalo Garramuño from the swig-user list) in http...Monty Taylor7 May