Commit 42286d09 authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Get equality functions working again, but keep it in the SWIG file rather...

ENH: Get equality functions working again, but keep it in the SWIG file rather the polluting the C++.
parent be7a6349
This diff is collapsed.
......@@ -84,8 +84,8 @@ protected:
private:
XdmfAttribute(const XdmfAttribute & attribute); // Not implemented.
void operator=(const XdmfAttribute & attribute); // Not implemented.
XdmfAttribute(const XdmfAttribute &); // Not implemented.
void operator=(const XdmfAttribute &); // Not implemented.
boost::shared_ptr<const XdmfAttributeCenter> mCenter;
std::string mName;
......
......@@ -81,26 +81,6 @@ boost::shared_ptr<const XdmfAttributeCenter> XdmfAttributeCenter::New(const std:
assert(false);
}
bool XdmfAttributeCenter::operator==(const XdmfAttributeCenter & attributeCenter) const
{
return mName.compare(attributeCenter.mName) == 0;
}
bool XdmfAttributeCenter::operator!=(const XdmfAttributeCenter & attributeCenter) const
{
return !this->operator==(attributeCenter);
}
bool XdmfAttributeCenter::IsEqual(boost::shared_ptr<XdmfAttributeCenter> attributeCenter)
{
if(attributeCenter == NULL) return false;
if(this == attributeCenter.get()
&& mName == attributeCenter->mName
) return true;
return false;
}
void XdmfAttributeCenter::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
collectedProperties["Center"] = mName;
......
......@@ -35,29 +35,6 @@ public:
void getProperties(std::map<std::string, std::string> & collectedProperties) const;
/**
* Compare two XdmfAttributeCenters for equality.
*
* @param attributeCenter an XdmfAttributeCenter to compare equality to.
* @return true if the XdmfAttributeCenters are equal.
*/
bool operator==(const XdmfAttributeCenter & attributeCenter) const;
/**
* Compare two XdmfAttributeCenters for inequality.
*
* @param attributeCenter an XdmfAttributeCenter to compare inequality to.
* @return true if the XdmfAttributeCenters are not equal.
*/
bool operator!=(const XdmfAttributeCenter & attributeCenter) const;
/**
* Compare two XdmfAttributeCenter for equality (for wrapping)
*
* @param attributeCenter a boost shared pointer to an XdmfAttributeCenter to compare equality to.
* @return true if the XdmfAttributeCenter are equal.
*/
bool IsEqual(boost::shared_ptr<XdmfAttributeCenter> attributeCenter);
protected:
......
......@@ -105,26 +105,6 @@ boost::shared_ptr<const XdmfAttributeType> XdmfAttributeType::New(const std::map
assert(false);
}
bool XdmfAttributeType::operator==(const XdmfAttributeType & attributeType) const
{
return mName.compare(attributeType.mName) == 0;
}
bool XdmfAttributeType::operator!=(const XdmfAttributeType & attributeType) const
{
return !this->operator==(attributeType);
}
bool XdmfAttributeType::IsEqual(boost::shared_ptr<XdmfAttributeType> attributeType)
{
if(attributeType == NULL) return false;
if(this == attributeType.get()
&& mName == attributeType->mName
) return true;
return false;
}
void XdmfAttributeType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
collectedProperties["Type"] = mName;
......
......@@ -39,31 +39,6 @@ public:
void getProperties(std::map<std::string, std::string> & collectedProperties) const;
/*
* Compare two XdmfAttributeTypes for equality.
*
* @param attributeType an XdmfAttributeType to compare equality to.
* @return true if the XdmfAttributeTypes are equal.
*/
bool operator==(const XdmfAttributeType & attributeType) const;
/**
* Compare two XdmfAttributeTypes for inequality.
*
* @param attributeType an XdmfAttributeType to compare inequality to.
* @return true if the XdmfAttributeTypes are not equal.
*/
bool operator!=(const XdmfAttributeType & attributeType) const;
/**
* Compare two XdmfAttributeType for equality (for wrapping)
*
* @param attributeType a boost shared pointer to an XdmfAttributeType to compare equality to.
* @return true if the XdmfAttributeType are equal.
*/
bool IsEqual(boost::shared_ptr<XdmfAttributeType> attributeType);
protected:
/**
......
......@@ -107,27 +107,6 @@ boost::shared_ptr<const XdmfGeometryType> XdmfGeometryType::New(const std::map<s
assert(false);
}
bool XdmfGeometryType::operator==(const XdmfGeometryType& geometryType) const
{
return mDimensions == geometryType.mDimensions && mName.compare(geometryType.mName) == 0;
}
bool XdmfGeometryType::operator!=(const XdmfGeometryType& geometryType) const
{
return !this->operator==(geometryType);
}
bool XdmfGeometryType::IsEqual(boost::shared_ptr<XdmfGeometryType> geometryType)
{
if(geometryType == NULL) return false;
if(this == geometryType.get()
&& mDimensions == geometryType->mDimensions
&& mName == geometryType->mName
) return true;
return false;
}
unsigned int XdmfGeometryType::getDimensions() const
{
return mDimensions;
......
......@@ -55,30 +55,6 @@ public:
virtual void getProperties(std::map<std::string, std::string> & collectedProperties) const;
/*
* Compare two XdmfGeometryTypes for equality.
*
* @param geometryType a XdmfGeometryType to compare equality to.
* @return true if the XdmfGeometryTypes are equal.
*/
bool operator==(const XdmfGeometryType & geometryType) const;
/**
* Compare two XdmfGeometryTypes for inequality.
*
* @param geometryType a XdmfGeometryType to compare inequality to.
* @return true if the XdmfGeometryTypes are not equal.
*/
bool operator!=(const XdmfGeometryType & geometryType) const;
/**
* Compare two XdmfGeometryType for equality (for wrapping)
*
* @param geometryType a boost shared pointer to an XdmfGeometryType to compare equality to.
* @return true if the XdmfGeometryType are equal.
*/
bool IsEqual(boost::shared_ptr<XdmfGeometryType> geometryType);
protected:
/**
......
......@@ -61,25 +61,6 @@ boost::shared_ptr<const XdmfGridCollectionType> XdmfGridCollectionType::New(cons
assert(false);
}
bool XdmfGridCollectionType::operator==(const XdmfGridCollectionType & collectionType) const
{
return mName.compare(collectionType.mName) == 0;
}
bool XdmfGridCollectionType::operator!=(const XdmfGridCollectionType & collectionType) const
{
return !this->operator==(collectionType);
}
bool XdmfGridCollectionType::IsEqual(boost::shared_ptr<XdmfGridCollectionType> collectionType)
{
if(collectionType == NULL) return false;
if(this == collectionType.get()
&& mName == collectionType->mName
) return true;
return false;
}
void XdmfGridCollectionType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
collectedProperties["CollectionType"] = mName;
......
......@@ -31,30 +31,6 @@ public:
void getProperties(std::map<std::string, std::string> & collectedProperties) const;
/*
* Compare two XdmfGridCollectionTypes for equality.
*
* @param collectionType an XdmfGridCollectionType to compare equality to.
* @return true if the XdmfGridCollectionTypes are equal.
*/
bool operator==(const XdmfGridCollectionType & collectionype) const;
/**
* Compare two XdmfGridCollectionTypes for inequality.
*
* @param collectionType an XdmfGridCollectionType to compare inequality to.
* @return true if the XdmfGridCollectionTypes are not equal.
*/
bool operator!=(const XdmfGridCollectionType & collectionType) const;
/**
* Compare two XdmfGridCollectionType for equality (for wrapping)
*
* @param collectionType a boost shared pointer to an XdmfGridCollectionType to compare equality to.
* @return true if the XdmfGridCollectionType are equal.
*/
bool IsEqual(boost::shared_ptr<XdmfGridCollectionType> collectionType);
protected:
/**
......
......@@ -85,26 +85,6 @@ boost::shared_ptr<const XdmfSetType> XdmfSetType::New(const std::map<std::string
assert(false);
}
bool XdmfSetType::operator==(const XdmfSetType & setType) const
{
return mName.compare(setType.mName) == 0;
}
bool XdmfSetType::operator!=(const XdmfSetType & setType) const
{
return !this->operator==(setType);
}
bool XdmfSetType::IsEqual(boost::shared_ptr<XdmfSetType> setType)
{
if(setType == NULL) return false;
if(this == setType.get()
&& mName == setType->mName
) return true;
return false;
}
void XdmfSetType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
collectedProperties["Type"] = this->mName;
......
......@@ -34,30 +34,6 @@ public:
void getProperties(std::map<std::string, std::string> & collectedProperties) const;
/*
* Compare two XdmfSetTypes for equality.
*
* @param setType a XdmfSetType to compare equality to.
* @return true if the XdmfSetTypes are equal.
*/
bool operator==(const XdmfSetType & setType) const;
/**
* Compare two XdmfSetTypes for inequality.
*
* @param setType a XdmfSetType to compare inequality to.
* @return true if the XdmfSetTypes are not equal.
*/
bool operator!=(const XdmfSetType & setType) const;
/**
* Compare two XdmfSetType for equality (for wrapping)
*
* @param setType a boost shared pointer to an XdmfSetType to compare equality to.
* @return true if the XdmfSetType are equal.
*/
bool IsEqual(boost::shared_ptr<XdmfSetType> setType);
protected:
/**
......
......@@ -172,43 +172,6 @@ boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::Mixed()
return p;
}
/*
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::TwoDSMesh()
{
static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(1, "2DSMesh", Structured));
return p;
}
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::TwoDRectMesh()
{
static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(1, "2DRectMesh", Structured));
return p;
}
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::TwoDCoRectMesh()
{
static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(1, "2DCoRectMesh", Structured));
return p;
}
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::ThreeDSMesh()
{
static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(1, "3DSMesh", Structured));
return p;
}
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::ThreeDRectMesh()
{
static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(1, "3DRectMesh", Structured));
return p;
}
boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::ThreeDCoRectMesh()
{
static boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(1, "3DCoRectMesh", Structured));
return p;
}*/
XdmfTopologyType::XdmfTopologyType(const unsigned int nodesPerElement, const std::string & name, const CellType cellType) :
mCellType(cellType),
mName(name),
......@@ -321,28 +284,6 @@ boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::New(const std::map<s
{
return Mixed();
}
/*else if(typeVal.compare("2DSMESH") == 0)
{
return TwoDSMesh();
}
else if(typeVal.compare("2DRECTMESH") == 0)
{
return TwoDRectMesh();
}
else if(typeVal.compare("2DCORECTMESH") == 0 || typeVal.compare("3DCORECTMESH") == 0)
{
// Special case --- Regular Grid
boost::shared_ptr<const XdmfTopologyType> p(new XdmfTopologyType(0, "REGULAR", Structured));
return p;
}
else if(typeVal.compare("3DSMESH") == 0)
{
return ThreeDSMesh();
}
else if(typeVal.compare("3DRECTMESH") == 0)
{
return ThreeDRectMesh();
}*/
else
{
assert(false);
......@@ -351,27 +292,6 @@ boost::shared_ptr<const XdmfTopologyType> XdmfTopologyType::New(const std::map<s
assert(false);
}
bool XdmfTopologyType::operator==(const XdmfTopologyType& topologyType) const
{
return mNodesPerElement == topologyType.mNodesPerElement && mName.compare(topologyType.mName) == 0 && mCellType == topologyType.mCellType;
}
bool XdmfTopologyType::operator!=(const XdmfTopologyType& topologyType) const
{
return !this->operator==(topologyType);
}
bool XdmfTopologyType::IsEqual(boost::shared_ptr<XdmfTopologyType> topologyType)
{
if(topologyType == NULL) return false;
if(this == topologyType.get()
&& mNodesPerElement == topologyType->mNodesPerElement
&& mCellType == topologyType->mCellType
&& mName == topologyType->mName
) return true;
return false;
}
XdmfTopologyType::CellType XdmfTopologyType::getCellType() const
{
return mCellType;
......
......@@ -82,10 +82,6 @@ public:
static boost::shared_ptr<const XdmfTopologyType> Hexahedron_125();
static boost::shared_ptr<const XdmfTopologyType> Hexahedron_125_GLL();
static boost::shared_ptr<const XdmfTopologyType> Mixed();
//static boost::shared_ptr<const XdmfTopologyType> TwoDRectMesh();
//static boost::shared_ptr<const XdmfTopologyType> TwoDCoRectMesh();
//static boost::shared_ptr<const XdmfTopologyType> ThreeDRectMesh();
//static boost::shared_ptr<const XdmfTopologyType> ThreeDCoRectMesh();
/**
* Get the cell type associated with this topology type.
......@@ -110,30 +106,6 @@ public:
void getProperties(std::map<std::string, std::string> & collectedProperties) const;
/*
* Compare two XdmfTopologyTypes for equality.
*
* @param topologyType an XdmfTopologyType to compare equality to.
* @return true if the XdmfTopologyTypes are equal.
*/
bool operator==(const XdmfTopologyType & topologyType) const;
/**
* Compare two XdmfTopologyTypes for inequality
*
* @param topologyType XdmfTopologyType to compare inequality to.
* @return true if the XdmfTopologyTypes are not equal.
*/
bool operator!=(const XdmfTopologyType & topologyType) const;
/**
* Compare two XdmfTopologyType for equality (for wrapping)
*
* @param topologyType a boost shared pointer to an XdmfTopologyType to compare equality to.
* @return true if the XdmfTopologyType are equal.
*/
bool IsEqual(boost::shared_ptr<XdmfTopologyType> topologyType);
protected:
/**
......
......@@ -143,29 +143,6 @@ boost::shared_ptr<const XdmfArrayType> XdmfArrayType::New(const std::map<std::st
assert(false);
}
bool XdmfArrayType::operator==(const XdmfArrayType & arrayType) const
{
return mName.compare(arrayType.mName) == 0 && mPrecision == arrayType.mPrecision;
}
bool XdmfArrayType::operator!=(const XdmfArrayType & arrayType) const
{
return !this->operator==(arrayType);
}
bool XdmfArrayType::IsEqual(boost::shared_ptr<XdmfArrayType> arrayType)
{
if(arrayType == NULL)
{
return false;
}
if(this == arrayType.get() && mName == arrayType->mName && mPrecision == arrayType->mPrecision)
{
return true;
}
return false;
}
void XdmfArrayType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
collectedProperties["DataType"] = mName;
......
......@@ -45,30 +45,6 @@ public:
void getProperties(std::map<std::string, std::string> & collectedProperties) const;
/*
* Compare two XdmfArrayTypes for equality.
*
* @param arrayType an XdmfArrayType to compare equality to.
* @return true if the XdmfArrayTypes are equal.
*/
bool operator==(const XdmfArrayType & arrayType) const;
/**
* Compare two XdmfArrayTypes for inequality.
*
* @param arrayType an XdmfArrayType to compare inequality to.
* @return true if the XdmfArrayTypes are not equal.
*/
bool operator!=(const XdmfArrayType & arrayType) const;
/**
* Compare two XdmfArrayTypes for equality (for java wrapping)
*
* @param arrayType a boost shared pointer to an XdmfArrayType to compare equality to.
* @return true if the XdmfArrayTypes are equal.
*/
bool IsEqual(boost::shared_ptr<XdmfArrayType> arrayType);
int getElementSize() const;
protected:
......
......@@ -24,25 +24,6 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
%include std_vector.i
%include loki/Visitor.h
#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
// Shared Pointer Templates
%shared_ptr(XdmfArray)
%shared_ptr(XdmfArrayType)
......@@ -62,43 +43,6 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
%template() Loki::Visitor<XdmfArray>;
%template() Loki::Visitor<XdmfItem>;
#ifdef SWIGJAVA
%ignore XdmfArray::getHDF5Controller() const;
%ignore XdmfArray::getValuesInternal() const;
%ignore XdmfArray::ItemTag;
%ignore XdmfInformation::ItemTag;
%ignore XdmfItem::getInformation(const unsigned int index) const;
%ignore XdmfItem::getInformation(const std::string & name) const;
%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);
}
}
%}
#endif /* SWIGJAVA */
#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
%include XdmfItem.hpp
%include XdmfItemProperty.hpp
%include XdmfVisitor.hpp
......@@ -143,61 +87,65 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
%template(resizeAsUInt16) XdmfArray::resize<unsigned short>;
%template(resizeAsUInt32) XdmfArray::resize<unsigned int>;
#ifndef SWIGJAVA
#ifdef SWIGPYTHON
// Provide accessors from python lists to XdmfArrays
%extend XdmfArray {
PyObject * getBuffer ()
{
void *vp = $self->getValuesInternal();
Py_ssize_t sz = $self->getSize() * $self->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
};
%extend XdmfArray
{
PyObject * getBuffer ()
{
void *vp = $self->getValuesInternal();
Py_ssize_t sz = $self->getSize() * $self->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
};
void copyValueAsInt8(int index, char value) {
$self->insert(index, value);
......@@ -234,10 +182,9 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
void copyValueAsUInt32(int index, unsigned int value) {
$self->insert(index, value);
}
};
%extend XdmfArray {
%pythoncode {
%pythoncode
{
def insertAsInt8(self, startIndex, values):
for i in range(0, len(values)):
self.copyValueAsInt8(i+startIndex, values[i])
......@@ -275,5 +222,50 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
self.copyValueAsUInt32(i+startIndex, values[i])
};
};
#endif /* SWIGJAVA */
%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 */
#ifdef SWIGJAVA
%ignore XdmfArray::getHDF5Controller() const;
%ignore XdmfArray::getValuesInternal() const;
%ignore XdmfArray::ItemTag;
%ignore XdmfInformation::ItemTag;
%ignore XdmfItem::getInformation(const unsigned int index) const;
%ignore XdmfItem::getInformation(const std::string & name) const;
%ignore XdmfWriter::getHDF5Writer() const;
%pragma(java) jniclasscode=%{
static
{
try
{
System.loadLibrary("XdmfCoreJava");
}
catch (UnsatisfiedLinkError e)
{