XdmfGrid.cpp 4.27 KB
Newer Older
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
1 2 3 4 5 6 7
/*
 * XdmfGrid.cpp
 *
 *  Created on: Jan 25, 2010
 *      Author: kleiter
 */

8
#include "XdmfAttribute.hpp"
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
9
#include "XdmfGeometry.hpp"
10
#include "XdmfGrid.hpp"
11
#include "XdmfMap.hpp"
12
#include "XdmfSet.hpp"
13
#include "XdmfTime.hpp"
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
14 15
#include "XdmfTopology.hpp"

16 17 18
XDMF_CHILDREN_IMPLEMENTATION(XdmfGrid, XdmfAttribute, Attribute, Name)
XDMF_CHILDREN_IMPLEMENTATION(XdmfGrid, XdmfSet, Set, Name)

19 20 21 22 23 24
boost::shared_ptr<XdmfGrid> XdmfGrid::New()
{
	boost::shared_ptr<XdmfGrid> p(new XdmfGrid());
	return p;
}

25
XdmfGrid::XdmfGrid(const std::string & name) :
Ken Leiter (Civ ARL/CISD) kleiter's avatar
ENH:  
Ken Leiter (Civ ARL/CISD) kleiter committed
26
	mGeometry(XdmfGeometry::New()),
27
	mMap(boost::shared_ptr<XdmfMap>()),
28
	mName(name),
29
	mTime(boost::shared_ptr<XdmfTime>()),
30
	mTopology(XdmfTopology::New())
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
31 32 33 34 35 36 37
{
}

XdmfGrid::~XdmfGrid()
{
}

38
const std::string XdmfGrid::ItemTag = "Grid";
39

40 41
boost::shared_ptr<XdmfGeometry> XdmfGrid::getGeometry()
{
42
	return boost::const_pointer_cast<XdmfGeometry>(static_cast<const XdmfGrid &>(*this).getGeometry());
43 44 45 46
}

boost::shared_ptr<const XdmfGeometry> XdmfGrid::getGeometry() const
{
47
	return mGeometry;
48 49
}

50 51 52 53 54 55 56
std::map<std::string, std::string> XdmfGrid::getItemProperties() const
{
	std::map<std::string, std::string> gridProperties;
	gridProperties["Name"] = mName;
	return gridProperties;
}

57 58
std::string XdmfGrid::getItemTag() const
{
59
	return ItemTag;
60 61
}

62 63 64 65 66 67 68 69 70 71
boost::shared_ptr<XdmfMap> XdmfGrid::getMap()
{
	return boost::const_pointer_cast<XdmfMap>(static_cast<const XdmfGrid &>(*this).getMap());
}

boost::shared_ptr<const XdmfMap> XdmfGrid::getMap() const
{
	return mMap;
}

72
std::string XdmfGrid::getName() const
73
{
74
	return mName;
75 76
}

77 78 79 80 81 82 83 84 85 86
boost::shared_ptr<XdmfTime> XdmfGrid::getTime()
{
	return boost::const_pointer_cast<XdmfTime>(static_cast<const XdmfGrid &>(*this).getTime());
}

boost::shared_ptr<const XdmfTime> XdmfGrid::getTime() const
{
	return mTime;
}

87
boost::shared_ptr<XdmfTopology> XdmfGrid::getTopology()
88
{
89
	return boost::const_pointer_cast<XdmfTopology>(static_cast<const XdmfGrid &>(*this).getTopology());
90
}
91

92
boost::shared_ptr<const XdmfTopology> XdmfGrid::getTopology() const
93
{
94
	return mTopology;
95 96
}

97
void XdmfGrid::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader)
98
{
99
	XdmfItem::populateItem(itemProperties, childItems, reader);
100 101 102 103 104 105 106
	std::map<std::string, std::string>::const_iterator name = itemProperties.find("Name");
	if(name != itemProperties.end())
	{
		mName = name->second;
	}
	else
	{
107
		mName = "";
108 109 110 111 112 113 114 115 116 117 118
	}
	for(std::vector<boost::shared_ptr<XdmfItem> >::const_iterator iter = childItems.begin(); iter != childItems.end(); ++iter)
	{
		if(boost::shared_ptr<XdmfAttribute> attribute = boost::shared_dynamic_cast<XdmfAttribute>(*iter))
		{
			this->insert(attribute);
		}
		else if(boost::shared_ptr<XdmfGeometry> geometry = boost::shared_dynamic_cast<XdmfGeometry>(*iter))
		{
			mGeometry = geometry;
		}
119 120 121 122
		else if(boost::shared_ptr<XdmfMap> map = boost::shared_dynamic_cast<XdmfMap>(*iter))
		{
			mMap = map;
		}
123
		else if(boost::shared_ptr<XdmfSet> set = boost::shared_dynamic_cast<XdmfSet>(*iter))
124 125 126
		{
			this->insert(set);
		}
127 128 129 130
		else if(boost::shared_ptr<XdmfTime> time = boost::shared_dynamic_cast<XdmfTime>(*iter))
		{
			mTime = time;
		}
131 132 133 134 135 136 137
		else if(boost::shared_ptr<XdmfTopology> topology = boost::shared_dynamic_cast<XdmfTopology>(*iter))
		{
			mTopology = topology;
		}
	}
}

138
void XdmfGrid::setGeometry(const boost::shared_ptr<XdmfGeometry> geometry)
139
{
140
	mGeometry = geometry;
141 142
}

143 144 145 146 147
void XdmfGrid::setMap(boost::shared_ptr<XdmfMap> map)
{
	mMap = map;
}

148
void XdmfGrid::setName(const std::string & name)
149
{
150
	mName = name;
151 152
}

153 154 155 156 157
void XdmfGrid::setTime(const boost::shared_ptr<XdmfTime> time)
{
	mTime = time;
}

158
void XdmfGrid::setTopology(const boost::shared_ptr<XdmfTopology> topology)
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
159
{
160
	mTopology = topology;
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
161
}
162

163
void XdmfGrid::traverse(const boost::shared_ptr<XdmfBaseVisitor> visitor)
164
{
165
	XdmfItem::traverse(visitor);
166
	if(mTime)
167 168 169
	{
		mTime->accept(visitor);
	}
170
	if(mGeometry)
171 172 173
	{
		mGeometry->accept(visitor);
	}
174
	if(mTopology)
175 176 177
	{
		mTopology->accept(visitor);
	}
178
	if(mMap)
179 180 181
	{
		mMap->accept(visitor);
	}
182 183
	for(std::vector<boost::shared_ptr<XdmfAttribute> >::const_iterator iter = mAttributes.begin(); iter != mAttributes.end(); ++iter)
	{
184
		(*iter)->accept(visitor);
185
	}
186 187 188 189
	for(std::vector<boost::shared_ptr<XdmfSet> >::const_iterator iter = mSets.begin(); iter != mSets.end(); ++iter)
	{
		(*iter)->accept(visitor);
	}
190
}