Commit 4acdd29e authored by Ken Leiter (Civ's avatar Ken Leiter (Civ

ENH: Replace old way of creating static instances of XdmfTopologyType,...

ENH:  Replace old way of creating static instances of XdmfTopologyType, XdmfGeometryType, and storing them by reference in their respective topologies.  These now work by providing a specific constructor method that returns specific instances of the objects populated with correct values.  This was changed because there are some type options in Xdmf where static instances don't make sense (e.g. XdmfTopologyType Polygon can have many different values for nodesPerElement) but we still need to restrict construction of these types with specific values.  Each parent item merely keeps a copy of a topology type.  I considered doing this with smart pointers, but I believe it to be unnecessarily complicated, especially when direct comparison of topology types is needed.  I am considering separating these types into separate classes.

Added XdmfAttribute implementation and began populating XdmfVisitor to write out XML.
parent 6f12cfa6
......@@ -20,6 +20,7 @@ if(XDMF_WRAP_PYTHON)
endif(XDMF_WRAP_PYTHON)
set(XdmfSources
XdmfAttribute
XdmfGeometry
XdmfGrid
XdmfItem
......@@ -43,6 +44,7 @@ configure_file(Xdmf.py Xdmf.py COPYONLY)
option(BUILD_TESTING OFF)
if(BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
add_executable(XdmfTest test.cpp)
target_link_libraries(XdmfTest Xdmf)
......
......@@ -14,6 +14,7 @@ namespace boost {
};
}
%template(XdmfAttributePtr) boost::shared_ptr<XdmfAttribute>;
%template(XdmfGeometryPtr) boost::shared_ptr<XdmfGeometry>;
%template(XdmfGridPtr) boost::shared_ptr<XdmfGrid>;
%template(XdmfItemPtr) boost::shared_ptr<XdmfItem>;
......@@ -23,6 +24,7 @@ namespace boost {
%module Xdmf
%{
#include <XdmfAttribute.hpp>
#include <XdmfGeometry.hpp>
#include <XdmfGrid.hpp>
#include <XdmfItem.hpp>
......@@ -36,6 +38,7 @@ namespace boost {
%include XdmfItem.hpp
%include XdmfVisitor.hpp
%include XdmfAttribute.hpp
%include XdmfGeometry.hpp
%include XdmfGrid.hpp
%include XdmfTopology.hpp
This diff is collapsed.
/*
* XdmfAttribute.cpp
*
* Created on: Jan 29, 2010
* Author: kleiter
*/
#include "XdmfAttribute.hpp"
#include "XdmfVisitor.hpp"
// Supported XdmfAttributeTypes
XdmfAttributeType XdmfAttributeType::NoAttributeType()
{
return XdmfAttributeType("None");
}
XdmfAttributeType XdmfAttributeType::Scalar()
{
return XdmfAttributeType("Scalar");
}
XdmfAttributeType XdmfAttributeType::Vector()
{
return XdmfAttributeType("Vector");
}
XdmfAttributeType XdmfAttributeType::Tensor()
{
return XdmfAttributeType("Tensor");
}
XdmfAttributeType XdmfAttributeType::Matrix()
{
return XdmfAttributeType("Matrix");
}
XdmfAttributeType XdmfAttributeType::Tensor6()
{
return XdmfAttributeType("Tensor6");
}
XdmfAttributeType XdmfAttributeType::GlobalId()
{
return XdmfAttributeType("GlobalId");
}
XdmfAttributeType::XdmfAttributeType(const XdmfAttributeType& attributeType):
mName(attributeType.mName)
{
}
XdmfAttributeType& XdmfAttributeType::operator=(const XdmfAttributeType& attributeType)
{
if(this != &attributeType)
{
mName = attributeType.mName;
}
return *this;
}
std::string XdmfAttributeType::getName() const
{
return mName;
}
XdmfAttribute::XdmfAttribute() :
mAttributeType(XdmfAttributeType::NoAttributeType())
{
std::cout << "Created Attribute " << this << std::endl;
}
XdmfAttribute::~XdmfAttribute()
{
std::cout << "Deleted Attribute " << this << std::endl;
}
XdmfAttributeType XdmfAttribute::getAttributeType() const
{
return mAttributeType;
}
std::string XdmfAttribute::getAttributeTypeAsString() const
{
return mAttributeType.getName();
}
void XdmfAttribute::setAttributeType(const XdmfAttributeType& attributeType)
{
mAttributeType = attributeType;
}
std::string XdmfAttribute::getName() const
{
return mName;
}
void XdmfAttribute::setName(const std::string& name)
{
mName= name;
}
void XdmfAttribute::write(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this);
}
const std::string XdmfAttribute::printSelf() const
{
return "<XdmfAttribute>";
}
......@@ -10,10 +10,124 @@
#include "XdmfItem.hpp"
class XdmfAttributeType {
public:
// Supported Xdmf Attribute Types
static XdmfAttributeType NoAttributeType();
static XdmfAttributeType Scalar();
static XdmfAttributeType Vector();
static XdmfAttributeType Tensor();
static XdmfAttributeType Matrix();
static XdmfAttributeType Tensor6();
static XdmfAttributeType GlobalId();
/**
* Get the name of this attribute type
*
* @return a string containing the name.
*/
std::string getName() const;
/*
* Compare two XdmfAttribute types for equality.
*
* @param an XdmfAttributeType to compare equality to.
* @return true iff the XdmfAttributeTypes are equal.
*/
bool operator==(const XdmfAttributeType& top) const
{
return mName.compare(top.mName) == 0;
}
/**
* Compare two XdmfAttribute types for inequality.
*
* @param XdmfAttributeType to compare inequality to.
* @return true iff the XdmfAttributeTypes are not equal.
*/
bool operator!=(const XdmfAttributeType& top) const
{
return !this->operator ==(top);
}
XdmfAttributeType(const XdmfAttributeType&);
XdmfAttributeType& operator=(const XdmfAttributeType&);
protected:
/**
* Protected constructor for XdmfAttributeType. The constructor is protected because all attribute types supported
* by Xdmf should be accessed through more specific static methods that construct XdmfAttributeTypes - i.e. XdmfAttributeType::Scalar().
*/
XdmfAttributeType(const std::string& name) :
mName(name)
{};
private:
std::string mName;
};
class XdmfAttribute : public XdmfItem {
public:
XdmfNewMacro(XdmfAttribute);
/**
* Get the name of the attribute.
*
* @return a string containing the name of the attribute.
*/
std::string getName() const;
/**
* Set the name of the attribute.
*
* @param a string containing the name to set.
*/
void setName(const std::string&);
/**
* Get the XdmfAttributeType associated with this Attribute.
*
* @return XdmfAttributeType.
*/
XdmfAttributeType getAttributeType() const;
/**
* Get the name of the AttributeType associated with this Attribute.
*
* @return std::string containing name of the AttributeType.
*/
std::string getAttributeTypeAsString() const;
/**
* Set the XdmfAttributeType associated with this Attribute.
*
* @param XdmfAttributeType to set.
*/
void setAttributeType(const XdmfAttributeType&);
void write(boost::shared_ptr<XdmfVisitor> visitor) const;
virtual const std::string printSelf() const;
protected:
XdmfAttribute();
virtual ~XdmfAttribute();
private:
XdmfAttribute(const XdmfAttribute&); // Not implemented.
void operator=(const XdmfAttribute&); // Not implemented.
std::string mName;
XdmfAttributeType mAttributeType;
};
......
......@@ -6,56 +6,109 @@
*/
#include "XdmfGeometry.hpp"
#include "XdmfVisitor.hpp"
// Supported XdmfGeometryTypes
const XdmfGeometryType XdmfGeometryType::NoGeometry("NONE", 0);
const XdmfGeometryType XdmfGeometryType::XYZ("XYZ", 3);
const XdmfGeometryType XdmfGeometryType::XY("XY", 2);
const XdmfGeometryType XdmfGeometryType::X_Y_Z("X_Y_Z", 3);
const XdmfGeometryType XdmfGeometryType::X_Y("X_Y", 2);
const XdmfGeometryType XdmfGeometryType::VXVYVZ("VXVYVZ", 3);
const XdmfGeometryType XdmfGeometryType::Origin_DXDYDZ("ORIGIN_DXDYDZ", 3);
const XdmfGeometryType XdmfGeometryType::VXVY("VXVY", 2);
const XdmfGeometryType XdmfGeometryType::Origin_DXDY("ORIGIN_DXDY", 2);
XdmfGeometryType XdmfGeometryType::NoGeometryType()
{
return XdmfGeometryType("NONE", 0);
}
XdmfGeometryType XdmfGeometryType::XYZ()
{
return XdmfGeometryType("XYZ", 3);
}
XdmfGeometryType XdmfGeometryType::XY()
{
return XdmfGeometryType("XY", 2);
}
XdmfGeometryType XdmfGeometryType::X_Y_Z()
{
return XdmfGeometryType("X_Y_Z", 3);
}
XdmfGeometryType XdmfGeometryType::X_Y()
{
return XdmfGeometryType("X_Y", 2);
}
XdmfGeometryType XdmfGeometryType::VXVYVZ()
{
return XdmfGeometryType("VXVYVZ", 3);
}
XdmfGeometryType XdmfGeometryType::Origin_DXDYDZ()
{
return XdmfGeometryType("ORIGIN_DXDYDZ", 3);
}
XdmfGeometryType XdmfGeometryType::VXVY()
{
return XdmfGeometryType("VXVY", 2);
}
XdmfGeometryType XdmfGeometryType::Origin_DXDY()
{
return XdmfGeometryType("ORIGIN_DXDY", 2);
}
XdmfGeometry::XdmfGeometry() :
mGeometryType(&XdmfGeometryType::NoGeometry)
XdmfGeometryType::XdmfGeometryType(const XdmfGeometryType& geomType):
mDimensions(geomType.mDimensions),
mName(geomType.mName)
{
std::cout << "Created Geometry " << this << std::endl;
}
XdmfGeometry::~XdmfGeometry()
XdmfGeometryType& XdmfGeometryType::operator=(const XdmfGeometryType& geomType)
{
std::cout << "Deleted Geometry " << this << std::endl;
if(this != &geomType)
{
mDimensions = geomType.mDimensions;
mName = geomType.mName;
}
return *this;
}
int XdmfGeometryType::getDimensions() const
{
return mDimensions;
}
std::string XdmfGeometryType::getName() const
{
return mName;
}
void XdmfGeometry::write(boost::shared_ptr<XdmfVisitor>) const
XdmfGeometry::XdmfGeometry() :
mGeometryType(XdmfGeometryType::NoGeometryType())
{
std::cout << "Created Geometry " << this << std::endl;
}
XdmfGeometry::~XdmfGeometry()
{
std::cout << "Deleted Geometry " << this << std::endl;
}
const XdmfGeometryType& XdmfGeometry::getGeometryType() const
XdmfGeometryType XdmfGeometry::getGeometryType() const
{
return *mGeometryType;
return mGeometryType;
}
void XdmfGeometry::setGeometryType(const XdmfGeometryType& geomType)
{
mGeometryType = &geomType;
return;
mGeometryType = geomType;
}
const std::string XdmfGeometry::getGeometryTypeAsString() const
std::string XdmfGeometry::getGeometryTypeAsString() const
{
return mGeometryType->name;
return mGeometryType.getName();
}
const int XdmfGeometry::getDimensions() const
int XdmfGeometry::getDimensions() const
{
return mGeometryType->dimensions;
return mGeometryType.getDimensions();
}
const std::string XdmfGeometry::printSelf() const
{
return "XdmfGeometry";
}
void XdmfGeometry::write(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this);
}
......@@ -8,66 +8,78 @@
#ifndef XDMFGEOMETRY_HPP_
#define XDMFGEOMETRY_HPP_
// Includes
#include "XdmfItem.hpp"
class XdmfGeometryType {
public:
const int dimensions;
const std::string name;
// Supported Xdmf Geometry Types
static const XdmfGeometryType NoGeometry;
static const XdmfGeometryType XYZ;
static const XdmfGeometryType XY;
static const XdmfGeometryType X_Y_Z;
static const XdmfGeometryType X_Y;
static const XdmfGeometryType VXVYVZ;
static const XdmfGeometryType Origin_DXDYDZ;
static const XdmfGeometryType VXVY;
static const XdmfGeometryType Origin_DXDY;
static XdmfGeometryType NoGeometryType();
static XdmfGeometryType XYZ();
static XdmfGeometryType XY();
static XdmfGeometryType X_Y_Z();
static XdmfGeometryType X_Y();
static XdmfGeometryType VXVYVZ();
static XdmfGeometryType Origin_DXDYDZ();
static XdmfGeometryType VXVY();
static XdmfGeometryType Origin_DXDY();
/**
* Get the dimensions of this geometry type - i.e. XYZ = 3.
*
* @return an int containing number of dimensions.
*/
int getDimensions() const;
/**
* Get the name of this geometry type
*
* @return a string containing the name.
*/
std::string getName() const;
/*
* Compare two XdmfGeometry types for equality. Each geometry type has a single static instance meaning that
* equality can be determined by determining if they have the same pointer value.
* Compare two XdmfGeometry types for equality.
*
* @param an XdmfGeometryType to compare equality to.
* @return true iff the XdmfGeometryTypes are equal.
*/
bool operator==(const XdmfGeometryType& top) const
{
return (this == &top) ? true : false;
return mDimensions == top.mDimensions && mName.compare(top.mName) == 0;
}
/**
* Compare two XdmfGeometry types for inequality. Each geometry type has a single static instance meaning that
* equality can be determined by determining if they have the same pointer value.
* Compare two XdmfGeometry types for inequality.
*
* @param XdmfGeometryType to compare inequality to.
* @return true iff the XdmfGeometryTypes are not equal.
*/
bool operator!=(const XdmfGeometryType& top) const
{
return (this != &top) ? true : false;
return !this->operator ==(top);
}
XdmfGeometryType(const XdmfGeometryType&);
XdmfGeometryType& operator=(const XdmfGeometryType&);
protected:
/**
* Protected constructor for XdmfGeometryType. The constructor is protected because all geometry types supported
* by Xdmf should be accessed through static public instances of XdmfGeometryType - i.e. XdmfGeometryType::XYZ.
* by Xdmf should be accessed through more specific static methods that construct XdmfGeometryTypes - i.e. XdmfGeometryType::XYZ().
*/
XdmfGeometryType(const std::string& name, const int& dimensions) :
name(name),
dimensions(dimensions)
mName(name),
mDimensions(dimensions)
{};
private:
//XdmfTopologyType(const XdmfTopologyType&); // Not implemented.
//void operator=(const XdmfTopologyType&); // Not implemented.
int mDimensions;
std::string mName;
};
class XdmfGeometry : public XdmfItem {
......@@ -76,14 +88,12 @@ public:
XdmfNewMacro(XdmfGeometry);
virtual void write(boost::shared_ptr<XdmfVisitor>) const;
/**
* Get the XdmfGeometryType associated with this Geometry.
*
* @return XdmfGeometryType.
*/
const XdmfGeometryType& getGeometryType() const;
XdmfGeometryType getGeometryType() const;
/**
* Set the XdmfGeometryType associated with this Geometry.
......@@ -97,17 +107,19 @@ public:
*
* @return std::string containing name of the GeometryType.
*/
const std::string getGeometryTypeAsString() const;
std::string getGeometryTypeAsString() const;
/**
* Get the number of dimensions for this Geometry.
*
* @return int giving number of dimensions: i.e. XY = 2, XYZ = 3.
*/
const int getDimensions() const;
int getDimensions() const;
virtual const std::string printSelf() const;
virtual void write(boost::shared_ptr<XdmfVisitor> visitor) const;
protected:
XdmfGeometry();
......@@ -115,10 +127,10 @@ protected:
private:
XdmfGeometry(const XdmfGeometry&); // Not implemented.
void operator=(const XdmfGeometry&); // Not implemented.
XdmfGeometry(const XdmfGeometry&); // Not implemented.
void operator=(const XdmfGeometry&); // Not implemented.
const XdmfGeometryType * mGeometryType;
XdmfGeometryType mGeometryType;
};
......
......@@ -8,10 +8,13 @@
#include "XdmfGrid.hpp"
#include "XdmfGeometry.hpp"
#include "XdmfTopology.hpp"
#include "XdmfVisitor.hpp"
#include <sstream>
XdmfGrid::XdmfGrid() :
mGeometry(XdmfGeometry::New()),
mTopology(XdmfTopology::New())
mTopology(XdmfTopology::New()),
mName("Grid")
{
std::cout << "Created Grid " << this << std::endl;
}
......@@ -21,12 +24,61 @@ XdmfGrid::~XdmfGrid()
std::cout << "Deleted Grid " << this << std::endl;
}
void XdmfGrid::write(boost::shared_ptr<XdmfVisitor>) const
/**
* Set the geometry associated with this grid.
*
* @param a smart pointer to the geometry to attach
*/
void setGeometry(boost::shared_ptr<const XdmfGeometry>);
boost::shared_ptr<XdmfGeometry> XdmfGrid::getGeometry()
{
return mGeometry;
}
boost::shared_ptr<const XdmfGeometry> XdmfGrid::getGeometry() const
{
return mGeometry;
}
void XdmfGrid::setGeometry(boost::shared_ptr<XdmfGeometry> geometry)
{
mGeometry = geometry;
}
boost::shared_ptr<XdmfTopology> XdmfGrid::getTopology()
{
return mTopology;
}
boost::shared_ptr<const XdmfTopology> XdmfGrid::getTopology() const
{
return mTopology;
}
void XdmfGrid::setTopology(boost::shared_ptr<XdmfTopology> topology)
{
mTopology = topology;
}
std::string XdmfGrid::getName() const
{
return mName;
}
void XdmfGrid::setName(const std::string& name)
{
mName= name;
}
const std::string XdmfGrid::printSelf() const
{
return "XdmfGrid containing a " + mGeometry->printSelf() + " and a " + mTopology->printSelf();
}
void XdmfGrid::write(boost::shared_ptr<XdmfVisitor> visitor) const
{
visitor->visit(this);
}
......@@ -8,7 +8,6 @@
class XdmfAttribute;
class XdmfGeometry;
class XdmfTopology;
class XdmfVisitor;
// Includes
#include "XdmfItem.hpp"
......@@ -20,22 +19,66 @@ public:
XdmfNewMacro(XdmfGrid);
virtual void write(boost::shared_ptr<XdmfVisitor>) const;
// Get the XdmfGeometry for this grid
XdmfGetValueMacro(Geometry, boost::shared_ptr<XdmfGeometry>);
// Set the XdmfGeometry for this grid
XdmfSetValueMacro(Geometry, boost::shared_ptr<XdmfGeometry>);
// Get the XdmfTopology for this grid
XdmfGetValueMacro(Topology, boost::shared_ptr<XdmfTopology>);
// Set the XdmfTopology for this grid
XdmfSetValueMacro(Topology, boost::shared_ptr<XdmfTopology>);
//virtual void write(XdmfVisitor&) const;
/**
* Get the geometry associated with this grid.
*
* @return a smart pointer to the geometry.
*/
boost::shared_ptr<XdmfGeometry> getGeometry();
/**
* Get the geometry associated with this grid (const version).
*
* @return a smart pointer to the geometry.
*/
boost::shared_ptr<const XdmfGeometry> getGeometry() const;
/**
* Set the geometry associated with this grid.
*
* @param a smart pointer to the geometry to attach to this grid.
*/
void setGeometry(boost::shared_ptr<XdmfGeometry>);
/**
* Get the topology associated with this grid.
*
* @return a smart pointer to the topology.
*/
boost::shared_ptr<XdmfTopology> getTopology();
/**
* Get the topology associated with this grid (const version).
*
* @return a smart pointer to the topology.
*/
boost::shared_ptr<const XdmfTopology> getTopology() const;
/**
* Set the geometry associated with this grid.
*
* @param a smart pointer to the topology to attach to this grid.
*/
void setTopology(boost::shared_ptr<XdmfTopology>);
/**
* Get the name of the grid.
*
* @return a string containing the name of the grid.
*/
std::string getName() const;
/**
* Set the name of the grid.
*
* @param a string containing the name to set.
*/
void setName(const std::string&);
virtual const std::string printSelf() const;
virtual void write(boost::shared_ptr<XdmfVisitor> visitor) const;
protected:
XdmfGrid();
......@@ -43,13 +86,13 @@ protected:
private:
XdmfGrid(const XdmfGrid&); // Not implemented.
void operator=(const XdmfGrid&); // Not implemented.
XdmfGrid(const XdmfGrid&); // Not implemented.
void operator=(const XdmfGrid&); // Not implemented.
boost::shared_ptr<XdmfGeometry> mGeometry;
boost::shared_ptr<XdmfTopology> mTopology;
std::vector<boost::shared_ptr<XdmfAttribute> > mAttributes;
std::string mName;
};
#endif /* XDMFGRID_HPP_ */
......@@ -18,7 +18,6 @@ class XdmfItem : public XdmfObject {
public:
//virtual const std::string printSelf() const = 0;
virtual void write(boost::shared_ptr<XdmfVisitor>) const = 0;
protected:
......@@ -28,8 +27,8 @@ protected:
private:
//XdmfItem(const XdmfItem&); // Not implemented.
//void operator=(const XdmfItem&); // Not implemented.
XdmfItem(const XdmfItem&); // Not implemented.
void operator=(const XdmfItem&); // Not implemented.
};
......