Commit e6f105ce authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Improve python interface by rewriting swig wrapping and moving XdmfObject

destructors to be publicly accessible.  Modify tests to work with new wrapping.
parent 5b153544
......@@ -6,6 +6,7 @@ swig -v -c++ -python -o XdmfPython.cpp Xdmf.i
%module Xdmf
%{
#include <XdmfArray.hpp>
#include <XdmfArrayType.hpp>
#include <XdmfAttribute.hpp>
#include <XdmfAttributeCenter.hpp>
#include <XdmfAttributeType.hpp>
......@@ -30,58 +31,38 @@ swig -v -c++ -python -o XdmfPython.cpp Xdmf.i
#include <XdmfWriter.hpp>
%}
namespace boost {
template<class T> class shared_ptr
{
public:
T * operator-> () const;
};
}
// Macro for defining shared pointer templates:
%define SWIG_SHARED_PTR_TEMPLATE(CLASS...)
%template(CLASS ## _Ptr) boost::shared_ptr< CLASS >;
%template(CLASS ## _ConstPtr) boost::shared_ptr< const CLASS >;
%enddef
// Macro for defining shared pointer inheritances:
%define SWIG_SHARED_PTR_DERIVED(CLASS, BASECLASS...)
%types(boost::shared_ptr< CLASS > = boost::shared_ptr< BASECLASS > ) %{
boost::shared_ptr< BASECLASS > p = *(boost::shared_ptr< CLASS >*)$from;
boost::shared_ptr< BASECLASS > * pPtr = &p;
return pPtr;
%}
%enddef
%include boost_shared_ptr.i
%include std_string.i
%include std_vector.i
%include loki/Visitor.h
// Shared Pointer Templates
SWIG_SHARED_PTR_TEMPLATE(XdmfArray);
SWIG_SHARED_PTR_TEMPLATE(XdmfAttribute);
SWIG_SHARED_PTR_TEMPLATE(XdmfAttributeCenter);
SWIG_SHARED_PTR_TEMPLATE(XdmfAttributeType);
SWIG_SHARED_PTR_TEMPLATE(XdmfBaseVisitor);
SWIG_SHARED_PTR_TEMPLATE(XdmfDataItem);
SWIG_SHARED_PTR_TEMPLATE(XdmfDomain);
SWIG_SHARED_PTR_TEMPLATE(XdmfGeometry);
SWIG_SHARED_PTR_TEMPLATE(XdmfGeometryType);
SWIG_SHARED_PTR_TEMPLATE(XdmfGrid);
SWIG_SHARED_PTR_TEMPLATE(XdmfGridCollection);
SWIG_SHARED_PTR_TEMPLATE(XdmfGridCollectionType);
SWIG_SHARED_PTR_TEMPLATE(XdmfHDF5Controller);
SWIG_SHARED_PTR_TEMPLATE(XdmfHDF5Writer);
SWIG_SHARED_PTR_TEMPLATE(XdmfItem);
SWIG_SHARED_PTR_TEMPLATE(XdmfItemProperty);
SWIG_SHARED_PTR_TEMPLATE(XdmfObject);
SWIG_SHARED_PTR_TEMPLATE(XdmfReader);
SWIG_SHARED_PTR_TEMPLATE(XdmfSet);
SWIG_SHARED_PTR_TEMPLATE(XdmfSetType);
SWIG_SHARED_PTR_TEMPLATE(XdmfTopology);
SWIG_SHARED_PTR_TEMPLATE(XdmfTopologyType);
SWIG_SHARED_PTR_TEMPLATE(XdmfVisitor);
SWIG_SHARED_PTR_TEMPLATE(XdmfWriter);
%shared_ptr(XdmfArray)
%shared_ptr(XdmfAttribute)
%shared_ptr(XdmfBaseVisitor)
%shared_ptr(XdmfDataItem)
%shared_ptr(XdmfDomain)
%shared_ptr(XdmfGeometry)
%shared_ptr(XdmfGrid)
%shared_ptr(XdmfGridCollection)
%shared_ptr(XdmfHDF5Controller)
%shared_ptr(XdmfHDF5Writer)
%shared_ptr(XdmfItem)
%shared_ptr(XdmfItemProperty)
%shared_ptr(XdmfObject)
%shared_ptr(XdmfReader)
%shared_ptr(XdmfSet)
%shared_ptr(XdmfTopology)
%shared_ptr(XdmfVisitor)
%shared_ptr(XdmfWriter)
%shared_ptr(XdmfArrayType)
%shared_ptr(XdmfAttributeCenter)
%shared_ptr(XdmfAttributeType)
%shared_ptr(XdmfGeometryType)
%shared_ptr(XdmfGridCollectionType)
%shared_ptr(XdmfSetType)
%shared_ptr(XdmfTopologyType)
// Abstract Base Classes
%template() Loki::BaseVisitable<void>;
......@@ -93,54 +74,6 @@ SWIG_SHARED_PTR_TEMPLATE(XdmfWriter);
%template() Loki::Visitor<XdmfItem>;
%template() Loki::Visitor<XdmfTopology>;
SWIG_SHARED_PTR_DERIVED(XdmfArray, XdmfItem);
SWIG_SHARED_PTR_DERIVED(XdmfArray, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfAttribute, XdmfDataItem);
SWIG_SHARED_PTR_DERIVED(XdmfAttribute, XdmfItem);
SWIG_SHARED_PTR_DERIVED(XdmfAttribute, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfAttributeCenter, XdmfItemProperty)
SWIG_SHARED_PTR_DERIVED(XdmfAttributeCenter, XdmfObject)
SWIG_SHARED_PTR_DERIVED(XdmfAttributeType, XdmfItemProperty)
SWIG_SHARED_PTR_DERIVED(XdmfAttributeType, XdmfObject)
SWIG_SHARED_PTR_DERIVED(XdmfDataItem, XdmfItem);
SWIG_SHARED_PTR_DERIVED(XdmfDataItem, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfDomain, XdmfItem);
SWIG_SHARED_PTR_DERIVED(XdmfDomain, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfGeometry, XdmfDataItem);
SWIG_SHARED_PTR_DERIVED(XdmfGeometry, XdmfItem);
SWIG_SHARED_PTR_DERIVED(XdmfGeometry, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfGeometryType, XdmfItemProperty)
SWIG_SHARED_PTR_DERIVED(XdmfGeometryType, XdmfObject)
SWIG_SHARED_PTR_DERIVED(XdmfGrid, XdmfItem);
SWIG_SHARED_PTR_DERIVED(XdmfGrid, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfGridCollection, XdmfGrid);
SWIG_SHARED_PTR_DERIVED(XdmfGridCollection, XdmfItem);
SWIG_SHARED_PTR_DERIVED(XdmfGridCollection, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfGridCollectionType, XdmfItemProperty)
SWIG_SHARED_PTR_DERIVED(XdmfGridCollectionType, XdmfObject)
SWIG_SHARED_PTR_DERIVED(XdmfHDF5Controller, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfHDF5Writer, XdmfVisitor);
SWIG_SHARED_PTR_DERIVED(XdmfHDF5Writer, Loki::BaseVisitor);
SWIG_SHARED_PTR_DERIVED(XdmfHDF5Writer, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfItem, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfItemProperty, XdmfObject)
SWIG_SHARED_PTR_DERIVED(XdmfReader, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfSet, XdmfDataItem);
SWIG_SHARED_PTR_DERIVED(XdmfSet, XdmfItem);
SWIG_SHARED_PTR_DERIVED(XdmfSet, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfSetType, XdmfItemProperty)
SWIG_SHARED_PTR_DERIVED(XdmfSetType, XdmfObject)
SWIG_SHARED_PTR_DERIVED(XdmfTopology, XdmfDataItem);
SWIG_SHARED_PTR_DERIVED(XdmfTopology, XdmfItem);
SWIG_SHARED_PTR_DERIVED(XdmfTopology, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfTopologyType, XdmfItemProperty)
SWIG_SHARED_PTR_DERIVED(XdmfTopologyType, XdmfObject)
SWIG_SHARED_PTR_DERIVED(XdmfVisitor, XdmfBaseVisitor);
SWIG_SHARED_PTR_DERIVED(XdmfVisitor, XdmfObject);
SWIG_SHARED_PTR_DERIVED(XdmfWriter, XdmfVisitor);
SWIG_SHARED_PTR_DERIVED(XdmfWriter, XdmfBaseVisitor);
SWIG_SHARED_PTR_DERIVED(XdmfWriter, XdmfObject);
%include XdmfObject.hpp
%include XdmfItem.hpp
......@@ -157,6 +90,7 @@ SWIG_SHARED_PTR_DERIVED(XdmfWriter, XdmfObject);
%include XdmfAttributeCenter.hpp
%include XdmfAttributeType.hpp
%include XdmfArray.hpp
%include XdmfArrayType.hpp
%include XdmfDomain.hpp
%include XdmfGeometry.hpp
%include XdmfGeometryType.hpp
......@@ -169,81 +103,111 @@ SWIG_SHARED_PTR_DERIVED(XdmfWriter, XdmfObject);
%include XdmfGridCollection.hpp
%include XdmfGridCollectionType.hpp
%template(getValueCopyAsInt8) XdmfArray::getValueCopy<char>;
%template(getValueCopyAsInt16) XdmfArray::getValueCopy<short>;
%template(getValueCopyAsInt32) XdmfArray::getValueCopy<int>;
%template(getValueCopyAsInt64) XdmfArray::getValueCopy<long>;
%template(getValueCopyAsFloat32) XdmfArray::getValueCopy<float>;
%template(getValueCopyAsFloat64) XdmfArray::getValueCopy<double>;
%template(getValueCopyAsUInt8) XdmfArray::getValueCopy<unsigned char>;
%template(getValueCopyAsUInt16) XdmfArray::getValueCopy<unsigned short>;
%template(getValueCopyAsUInt32) XdmfArray::getValueCopy<unsigned int>;
%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>;
// Provide accessors from python lists to XdmfArrays
%extend XdmfArray {
void copyValueAsChar(int index, char value) {
void copyValueAsInt8(int index, char value) {
$self->copyValues(index, &value);
}
void copyValueAsShort(int index, short value) {
void copyValueAsInt16(int index, short value) {
$self->copyValues(index, &value);
}
void copyValueAsInt(int index, int value) {
void copyValueAsInt32(int index, int value) {
$self->copyValues(index, &value);
}
void copyValueAsLong(int index, long value) {
void copyValueAsInt64(int index, long value) {
$self->copyValues(index, &value);
}
void copyValueAsFloat(int index, float value) {
void copyValueAsFloat32(int index, float value) {
$self->copyValues(index, &value);
}
void copyValueAsDouble(int index, double value) {
void copyValueAsFloat64(int index, double value) {
$self->copyValues(index, &value);
}
void copyValueAsUChar(int index, unsigned char value) {
void copyValueAsUInt8(int index, unsigned char value) {
$self->copyValues(index, &value);
}
void copyValueAsUShort(int index, unsigned short value) {
void copyValueAsUInt16(int index, unsigned short value) {
$self->copyValues(index, &value);
}
void copyValueAsUInt(int index, unsigned int value) {
void copyValueAsUInt32(int index, unsigned int value) {
$self->copyValues(index, &value);
}
};
%extend boost::shared_ptr<XdmfArray> {
%extend XdmfArray {
%pythoncode {
def copyValuesAsChar(self, startIndex, values):
def copyValuesAsInt8(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsChar(i+startIndex, values[i])
self.copyValueAsInt8(i+startIndex, values[i])
def copyValuesAsShort(self, startIndex, values):
def copyValuesAsInt16(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsShort(i+startIndex, values[i])
self.copyValueAsInt16(i+startIndex, values[i])
def copyValuesAsInt(self, startIndex, values):
def copyValuesAsInt32(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsInt(i+startIndex, values[i])
self.copyValueAsInt32(i+startIndex, values[i])
def copyValuesAsLong(self, startIndex, values):
def copyValuesAsInt64(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsLong(i+startIndex, values[i])
self.copyValueAsInt64(i+startIndex, values[i])
def copyValuesAsFloat(self, startIndex, values):
def copyValuesAsFloat32(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsFloat(i+startIndex, values[i])
self.copyValueAsFloat32(i+startIndex, values[i])
def copyValuesAsDouble(self, startIndex, values):
def copyValuesAsFloat64(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsDouble(i+startIndex, values[i])
self.copyValueAsFloat64(i+startIndex, values[i])
def copyValuesAsUChar(self, startIndex, values):
def copyValuesAsUInt8(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsUChar(i+startIndex, values[i])
self.copyValueAsUInt8(i+startIndex, values[i])
def copyValuesAsUShort(self, startIndex, values):
def copyValuesAsUInt16(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsUShort(i+startIndex, values[i])
self.copyValueAsUInt16(i+startIndex, values[i])
def copyValuesAsUInt(self, startIndex, values):
def copyValuesAsUInt32(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsUInt(i+startIndex, values[i])
self.copyValueAsUInt32(i+startIndex, values[i])
};
};
......@@ -431,7 +431,12 @@ boost::shared_ptr<const XdmfArrayType> XdmfArray::getType() const
return XdmfArrayType::Uninitialized();
}
const void * const XdmfArray::getValuesPointer() const
void * XdmfArray::getValuesPointer()
{
return const_cast<void *>(static_cast<const XdmfArray &>(*this).getValuesPointer());
}
const void * XdmfArray::getValuesPointer() const
{
if(mHaveArray)
{
......
......@@ -20,7 +20,7 @@ class XdmfHDF5Controller;
* By Copy:
*
* copyValues
* getCopyValues
* getValuesCopy
*
* XdmfArray stores its own copy of the data. Modifications to the data stored in the XdmfArray will
* not change values stored in the original array.
......@@ -35,21 +35,23 @@ class XdmfHDF5Controller;
* array.
*
* Xdmf supports the following datatypes:
* Char
* Short
* Int
* Long
* Float
* Double
* Unsigned Char
* Unsigned Short
* Unsigned Int
* Int8
* Int16
* Int32
* Int64
* Float32
* Float64
* UInt8
* UInt16
* UInt32
*/
class XdmfArray : public XdmfItem {
public:
XdmfNewMacro(XdmfArray);
virtual ~XdmfArray();
LOKI_DEFINE_VISITABLE(XdmfArray, XdmfItem)
friend class XdmfHDF5Writer;
static std::string ItemTag;
......@@ -67,7 +69,7 @@ public:
void copyValues(const unsigned int startIndex, const boost::shared_ptr<const XdmfArray> values, const unsigned int valuesStartIndex= 0, const unsigned int numValues = 1, const unsigned int arrayStride = 1, const unsigned int valuesStride = 1);
/**
* Copy values from an array into this array.
* Copy values into this array.
*
* @param startIndex the index in this XdmfArray to begin insertion.
* @param valuesPointer a pointer to the values to copy into this XdmfArray.
......@@ -144,14 +146,6 @@ public:
template <typename T>
boost::shared_ptr<std::vector<T> > getValues();
/**
* Get a smart pointer to the values stored in this array (const version).
*
* @return a smart pointer to the internal vector of values stored in this array.
*/
//template <typename T>
//const boost::shared_ptr<const std::vector<T> > getValues() const;
/**
* Get a copy of the values stored in this array
*
......@@ -164,12 +158,19 @@ public:
template <typename T>
void getValuesCopy(const unsigned int startIndex, T * const valuesPointer, const unsigned int numValues = 1, const unsigned int arrayStride = 1, const unsigned int valuesStride = 1) const;
/**
* Get a pointer to the values stored in this array.
*
* @return a void pointer to the first value stored in this array.
*/
void * getValuesPointer();
/**
* Get a pointer to the values stored in this array (const version).
*
* @return a void pointer to the first value stored in this array.
*/
const void * const getValuesPointer() const;
const void * getValuesPointer() const;
/**
* Get the values stored in this array as a string.
......@@ -300,7 +301,6 @@ public:
protected:
XdmfArray();
virtual ~XdmfArray();
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems);
private:
......
......@@ -27,8 +27,9 @@ class XdmfArrayType : public XdmfItemProperty {
public:
virtual ~XdmfArrayType();
friend class XdmfArray;
template <typename T> friend void boost::checked_delete(T * x);
// Supported XdmfArrayTypes
static boost::shared_ptr<const XdmfArrayType> Uninitialized();
......@@ -71,7 +72,6 @@ protected:
* @param precision the precision, in bytes, of the XdmfArrayType to construct.
*/
XdmfArrayType(const std::string & name, const unsigned int precision);
~XdmfArrayType();
private:
......
......@@ -19,6 +19,8 @@ class XdmfAttribute : public XdmfDataItem {
public:
XdmfNewMacro(XdmfAttribute);
virtual ~XdmfAttribute();
LOKI_DEFINE_VISITABLE(XdmfAttribute, XdmfDataItem)
static std::string ItemTag;
......@@ -71,7 +73,6 @@ public:
protected:
XdmfAttribute();
virtual ~XdmfAttribute();
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems);
private:
......
......@@ -22,8 +22,9 @@ class XdmfAttributeCenter : public XdmfItemProperty {
public:
virtual ~XdmfAttributeCenter();
friend class XdmfAttribute;
template <typename T> friend void boost::checked_delete(T * x);
// Supported Xdmf Attribute Centers
static boost::shared_ptr<const XdmfAttributeCenter> Grid();
......@@ -60,7 +61,6 @@ protected:
* @param name the name of the XdmfAttributeCenter to construct.
*/
XdmfAttributeCenter(const std::string & name);
~XdmfAttributeCenter();
private:
......
......@@ -24,8 +24,9 @@ class XdmfAttributeType : public XdmfItemProperty {
public:
virtual ~XdmfAttributeType();
friend class XdmfAttribute;
template <typename T> friend void boost::checked_delete(T * x);
// Supported Xdmf Attribute Types
static boost::shared_ptr<const XdmfAttributeType> NoAttributeType();
......@@ -64,7 +65,6 @@ protected:
* @param name the name of the XdmfAttributeType to construct.
*/
XdmfAttributeType(const std::string & name);
~XdmfAttributeType();
private:
......
......@@ -17,6 +17,8 @@ class XdmfDataItem : public XdmfItem {
public:
virtual ~XdmfDataItem();
LOKI_DEFINE_VISITABLE(XdmfDataItem, XdmfItem)
/**
......@@ -45,7 +47,6 @@ public:
protected:
XdmfDataItem();
virtual ~XdmfDataItem();
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem > > & childItems);
private:
......
......@@ -18,6 +18,8 @@ class XdmfDomain : public XdmfItem {
public:
XdmfNewMacro(XdmfDomain);
virtual ~XdmfDomain();
LOKI_DEFINE_VISITABLE(XdmfDomain, XdmfItem)
static std::string ItemTag;
......@@ -67,7 +69,6 @@ public:
protected:
XdmfDomain();
virtual ~XdmfDomain();
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems);
private:
......
......@@ -19,6 +19,8 @@ class XdmfGeometry : public XdmfDataItem {
public:
XdmfNewMacro(XdmfGeometry);
virtual ~XdmfGeometry();
LOKI_DEFINE_VISITABLE(XdmfGeometry, XdmfDataItem)
static std::string ItemTag;
......@@ -48,7 +50,6 @@ public:
protected:
XdmfGeometry();
virtual ~XdmfGeometry();
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems);
private:
......
......@@ -68,6 +68,10 @@ XdmfGeometryType::XdmfGeometryType(const std::string& name, const int& dimension
{
}
XdmfGeometryType::~XdmfGeometryType()
{
}
boost::shared_ptr<const XdmfGeometryType> XdmfGeometryType::New(const std::map<std::string, std::string> & itemProperties)
{
std::map<std::string, std::string>::const_iterator type = itemProperties.find("GeometryType");
......
......@@ -26,8 +26,9 @@ class XdmfGeometryType : public XdmfItemProperty {
public:
virtual ~XdmfGeometryType();
friend class XdmfGeometry;
template <typename T> friend void boost::checked_delete(T * x);
// Supported Xdmf Geometry Types
static boost::shared_ptr<const XdmfGeometryType> NoGeometryType();
......
......@@ -23,6 +23,8 @@ class XdmfGrid : public XdmfItem {
public:
XdmfNewMacro(XdmfGrid);
virtual ~XdmfGrid();
LOKI_DEFINE_VISITABLE(XdmfGrid, XdmfItem)
static std::string ItemTag;
......@@ -181,7 +183,6 @@ public:
protected:
XdmfGrid();
virtual ~XdmfGrid();
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems);
std::string mName;
......
......@@ -20,6 +20,8 @@ class XdmfGridCollection : public XdmfGrid {
public:
XdmfNewMacro(XdmfGridCollection);
virtual ~XdmfGridCollection();
LOKI_DEFINE_VISITABLE(XdmfGridCollection, XdmfGrid)
static std::string ItemTag;
......@@ -81,7 +83,6 @@ public:
protected:
XdmfGridCollection();
virtual ~XdmfGridCollection();
virtual void populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems);
private:
......
......@@ -31,6 +31,10 @@ XdmfGridCollectionType::XdmfGridCollectionType(const std::string & name) :
{
}
XdmfGridCollectionType::~XdmfGridCollectionType()
{
}
boost::shared_ptr<const XdmfGridCollectionType> XdmfGridCollectionType::New(const std::map<std::string, std::string> & itemProperties)
{
std::map<std::string, std::string>::const_iterator type = itemProperties.find("CollectionType");
......
......@@ -20,8 +20,9 @@ class XdmfGridCollectionType : public XdmfItemProperty {
public:
virtual ~XdmfGridCollectionType();
friend class XdmfGridCollection;
template <typename T> friend void boost::checked_delete(T * x);
// Supported XdmfGridCollectionTypes
static boost::shared_ptr<const XdmfGridCollectionType> NoCollectionType();
......
......@@ -63,73 +63,15 @@ boost::shared_ptr<const XdmfArrayType> XdmfHDF5Controller::getType() const
void XdmfHDF5Controller::read(XdmfArray * const array)
{
hid_t hdf5Handle = H5Fopen(mHDF5FilePath.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
hid_t hdf5Handle = H5Fopen(mHDF5FilePath.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
hid_t dataset = H5Dopen(hdf5Handle, mDataSetName.c_str(), H5P_DEFAULT);
hid_t dataspace = H5Dget_space(dataset);
hssize_t numVals = H5Sget_simple_extent_npoints(dataspace);
hid_t datatype = H5Dget_type(dataset);
void * valuesPointer;
if(H5Tequal(datatype, H5T_NATIVE_CHAR))
{
boost::shared_ptr<std::vector<char> > arrayValues = array->initialize<char>();
array->resize(numVals, 0);
valuesPointer = &arrayValues->operator[](0);
}
else if(H5Tequal(datatype, H5T_NATIVE_SHORT))
{
boost::shared_ptr<std::vector<short> > arrayValues = array->initialize<short>();
array->resize(numVals, 0);
valuesPointer = &arrayValues->operator[](0);
}
else if(H5Tequal(datatype, H5T_NATIVE_INT))
{
boost::shared_ptr<std::vector<int> > arrayValues = array->initialize<int>();
array->resize(numVals, 0);
valuesPointer = &arrayValues->operator[](0);
}
else if(H5Tequal(datatype, H5T_NATIVE_LONG))
{
boost::shared_ptr<std::vector<long> > arrayValues = array->initialize<long>();
array->resize(numVals, 0);
valuesPointer = &arrayValues->operator[](0);
}
else if(H5Tequal(datatype, H5T_NATIVE_FLOAT))
{
boost::shared_ptr<std::vector<float> > arrayValues = array->initialize<float>();
array->resize(numVals, 0);
valuesPointer = &arrayValues->operator[](0);
}
else if(H5Tequal(datatype, H5T_NATIVE_DOUBLE))
{
boost::shared_ptr<std::vector<double> > arrayValues = array->initialize<double>();
array->resize(numVals, 0);
valuesPointer = &arrayValues->operator[](0);
}
else if(H5Tequal(datatype, H5T_NATIVE_UCHAR))
{
boost::shared_ptr<std::vector<unsigned char> > arrayValues = array->initialize<unsigned char>();
array->resize(numVals, 0);
valuesPointer = &arrayValues->operator[](0);
}
else if(H5Tequal(datatype, H5T_NATIVE_USHORT))
{
boost::shared_ptr<std::vector<unsigned short> > arrayValues = array->initialize<unsigned short>();
array->resize(numVals, 0);
valuesPointer = &arrayValues->operator[](0);
}
else if(H5Tequal(datatype, H5T_NATIVE_UINT))
{
boost::shared_ptr<std::vector<unsigned int> > arrayValues = array->initialize<unsigned int>();
array->resize(numVals, 0);
valuesPointer = &arrayValues->operator[](0);
}
else
{
assert(false);
}
H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, valuesPointer);
array->initialize(mType);
array->resize(numVals, 0);
H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, array->getValuesPointer());
herr_t status;
status = H5Tclose(datatype);
......
......@@ -19,7 +19,7 @@ class XdmfHDF5Controller : public XdmfObject {
public:
template <typename T> friend void boost::checked_delete(T * x);
virtual ~XdmfHDF5Controller();
/**
* Create a new controller for an hdf5 data set on disk.
......@@ -75,7 +75,6 @@ public:
protected:
XdmfHDF5Controller(const std::string & dataSetPath, const unsigned int size, const boost::shared_ptr<const XdmfArrayType> type);
virtual ~XdmfHDF5Controller();
private:
......
......@@ -28,12 +28,12 @@ class XdmfHDF5Writer : public XdmfVisitor,
public:
virtual ~XdmfHDF5Writer();
enum Mode {
Default, Overwrite, Append
};
template <typename T> friend void boost::checked_delete(T * x);
/**
* Construct XdmfHDF5Writer
*
......@@ -65,7 +65,6 @@ public:
protected:
XdmfHDF5Writer(const std::string & hdf5FilePath);
virtual ~XdmfHDF5Writer();