Commit bacda4b0 authored by Kenneth D. Renard (Cont ARL/CISD) kdrenard's avatar Kenneth D. Renard (Cont ARL/CISD) kdrenard Committed by Kenneth Leiter

Cleanup: 1. XdmfArray -- took out getElementSize() 2. XdmfArrayType -- took...

Cleanup: 1. XdmfArray -- took out getElementSize() 2. XdmfArrayType -- took out IsEqual() 3. Xdmf.i -- implement IsEqual() function here for Python and Java in XdmfArrayType and XdmfItem (see #2 and #5) 4. Xdmf.i -- getNumpyArray uses getElementSize on XdmfArrayType instead of on XdmfArray (see #1) 5. XdmfItem -- took out IsEqual() 6. XdmfWriter -- made setDocumentTitle() and setCersionString() protected functions 7. Java test TestXdmfEquals -- took out test of XdmfItem->IsEqual()
parent bddb0698
...@@ -386,13 +386,6 @@ std::string XdmfArray::getDimensionString() const ...@@ -386,13 +386,6 @@ std::string XdmfArray::getDimensionString() const
return mDimensionString; return mDimensionString;
} }
int XdmfArray::getElementSize() const
{
boost::shared_ptr<const XdmfArrayType> aType = getArrayType();
if (aType == NULL) return(0);
return(aType->getElementSize());
}
boost::shared_ptr<XdmfHeavyDataController> XdmfArray::getHeavyDataController() boost::shared_ptr<XdmfHeavyDataController> XdmfArray::getHeavyDataController()
{ {
return boost::const_pointer_cast<XdmfHeavyDataController>(static_cast<const XdmfArray &>(*this).getHeavyDataController()); return boost::const_pointer_cast<XdmfHeavyDataController>(static_cast<const XdmfArray &>(*this).getHeavyDataController());
......
...@@ -94,13 +94,6 @@ public: ...@@ -94,13 +94,6 @@ public:
*/ */
std::string getDimensionString() const; std::string getDimensionString() const;
/**
* Get the size of an element in this array
*
* @return the size of an array element (0 if ArrayType is undefined)
*/
int getElementSize() const;
/** /**
* Get the heavy data controller attached to this XdmfArray. * Get the heavy data controller attached to this XdmfArray.
* *
......
...@@ -143,6 +143,11 @@ boost::shared_ptr<const XdmfArrayType> XdmfArrayType::New(const std::map<std::st ...@@ -143,6 +143,11 @@ boost::shared_ptr<const XdmfArrayType> XdmfArrayType::New(const std::map<std::st
assert(false); assert(false);
} }
unsigned int XdmfArrayType::getElementSize() const
{
return mPrecision;
}
void XdmfArrayType::getProperties(std::map<std::string, std::string> & collectedProperties) const void XdmfArrayType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{ {
collectedProperties["DataType"] = mName; collectedProperties["DataType"] = mName;
...@@ -150,8 +155,3 @@ void XdmfArrayType::getProperties(std::map<std::string, std::string> & collected ...@@ -150,8 +155,3 @@ void XdmfArrayType::getProperties(std::map<std::string, std::string> & collected
precision << mPrecision; precision << mPrecision;
collectedProperties["Precision"] = precision.str(); collectedProperties["Precision"] = precision.str();
} }
int XdmfArrayType::getElementSize() const
{
return (mPrecision);
}
...@@ -43,9 +43,9 @@ public: ...@@ -43,9 +43,9 @@ public:
static boost::shared_ptr<const XdmfArrayType> UInt16(); static boost::shared_ptr<const XdmfArrayType> UInt16();
static boost::shared_ptr<const XdmfArrayType> UInt32(); static boost::shared_ptr<const XdmfArrayType> UInt32();
void getProperties(std::map<std::string, std::string> & collectedProperties) const; unsigned int getElementSize() const;
int getElementSize() const; void getProperties(std::map<std::string, std::string> & collectedProperties) const;
protected: protected:
......
...@@ -20,6 +20,45 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i ...@@ -20,6 +20,45 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
%} %}
#ifdef SWIGJAVA #ifdef SWIGJAVA
<<<<<<< HEAD
=======
%extend XdmfArrayType {
bool equals(boost::shared_ptr<XdmfArrayType> arrayType) {
return(self == arrayType.get());
}
};
%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 == arrayType.get());
}
};
#endif
// Shared Pointer Templates
%shared_ptr(XdmfArray)
%shared_ptr(XdmfArrayType)
%shared_ptr(XdmfBaseVisitor)
%shared_ptr(XdmfCoreItemFactory)
%shared_ptr(XdmfCoreReader)
%shared_ptr(XdmfHDF5Controller)
%shared_ptr(XdmfHDF5Writer)
%shared_ptr(XdmfInformation)
%shared_ptr(XdmfItem)
%shared_ptr(XdmfItemProperty)
%shared_ptr(XdmfVisitor)
%shared_ptr(XdmfWriter)
// Abstract Base Classes
%template() Loki::BaseVisitable<void>;
%template() Loki::Visitor<XdmfArray>;
%template() Loki::Visitor<XdmfItem>;
>>>>>>> Cleanup: 1. XdmfArray -- took out getElementSize() 2. XdmfArrayType -- took out IsEqual() 3. Xdmf.i -- implement IsEqual() function here for Python and Java in XdmfArrayType and XdmfItem (see #2 and #5) 4. Xdmf.i -- getNumpyArray uses getElementSize on XdmfArrayType instead of on XdmfArray (see #1) 5. XdmfItem -- took out IsEqual() 6. XdmfWriter -- made setDocumentTitle() and setCersionString() protected functions 7. Java test TestXdmfEquals -- took out test of XdmfItem->IsEqual()
// Ignore const overloaded methods // Ignore const overloaded methods
%ignore XdmfArray::getHDF5Controller() const; %ignore XdmfArray::getHDF5Controller() const;
...@@ -34,6 +73,7 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i ...@@ -34,6 +73,7 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
// Define equality operator // Define equality operator
%extend XdmfItem { %extend XdmfItem {
<<<<<<< HEAD
bool equals(boost::shared_ptr<XdmfItem> item) bool equals(boost::shared_ptr<XdmfItem> item)
{ {
...@@ -45,6 +85,23 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i ...@@ -45,6 +85,23 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
return self == item.get(); return self == item.get();
} }
=======
bool __eq__(boost::shared_ptr<XdmfItem> item) {
if (item == NULL) return (false);
if (self == item.get()) return(true);
return(false);
}
};
#endif
#ifdef SWIGJAVA
%extend XdmfItem {
bool equals(boost::shared_ptr<XdmfItem> item) {
if (item == NULL) return (false);
if (self == item.get()) return(true);
return(false);
}
>>>>>>> Cleanup: 1. XdmfArray -- took out getElementSize() 2. XdmfArrayType -- took out IsEqual() 3. Xdmf.i -- implement IsEqual() function here for Python and Java in XdmfArrayType and XdmfItem (see #2 and #5) 4. Xdmf.i -- getNumpyArray uses getElementSize on XdmfArrayType instead of on XdmfArray (see #1) 5. XdmfItem -- took out IsEqual() 6. XdmfWriter -- made setDocumentTitle() and setCersionString() protected functions 7. Java test TestXdmfEquals -- took out test of XdmfItem->IsEqual()
}; };
%extend XdmfItemProperty { %extend XdmfItemProperty {
...@@ -81,62 +138,60 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i ...@@ -81,62 +138,60 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
#ifdef SWIGPYTHON #ifdef SWIGPYTHON
// Provide accessors from python lists to XdmfArrays // Provide accessors from python lists to XdmfArrays
%extend XdmfArray {
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
};
%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) { void copyValueAsInt8(int index, char value) {
$self->insert(index, value); $self->insert(index, value);
......
...@@ -147,7 +147,6 @@ public: ...@@ -147,7 +147,6 @@ public:
*/ */
virtual void traverse(const boost::shared_ptr<XdmfBaseVisitor> visitor); virtual void traverse(const boost::shared_ptr<XdmfBaseVisitor> visitor);
protected: protected:
XdmfItem(); XdmfItem();
......
...@@ -150,16 +150,6 @@ void XdmfWriter::setWriteXPaths(const bool writeXPaths) ...@@ -150,16 +150,6 @@ void XdmfWriter::setWriteXPaths(const bool writeXPaths)
mImpl->mWriteXPaths = writeXPaths; mImpl->mWriteXPaths = writeXPaths;
} }
void XdmfWriter::setDocumentTitle(const std::string title)
{
mImpl->mDocumentTitle = title;
}
void XdmfWriter::setVersionString(const std::string version)
{
mImpl->mVersionString = version;
}
void XdmfWriter::visit(XdmfArray & array, const boost::shared_ptr<XdmfBaseVisitor> visitor) void XdmfWriter::visit(XdmfArray & array, const boost::shared_ptr<XdmfBaseVisitor> visitor)
{ {
bool isSubclassed = array.getItemTag().compare(XdmfArray::ItemTag) != 0; bool isSubclassed = array.getItemTag().compare(XdmfArray::ItemTag) != 0;
...@@ -301,3 +291,14 @@ void XdmfWriter::visit(XdmfItem & item, const boost::shared_ptr<XdmfBaseVisitor> ...@@ -301,3 +291,14 @@ void XdmfWriter::visit(XdmfItem & item, const boost::shared_ptr<XdmfBaseVisitor>
mImpl->closeFile(); mImpl->closeFile();
} }
} }
void
XdmfWriter::setDocumentTitle(std::string title)
{
mImpl->mDocumentTitle = title;
}
void
XdmfWriter::setVersionString(std::string version)
{
mImpl->mVersionString = version;
}
...@@ -80,18 +80,18 @@ public: ...@@ -80,18 +80,18 @@ public:
unsigned int getLightDataLimit() const; unsigned int getLightDataLimit() const;
/** /**
* Get whether this writer is set to write xpaths. * Get the Mode of operation for this writer.
* *
* @return bool whether this writer is set to write xpaths. * @return the Mode of operation for this writer.
*/ */
bool getWriteXPaths() const; Mode getMode() const;
/** /**
* Get the Mode of operation for this writer. * Get whether this writer is set to write xpaths.
* *
* @return the Mode of operation for this writer. * @return bool whether this writer is set to write xpaths.
*/ */
Mode getMode() const; bool getWriteXPaths() const;
/** /**
* Set the number of values that this writer writes to light data (XML) before switching to a heavy data format. * Set the number of values that this writer writes to light data (XML) before switching to a heavy data format.
...@@ -107,20 +107,6 @@ public: ...@@ -107,20 +107,6 @@ public:
*/ */
void setMode(const Mode mode); void setMode(const Mode mode);
/**
* Set XML document title
*
* @param title, title to use for this XML document
*/
void setDocumentTitle(const std::string title);
/**
* Set version String
*
* @param version, string to use as version attribute in document title
*/
void setVersionString(const std::string version);
/** /**
* Set whether to write xpaths for this writer. * Set whether to write xpaths for this writer.
* *
...@@ -149,6 +135,9 @@ protected: ...@@ -149,6 +135,9 @@ protected:
XdmfWriter(const std::string & xmlFilePath, boost::shared_ptr<XdmfHeavyDataWriter> heavyDataWriter); XdmfWriter(const std::string & xmlFilePath, boost::shared_ptr<XdmfHeavyDataWriter> heavyDataWriter);
void setDocumentTitle(std::string title);
void setVersionString(std::string version);
private: private:
/** /**
......
...@@ -34,5 +34,6 @@ public class TestXdmfEquals { ...@@ -34,5 +34,6 @@ public class TestXdmfEquals {
if(type1a == type2) /*False*/ { if(type1a == type2) /*False*/ {
throw new SecurityException("Failed False Check (==)"); throw new SecurityException("Failed False Check (==)");
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment