XdmfCore.i 10.6 KB
Newer Older
1
2
3
4
5
6
7
/*
XdmfCorePython.cpp:
swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
*/

%module XdmfCore
%{
8

9
10
11
12
13
14
15
16
17
    #include <XdmfArray.hpp>
    #include <XdmfArrayType.hpp>
    #include <XdmfCore.hpp>
    #include <XdmfCoreItemFactory.hpp>
    #include <XdmfCoreReader.hpp>
    #include <XdmfHeavyDataController.hpp>
    #include <XdmfHeavyDataWriter.hpp>
    #include <XdmfHDF5Controller.hpp>
    #include <XdmfHDF5Writer.hpp>
18
#ifdef XDMF_BUILD_DSM
19
20
    #include <XdmfHDF5ControllerDSM.hpp>
    #include <XdmfHDF5WriterDSM.hpp>
21
#endif
22
23
24
25
26
27
28
    #include <XdmfInformation.hpp>
    #include <XdmfItem.hpp>
    #include <XdmfItemProperty.hpp>
    #include <XdmfSystemUtils.hpp>
    #include <XdmfVersion.hpp>
    #include <XdmfVisitor.hpp>
    #include <XdmfWriter.hpp>
29
30

    #include <ProjectVersion.hpp>
31
32
%}

33
#ifdef SWIGJAVA
34

35
// Ignore const overloaded methods
36
%ignore XdmfArray::getHeavyDataController() const;
37
38
39
%ignore XdmfArray::getValuesInternal() const;
%ignore XdmfItem::getInformation(const unsigned int) const;
%ignore XdmfItem::getInformation(const std::string &) const;
40
%ignore XdmfWriter::getHeavyDataWriter() const;
41

42
43
44
// Ignore ItemTags
%ignore XdmfArray::ItemTag;
%ignore XdmfInformation::ItemTag;
45

46
// Define equality operators
47
%extend XdmfItem {
48

49
50
51
52
53
54
55
56
57
58
59
60
61
    bool equals(boost::shared_ptr<XdmfItem> item) {
        if (item == NULL) {
            return false;
        }
        return self == item.get();
    }

    bool IsEqual(boost::shared_ptr<XdmfItem> item) {
        if (item == NULL) {
            return false;
        }
        return self == item.get();
    }
62
};
63

64
%extend XdmfItemProperty {
65

66
67
68
69
70
71
72
73
74
75
76
77
78
    bool equals(boost::shared_ptr<XdmfItemProperty> itemProperty) {
        if (itemProperty == NULL) {
            return false;
        }
        return self == itemProperty.get();
    }

    bool IsEqual(boost::shared_ptr<XdmfItemProperty> itemProperty) {
        if (itemProperty == NULL) {
            return false;
        }
        return self == itemProperty.get();
    }
79
80
81
82

};

%pragma(java) jniclasscode=%{
83
84
85
86
87
88
89
90
91
92
    static {
        try {
            System.loadLibrary("XdmfCoreJava");
        }
        catch (UnsatisfiedLinkError e) {
            System.err.println("Native code library failed to load for
                                XdmfCoreJava\n" + e);
            System.exit(1);
        }
    }
93
94
95
%}

#endif /* SWIGJAVA */
96

97
98
#ifdef SWIGPYTHON

99
// Provide accessors from python lists to XdmfArrays
100
%extend XdmfArray {
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228

    PyObject * getBuffer() {
        void *vp = $self->getValuesInternal();
        Py_ssize_t sz =
            $self->getSize() * $self->getArrayType()->getElementSize();
        PyObject * c = PyBuffer_FromMemory(vp, sz);
        return(c);
    }

    %pythoncode {
        def getNumpyArray(self):
            h5ctl = self.getHDF5Controller()
            if h5ctl == None :
                try :
                    from numpy import frombuffer as ___frombuffer
                except :
                    return None
                buf = self.getBuffer()
                aType = self.getArrayType()
                if aType == XdmfArrayType.Int8() :
                    return(___frombuffer(buf, 'int8'))
                if aType == XdmfArrayType.Int16() :
                    return(___frombuffer(buf, 'int16'))
                if aType == XdmfArrayType.Int32() :
                    return(___frombuffer(buf, 'int32'))
                if aType == XdmfArrayType.Int64() :
                    return(___frombuffer(buf, 'int64'))
                if aType == XdmfArrayType.Float32() :
                    return(___frombuffer(buf, 'float32'))
                if aType == XdmfArrayType.Float64() :
                    return(___frombuffer(buf, 'float64'))
                if aType == XdmfArrayType.UInt8() :
                    return(___frombuffer(buf, 'uint8'))
                if aType == XdmfArrayType.UInt16() :
                    return(___frombuffer(buf, 'uint16'))
                if aType == XdmfArrayType.UInt32() :
                    return(___frombuffer(buf, 'uint32'))
                return None
            else :
                h5FileName = h5ctl.getFilePath()
                h5DataSetName = h5ctl.getDataSetPath()
                if (h5FileName == None) | (h5DataSetName == None) :
                    return None
                try :
                    from h5py import File as ___File
                    from numpy import array as ___array
                    f = ___File(h5FileName, 'r')
                    if h5DataSetName in f.keys() :
                        return(___array(f[h5DataSetName]))
                except :
                    pass
                return None
    };

    %pythoncode {
        def insertAsInt8(self, startIndex, values):
            for i in range(0, len(values)):
                self.insertValueAsInt8(i+startIndex, values[i])

        def insertAsInt16(self, startIndex, values):
            for i in range(0, len(values)):
                self.insertValueAsInt16(i+startIndex, values[i])

        def insertAsInt32(self, startIndex, values):
            for i in range(0, len(values)):
                self.insertValueAsInt32(i+startIndex, values[i])

        def insertAsInt64(self, startIndex, values):
            for i in range(0, len(values)):
                self.insertValueAsInt64(i+startIndex, values[i])

        def insertAsFloat32(self, startIndex, values):
            for i in range(0, len(values)):
                self.insertValueAsFloat32(i+startIndex, values[i])

        def insertAsFloat64(self, startIndex, values):
            for i in range(0, len(values)):
                self.insertValueAsFloat64(i+startIndex, values[i])

        def insertAsUInt8(self, startIndex, values):
            for i in range(0, len(values)):
                self.insertValueAsUInt8(i+startIndex, values[i])

        def insertAsUInt16(self, startIndex, values):
            for i in range(0, len(values)):
                self.insertValueAsUInt16(i+startIndex, values[i])

        def insertAsUInt32(self, startIndex, values):
            for i in range(0, len(values)):
                self.insertValueAsUInt32(i+startIndex, values[i])
    };

    void insertValueAsInt8(int index, char value) {
        $self->insert(index, value);
    }

    void insertValueAsInt16(int index, short value) {
        $self->insert(index, value);
    }

    void insertValueAsInt32(int index, int value) {
        $self->insert(index, value);
    }

    void insertValueAsInt64(int index, long value) {
        $self->insert(index, value);
    }

    void insertValueAsFloat32(int index, float value) {
        $self->insert(index, value);
    }

    void insertValueAsFloat64(int index, double value) {
        $self->insert(index, value);
    }

    void insertValueAsUInt8(int index, unsigned char value) {
        $self->insert(index, value);
    }

    void insertValueAsUInt16(int index, unsigned short value) {
        $self->insert(index, value);
    }

    void insertValueAsUInt32(int index, unsigned int value) {
        $self->insert(index, value);
    }

229
};
230

231
// Define equality operators
232
233
%extend XdmfItem {

234
235
236
    bool __eq__(boost::shared_ptr<XdmfItem> item) {
        return self == item.get();
    }
237
238
239
240
241

};

%extend XdmfItemProperty {

242
243
244
    bool __eq__(boost::shared_ptr<XdmfItemProperty> itemProperty) {
        return self == itemProperty.get();
    }
245
246
247
248
249

};

#endif /* SWIGPYTHON */

250
251
252
253
%include boost_shared_ptr.i
%include std_string.i
%include std_vector.i
%include loki/Visitor.h
254

255
256
257
258
259
260
261
262
// Shared Pointer Templates
%shared_ptr(XdmfArray)
%shared_ptr(XdmfArrayType)
%shared_ptr(XdmfBaseVisitor)
%shared_ptr(XdmfCoreItemFactory)
%shared_ptr(XdmfCoreReader)
%shared_ptr(XdmfHDF5Controller)
%shared_ptr(XdmfHDF5Writer)
263
#ifdef XDMF_BUILD_DSM
264
265
    %shared_ptr(XdmfHDF5ControllerDSM)
    %shared_ptr(XdmfHDF5WriterDSM)
266
#endif
267
268
%shared_ptr(XdmfHeavyDataController)
%shared_ptr(XdmfHeavyDataWriter)
269
270
271
272
273
%shared_ptr(XdmfInformation)
%shared_ptr(XdmfItem)
%shared_ptr(XdmfItemProperty)
%shared_ptr(XdmfVisitor)
%shared_ptr(XdmfWriter)
274

275
276
277
278
// Abstract Base Classes
%template() Loki::BaseVisitable<void>;
%template() Loki::Visitor<XdmfArray>;
%template() Loki::Visitor<XdmfItem>;
279

280
%include XdmfCore.hpp
281
282
283
%include XdmfItem.hpp
%include XdmfItemProperty.hpp
%include XdmfVisitor.hpp
284
285
286
%include XdmfHeavyDataController.hpp
%include XdmfHeavyDataWriter.hpp

287
288
289
290
291
292
293
%include XdmfCoreItemFactory.hpp
%include XdmfCoreReader.hpp
%include XdmfInformation.hpp
%include XdmfHDF5Controller.hpp
%include XdmfHDF5Writer.hpp
%include XdmfWriter.hpp

294
295
296
%include CMake/VersionSuite/ProjectVersion.hpp
%include XdmfVersion.hpp

297
#ifdef XDMF_BUILD_DSM
298
299
    %include XdmfHDF5ControllerDSM.hpp
    %include XdmfHDF5WriterDSM.hpp
300
301
#endif

302
303
304
%include XdmfArray.hpp
%include XdmfArrayType.hpp

305
306
307
308
309
310
311
312
#ifdef SWIGPYTHON

%pythoncode {
    XdmfVersion = _XdmfCore.cvar.XdmfVersion
};

#endif /* SWIGPYTHON */

313
314
315
316
317
318
319
320
321
%template(getValueAsInt8) XdmfArray::getValue<char>;
%template(getValueAsInt16) XdmfArray::getValue<short>;
%template(getValueAsInt32) XdmfArray::getValue<int>;
%template(getValueAsInt64) XdmfArray::getValue<long>;
%template(getValueAsFloat32) XdmfArray::getValue<float>;
%template(getValueAsFloat64) XdmfArray::getValue<double>;
%template(getValueAsUInt8) XdmfArray::getValue<unsigned char>;
%template(getValueAsUInt16) XdmfArray::getValue<unsigned short>;
%template(getValueAsUInt32) XdmfArray::getValue<unsigned int>;
322
323
324
325
326
327
328
329
330
331

%template(initializeAsInt8) XdmfArray::initialize<char>;
%template(initializeAsInt16) XdmfArray::initialize<short>;
%template(initializeAsInt32) XdmfArray::initialize<int>;
%template(initializeAsInt64) XdmfArray::initialize<long>;
%template(initializeAsFloat32) XdmfArray::initialize<float>;
%template(initializeAsFloat64) XdmfArray::initialize<double>;
%template(initializeAsUInt8) XdmfArray::initialize<unsigned char>;
%template(initializeAsUInt16) XdmfArray::initialize<unsigned short>;
%template(initializeAsUInt32) XdmfArray::initialize<unsigned int>;
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351

%template(pushBackAsInt8) XdmfArray::pushBack<char>;
%template(pushBackAsInt16) XdmfArray::pushBack<short>;
%template(pushBackAsInt32) XdmfArray::pushBack<int>;
%template(pushBackAsInt64) XdmfArray::pushBack<long>;
%template(pushBackAsFloat32) XdmfArray::pushBack<float>;
%template(pushBackAsFloat64) XdmfArray::pushBack<double>;
%template(pushBackAsUInt8) XdmfArray::pushBack<unsigned char>;
%template(pushBackAsUInt16) XdmfArray::pushBack<unsigned short>;
%template(pushBackAsUInt32) XdmfArray::pushBack<unsigned int>;

%template(resizeAsInt8) XdmfArray::resize<char>;
%template(resizeAsInt16) XdmfArray::resize<short>;
%template(resizeAsInt32) XdmfArray::resize<int>;
%template(resizeAsInt64) XdmfArray::resize<long>;
%template(resizeAsFloat32) XdmfArray::resize<float>;
%template(resizeAsFloat64) XdmfArray::resize<double>;
%template(resizeAsUInt8) XdmfArray::resize<unsigned char>;
%template(resizeAsUInt16) XdmfArray::resize<unsigned short>;
%template(resizeAsUInt32) XdmfArray::resize<unsigned int>;