From 3bf9df6b2785fa6d951086978a3e66f49427166a Mon Sep 17 00:00:00 2001 From: FluorescentCIAAfricanAmerican <0934gj3049fk@protonmail.com> Date: Wed, 22 Apr 2020 12:56:21 -0400 Subject: 1 --- devtools/swigwin-1.3.34/Lib/ruby/rubystdcommon.swg | 265 +++++++++++++++++++++ 1 file changed, 265 insertions(+) create mode 100644 devtools/swigwin-1.3.34/Lib/ruby/rubystdcommon.swg (limited to 'devtools/swigwin-1.3.34/Lib/ruby/rubystdcommon.swg') diff --git a/devtools/swigwin-1.3.34/Lib/ruby/rubystdcommon.swg b/devtools/swigwin-1.3.34/Lib/ruby/rubystdcommon.swg new file mode 100644 index 0000000..4e1b9d9 --- /dev/null +++ b/devtools/swigwin-1.3.34/Lib/ruby/rubystdcommon.swg @@ -0,0 +1,265 @@ + +/* ------------------------------------------------------------ + * The Ruby classes, for C++ + * ------------------------------------------------------------ */ +%include + +%fragment("StdTraits","header",fragment="StdTraitsCommon") +{ + +namespace swig { + /* + Traits that provides the from method + */ + template struct traits_from_ptr { + static VALUE from(Type *val, int owner = 0) { + return SWIG_NewPointerObj(val, type_info(), owner); + } + }; + + template struct traits_from { + static VALUE from(const Type& val) { + return traits_from_ptr::from(new Type(val), 1); + } + }; + + template struct traits_from { + static VALUE from(Type* val) { + return traits_from_ptr::from(val, 0); + } + }; + + template struct traits_from { + static VALUE from(const Type* val) { + return traits_from_ptr::from(const_cast(val), 0); + } + }; + + + template + inline VALUE from(const Type& val) { + return traits_from::from(val); + } + + template + inline VALUE from_ptr(Type* val, int owner) { + return traits_from_ptr::from(val, owner); + } + + /* + Traits that provides the asval/as/check method + */ + template + struct traits_asptr { + static int asptr(VALUE obj, Type **val) { + Type *p; + int res = SWIG_ConvertPtr(obj, (void**)&p, type_info(), 0); + if (SWIG_IsOK(res)) { + if (val) *val = p; + } + return res; + } + }; + + template + inline int asptr(VALUE obj, Type **vptr) { + return traits_asptr::asptr(obj, vptr); + } + + template + struct traits_asval { + static int asval(VALUE obj, Type *val) { + if (val) { + Type *p = 0; + int res = traits_asptr::asptr(obj, &p); + if (!SWIG_IsOK(res)) return res; + if (p) { + typedef typename noconst_traits::noconst_type noconst_type; + *(const_cast(val)) = *p; + if (SWIG_IsNewObj(res)){ + %delete(p); + res = SWIG_DelNewMask(res); + } + return res; + } else { + return SWIG_ERROR; + } + } else { + return traits_asptr::asptr(obj, (Type **)(0)); + } + } + }; + + template struct traits_asval { + static int asval(VALUE obj, Type **val) { + if (val) { + typedef typename noconst_traits::noconst_type noconst_type; + noconst_type *p = 0; + int res = traits_asptr::asptr(obj, &p); + if (SWIG_IsOK(res)) { + *(const_cast(val)) = p; + } + return res; + } else { + return traits_asptr::asptr(obj, (Type **)(0)); + } + } + }; + + template + inline int asval(VALUE obj, Type *val) { + return traits_asval::asval(obj, val); + } + + template + struct traits_as { + static Type as(VALUE obj, bool throw_error) { + Type v; + int res = asval(obj, &v); + if (!obj || !SWIG_IsOK(res)) { + if (throw_error) throw std::invalid_argument("bad type"); + VALUE lastErr = rb_gv_get("$!"); + if (lastErr == Qnil) { + %type_error(swig::type_name()); + } + } + return v; + } + }; + + template + struct traits_as { + static Type as(VALUE obj, bool throw_error) { + Type *v = 0; + int res = (obj ? traits_asptr::asptr(obj, &v) : SWIG_ERROR); + if (SWIG_IsOK(res) && v) { + if (SWIG_IsNewObj(res)) { + Type r(*v); + %delete(v); + return r; + } else { + return *v; + } + } else { + // Uninitialized return value, no Type() constructor required. + if (throw_error) throw std::invalid_argument("bad type"); + VALUE lastErr = rb_gv_get("$!"); + if (lastErr == Qnil) { + %type_error(swig::type_name()); + } + static Type *v_def = (Type*) malloc(sizeof(Type)); + memset(v_def,0,sizeof(Type)); + return *v_def; + } + } + }; + + template + struct traits_as { + static Type* as(VALUE obj, bool throw_error) { + Type *v = 0; + int res = (obj ? traits_asptr::asptr(obj, &v) : SWIG_ERROR); + if (SWIG_IsOK(res)) { + return v; + } else { + if (throw_error) throw std::invalid_argument("bad type"); + VALUE lastErr = rb_gv_get("$!"); + if (lastErr == Qnil) { + %type_error(swig::type_name()); + } + return 0; + } + } + }; + + template + inline Type as(VALUE obj, bool te = false) { + return traits_as< Type, typename traits< Type >::category >::as(obj, te); + } + + template + struct traits_check { + static bool check(VALUE obj) { + int res = obj ? asval(obj, (Type *)(0)) : SWIG_ERROR; + return SWIG_IsOK(res) ? true : false; + } + }; + + template + struct traits_check { + static bool check(VALUE obj) { + int res = obj ? asptr(obj, (Type **)(0)) : SWIG_ERROR; + return SWIG_IsOK(res) ? true : false; + } + }; + + template + inline bool check(VALUE obj) { + return traits_check::category>::check(obj); + } +} +} + + +// Define GC marking template traits for a container type +%define %create_mark_traits(Type) +%{ + namespace swig { + template + struct mark_traits { + typedef typename Type::const_iterator const_iterator; + + inline void operator()(const Type& c ) const + { + const_iterator i = c.begin(); + const_iterator e = c.end(); + for ( ; i != e; ++i ) + { + rb_gc_mark( swig::from( &(*i) ) ); + } + } + }; + + // Partial specializations for classes that requires no GC marking + // or a special GC marking algorithm. + template< > + struct mark_traits { + inline void operator()(const Type& c ) const {} + }; + + template< > + struct mark_traits { + inline void operator()(const Type& c ) const {} + }; + + template< > + struct mark_traits { + inline void operator()(const Type& c ) const {} + }; + + template< > + struct mark_traits { + inline void operator()(const Type& c ) const {} + }; + + template< > + struct mark_traits { + typedef Type::const_iterator const_iterator; + + inline void operator()(const Type& c ) const { + const_iterator i = c.begin(); + const_iterator e = c.end(); + for ( ; i != e; ++i ) + { + VALUE v = *i; + if ( FIXNUM_P(v) || SPECIAL_CONST_P(v) || SYMBOL_P(v) || + ( BUILTIN_TYPE(v) == T_NONE ) ) continue; + + rb_gc_mark( v ); + } + } + }; + + } +%} +%enddef -- cgit v1.2.3