Commit 08b41ff6 authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Add XdmfItemProperty to genericize properties attached to XdmfItems. Add...

ENH: Add XdmfItemProperty to genericize properties attached to XdmfItems.  Add a pure virtual getItemProperties() method
to XdmfItem to force children to implement a way to retrieve properties.
parent e93ca0fd
...@@ -43,6 +43,7 @@ set(XdmfSources ...@@ -43,6 +43,7 @@ set(XdmfSources
XdmfGeometryType XdmfGeometryType
XdmfGrid XdmfGrid
XdmfItem XdmfItem
XdmfItemProperty
XdmfObject XdmfObject
XdmfTopology XdmfTopology
XdmfTopologyType XdmfTopologyType
......
...@@ -468,6 +468,16 @@ hid_t XdmfArray::getHDF5Type() const ...@@ -468,6 +468,16 @@ hid_t XdmfArray::getHDF5Type() const
return -1; return -1;
} }
std::map<std::string, std::string> XdmfArray::getItemProperties() const
{
std::map<std::string, std::string> arrayProperties;
arrayProperties["Format"] = "HDF";
arrayProperties["DataType"] = this->getType();
arrayProperties["Precision"] = this->getPrecision();
arrayProperties["Dimensions"] = this->getSize();
return arrayProperties;
}
unsigned int XdmfArray::getPrecision() const unsigned int XdmfArray::getPrecision() const
{ {
if(mHaveArray) if(mHaveArray)
......
...@@ -92,6 +92,8 @@ public: ...@@ -92,6 +92,8 @@ public:
*/ */
virtual hid_t getHDF5Type() const; virtual hid_t getHDF5Type() const;
std::map<std::string, std::string> getItemProperties() const;
/** /**
* Get the precision, in bytes, of the data type of this array. * Get the precision, in bytes, of the data type of this array.
* *
......
...@@ -31,6 +31,15 @@ XdmfAttributeType XdmfAttribute::getAttributeType() const ...@@ -31,6 +31,15 @@ XdmfAttributeType XdmfAttribute::getAttributeType() const
return mAttributeType; return mAttributeType;
} }
std::map<std::string, std::string> XdmfAttribute::getItemProperties() const
{
std::map<std::string, std::string> attributeProperties;
attributeProperties["Name"] = mName;
mAttributeType.getProperties(attributeProperties);
mAttributeCenter.getProperties(attributeProperties);
return attributeProperties;
}
std::string XdmfAttribute::getName() const std::string XdmfAttribute::getName() const
{ {
return mName; return mName;
......
...@@ -33,6 +33,8 @@ public: ...@@ -33,6 +33,8 @@ public:
*/ */
XdmfAttributeType getAttributeType() const; XdmfAttributeType getAttributeType() const;
std::map<std::string, std::string> getItemProperties() const;
/** /**
* Get the name of the attribute. * Get the name of the attribute.
* *
......
...@@ -65,3 +65,8 @@ std::string XdmfAttributeCenter::getName() const ...@@ -65,3 +65,8 @@ std::string XdmfAttributeCenter::getName() const
{ {
return mName; return mName;
} }
void XdmfAttributeCenter::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
collectedProperties["Center"] = this->mName;
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#define XDMFATTRIBUTECENTER_HPP_ #define XDMFATTRIBUTECENTER_HPP_
// Includes // Includes
#include <string> #include "XdmfItemProperty.hpp"
/** /**
* @brief Property describing where XdmfAttribute values are centered. * @brief Property describing where XdmfAttribute values are centered.
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* Edge * Edge
* Node * Node
*/ */
class XdmfAttributeCenter { class XdmfAttributeCenter : public XdmfItemProperty {
public: public:
...@@ -30,12 +30,14 @@ public: ...@@ -30,12 +30,14 @@ public:
static XdmfAttributeCenter Node(); static XdmfAttributeCenter Node();
/** /**
* Create the name of this attribute center. * Get the name of this attribute center.
* *
* @return a string containing the name. * @return a string containing the name.
*/ */
std::string getName() const; std::string getName() const;
void getProperties(std::map<std::string, std::string> & collectedProperties) const;
/** /**
* Compare two XdmfAttributeCenters for equality. * Compare two XdmfAttributeCenters for equality.
* *
...@@ -55,7 +57,6 @@ public: ...@@ -55,7 +57,6 @@ public:
XdmfAttributeCenter(const XdmfAttributeCenter & attributeCenter); XdmfAttributeCenter(const XdmfAttributeCenter & attributeCenter);
XdmfAttributeCenter& operator=(const XdmfAttributeCenter & attributeCenter); XdmfAttributeCenter& operator=(const XdmfAttributeCenter & attributeCenter);
protected: protected:
/** /**
......
...@@ -75,3 +75,8 @@ std::string XdmfAttributeType::getName() const ...@@ -75,3 +75,8 @@ std::string XdmfAttributeType::getName() const
{ {
return mName; return mName;
} }
void XdmfAttributeType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
collectedProperties["AttributeType"] = this->mName;
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#define XDMFATTRIBUTETYPE_HPP_ #define XDMFATTRIBUTETYPE_HPP_
// Includes // Includes
#include <string> #include "XdmfItemProperty.hpp"
/** /**
* @brief Property describing what types of values an XdmfAttribute contains. * @brief Property describing what types of values an XdmfAttribute contains.
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
* Tensor6 * Tensor6
* GlobalId * GlobalId
*/ */
class XdmfAttributeType { class XdmfAttributeType : public XdmfItemProperty {
public: public:
...@@ -40,6 +40,8 @@ public: ...@@ -40,6 +40,8 @@ public:
*/ */
std::string getName() const; std::string getName() const;
void getProperties(std::map<std::string, std::string> & collectedProperties) const;
/* /*
* Compare two XdmfAttributeTypes for equality. * Compare two XdmfAttributeTypes for equality.
* *
......
...@@ -44,6 +44,12 @@ boost::shared_ptr<const XdmfGrid> XdmfDomain::getGrid(unsigned int index) const ...@@ -44,6 +44,12 @@ boost::shared_ptr<const XdmfGrid> XdmfDomain::getGrid(unsigned int index) const
return mGrids[index]; return mGrids[index];
} }
std::map<std::string, std::string> XdmfDomain::getItemProperties() const
{
std::map<std::string, std::string> domainProperties;
return domainProperties;
}
unsigned int XdmfDomain::getNumberOfGrids() const unsigned int XdmfDomain::getNumberOfGrids() const
{ {
return mGrids.size(); return mGrids.size();
......
...@@ -37,12 +37,7 @@ public: ...@@ -37,12 +37,7 @@ public:
*/ */
boost::shared_ptr<const XdmfGrid> getGrid(unsigned int index) const; boost::shared_ptr<const XdmfGrid> getGrid(unsigned int index) const;
/** std::map<std::string, std::string> getItemProperties() const;
* Insert a XdmfGrid into the domain.
*
* @param grid a shared pointer to an XdmfGrid to insert into the domain.
*/
void insert(boost::shared_ptr<XdmfGrid> grid);
/** /**
* Get the number of XdmfGrids attached to this domain. * Get the number of XdmfGrids attached to this domain.
...@@ -51,6 +46,13 @@ public: ...@@ -51,6 +46,13 @@ public:
*/ */
unsigned int getNumberOfGrids() const; unsigned int getNumberOfGrids() const;
/**
* Insert a XdmfGrid into the domain.
*
* @param grid a shared pointer to an XdmfGrid to insert into the domain.
*/
void insert(boost::shared_ptr<XdmfGrid> grid);
virtual void traverse(boost::shared_ptr<Loki::BaseVisitor> visitor); virtual void traverse(boost::shared_ptr<Loki::BaseVisitor> visitor);
protected: protected:
......
...@@ -25,6 +25,13 @@ XdmfGeometryType XdmfGeometry::getGeometryType() const ...@@ -25,6 +25,13 @@ XdmfGeometryType XdmfGeometry::getGeometryType() const
return mGeometryType; return mGeometryType;
} }
std::map<std::string, std::string> XdmfGeometry::getItemProperties() const
{
std::map<std::string, std::string> geometryProperties;
mGeometryType.getProperties(geometryProperties);
return geometryProperties;
}
void XdmfGeometry::setGeometryType(const XdmfGeometryType & geometryType) void XdmfGeometry::setGeometryType(const XdmfGeometryType & geometryType)
{ {
mGeometryType = geometryType; mGeometryType = geometryType;
......
...@@ -26,6 +26,8 @@ public: ...@@ -26,6 +26,8 @@ public:
*/ */
XdmfGeometryType getGeometryType() const; XdmfGeometryType getGeometryType() const;
std::map<std::string, std::string> getItemProperties() const;
/** /**
* Set the XdmfGeometryType associated with this geometry. * Set the XdmfGeometryType associated with this geometry.
* *
......
...@@ -85,3 +85,8 @@ std::string XdmfGeometryType::getName() const ...@@ -85,3 +85,8 @@ std::string XdmfGeometryType::getName() const
{ {
return mName; return mName;
} }
void XdmfGeometryType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
collectedProperties["GeometryType"] = this->mName;
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#define XDMFGEOMETRYTYPE_HPP_ #define XDMFGEOMETRYTYPE_HPP_
// Includes // Includes
#include <string> #include "XdmfItemProperty.hpp"
/** /**
* @brief Property describing the types of coordinate values stored in an XdmfGeometry. * @brief Property describing the types of coordinate values stored in an XdmfGeometry.
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
* VXVY * VXVY
* Origin_DXDY * Origin_DXDY
*/ */
class XdmfGeometryType { class XdmfGeometryType : public XdmfItemProperty {
public: public:
...@@ -51,6 +51,8 @@ public: ...@@ -51,6 +51,8 @@ public:
*/ */
std::string getName() const; std::string getName() const;
void getProperties(std::map<std::string, std::string> & collectedProperties) const;
/* /*
* Compare two XdmfGeometry types for equality. * Compare two XdmfGeometry types for equality.
* *
......
...@@ -55,6 +55,13 @@ boost::shared_ptr<const XdmfGeometry> XdmfGrid::getGeometry() const ...@@ -55,6 +55,13 @@ boost::shared_ptr<const XdmfGeometry> XdmfGrid::getGeometry() const
return mGeometry; return mGeometry;
} }
std::map<std::string, std::string> XdmfGrid::getItemProperties() const
{
std::map<std::string, std::string> gridProperties;
gridProperties["Name"] = mName;
return gridProperties;
}
std::string XdmfGrid::getName() const std::string XdmfGrid::getName() const
{ {
return mName; return mName;
......
...@@ -54,6 +54,8 @@ public: ...@@ -54,6 +54,8 @@ public:
*/ */
boost::shared_ptr<const XdmfGeometry> getGeometry() const; boost::shared_ptr<const XdmfGeometry> getGeometry() const;
std::map<std::string, std::string> getItemProperties() const;
/** /**
* Get the name of the grid. * Get the name of the grid.
* *
......
...@@ -14,6 +14,7 @@ class XdmfVisitor; ...@@ -14,6 +14,7 @@ class XdmfVisitor;
// Includes // Includes
#include <loki/Visitor.h> #include <loki/Visitor.h>
#include <map>
#include "XdmfObject.hpp" #include "XdmfObject.hpp"
/** /**
...@@ -28,6 +29,19 @@ class XdmfItem : public XdmfObject, ...@@ -28,6 +29,19 @@ class XdmfItem : public XdmfObject,
public: public:
LOKI_DEFINE_VISITABLE_BASE() LOKI_DEFINE_VISITABLE_BASE()
/**
* Get the key/value property pairs for this XdmfItem. These are equivalent to attributes in XML parlance.
*
* @return a map of key/value properties associated with this XdmfItem.
*/
virtual std::map<std::string, std::string> getItemProperties() const = 0;
/**
* Traverse this XdmfItem by passing the visitor to its children XdmfItems.
*
* @param a visitor to pass to this XdmfItem's children.
*/
virtual void traverse(boost::shared_ptr<Loki::BaseVisitor> visitor); virtual void traverse(boost::shared_ptr<Loki::BaseVisitor> visitor);
protected: protected:
......
#include "XdmfItemProperty.hpp"
XdmfItemProperty::XdmfItemProperty()
{
}
XdmfItemProperty::~XdmfItemProperty()
{
}
#ifndef XDMFITEMPROPERTY_HPP_
#define XDMFITEMPROPERTY_HPP_
// Includes
#include <string>
#include <map>
#include "XdmfObject.hpp"
/**
* @brief Represents a property attached to an XdmfItem.
*
* XdmfItems can have zero or more properties attached to them that describe a specific characteristic of that item.
* For instance, XdmfAttributes have both Type and Center Properties.
*
* This is an abstract base class to facilitate reading and writing of properties in a generic way.
*/
class XdmfItemProperty : public XdmfObject {
public:
/**
* Retrieve the key/value pairs that this XdmfItemProperty contains by inserting into the passed vector.
*
* @param a std::vector<std::pair<std::string, std::string> > to insert name / value pairs into.
*/
virtual void getProperties(std::map<std::string, std::string> & collectedProperties) const = 0;
protected:
XdmfItemProperty();
virtual ~XdmfItemProperty();
private:
XdmfItemProperty(const XdmfItemProperty&); // Not implemented.
void operator=(const XdmfItemProperty&); // Not implemented.
};
#endif /* XDMFITEMPROPERTY_HPP_ */
...@@ -21,6 +21,13 @@ XdmfTopology::~XdmfTopology() ...@@ -21,6 +21,13 @@ XdmfTopology::~XdmfTopology()
std::cout << "Deleted Topology " << this << std::endl; std::cout << "Deleted Topology " << this << std::endl;
} }
std::map<std::string, std::string> XdmfTopology::getItemProperties() const
{
std::map<std::string, std::string> topologyProperties;
mTopologyType.getProperties(topologyProperties);
return topologyProperties;
}
unsigned int XdmfTopology::getNumberElements() const unsigned int XdmfTopology::getNumberElements() const
{ {
if(this->getTopologyType().getNodesPerElement() == 0) if(this->getTopologyType().getNodesPerElement() == 0)
......
...@@ -19,6 +19,8 @@ public: ...@@ -19,6 +19,8 @@ public:
XdmfNewMacro(XdmfTopology); XdmfNewMacro(XdmfTopology);
LOKI_DEFINE_VISITABLE(XdmfTopology, XdmfDataItem) LOKI_DEFINE_VISITABLE(XdmfTopology, XdmfDataItem)
std::map<std::string, std::string> getItemProperties() const;
/** /**
* Get the number of elements this Topology contains. * Get the number of elements this Topology contains.
* *
......
...@@ -23,7 +23,7 @@ XdmfTopologyType XdmfTopologyType::Polyline() ...@@ -23,7 +23,7 @@ XdmfTopologyType XdmfTopologyType::Polyline()
return XdmfTopologyType(1, "Polyline", Linear); return XdmfTopologyType(1, "Polyline", Linear);
} }
XdmfTopologyType XdmfTopologyType::Polygon(const int& nodesPerElement) XdmfTopologyType XdmfTopologyType::Polygon(const int nodesPerElement)
{ {
return XdmfTopologyType(nodesPerElement, "Polygon", Linear); return XdmfTopologyType(nodesPerElement, "Polygon", Linear);
} }
...@@ -176,3 +176,12 @@ unsigned int XdmfTopologyType::getNodesPerElement() const ...@@ -176,3 +176,12 @@ unsigned int XdmfTopologyType::getNodesPerElement() const
{ {
return mNodesPerElement; return mNodesPerElement;
} }
void XdmfTopologyType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
collectedProperties["TopologyType"] = this->mName;
if(this->getName().compare("Polygon") == 0)
{
collectedProperties["NodesPerElement"] = this->mNodesPerElement;
}
}
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
#define XDMFTOPOLOGYTYPE_HPP_ #define XDMFTOPOLOGYTYPE_HPP_
// Includes // Includes
#include <string> #include "XdmfItemProperty.hpp"
/** /**
* @brief Property describing the types of elements stored in an XdmfTopology. * @brief Property describing the types of elements stored in an XdmfTopology.
* *
...@@ -36,7 +35,7 @@ ...@@ -36,7 +35,7 @@
* ThreeDRectMesh * ThreeDRectMesh
* ThreeDCoRectMesh * ThreeDCoRectMesh
*/ */
class XdmfTopologyType { class XdmfTopologyType : public XdmfItemProperty {
public: public:
...@@ -48,7 +47,7 @@ public: ...@@ -48,7 +47,7 @@ public:
static XdmfTopologyType NoTopologyType(); static XdmfTopologyType NoTopologyType();
static XdmfTopologyType Polyvertex(); static XdmfTopologyType Polyvertex();
static XdmfTopologyType Polyline(); static XdmfTopologyType Polyline();
static XdmfTopologyType Polygon(const int & numNodes); static XdmfTopologyType Polygon(const int numNodes);
static XdmfTopologyType Triangle(); static XdmfTopologyType Triangle();
static XdmfTopologyType Quadrilateral(); static XdmfTopologyType Quadrilateral();
static XdmfTopologyType Tetrahedron(); static XdmfTopologyType Tetrahedron();
...@@ -91,6 +90,8 @@ public: ...@@ -91,6 +90,8 @@ public:
*/ */
unsigned int getNodesPerElement() const; unsigned int getNodesPerElement() const;
void getProperties(std::map<std::string, std::string> & collectedProperties) const;
/* /*
* Compare two XdmfTopologyTypes for equality. * Compare two XdmfTopologyTypes for equality.
* *
......
...@@ -1211,7 +1211,7 @@ ENABLE_PREPROCESSING = YES ...@@ -1211,7 +1211,7 @@ ENABLE_PREPROCESSING = YES
# compilation will be performed. Macro expansion can be done in a controlled # compilation will be performed. Macro expansion can be done in a controlled
# way by setting EXPAND_ONLY_PREDEF to YES. # way by setting EXPAND_ONLY_PREDEF to YES.
MACRO_EXPANSION = NO MACRO_EXPANSION = YES
# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
# then the macro expansion is limited to the macros specified with the # then the macro expansion is limited to the macros specified with the
......
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