XdmfCore.i 9.38 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
/*
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>
12
13
	#include <XdmfHeavyDataController.hpp>
	#include <XdmfHeavyDataWriter.hpp>
14
	#include <XdmfHDF5Controller.hpp>
15
	#include <XdmfHDF5Writer.hpp>
16
17
18
19
#ifdef XDMF_BUILD_DSM
	#include <XdmfHDF5ControllerDSM.hpp>
	#include <XdmfHDF5WriterDSM.hpp>
#endif
20
	#include <XdmfInformation.hpp>
21
22
	#include <XdmfItem.hpp>
	#include <XdmfItemProperty.hpp>
23
	#include <XdmfSystemUtils.hpp>
24
	#include <XdmfVisitor.hpp>
25
	#include <XdmfWriter.hpp>
26
27
28

    #include <ProjectVersion.hpp>
    #include <XdmfVersion.hpp>
29
30
%}

31
#ifdef SWIGJAVA
32

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

40
41
42
// Ignore ItemTags
%ignore XdmfArray::ItemTag;
%ignore XdmfInformation::ItemTag;
43

44
// Define equality operators
45
%extend XdmfItem {
46

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

66
%extend XdmfItemProperty {
67

68
69
	bool equals(boost::shared_ptr<XdmfItemProperty> itemProperty)
	{
70
71
72
73
		if (itemProperty == NULL)
		{
			return false;
		}
74
75
		return self == itemProperty.get();
	}
76
77
	
	bool IsEqual(boost::shared_ptr<XdmfItemProperty> itemProperty) 
78
	{
79
80
81
82
		if (itemProperty == NULL)
		{
			return false;
		}
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
		return self == itemProperty.get();
	}

};

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

#endif /* SWIGJAVA */
104

105
106
#ifdef SWIGPYTHON

107
// Provide accessors from python lists to XdmfArrays
108
%extend XdmfArray {
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
	
	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
	};
162

163
164
	%pythoncode 
	{
165
		def insertAsInt8(self, startIndex, values):
166
			for i in range(0, len(values)):
167
				self.insertValueAsInt8(i+startIndex, values[i])
168

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

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

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

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

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

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

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

197
		def insertAsUInt32(self, startIndex, values):
198
			for i in range(0, len(values)):
199
				self.insertValueAsUInt32(i+startIndex, values[i])
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
229
230
231
232
233
234
235
236
237
	
	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);
	}
	
238
};
239

240
// Define equality operator
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
%extend XdmfItem {

	bool __eq__(boost::shared_ptr<XdmfItem> item)
	{
		return self == item.get();
	}

};

%extend XdmfItemProperty {

	bool __eq__(boost::shared_ptr<XdmfItemProperty> itemProperty)
	{
		return self == itemProperty.get();
	}

};

#endif /* SWIGPYTHON */

261
262
263
264
%include boost_shared_ptr.i
%include std_string.i
%include std_vector.i
%include loki/Visitor.h
265

266
267
268
269
270
271
272
273
// Shared Pointer Templates
%shared_ptr(XdmfArray)
%shared_ptr(XdmfArrayType)
%shared_ptr(XdmfBaseVisitor)
%shared_ptr(XdmfCoreItemFactory)
%shared_ptr(XdmfCoreReader)
%shared_ptr(XdmfHDF5Controller)
%shared_ptr(XdmfHDF5Writer)
274
275
276
277
#ifdef XDMF_BUILD_DSM
	%shared_ptr(XdmfHDF5ControllerDSM)
	%shared_ptr(XdmfHDF5WriterDSM)
#endif
278
279
%shared_ptr(XdmfHeavyDataController)
%shared_ptr(XdmfHeavyDataWriter)
280
281
282
283
284
%shared_ptr(XdmfInformation)
%shared_ptr(XdmfItem)
%shared_ptr(XdmfItemProperty)
%shared_ptr(XdmfVisitor)
%shared_ptr(XdmfWriter)
285

286
287
288
289
// Abstract Base Classes
%template() Loki::BaseVisitable<void>;
%template() Loki::Visitor<XdmfArray>;
%template() Loki::Visitor<XdmfItem>;
290

291
292
293
%include XdmfItem.hpp
%include XdmfItemProperty.hpp
%include XdmfVisitor.hpp
294
295
296
%include XdmfHeavyDataController.hpp
%include XdmfHeavyDataWriter.hpp

297
298
299
300
301
302
303
%include XdmfCoreItemFactory.hpp
%include XdmfCoreReader.hpp
%include XdmfInformation.hpp
%include XdmfHDF5Controller.hpp
%include XdmfHDF5Writer.hpp
%include XdmfWriter.hpp

304
305
306
307
308
309
310
311
312
%include CMake/VersionSuite/ProjectVersion.hpp
%include XdmfVersion.hpp
#ifdef SWIGPYTHON
%pythoncode
{
    XdmfVersion = _XdmfCore.cvar.XdmfVersion
};
#endif

313
314
315
316
317
#ifdef XDMF_BUILD_DSM
	%include XdmfHDF5ControllerDSM.hpp
	%include XdmfHDF5WriterDSM.hpp
#endif

318
319
320
321
322
323
324
325
326
327
328
329
%include XdmfArray.hpp
%include XdmfArrayType.hpp

%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>;
330
331
332
333
334
335
336
337
338
339

%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>;
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359

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