XdmfGrid.cpp 6.38 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 10
#include "XdmfGrid.hpp"
#include "XdmfGeometry.hpp"
11
#include "XdmfSet.hpp"
12
#include "XdmfTime.hpp"
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
13 14
#include "XdmfTopology.hpp"

15 16 17 18 19 20
boost::shared_ptr<XdmfGrid> XdmfGrid::New()
{
	boost::shared_ptr<XdmfGrid> p(new XdmfGrid());
	return p;
}

21
XdmfGrid::XdmfGrid() :
Ken Leiter (Civ ARL/CISD) kleiter's avatar
ENH:  
Ken Leiter (Civ ARL/CISD) kleiter committed
22
	mGeometry(XdmfGeometry::New()),
23
	mTime(boost::shared_ptr<XdmfTime>()),
Ken Leiter (Civ ARL/CISD) kleiter's avatar
ENH:  
Ken Leiter (Civ ARL/CISD) kleiter committed
24 25
	mTopology(XdmfTopology::New()),
	mName("Grid")
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
26 27 28 29 30 31 32
{
}

XdmfGrid::~XdmfGrid()
{
}

33
const std::string XdmfGrid::ItemTag = "Grid";
34

35
boost::shared_ptr<XdmfAttribute> XdmfGrid::getAttribute(const unsigned int index)
36 37 38 39 40
{
	return boost::const_pointer_cast<XdmfAttribute>(static_cast<const XdmfGrid &>(*this).getAttribute(index));
}

boost::shared_ptr<const XdmfAttribute> XdmfGrid::getAttribute(const unsigned int index) const
41
{
42
	if(index < mAttributes.size())
43
	{
44
		return mAttributes[index];
45
	}
46
	return boost::shared_ptr<XdmfAttribute>();
47
}
48

49
boost::shared_ptr<XdmfAttribute> XdmfGrid::getAttribute(const std::string & name)
50
{
51
	return boost::const_pointer_cast<XdmfAttribute>(static_cast<const XdmfGrid &>(*this).getAttribute(name));
52 53
}

54
boost::shared_ptr<const XdmfAttribute> XdmfGrid::getAttribute(const std::string & name) const
55 56
{
	for(std::vector<boost::shared_ptr<XdmfAttribute> >::const_iterator iter = mAttributes.begin(); iter != mAttributes.end(); ++iter)
57
	{
58
		if((*iter)->getName().compare(name) == 0)
59 60 61
		{
			return *iter;
		}
62
	}
63 64 65
	return boost::shared_ptr<XdmfAttribute>();
}

66 67
boost::shared_ptr<XdmfGeometry> XdmfGrid::getGeometry()
{
68
	return boost::const_pointer_cast<XdmfGeometry>(static_cast<const XdmfGrid &>(*this).getGeometry());
69 70 71 72
}

boost::shared_ptr<const XdmfGeometry> XdmfGrid::getGeometry() const
{
73
	return mGeometry;
74 75
}

76 77 78 79 80 81 82
std::map<std::string, std::string> XdmfGrid::getItemProperties() const
{
	std::map<std::string, std::string> gridProperties;
	gridProperties["Name"] = mName;
	return gridProperties;
}

83 84
std::string XdmfGrid::getItemTag() const
{
85
	return ItemTag;
86 87
}

88
std::string XdmfGrid::getName() const
89
{
90
	return mName;
91 92
}

93
unsigned int XdmfGrid::getNumberAttributes() const
94
{
95
	return mAttributes.size();
96 97
}

98
unsigned int XdmfGrid::getNumberSets() const
99 100 101 102
{
	return mSets.size();
}

103
boost::shared_ptr<XdmfSet> XdmfGrid::getSet(const unsigned int index)
104 105 106 107 108
{
	return boost::const_pointer_cast<XdmfSet>(static_cast<const XdmfGrid &>(*this).getSet(index));
}

boost::shared_ptr<const XdmfSet> XdmfGrid::getSet(const unsigned int index) const
109
{
110
	if(index < mSets.size())
111
	{
112
		return mSets[index];
113
	}
114
	return boost::shared_ptr<XdmfSet>();
115 116
}

117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
boost::shared_ptr<XdmfSet> XdmfGrid::getSet(const std::string & name)
{
	return boost::const_pointer_cast<XdmfSet>(static_cast<const XdmfGrid &>(*this).getSet(name));
}

boost::shared_ptr<const XdmfSet> XdmfGrid::getSet(const std::string & name) const
{
	for(std::vector<boost::shared_ptr<XdmfSet> >::const_iterator iter = mSets.begin(); iter != mSets.end(); ++iter)
	{
		if((*iter)->getName().compare(name) == 0)
		{
			return *iter;
		}
	}
	return boost::shared_ptr<XdmfSet>();
}

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;
}

144
boost::shared_ptr<XdmfTopology> XdmfGrid::getTopology()
145
{
146
	return boost::const_pointer_cast<XdmfTopology>(static_cast<const XdmfGrid &>(*this).getTopology());
147
}
148

149
boost::shared_ptr<const XdmfTopology> XdmfGrid::getTopology() const
150
{
151
	return mTopology;
152 153
}

154
void XdmfGrid::insert(const boost::shared_ptr<XdmfAttribute> attribute)
155 156 157 158
{
	mAttributes.push_back(attribute);
}

159
void XdmfGrid::insert(const boost::shared_ptr<XdmfSet> set)
160 161 162 163
{
	mSets.push_back(set);
}

164 165 166 167 168 169 170 171 172
void XdmfGrid::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems)
{
	std::map<std::string, std::string>::const_iterator name = itemProperties.find("Name");
	if(name != itemProperties.end())
	{
		mName = name->second;
	}
	else
	{
173
		mName = "";
174 175 176 177 178 179 180 181 182 183 184
	}
	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;
		}
185
		else if(boost::shared_ptr<XdmfSet> set = boost::shared_dynamic_cast<XdmfSet>(*iter))
186 187 188
		{
			this->insert(set);
		}
189 190 191 192
		else if(boost::shared_ptr<XdmfTime> time = boost::shared_dynamic_cast<XdmfTime>(*iter))
		{
			mTime = time;
		}
193 194 195 196 197 198 199
		else if(boost::shared_ptr<XdmfTopology> topology = boost::shared_dynamic_cast<XdmfTopology>(*iter))
		{
			mTopology = topology;
		}
	}
}

200 201
void XdmfGrid::removeAttribute(const unsigned int index)
{
202
	if(index < mAttributes.size())
203
	{
204
		mAttributes.erase(mAttributes.begin() + index);
205 206 207
	}
}

208 209 210 211 212 213 214 215 216 217 218 219 220
void XdmfGrid::removeAttribute(const std::string & name)
{
	for(std::vector<boost::shared_ptr<XdmfAttribute> >::iterator iter = mAttributes.begin(); iter != mAttributes.end(); ++iter)
	{
		if((*iter)->getName().compare(name) == 0)
		{
			mAttributes.erase(iter);
			return;
		}
	}
	return;
}

221 222
void XdmfGrid::removeSet(const unsigned int index)
{
223
	if(index < mSets.size())
224
	{
225
		mSets.erase(mSets.begin() + index);
226 227 228
	}
}

229 230 231 232 233 234 235 236 237 238 239 240 241
void XdmfGrid::removeSet(const std::string & name)
{
	for(std::vector<boost::shared_ptr<XdmfSet> >::iterator iter = mSets.begin(); iter != mSets.end(); ++iter)
	{
		if((*iter)->getName().compare(name) == 0)
		{
			mSets.erase(iter);
			return;
		}
	}
	return;
}

242
void XdmfGrid::setGeometry(const boost::shared_ptr<XdmfGeometry> geometry)
243
{
244
	mGeometry = geometry;
245 246
}

247
void XdmfGrid::setName(const std::string & name)
248
{
249
	mName = name;
250 251
}

252 253 254 255 256
void XdmfGrid::setTime(const boost::shared_ptr<XdmfTime> time)
{
	mTime = time;
}

257
void XdmfGrid::setTopology(const boost::shared_ptr<XdmfTopology> topology)
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
258
{
259
	mTopology = topology;
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
260
}
261

262
void XdmfGrid::traverse(const boost::shared_ptr<XdmfBaseVisitor> visitor) const
263
{
264 265 266 267
	if(mTime != NULL)
	{
		mTime->accept(visitor);
	}
268 269
	mGeometry->accept(visitor);
	mTopology->accept(visitor);
270 271
	for(std::vector<boost::shared_ptr<XdmfAttribute> >::const_iterator iter = mAttributes.begin(); iter != mAttributes.end(); ++iter)
	{
272
		(*iter)->accept(visitor);
273
	}
274 275 276 277
	for(std::vector<boost::shared_ptr<XdmfSet> >::const_iterator iter = mSets.begin(); iter != mSets.end(); ++iter)
	{
		(*iter)->accept(visitor);
	}
278
}