XdmfCore.i 8.99 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
/*
XdmfCorePython.cpp:
swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
*/

%module XdmfCore
%{
	#include <XdmfArray.hpp>
	#include <XdmfArrayType.hpp>
	#include <XdmfCoreItemFactory.hpp>
	#include <XdmfCoreReader.hpp>
	#include <XdmfHDF5Controller.hpp>
13
	#include <XdmfHDF5Writer.hpp>
14
	#include <XdmfInformation.hpp>
15
16
	#include <XdmfItem.hpp>
	#include <XdmfItemProperty.hpp>
17
	#include <XdmfSystemUtils.hpp>
18
	#include <XdmfVisitor.hpp>
19
	#include <XdmfWriter.hpp>
20
21
22
23
24
25
26
%}

%include boost_shared_ptr.i
%include std_string.i
%include std_vector.i
%include loki/Visitor.h

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifdef SWIGJAVA
    %extend XdmfArrayType {
            bool equals(boost::shared_ptr<XdmfArrayType> arrayType) {
                    return(self->IsEqual(arrayType));
            }
    };
    %ignore XdmfArrayType::operator==(const XdmfArrayType & arrayType) const;
    %ignore XdmfArrayType::operator!=(const XdmfArrayType & arrayType) const;
#endif


#ifdef SWIGPYTHON
%extend XdmfArrayType {
  bool __eq__(boost::shared_ptr<XdmfArrayType> arrayType) {
    return(self->IsEqual(arrayType));
  }
};
#endif

46
47
48
49
50
51
52
53
// Shared Pointer Templates
%shared_ptr(XdmfArray)
%shared_ptr(XdmfArrayType)
%shared_ptr(XdmfBaseVisitor)
%shared_ptr(XdmfCoreItemFactory)
%shared_ptr(XdmfCoreReader)
%shared_ptr(XdmfHDF5Controller)
%shared_ptr(XdmfHDF5Writer)
54
%shared_ptr(XdmfInformation)
55
56
57
%shared_ptr(XdmfItem)
%shared_ptr(XdmfItemProperty)
%shared_ptr(XdmfVisitor)
58
59
60
61
62
63
%shared_ptr(XdmfWriter)

// Abstract Base Classes
%template() Loki::BaseVisitable<void>;
%template() Loki::Visitor<XdmfArray>;
%template() Loki::Visitor<XdmfItem>;
64

65
#ifdef SWIGJAVA
66
67
%ignore XdmfArray::getHDF5Controller() const;
%ignore XdmfArray::getValuesInternal() const;
68
69
%ignore XdmfArray::ItemTag;
%ignore XdmfInformation::ItemTag;
70
71
%ignore XdmfItem::getInformation(const unsigned int index) const;
%ignore XdmfItem::getInformation(const std::string & name) const;
72
73
74
75
76
77
78
79
80
81
82
83
%ignore XdmfWriter::getHDF5Writer() const;

%pragma(java) jniclasscode=%{
  static {
    try {
        System.loadLibrary("XdmfCoreJava");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load for XdmfCoreJava\n" + e);
      System.exit(1);
    }
  }
%}
84
#endif /* SWIGJAVA */
85

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifdef SWIGPYTHON
%extend XdmfItem {
  bool __eq__(boost::shared_ptr<XdmfItem> item) {
    return(self->IsEqual(item));
  }
};
#endif

#ifdef SWIGJAVA
%extend XdmfItem {
  bool equals(boost::shared_ptr<XdmfItem> item) {
    return(self->IsEqual(item));
  }
};
#endif

102
103
104
105
106
107
%include XdmfItem.hpp
%include XdmfItemProperty.hpp
%include XdmfVisitor.hpp

%include XdmfCoreItemFactory.hpp
%include XdmfCoreReader.hpp
108
%include XdmfInformation.hpp
109
110
%include XdmfHDF5Controller.hpp
%include XdmfHDF5Writer.hpp
111
%include XdmfWriter.hpp
112
113
114
115

%include XdmfArray.hpp
%include XdmfArrayType.hpp

116
117
118
119
120
121
122
123
124
%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>;
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

%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>;

146
#ifndef SWIGJAVA
147
148
// Provide accessors from python lists to XdmfArrays
%extend XdmfArray {
149
150
        PyObject * getBuffer ()
        {
151
152
                void *vp = $self->getValuesInternal();
                Py_ssize_t sz = $self->getSize() * $self->getElementSize();
153
154
155
156
157
                PyObject * c = PyBuffer_FromMemory(vp, sz);
                return(c);
        }
        %pythoncode {
                def getNumpyArray(self):
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
                        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
199
200
201
        };


202
	void copyValueAsInt8(int index, char value) {
203
		$self->insert(index, value);
204
205
206
	}

	void copyValueAsInt16(int index, short value) {
207
		$self->insert(index, value);
208
209
210
	}

	void copyValueAsInt32(int index, int value) {
211
		$self->insert(index, value);
212
213
214
	}

	void copyValueAsInt64(int index, long value) {
215
		$self->insert(index, value);
216
217
218
	}

	void copyValueAsFloat32(int index, float value) {
219
		$self->insert(index, value);
220
221
222
	}

	void copyValueAsFloat64(int index, double value) {
223
		$self->insert(index, value);
224
225
226
	}

	void copyValueAsUInt8(int index, unsigned char value) {
227
		$self->insert(index, value);
228
229
230
	}

	void copyValueAsUInt16(int index, unsigned short value) {
231
		$self->insert(index, value);
232
233
234
	}

	void copyValueAsUInt32(int index, unsigned int value) {
235
		$self->insert(index, value);
236
237
238
239
240
	}
};

%extend XdmfArray {
	%pythoncode {
241
		def insertAsInt8(self, startIndex, values):
242
243
244
			for i in range(0, len(values)):
				self.copyValueAsInt8(i+startIndex, values[i])

245
		def insertAsInt16(self, startIndex, values):
246
247
248
			for i in range(0, len(values)):
				self.copyValueAsInt16(i+startIndex, values[i])

249
		def insertAsInt32(self, startIndex, values):
250
251
252
			for i in range(0, len(values)):
				self.copyValueAsInt32(i+startIndex, values[i])

253
		def insertAsInt64(self, startIndex, values):
254
255
256
			for i in range(0, len(values)):
				self.copyValueAsInt64(i+startIndex, values[i])

257
		def insertAsFloat32(self, startIndex, values):
258
259
260
			for i in range(0, len(values)):
				self.copyValueAsFloat32(i+startIndex, values[i])

261
		def insertAsFloat64(self, startIndex, values):
262
263
264
			for i in range(0, len(values)):
				self.copyValueAsFloat64(i+startIndex, values[i])

265
		def insertAsUInt8(self, startIndex, values):
266
267
268
			for i in range(0, len(values)):
				self.copyValueAsUInt8(i+startIndex, values[i])

269
		def insertAsUInt16(self, startIndex, values):
270
271
272
			for i in range(0, len(values)):
				self.copyValueAsUInt16(i+startIndex, values[i])

273
		def insertAsUInt32(self, startIndex, values):
274
275
276
277
			for i in range(0, len(values)):
				self.copyValueAsUInt32(i+startIndex, values[i])
	};
};
278
#endif /* SWIGJAVA */
279