- added to_a functions
authorArvin Schnell <aschnell@suse.de>
Thu, 23 Aug 2007 15:07:25 +0000 (15:07 +0000)
committerArvin Schnell <aschnell@suse.de>
Thu, 23 Aug 2007 15:07:25 +0000 (15:07 +0000)
package/libzypp-bindings.changes
swig/ruby/ruby.i

index 13f0284..9136f0a 100644 (file)
@@ -1,4 +1,9 @@
 -------------------------------------------------------------------
+Thu Aug 23 17:10:56 CEST 2007 - aschnell@suse.de
+
+- added to_a functions
+
+-------------------------------------------------------------------
 Thu Aug 23 12:49:01 CEST 2007 - aschnell@suse.de
 
 - added some comparison functions
index 20fe3d3..5782df3 100644 (file)
@@ -1,19 +1,31 @@
 
 
 /*
- *  Extend cls with an ruby-like each iterator.  Yields objects of type storetype.
- *  Parameter storetype must be a pointer type.
+ *  Extend cls with an ruby-like each iterator and a to_a method.  Yields
+ *  objects of type storetype.  Parameter storetype must be a pointer type.
  */
 #define iter2(cls, storetype) \
 %mixin cls "Enumerable"; \
-%extend cls { \
+%extend cls \
+{ \
     void each() { \
        cls::const_iterator i = self->begin(); \
         while (i != self->end()) { \
            const storetype tmp = &**i; \
            rb_yield(SWIG_NewPointerObj((void*) tmp, $descriptor(storetype), 0)); \
-            ++i; \
+            i++; \
+        } \
+    } \
+\
+    VALUE to_a() { \
+        VALUE ary = rb_ary_new(); \
+       cls::const_iterator i = self->begin(); \
+        while (i != self->end()) { \
+           const storetype tmp = &**i; \
+            rb_ary_push(ary, SWIG_NewPointerObj((void*) tmp, $descriptor(storetype), 0)); \
+            i++; \
         } \
+        return ary; \
     } \
 }
 
  */
 #define iter3(cls, storetype) \
 %mixin cls "Enumerable"; \
-%extend cls { \
+%extend cls \
+{ \
     void each() { \
        cls::const_iterator i = self->begin(); \
         while (i != self->end()) { \
            const storetype tmp = &*i; \
            rb_yield(SWIG_NewPointerObj((void*) tmp, $descriptor(storetype), 0)); \
-            ++i; \
+            i++; \
+        } \
+    } \
+\
+    VALUE to_a() { \
+        VALUE ary = rb_ary_new(); \
+       cls::const_iterator i = self->begin(); \
+        while (i != self->end()) { \
+           const storetype tmp = &*i; \
+            rb_ary_push(ary, SWIG_NewPointerObj((void*) tmp, $descriptor(storetype), 0)); \
+            i++; \
         } \
+        return ary; \
     } \
 }