Commit 1e29d5ae authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Add XdmfDataItem which stores array data to write to Xdmf.

parent 2be47fed
......@@ -23,6 +23,8 @@ set(XdmfSources
XdmfAttribute
XdmfAttributeCenter
XdmfAttributeType
XdmfDataItem
XdmfDataItemType
XdmfGeometry
XdmfGeometryType
XdmfGrid
......
......@@ -15,6 +15,7 @@ namespace boost {
}
%template(XdmfAttributePtr) boost::shared_ptr<XdmfAttribute>;
%template(XdmfDataItemPtr) boost::shared_ptr<XdmfDataItem>;
%template(XdmfGeometryPtr) boost::shared_ptr<XdmfGeometry>;
%template(XdmfGridPtr) boost::shared_ptr<XdmfGrid>;
%template(XdmfItemPtr) boost::shared_ptr<XdmfItem>;
......@@ -27,6 +28,8 @@ namespace boost {
#include <XdmfAttribute.hpp>
#include <XdmfAttributeCenter.hpp>
#include <XdmfAttributeType.hpp>
#include <XdmfDataItem.hpp>
#include <XdmfDataItemType.hpp>
#include <XdmfGeometry.hpp>
#include <XdmfGeometryType.hpp>
#include <XdmfGrid.hpp>
......@@ -45,6 +48,8 @@ namespace boost {
%include XdmfAttribute.hpp
%include XdmfAttributeCenter.hpp
%include XdmfAttributeType.hpp
%include XdmfDataItem.hpp
%include XdmfDataItemType.hpp
%include XdmfGeometry.hpp
%include XdmfGeometryType.hpp
%include XdmfGrid.hpp
......
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 1.3.37
# Version 1.3.40
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
......@@ -10,12 +10,18 @@ if version_info >= (2,6,0):
def swig_import_helper():
from os.path import dirname
import imp
fp = None
try:
fp, pathname, description = imp.find_module('_Xdmf', [dirname(__file__)])
_mod = imp.load_module('_Xdmf', fp, pathname, description)
finally:
if fp is not None: fp.close()
return _mod
except ImportError:
import _Xdmf
return _Xdmf
if fp is not None:
try:
_mod = imp.load_module('_Xdmf', fp, pathname, description)
finally:
fp.close()
return _mod
_Xdmf = swig_import_helper()
del swig_import_helper
else:
......@@ -65,7 +71,7 @@ class SwigPyIterator(_object):
__setattr__ = lambda self, name, value: _swig_setattr(self, SwigPyIterator, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, SwigPyIterator, name)
def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined")
def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined - class is abstract")
__repr__ = _swig_repr
__swig_destroy__ = _Xdmf.delete_SwigPyIterator
__del__ = lambda self : None;
......@@ -116,6 +122,25 @@ class XdmfAttributePtr(_object):
XdmfAttributePtr_swigregister = _Xdmf.XdmfAttributePtr_swigregister
XdmfAttributePtr_swigregister(XdmfAttributePtr)
class XdmfDataItemPtr(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, XdmfDataItemPtr, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, XdmfDataItemPtr, name)
__repr__ = _swig_repr
def __deref__(self): return _Xdmf.XdmfDataItemPtr___deref__(self)
def __init__(self):
this = _Xdmf.new_XdmfDataItemPtr()
try: self.this.append(this)
except: self.this = this
__swig_destroy__ = _Xdmf.delete_XdmfDataItemPtr
__del__ = lambda self : None;
def New(self): return _Xdmf.XdmfDataItemPtr_New(self)
def printSelf(self): return _Xdmf.XdmfDataItemPtr_printSelf(self)
def write(self, *args): return _Xdmf.XdmfDataItemPtr_write(self, *args)
XdmfDataItemPtr_swigregister = _Xdmf.XdmfDataItemPtr_swigregister
XdmfDataItemPtr_swigregister(XdmfDataItemPtr)
class XdmfGeometryPtr(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, XdmfGeometryPtr, name, value)
......@@ -251,7 +276,7 @@ class XdmfObject(_object):
__setattr__ = lambda self, name, value: _swig_setattr(self, XdmfObject, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, XdmfObject, name)
def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined")
def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined - class is abstract")
__repr__ = _swig_repr
def printSelf(self): return _Xdmf.XdmfObject_printSelf(self)
XdmfObject_swigregister = _Xdmf.XdmfObject_swigregister
......@@ -264,7 +289,7 @@ class XdmfItem(XdmfObject):
__swig_getmethods__ = {}
for _s in [XdmfObject]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{}))
__getattr__ = lambda self, name: _swig_getattr(self, XdmfItem, name)
def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined")
def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined - class is abstract")
__repr__ = _swig_repr
def write(self, *args): return _Xdmf.XdmfItem_write(self, *args)
XdmfItem_swigregister = _Xdmf.XdmfItem_swigregister
......@@ -426,6 +451,104 @@ def XdmfAttributeType_GlobalId():
return _Xdmf.XdmfAttributeType_GlobalId()
XdmfAttributeType_GlobalId = _Xdmf.XdmfAttributeType_GlobalId
class XdmfDataItem(XdmfItem):
__swig_setmethods__ = {}
for _s in [XdmfItem]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{}))
__setattr__ = lambda self, name, value: _swig_setattr(self, XdmfDataItem, name, value)
__swig_getmethods__ = {}
for _s in [XdmfItem]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{}))
__getattr__ = lambda self, name: _swig_getattr(self, XdmfDataItem, name)
def __init__(self, *args, **kwargs): raise AttributeError("No constructor defined")
__repr__ = _swig_repr
__swig_getmethods__["New"] = lambda x: _Xdmf.XdmfDataItem_New
if _newclass:New = staticmethod(_Xdmf.XdmfDataItem_New)
def printSelf(self): return _Xdmf.XdmfDataItem_printSelf(self)
def write(self, *args): return _Xdmf.XdmfDataItem_write(self, *args)
XdmfDataItem_swigregister = _Xdmf.XdmfDataItem_swigregister
XdmfDataItem_swigregister(XdmfDataItem)
def XdmfDataItem_New():
return _Xdmf.XdmfDataItem_New()
XdmfDataItem_New = _Xdmf.XdmfDataItem_New
class XdmfDataItemType(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, XdmfDataItemType, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, XdmfDataItemType, name)
__repr__ = _swig_repr
__swig_getmethods__["Unknown"] = lambda x: _Xdmf.XdmfDataItemType_Unknown
if _newclass:Unknown = staticmethod(_Xdmf.XdmfDataItemType_Unknown)
__swig_getmethods__["Int8"] = lambda x: _Xdmf.XdmfDataItemType_Int8
if _newclass:Int8 = staticmethod(_Xdmf.XdmfDataItemType_Int8)
__swig_getmethods__["Int16"] = lambda x: _Xdmf.XdmfDataItemType_Int16
if _newclass:Int16 = staticmethod(_Xdmf.XdmfDataItemType_Int16)
__swig_getmethods__["Int32"] = lambda x: _Xdmf.XdmfDataItemType_Int32
if _newclass:Int32 = staticmethod(_Xdmf.XdmfDataItemType_Int32)
__swig_getmethods__["Int64"] = lambda x: _Xdmf.XdmfDataItemType_Int64
if _newclass:Int64 = staticmethod(_Xdmf.XdmfDataItemType_Int64)
__swig_getmethods__["Float32"] = lambda x: _Xdmf.XdmfDataItemType_Float32
if _newclass:Float32 = staticmethod(_Xdmf.XdmfDataItemType_Float32)
__swig_getmethods__["Float64"] = lambda x: _Xdmf.XdmfDataItemType_Float64
if _newclass:Float64 = staticmethod(_Xdmf.XdmfDataItemType_Float64)
__swig_getmethods__["UInt8"] = lambda x: _Xdmf.XdmfDataItemType_UInt8
if _newclass:UInt8 = staticmethod(_Xdmf.XdmfDataItemType_UInt8)
__swig_getmethods__["UInt16"] = lambda x: _Xdmf.XdmfDataItemType_UInt16
if _newclass:UInt16 = staticmethod(_Xdmf.XdmfDataItemType_UInt16)
__swig_getmethods__["UInt32"] = lambda x: _Xdmf.XdmfDataItemType_UInt32
if _newclass:UInt32 = staticmethod(_Xdmf.XdmfDataItemType_UInt32)
def getName(self): return _Xdmf.XdmfDataItemType_getName(self)
def __eq__(self, *args): return _Xdmf.XdmfDataItemType___eq__(self, *args)
def __ne__(self, *args): return _Xdmf.XdmfDataItemType___ne__(self, *args)
def __init__(self, *args):
this = _Xdmf.new_XdmfDataItemType(*args)
try: self.this.append(this)
except: self.this = this
__swig_destroy__ = _Xdmf.delete_XdmfDataItemType
__del__ = lambda self : None;
XdmfDataItemType_swigregister = _Xdmf.XdmfDataItemType_swigregister
XdmfDataItemType_swigregister(XdmfDataItemType)
def XdmfDataItemType_Unknown():
return _Xdmf.XdmfDataItemType_Unknown()
XdmfDataItemType_Unknown = _Xdmf.XdmfDataItemType_Unknown
def XdmfDataItemType_Int8():
return _Xdmf.XdmfDataItemType_Int8()
XdmfDataItemType_Int8 = _Xdmf.XdmfDataItemType_Int8
def XdmfDataItemType_Int16():
return _Xdmf.XdmfDataItemType_Int16()
XdmfDataItemType_Int16 = _Xdmf.XdmfDataItemType_Int16
def XdmfDataItemType_Int32():
return _Xdmf.XdmfDataItemType_Int32()
XdmfDataItemType_Int32 = _Xdmf.XdmfDataItemType_Int32
def XdmfDataItemType_Int64():
return _Xdmf.XdmfDataItemType_Int64()
XdmfDataItemType_Int64 = _Xdmf.XdmfDataItemType_Int64
def XdmfDataItemType_Float32():
return _Xdmf.XdmfDataItemType_Float32()
XdmfDataItemType_Float32 = _Xdmf.XdmfDataItemType_Float32
def XdmfDataItemType_Float64():
return _Xdmf.XdmfDataItemType_Float64()
XdmfDataItemType_Float64 = _Xdmf.XdmfDataItemType_Float64
def XdmfDataItemType_UInt8():
return _Xdmf.XdmfDataItemType_UInt8()
XdmfDataItemType_UInt8 = _Xdmf.XdmfDataItemType_UInt8
def XdmfDataItemType_UInt16():
return _Xdmf.XdmfDataItemType_UInt16()
XdmfDataItemType_UInt16 = _Xdmf.XdmfDataItemType_UInt16
def XdmfDataItemType_UInt32():
return _Xdmf.XdmfDataItemType_UInt32()
XdmfDataItemType_UInt32 = _Xdmf.XdmfDataItemType_UInt32
class XdmfGeometry(XdmfItem):
__swig_setmethods__ = {}
for _s in [XdmfItem]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{}))
......
/*
* XdmfDataItem.cpp
*
* Created on: Jan 29, 2010
* Author: kleiter
*/
#include "XdmfDataItem.hpp"
#include "XdmfVisitor.hpp"
XdmfDataItem::XdmfDataItem() :
mDataType(XdmfDataItemType::Unknown())
{
std::cout << "Created DataItem " << this << std::endl;
}
XdmfDataItem::~XdmfDataItem()
{
std::cout << "Deleted DataItem " << this << std::endl;
}
std::string XdmfDataItem::printSelf() const
{
return "XdmfDataItem";
}
template <>
void XdmfDataItem::setData<int>(int* dataPointer)
{
mDataPointer = dataPointer;
mDataType = XdmfDataItemType::Int32();
}
void XdmfDataItem::write(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this);
}
/*
* XdmfDataItem.hpp
*
*
* Created on: Jan 25, 2010
* Author: kleiter
*/
#ifndef XDMFDATAITEM_HPP_
#define XDMFDATAITEM_HPP_
#include "XdmfDataItemType.hpp"
#include "XdmfItem.hpp"
class XdmfDataItem : public XdmfItem {
public:
XdmfNewMacro(XdmfDataItem);
template <typename T> void setData(T * dataPointer);
//int setData(int * dataPointer)
std::string printSelf() const;
void write(boost::shared_ptr<XdmfVisitor> visitor) const;
protected:
XdmfDataItem();
virtual ~XdmfDataItem();
private:
XdmfDataItem(const XdmfDataItem&); // Not implemented.
void operator=(const XdmfDataItem&); // Not implemented.
int* mDataPointer;
XdmfDataItemType mDataType;
};
#endif /* XDMFDATAITEM_HPP_ */
/*
* XdmfDataItemType.cpp
*
* Created on: Jan 29, 2010
* Author: kleiter
*/
#include "XdmfDataItemType.hpp"
// Supported XdmfDataItemTypes
XdmfDataItemType XdmfDataItemType::Unknown()
{
return XdmfDataItemType("Unknown");
}
XdmfDataItemType XdmfDataItemType::Int8()
{
return XdmfDataItemType("Int8");
}
XdmfDataItemType XdmfDataItemType::Int16()
{
return XdmfDataItemType("Int16");
}
XdmfDataItemType XdmfDataItemType::Int32()
{
return XdmfDataItemType("Int32");
}
XdmfDataItemType XdmfDataItemType::Int64()
{
return XdmfDataItemType("Int64");
}
XdmfDataItemType XdmfDataItemType::Float32()
{
return XdmfDataItemType("Float32");
}
XdmfDataItemType XdmfDataItemType::Float64()
{
return XdmfDataItemType("Float64");
}
XdmfDataItemType XdmfDataItemType::UInt8()
{
return XdmfDataItemType("UInt8");
}
XdmfDataItemType XdmfDataItemType::UInt16()
{
return XdmfDataItemType("UInt16");
}
XdmfDataItemType XdmfDataItemType::UInt32()
{
return XdmfDataItemType("UInt32");
}
XdmfDataItemType::XdmfDataItemType(const std::string& name) :
mName(name)
{};
XdmfDataItemType::XdmfDataItemType(const XdmfDataItemType& dataItemType):
mName(dataItemType.mName)
{
}
XdmfDataItemType& XdmfDataItemType::operator=(const XdmfDataItemType& dataItemType)
{
if(this != &dataItemType)
{
mName = dataItemType.mName;
}
return *this;
}
bool XdmfDataItemType::operator==(const XdmfDataItemType& dataItemType) const
{
return mName.compare(dataItemType.mName) == 0;
}
bool XdmfDataItemType::operator!=(const XdmfDataItemType& dataItemType) const
{
return !this->operator==(dataItemType);
}
std::string XdmfDataItemType::getName() const
{
return mName;
}
/*
* XdmfDataItemType.hpp
*
* Created on: Jan 25, 2010
* Author: kleiter
*/
#ifndef XDMFDATAITEMTYPE_HPP_
#define XDMFDATAITEMTYPE_HPP_
#include <string>
class XdmfDataItemType {
public:
// Supported Xdmf Data Item Types
static XdmfDataItemType Unknown();
static XdmfDataItemType Int8();
static XdmfDataItemType Int16();
static XdmfDataItemType Int32();
static XdmfDataItemType Int64();
static XdmfDataItemType Float32();
static XdmfDataItemType Float64();
static XdmfDataItemType UInt8();
static XdmfDataItemType UInt16();
static XdmfDataItemType UInt32();
/**
* Get the name of this data item type
*
* @return a string containing the name.
*/
std::string getName() const;
/*
* Compare two XdmfDataItemTypes for equality.
*
* @param an XdmfDataItemType to compare equality to.
* @return true iff the XdmfDataItemTypes are equal.
*/
bool operator==(const XdmfDataItemType& attributeType) const;
/**
* Compare two XdmfDataItemTypes for inequality.
*
* @param XdmfDataItemType to compare inequality to.
* @return true iff the XdmfDataItemTypes are not equal.
*/
bool operator!=(const XdmfDataItemType& top) const;
XdmfDataItemType(const XdmfDataItemType& attributeType);
XdmfDataItemType& operator=(const XdmfDataItemType& attributeType);
protected:
/**
* Protected constructor for XdmfDataItemType. The constructor is protected because all data item types supported
* by Xdmf should be accessed through more specific static methods that construct XdmfDataItemTypes - i.e. XdmfDataItemType::Int8().
*/
XdmfDataItemType(const std::string& name);
private:
std::string mName;
};
#endif /* XDMFDATAITEMTYPE_HPP_ */
/*
* XdmfGrid.cpp
* XdmfGeometry.cpp
*
* Created on: Jan 29, 2010
* Author: kleiter
......
This diff is collapsed.
......@@ -2,6 +2,7 @@
// Xdmf Smart Pointer Test
#include "XdmfAttribute.hpp"
#include "XdmfDataItem.hpp"
#include "XdmfGeometry.hpp"
#include "XdmfGrid.hpp"
#include "XdmfTopology.hpp"
......@@ -27,6 +28,11 @@ void XdmfVisitor::visit(const XdmfAttribute * const attribute)
xmlData << std::setw(mTabIndex) << "" << "</Attribute>\n";
}
void XdmfVisitor::visit(const XdmfDataItem * const dataItem)
{
}
void XdmfVisitor::visit(const XdmfGeometry * const geometry)
{
xmlData << std::setw(mTabIndex) << "" << "<Geometry GeometryType=\"" << geometry->getGeometryTypeAsString() << "\">\n";
......
......@@ -6,6 +6,7 @@
// Forward Declarations
class XdmfAttribute;
class XdmfDataItem;
class XdmfGeometry;
class XdmfGrid;
class XdmfTopology;
......@@ -22,6 +23,8 @@ public:
virtual void visit(const XdmfAttribute * const attribute);
virtual void visit(const XdmfDataItem * const geometry);
virtual void visit(const XdmfGeometry * const geometry);
virtual void visit(const XdmfGrid * const grid);
......
set(XdmfTests
TestXdmfAttribute
TestXdmfDataItem
TestXdmfGeometry
TestXdmfGrid
TestXdmfTopology
......
#include "XdmfDataItem.hpp"
int main(int argc, char* argv[])
{
boost::shared_ptr<XdmfDataItem> dataItem = XdmfDataItem::New();
int* intArray = new int[10];
dataItem->setData(intArray);
}
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