File: wrap_rbBase.i

package info (click to toggle)
insighttoolkit4 4.13.3withdata-dfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 489,260 kB
  • sloc: cpp: 557,342; ansic: 146,850; fortran: 34,788; python: 16,572; sh: 2,187; lisp: 2,070; tcl: 993; java: 362; perl: 200; makefile: 129; csh: 81; pascal: 69; xml: 19; ruby: 10
file content (178 lines) | stat: -rw-r--r-- 6,229 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
%module rbBaseRuby

%include <exception.i>
%include <typemaps.i>

/*
%include std_alloc.i
%include std_basic_string.i
%include std_char_traits.i
%include std_common.i
%include std_complex.i
%include std_container.i
%include std_deque.i
%include std_except.i
%include std_functors.i
%include std_ios.i
%include std_iostream.i
%include std_list.i
%include std_map.i
%include std_multimap.i
%include std_multiset.i
%include std_pair.i
%include std_queue.i
%include std_set.i
%include std_sstream.i
%include std_stack.i
%include std_streambuf.i
%include std_string.i
%include std_vector.i
// %include std_vectora.i
// %include std_wstring.i
*/

%exception {
  try {
    $action
  } catch (const std::out_of_range& e) {
    SWIG_exception_fail(SWIG_IndexError, e.what());
//  } catch (Swig::DirectorException &e) {
//    SWIG_fail;
  } catch (const std::exception& e) {
    SWIG_exception_fail(SWIG_RuntimeError, e.what());
  }
}

//%feature("director:except") {
//    if ($error != NULL) {
//        throw Swig::DirectorMethodException();
//    }
//}

// ignore reference count management
%ignore Delete;
%ignore SetReferenceCount;
%ignore Register;
%ignore UnRegister;

// This macro replaces the use of itk::SmartPointer.
// class_name is class name without namespace qualifiers.
// Reference: http://www.nabble.com/attachment/16653644/0/SwigRefCount.i
%define DECLARE_REF_COUNT_CLASS(class_name)

        // pointers and references
        %typemap(out) class_name *, class_name & {
                // always tell SWIG_NewPointerObj we're the owner
                $result = SWIG_NewPointerObj((void *) $1, $1_descriptor, 1);
                if ($1) {
                        $1->Register();
                }
        }

  // transform smart pointers in raw pointers
        %typemap(out) class_name##_Pointer {
          // get the raw pointer from the smart pointer
          class_name * ptr = $1;
                // always tell SWIG_NewPointerObj we're the owner
                $result = SWIG_NewPointerObj((void *) ptr, $descriptor(class_name *), 1);
                // register the object, it it exists
                if (ptr) {
                        ptr->Register();
                }
        }

  // transform smart pointers in raw pointers
        %typemap(out) class_name##_Pointer & {
          // get the raw pointer from the smart pointer
          class_name * ptr = *$1;
                // always tell SWIG_NewPointerObj we're the owner
                $result = SWIG_NewPointerObj((void *) ptr, $descriptor(class_name *), 1);
                // register the object, it it exists
                if (ptr) {
                        ptr->Register();
                }
        }

        // make "deletion" in scripting language just decrement ref. count
        %extend class_name {
                public:
                ~class_name() {self->UnRegister();};
        }

        %ignore class_name::~class_name;

        %ignore class_name##_Pointer;

        // a cast() static method to downcast objects
        %extend class_name {
                public:
                static class_name * cast( itkLightObject * obj ) {
                  if( obj == NULL ) {
                    return NULL;
                  }
                  class_name * cast_obj = dynamic_cast<class_name *>(obj);
                  if( cast_obj == NULL ) {
                    throw std::bad_cast();
                  }
                  return cast_obj;
                };
        }

%enddef


// some code from stl
/*
%template(VectorString)   std::vector< std::string >;
%template(ListString)     std::list< std::string >;

%template(MapULD)         std::map< unsigned long, double >;
%template(MapBB)          std::map< bool, bool >;
%template(MapUCUC)        std::map< unsigned char, unsigned char >;
%template(MapUSUS)        std::map< unsigned short, unsigned short >;
%template(MapULUL)        std::map< unsigned long, unsigned long >;
%template(MapSCSC)        std::map< signed char, signed char >;
%template(MapSSSS)        std::map< signed short, signed short >;
%template(MapSLSL)        std::map< signed long, signed long >;
%template(MapFF)          std::map< float, float >;
%template(MapDD)          std::map< double, double >;

%template(VectorB)        std::vector< bool >;
%template(VectorvectorB)  std::vector< std::vector< bool > >;
%template(VectorUC)       std::vector< unsigned char >;
%template(VectorvectorUC) std::vector< std::vector< unsigned char > >;
%template(VectorUS)       std::vector< unsigned short >;
%template(VectorvectorUS) std::vector< std::vector< unsigned short > >;
%template(VectorUL)       std::vector< unsigned long >;
%template(VectorvectorUL) std::vector< std::vector< unsigned long > >;
%template(VectorSC)       std::vector< signed char >;
%template(VectorvectorSC) std::vector< std::vector< signed char > >;
%template(VectorSS)       std::vector< signed short >;
%template(VectorvectorSS) std::vector< std::vector< signed short > >;
%template(VectorSL)       std::vector< signed long >;
%template(VectorvectorSL) std::vector< std::vector< signed long > >;
%template(VectorF)        std::vector< float >;
%template(VectorvectorF)  std::vector< std::vector< float > >;
%template(VectorD)        std::vector< double >;
%template(VectorvectorD)  std::vector< std::vector< double > >;

%template(ListB)          std::list< bool >;
%template(ListUC)         std::list< unsigned char >;
%template(ListUS)         std::list< unsigned short >;
%template(ListUL)         std::list< unsigned long >;
%template(ListSC)         std::list< signed char >;
%template(ListSS)         std::list< signed short >;
%template(ListSL)         std::list< signed long >;
%template(ListF)          std::list< float >;
%template(ListD)          std::list< double >;

%template(SetB)          std::set< bool >;
%template(SetUC)         std::set< unsigned char >;
%template(SetUS)         std::set< unsigned short >;
%template(SetUL)         std::set< unsigned long >;
%template(SetSC)         std::set< signed char >;
%template(SetSS)         std::set< signed short >;
%template(SetSL)         std::set< signed long >;
%template(SetF)          std::set< float >;
%template(SetD)          std::set< double >;
*/