Sha256: 78148aaa4025ebf5551c5b6c7aa36f26bc17e47b1fe45e45a247138c4f1ed1af

Contents?: true

Size: 1.67 KB

Versions: 36

Compression:

Stored size: 1.67 KB

Contents

//-*-c++-*-

VALUE r!class_varname!;
T!class_ptrmap! !class_ptrmap!;

!c_class_name!* ruby2!class_varcname!Ptr(VALUE rval) {
   !c_class_name!* ptr;
   Data_Get_Struct(rval, !c_class_name!, ptr);

   if ( ptr ) return reinterpret_cast< !c_class_name!* >(ptr);

   T!class_ptrmap!::iterator it = !class_ptrmap!.find(rval);

   if ( it == !class_ptrmap!.end() ) {
      rb_raise(rb_eRuntimeError, "Unable to find !c_class_name! instance for value %x (type %d)\\n", rval, TYPE(rval));
      return NULL;
   }

   return reinterpret_cast< !c_class_name!* >((*it).second);
}


!c_class_name!& ruby2!class_varcname!Ptr(VALUE rval) {
  return *ruby2!class_varcname!Ptr(rval);
}


VALUE cxx2ruby(!c_class_name!* instance) {
  if ( instance == NULL ) return Qnil;

  T!class_ptrmap!::iterator it, eend = !class_ptrmap!.end();

  for(it = !class_ptrmap!.begin(); it != eend; it++)
     if ( (*it).second == (!c_class_name!*)instance ) break;

   if ( it != !class_ptrmap!.end() )
      return (*it).first;
   else {
      VALUE klass = r!class_varname!;

      VALUE rval = Data_Wrap_Struct(klass, 0, 0, (void*)instance);
      !class_ptrmap![rval] = instance;

#ifdef DEBUG      
      fprintf(stderr, "rust: wrapping instance %p in value %x (type %d)\\n", instance, rval, TYPE(rval));
#endif

      return rval;
   }
}

static VALUE !class_varname!_alloc(VALUE self) {
   return Data_Wrap_Struct(self, 0, !class_free_function!, 0);
}

static void !class_varname!_free(void *p) {
  T!class_ptrmap!::iterator it, eend = !class_ptrmap!.end();
  for(it = !class_ptrmap!.begin(); it != eend; it++)
     if ( (*it).second == (!c_class_name!*)p ) {
        !class_ptrmap!.erase(it); break;
     }

  !cleanup_functions!;
}

Version data entries

36 entries across 36 versions & 2 rubygems

Version Path
gecoder-with-gecode-1.1.1.1 vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl
gecoder-with-gecode-1.1.1 vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl
gecoder-1.1.1 vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl
gecoder-with-gecode-1.1.0 vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl
gecoder-1.1.0 vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl
gecoder-with-gecode-0.8.3-mswin32 vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl
gecoder-with-gecode-0.8.2-mswin32 vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl
gecoder-with-gecode-0.8.1-mswin32 vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl
gecoder-with-gecode-0.8.0-mswin32 vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl
gecoder-with-gecode-0.7.1-mswin32 vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl
gecoder-0.3.0 vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl
gecoder-0.2.0 vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl
gecoder-0.5.0 vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl
gecoder-0.4.0 vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl
gecoder-0.7.1 vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl
gecoder-0.8.2 vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl
gecoder-0.7.0 vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl
gecoder-0.8.0 vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl
gecoder-0.6.1 vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl
gecoder-0.6.0 vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl