Commit e31b3ce0 authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Add ability to remove XdmfAttributes and XdmfSets from XdmfGrids.

parent cd0f247f
......@@ -26,7 +26,7 @@ XdmfGrid::~XdmfGrid()
std::string XdmfGrid::ItemTag = "Grid";
boost::shared_ptr<XdmfAttribute> XdmfGrid::getAttribute(unsigned int index)
boost::shared_ptr<XdmfAttribute> XdmfGrid::getAttribute(const unsigned int index)
{
if(index >= mAttributes.size())
{
......@@ -35,7 +35,7 @@ boost::shared_ptr<XdmfAttribute> XdmfGrid::getAttribute(unsigned int index)
return mAttributes[index];
}
boost::shared_ptr<const XdmfAttribute> XdmfGrid::getAttribute(unsigned int index) const
boost::shared_ptr<const XdmfAttribute> XdmfGrid::getAttribute(const unsigned int index) const
{
if(index >= mAttributes.size())
{
......@@ -81,7 +81,7 @@ unsigned int XdmfGrid::getNumberOfSets() const
return mSets.size();
}
boost::shared_ptr<XdmfSet> XdmfGrid::getSet(unsigned int index)
boost::shared_ptr<XdmfSet> XdmfGrid::getSet(const unsigned int index)
{
if(index >= mSets.size())
{
......@@ -90,7 +90,7 @@ boost::shared_ptr<XdmfSet> XdmfGrid::getSet(unsigned int index)
return mSets[index];
}
boost::shared_ptr<const XdmfSet> XdmfGrid::getSet(unsigned int index) const
boost::shared_ptr<const XdmfSet> XdmfGrid::getSet(const unsigned int index) const
{
if(index >= mSets.size())
{
......@@ -151,6 +151,24 @@ void XdmfGrid::populateItem(const std::map<std::string, std::string> & itemPrope
}
}
void XdmfGrid::removeAttribute(const unsigned int index)
{
if(index >= mAttributes.size())
{
assert(false);
}
mAttributes.erase(mAttributes.begin() + index);
}
void XdmfGrid::removeSet(const unsigned int index)
{
if(index >= mSets.size())
{
assert(false);
}
mSets.erase(mSets.begin() + index);
}
void XdmfGrid::setGeometry(boost::shared_ptr<XdmfGeometry> geometry)
{
mGeometry = geometry;
......
......@@ -33,7 +33,7 @@ public:
* @param index of the XdmfAttribute to retrieve.
* @return smart pointer to the XdmfAttribute attached to this grid.
*/
boost::shared_ptr<XdmfAttribute> getAttribute(unsigned int index);
boost::shared_ptr<XdmfAttribute> getAttribute(const unsigned int index);
/**
* Get an XdmfAttribute attached to this grid (const version).
......@@ -41,7 +41,7 @@ public:
* @param index of the XdmfAttribute to retrieve.
* @return pointer to the XdmfAttribute attached to this grid.
*/
boost::shared_ptr<const XdmfAttribute> getAttribute(unsigned int index) const;
boost::shared_ptr<const XdmfAttribute> getAttribute(const unsigned int index) const;
/**
* Get the XdmfGeometry associated with this grid.
......@@ -88,7 +88,7 @@ public:
* @param index of the XdmfSet to retrieve.
* @return pointer to the XdmfSet attached to this grid.
*/
boost::shared_ptr<XdmfSet> getSet(unsigned int index);
boost::shared_ptr<XdmfSet> getSet(const unsigned int index);
/**
* Get an XdmfSet attached to this grid (const version).
......@@ -96,7 +96,7 @@ public:
* @param index of the XdmfSet to retrieve.
* @return pointer to the XdmfSet attached to this grid.
*/
boost::shared_ptr<const XdmfSet> getSet(unsigned int index) const;
boost::shared_ptr<const XdmfSet> getSet(const unsigned int index) const;
/**
* Get the XdmfTopology associated with this grid.
......@@ -126,6 +126,20 @@ public:
*/
void insert(boost::shared_ptr<XdmfSet> set);
/**
* Remove an XdmfAttribute from the grid.
*
* @param index of the XdmfAttribute to remove.
*/
void removeAttribute(const unsigned int index);
/**
* Remove an XdmfSet from the grid.
*
* @param index of the XdmfSet to remove.
*/
void removeSet(const unsigned int index);
/**
* Set the XdmfGeometry associated with this grid.
*
......
#include "XdmfAttribute.hpp"
#include "XdmfGrid.hpp"
#include "XdmfSet.hpp"
int main(int argc, char* argv[])
{
......@@ -11,11 +12,21 @@ int main(int argc, char* argv[])
std::cout << grid->getName() << std::endl;
boost::shared_ptr<XdmfAttribute> attr = XdmfAttribute::New();
attr->setName("Attr1");
assert(grid->getNumberOfAttributes() == 0);
grid->insert(attr);
assert(grid->getNumberOfAttributes() == 1);
assert(grid->getAttribute(0) == attr);
boost::shared_ptr<XdmfSet> set = XdmfSet::New();
assert(grid->getNumberOfSets() == 0);
grid->insert(set);
assert(grid->getNumberOfSets() == 1);
assert(grid->getSet(0) == set);
grid->removeAttribute(0);
grid->removeSet(0);
assert(grid->getNumberOfAttributes() == 0);
assert(grid->getNumberOfSets() == 0);
return 0;
}
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