PageRenderTime 27ms CodeModel.GetById 21ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/ruby/free_function/example.i

#
Swig | 41 lines | 21 code | 10 blank | 10 comment | 0 complexity | ea0d7f322373c8b3465a7828324f24a7 MD5 | raw file
 1%module example
 2
 3%{
 4#include "example.h"
 5%}
 6
 7/* Specify that ownership is transferred to the zoo
 8	when calling add_animal */
 9%apply SWIGTYPE *DISOWN { Animal* animal };
10
11/* Track objects */
12%trackobjects;
13
14/* Specify the mark function */
15%freefunc Zoo "free_Zoo";
16
17%include "example.h"
18
19%header %{
20	static void free_Zoo(void* ptr) {
21		Zoo* zoo = (Zoo*) ptr;
22
23		/* Loop over each object and call SWIG_RubyRemoveTracking */
24		int count = zoo->get_num_animals();
25
26		for(int i = 0; i < count; ++i) {
27			/* Get an animal */
28			Animal* animal = zoo->get_animal(i);
29			/* Unlink the Ruby object from the C++ object */
30			SWIG_RubyUnlinkObjects(animal);
31			/* Now remove the tracking for this animal */
32			SWIG_RubyRemoveTracking(animal);
33		}
34
35	   /* Now call SWIG_RubyRemoveTracking for the zoo */
36		SWIG_RubyRemoveTracking(ptr);
37
38		/* Now free the zoo which will free the animals it contains */
39		delete zoo;
40	}
41%}