PageRenderTime 11ms CodeModel.GetById 3ms app.highlight 2ms RepoModel.GetById 3ms app.codeStats 0ms

/trunk/Lib/ruby/rubyprimtypes.swg

#
Unknown | 216 lines | 187 code | 29 blank | 0 comment | 0 complexity | 6be2e62eccc63d5ac2442427d2a88c3a MD5 | raw file
  1/* -----------------------------------------------------------------------------
  2 * rubyprimtypes.swg
  3 * ----------------------------------------------------------------------------- */
  4/* ------------------------------------------------------------
  5 * Primitive Types
  6 * ------------------------------------------------------------ */
  7
  8/* auxiliary ruby fail method */
  9
 10%fragment("SWIG_ruby_failed","header")
 11{
 12SWIGINTERN VALUE
 13SWIG_ruby_failed(void)
 14{
 15  return Qnil;
 16} 
 17}
 18
 19%define %ruby_aux_method(Type, Method, Action)
 20SWIGINTERN VALUE SWIG_AUX_##Method##(VALUE *args)
 21{
 22  VALUE obj = args[0];
 23  VALUE type = TYPE(obj);
 24  Type *res = (Type *)(args[1]);
 25  *res = Action;
 26  return obj;
 27}
 28%enddef
 29
 30
 31/* boolean */
 32
 33%fragment(SWIG_From_frag(bool),"header") {
 34SWIGINTERNINLINE VALUE
 35SWIG_From_dec(bool)(bool value)
 36{
 37  return value ? Qtrue : Qfalse;
 38}
 39}
 40
 41%fragment(SWIG_AsVal_frag(bool),"header",
 42	  fragment=SWIG_AsVal_frag(int)) {
 43SWIGINTERN int
 44SWIG_AsVal_dec(bool)(VALUE obj, bool *val)
 45{
 46  if (obj == Qtrue) {
 47    if (val) *val = true;
 48    return SWIG_OK;
 49  } else if (obj == Qfalse) {
 50    if (val) *val = false;
 51    return SWIG_OK;
 52  } else {
 53    int res = 0;
 54    if (SWIG_AsVal(int)(obj, &res) == SWIG_OK) {    
 55      if (val) *val = res ? true : false;
 56      return SWIG_OK;
 57    }
 58  }  
 59  return SWIG_TypeError;
 60}
 61}
 62
 63/* long */
 64
 65%fragment(SWIG_From_frag(long),"header",
 66	  fragment="<limits.h>") {
 67  %define_as(SWIG_From_dec(long),           LONG2NUM)
 68}
 69
 70%fragment(SWIG_AsVal_frag(long),"header",fragment="SWIG_ruby_failed") {
 71%ruby_aux_method(long, NUM2LONG, type == T_FIXNUM ? NUM2LONG(obj) : rb_big2long(obj))
 72
 73SWIGINTERN int
 74SWIG_AsVal_dec(long)(VALUE obj, long* val)
 75{
 76  VALUE type = TYPE(obj);
 77  if ((type == T_FIXNUM) || (type == T_BIGNUM)) {
 78    long v;
 79    VALUE a[2];
 80    a[0] = obj;
 81    a[1] = (VALUE)(&v);
 82    if (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2LONG), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
 83      if (val) *val = v;
 84      return SWIG_OK;
 85    }
 86  }
 87  return SWIG_TypeError;
 88}
 89}
 90
 91/* unsigned long */
 92
 93%fragment(SWIG_From_frag(unsigned long),"header",
 94	  fragment=SWIG_From_frag(long)) {
 95SWIGINTERNINLINE VALUE
 96SWIG_From_dec(unsigned long)(unsigned long value)
 97{
 98  return ULONG2NUM(value); 
 99}
100}
101
102%fragment(SWIG_AsVal_frag(unsigned long),"header",fragment="SWIG_ruby_failed") {
103%ruby_aux_method(unsigned long, NUM2ULONG, type == T_FIXNUM ? NUM2ULONG(obj) : rb_big2ulong(obj))
104
105SWIGINTERN int
106SWIG_AsVal_dec(unsigned long)(VALUE obj, unsigned long *val) 
107{
108  VALUE type = TYPE(obj);
109  if ((type == T_FIXNUM) || (type == T_BIGNUM)) {
110    unsigned long v;
111    VALUE a[2];
112    a[0] = obj;
113    a[1] = (VALUE)(&v);
114    if (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2ULONG), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
115      if (val) *val = v;
116      return SWIG_OK;
117    }
118  }
119  return SWIG_TypeError;
120}
121}
122
123/* long long */
124
125%fragment(SWIG_From_frag(long long),"header",
126	  fragment=SWIG_From_frag(long),
127	  fragment="<limits.h>") {
128SWIGINTERNINLINE VALUE 
129SWIG_From_dec(long long)(long long value)
130{
131  return LL2NUM(value);
132}
133}
134
135%fragment(SWIG_AsVal_frag(long long),"header",fragment="SWIG_ruby_failed") {
136%ruby_aux_method(long long, NUM2LL, type == T_FIXNUM ? NUM2LL(obj) : rb_big2ll(obj))
137
138SWIGINTERN int
139SWIG_AsVal_dec(long long)(VALUE obj, long long *val)
140{
141  VALUE type = TYPE(obj);
142  if ((type == T_FIXNUM) || (type == T_BIGNUM)) {
143    long long v;
144    VALUE a[2];
145    a[0] = obj;
146    a[1] = (VALUE)(&v);
147    if (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2LL), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
148      if (val) *val = v;
149      return SWIG_OK;
150    }
151  }
152  return SWIG_TypeError;
153}
154}
155
156/* unsigned long long */
157
158%fragment(SWIG_From_frag(unsigned long long),"header",
159	  fragment=SWIG_From_frag(long long),
160	  fragment="<limits.h>") {
161SWIGINTERNINLINE VALUE 
162SWIG_From_dec(unsigned long long)(unsigned long long value)
163{
164  return ULL2NUM(value);
165}
166}
167
168%fragment(SWIG_AsVal_frag(unsigned long long),"header",fragment="SWIG_ruby_failed") {
169%ruby_aux_method(long long, NUM2ULL,  type == T_FIXNUM ? NUM2ULL(obj) : rb_big2ull(obj))
170
171SWIGINTERN int
172SWIG_AsVal_dec(unsigned long long)(VALUE obj, unsigned long long *val)
173{ 
174  VALUE type = TYPE(obj);
175  if ((type == T_FIXNUM) || (type == T_BIGNUM)) {
176    unsigned long long v;
177    VALUE a[2];
178    a[0] = obj;
179    a[1] = (VALUE)(&v);
180    if (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2ULL), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
181      if (val) *val = v;
182      return SWIG_OK;
183    }
184  }
185  return SWIG_TypeError;
186}
187}
188
189/* double */
190
191%fragment(SWIG_From_frag(double),"header") {
192  %define_as(SWIG_From_dec(double),  rb_float_new)
193}
194
195%fragment(SWIG_AsVal_frag(double),"header",fragment="SWIG_ruby_failed") {
196%ruby_aux_method(double, NUM2DBL, NUM2DBL(obj))
197
198SWIGINTERN int
199SWIG_AsVal_dec(double)(VALUE obj, double *val)
200{
201  VALUE type = TYPE(obj);
202  if ((type == T_FLOAT) || (type == T_FIXNUM) || (type == T_BIGNUM)) {
203    double v;
204    VALUE a[2];
205    a[0] = obj;
206    a[1] = (VALUE)(&v);
207    if (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2DBL), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
208      if (val) *val = v;
209      return SWIG_OK;
210    }
211  }
212  return SWIG_TypeError;
213}
214}
215
216