Show
Ignore:
Timestamp:
11/27/07 20:09:45 (12 months ago)
Author:
gyuque
Message:

lang/ruby/RubyESRIShape: polyline support

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/RubyESRIShape/RubyESRIShape.c

    r2059 r2062  
    214214                free(ptr); 
    215215        } 
     216} 
     217 
     218static VALUE rb_polyline_aref(VALUE self, VALUE index) 
     219{ 
     220        RPolylineData* indata; 
     221    Data_Get_Struct(self, RPolylineData, indata); 
     222 
     223        return c_Polyline_getPartAt(indata->pThis, NUM2LONG(index)); 
     224} 
     225 
     226static VALUE rb_polyline_length(VALUE self) 
     227{ 
     228        RPolylineData* indata; 
     229    Data_Get_Struct(self, RPolylineData, indata); 
     230 
     231        return INT2NUM( c_Polyline_getPartsLength(indata->pThis) ); 
     232} 
     233 
     234static VALUE rb_polyline_each(VALUE self) 
     235{ 
     236        RPolylineData* indata; 
     237        int len, i; 
     238    Data_Get_Struct(self, RPolylineData, indata); 
     239 
     240        len = c_Polyline_getPartsLength(indata->pThis); 
     241        for (i = 0;i < len;i++) 
     242        { 
     243                VALUE arr = rb_ary_new2(2); 
     244                rb_ary_push(arr, INT2NUM(i) ); 
     245                rb_ary_push(arr, c_Polyline_getPartAt(indata->pThis, i) ); 
     246 
     247                rb_yield(arr); 
     248        } 
     249 
     250        return self; 
    216251} 
    217252 
     
    344379        rb_cPolyline = rb_define_class_under (rb_mRubyESRIShape, "Polyline", rb_cObject); 
    345380        rb_define_alloc_func(rb_cPolyline, rb_polyline_allocate); 
     381        rb_define_method(rb_cPolyline, "length", rb_polyline_length, 0); 
     382        rb_define_method(rb_cPolyline, "[]"    , rb_polyline_aref  , 1); 
     383        rb_define_method(rb_cPolyline, "each"  , rb_polyline_each  , 0); 
    346384 
    347385        // class