Changeset 2015
- Timestamp:
- 11/26/07 02:16:22 (5 years ago)
- Location:
- lang/ruby/RubyESRIShape
- Files:
-
- 5 modified
-
RubyESRIShape.c (modified) (9 diffs)
-
Shape.cpp (modified) (6 diffs)
-
Shape.h (modified) (2 diffs)
-
Shape_int.h (modified) (3 diffs)
-
ruby_min.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/RubyESRIShape/RubyESRIShape.c
r2000 r2015 4 4 static VALUE rb_cShape = 0; 5 5 static VALUE rb_cPolygon = 0; 6 static VALUE rb_cPoint = 0; 6 7 7 8 VALUE getRubyESRIShapePolygonClass() 8 9 { 9 10 return rb_cPolygon; 11 } 12 13 VALUE getRubyESRIShapePointClass() 14 { 15 return rb_cPoint; 10 16 } 11 17 … … 23 29 static VALUE rb_polygon_allocate(VALUE klass); 24 30 static void rb_polygon_free(void *ptr); 31 static void rb_polygon_mark(void *ptr); 25 32 26 33 // Shape … … 36 43 static void rb_shape_free(void *ptr) 37 44 { 38 puts("del!");39 45 if (ptr) 40 46 { … … 48 54 static void rb_shape_mark(void *ptr) 49 55 { 50 puts("mk!");51 56 if (ptr) 52 57 { … … 72 77 { 73 78 RShapeData* indata; 74 es_error_t rv;75 79 Data_Get_Struct(self, RShapeData, indata); 76 80 … … 81 85 { 82 86 RShapeData* indata; 83 es_error_t rv;84 87 Data_Get_Struct(self, RShapeData, indata); 85 88 86 89 return INT2NUM( c_Shape_getLength(indata->pThis) ); 90 } 91 92 static VALUE rb_shape_each(VALUE self) 93 { 94 RShapeData* indata; 95 int len, i; 96 Data_Get_Struct(self, RShapeData, indata); 97 98 len = c_Shape_getLength(indata->pThis); 99 for (i = 0;i < len;i++) 100 { 101 VALUE arr = rb_ary_new2(2); 102 rb_ary_push(arr, INT2NUM(i+1) ); 103 rb_ary_push(arr, c_Shape_getRecordAt(indata->pThis, i+1) ); 104 105 rb_yield(arr); 106 } 107 108 return self; 87 109 } 88 110 … … 94 116 indata->pThis = NULL; 95 117 96 return Data_Wrap_Struct(klass, 0, rb_polygon_free, indata);118 return Data_Wrap_Struct(klass, rb_polygon_mark, rb_polygon_free, indata); 97 119 } 98 120 … … 107 129 } 108 130 131 static void rb_polygon_mark(void *ptr) 132 { 133 if (ptr) 134 { 135 if (((RPolygonData*)ptr)->pThis) 136 c_Polygon_markRubyGC(((RPolygonData*)ptr)->pThis); 137 } 138 } 139 140 static VALUE rb_polygon_aref(VALUE self, VALUE index) 141 { 142 RPolygonData* indata; 143 Data_Get_Struct(self, RPolygonData, indata); 144 145 return c_Polygon_getPartAt(indata->pThis, NUM2LONG(index)); 146 } 147 148 static VALUE rb_polygon_length(VALUE self) 149 { 150 RPolygonData* indata; 151 Data_Get_Struct(self, RPolygonData, indata); 152 153 return INT2NUM( c_Polygon_getPartsLength(indata->pThis) ); 154 } 155 156 static VALUE rb_polygon_each(VALUE self) 157 { 158 RPolygonData* indata; 159 int len, i; 160 Data_Get_Struct(self, RPolygonData, indata); 161 162 len = c_Polygon_getPartsLength(indata->pThis); 163 for (i = 0;i < len;i++) 164 { 165 VALUE arr = rb_ary_new2(2); 166 rb_ary_push(arr, INT2NUM(i) ); 167 rb_ary_push(arr, c_Polygon_getPartAt(indata->pThis, i) ); 168 169 rb_yield(arr); 170 } 171 172 return self; 173 } 109 174 110 175 void Init_RubyESRIShape() … … 120 185 121 186 rb_define_private_method(rb_cShape, "initialize", rb_shape_initialize, 1); 122 rb_define_method(rb_cShape, "[]", rb_shape_aref, 1);187 rb_define_method(rb_cShape, "[]", rb_shape_aref , 1); 123 188 rb_define_method(rb_cShape, "length", rb_shape_length, 0); 189 rb_define_method(rb_cShape, "each", rb_shape_each , 0); 124 190 125 191 // class 126 192 rb_cPolygon = rb_define_class_under (rb_mRubyESRIShape, "Polygon", rb_cObject); 127 193 rb_define_alloc_func(rb_cPolygon, rb_polygon_allocate); 194 rb_define_method(rb_cPolygon, "[]" , rb_polygon_aref , 1); 195 rb_define_method(rb_cPolygon, "length", rb_polygon_length, 0); 196 rb_define_method(rb_cPolygon, "each" , rb_polygon_each , 0); 197 198 // class 199 rb_cPoint = rb_define_class_under (rb_mRubyESRIShape, "Point", rb_cObject); 128 200 129 201 } -
lang/ruby/RubyESRIShape/Shape.cpp
r2001 r2015 54 54 ShpReadContext rctx; 55 55 rctx.readSize = 0; 56 57 _tprintf(_T("%s\n"), filename);58 56 59 57 mSHPFHeader.filecode = freadBig32(fp); … … 191 189 void Shape::markRubyGC() 192 190 { 193 R ecordList::iterator it;191 RValueList::iterator it; 194 192 for (it = mRORecords.begin();it != mRORecords.end();it++) 195 193 rb_gc_mark(*it); … … 255 253 256 254 ESInt32 i; 255 257 256 for (i = 0;i < mNParts;i++) 258 257 { … … 268 267 rctx.readSize += 16; 269 268 rctx.readRecordContentSize += 16; 270 271 269 } 272 270 … … 319 317 } 320 318 319 void ShpPolygon::markRubyGC() 320 { 321 } 322 323 VALUE ShpPolygon::getPartAt(int index) 324 { 325 if (index < 0 || index >= mNParts) 326 return Qnil; 327 328 int len = (index == (mNParts-1)) ? mNPoints : mPartIndexes[index+1]; 329 len -= mPartIndexes[index]; 330 331 VALUE arr = rb_ary_new2(len); 332 for (int i = 0;i < len;i++) 333 rb_ary_push(arr, INT2FIX(9 /*dmy*/ )); 334 335 return arr; 336 } 337 338 int ShpPolygon::getPartsLength() 339 { 340 return mNParts; 341 } 342 343 344 321 345 void* c_Shape_new() 322 346 {return new Shape();} … … 339 363 void c_Polygon_delete(void* pThis) 340 364 {delete (ShpPolygon*)pThis;} 365 366 void c_Polygon_markRubyGC(void* pThis) 367 {((ShpPolygon*)pThis)->markRubyGC();} 368 369 VALUE c_Polygon_getPartAt(void* pThis, int index) 370 {return ((ShpPolygon*)pThis)->getPartAt(index);} 371 372 int c_Polygon_getPartsLength(void* pThis) 373 {return ((ShpPolygon*)pThis)->getPartsLength();} -
lang/ruby/RubyESRIShape/Shape.h
r2000 r2015 96 96 SHPFileHeader mSHPFHeader; 97 97 98 R ecordList mRORecords;98 RValueList mRORecords; 99 99 }; 100 100 … … 110 110 111 111 void* c_Shape_new(); 112 void c_Shape_delete(void* pThis);112 void c_Shape_delete(void* pThis); 113 113 es_error_t c_Shape_readFromFile(void* pThis, const TCHAR* filename); 114 114 VALUE c_Shape_getRecordAt(void* pThis, int index); 115 int c_Shape_getLength(void* pThis);116 void c_Shape_markRubyGC(void* pThis);115 int c_Shape_getLength(void* pThis); 116 void c_Shape_markRubyGC(void* pThis); 117 117 118 void c_Polygon_delete(void* pThis); 118 void c_Polygon_delete(void* pThis); 119 void c_Polygon_markRubyGC(void* pThis); 120 VALUE c_Polygon_getPartsArray(void* pThis); 121 VALUE c_Polygon_getPartAt(void* pThis, int index); 122 int c_Polygon_getPartsLength(void* pThis); 119 123 120 124 #ifdef __cplusplus -
lang/ruby/RubyESRIShape/Shape_int.h
r2000 r2015 5 5 6 6 #include <vector> 7 typedef std::vector<VALUE> R ecordList;7 typedef std::vector<VALUE> RValueList; 8 8 9 9 typedef struct _ShpReadContext { … … 29 29 virtual ~ShpPolygon(); 30 30 virtual VALUE toRubyObject(); 31 VALUE getPartAt(int index); 32 int getPartsLength(); 33 34 void markRubyGC(); 31 35 32 36 es_error_t readFromMainFile(FILE* fp, ShpReadContext& rctx); … … 49 53 }; 50 54 55 class ShpPoint : public ShpRecordObject 56 { 57 public: 58 ShpPoint(); 59 virtual ~ShpPoint(); 60 virtual VALUE toRubyObject(); 61 }; 62 51 63 #endif -
lang/ruby/RubyESRIShape/ruby_min.h
r2000 r2015 1 1 typedef unsigned long VALUE; 2 2 #define Qnil ((VALUE)4) 3 extern "C" VALUE rb_class_new_instance(int, VALUE*, VALUE); 4 extern "C" void rb_gc_mark (VALUE); 3 extern "C" { 4 VALUE rb_class_new_instance(int, VALUE*, VALUE); 5 void rb_gc_mark (VALUE); 6 VALUE rb_ary_new2 (long); 7 VALUE rb_yield (VALUE); 8 VALUE rb_ary_push (VALUE, VALUE); 9 } 10 11 #define FIXNUM_FLAG 0x01 12 #define INT2FIX(i) ((VALUE)(((long)(i))<<1 | FIXNUM_FLAG)) 5 13 6 14 struct RBasic {
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)