XdmfArray.cpp 13.8 KB
Newer Older
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
1 2 3 4 5 6 7
/*
 * XdmfArray.cpp
 *
 *  Created on: Jan 29, 2010
 *      Author: kleiter
 */

8 9
#include <boost/tokenizer.hpp>
#include <sstream>
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
10
#include "XdmfArray.hpp"
11
#include "XdmfArrayType.hpp"
12
#include "XdmfHDF5Controller.hpp"
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
13 14
#include "XdmfVisitor.hpp"

15
class XdmfArray::Clear : public boost::static_visitor<void> {
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
16
public:
17

18
	Clear()
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
19 20 21
	{
	}

22 23
	template<typename T>
	void operator()(const boost::shared_ptr<std::vector<T> > & array) const
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
24
	{
25
		return array->clear();
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
26
	}
27 28
};

29
class XdmfArray::CopyArrayValues : public boost::static_visitor<void> {
30
public:
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
31

32
	CopyArrayValues(const unsigned int startIndex, const unsigned int valuesStartIndex, const unsigned int numValues, const unsigned int arrayStride, const unsigned int valuesStride) :
33 34 35 36 37
		mStartIndex(startIndex),
		mValuesStartIndex(valuesStartIndex),
		mNumValues(numValues),
		mArrayStride(arrayStride),
		mValuesStride(valuesStride)
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
38 39 40
	{
	}

41 42
	template<typename T, typename U>
	void operator()(const boost::shared_ptr<std::vector<T> > & array, const boost::shared_ptr<std::vector<U> > & arrayToCopy) const
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
43
	{
44
		unsigned int size = mStartIndex + mNumValues;
45 46 47 48 49 50 51 52 53 54 55 56
		if(mArrayStride > 1)
		{
			size = mStartIndex + mNumValues * mArrayStride - 1;
		}
		if(array->size() < size)
		{
			array->resize(size);
		}
		for(int i=0; i<mNumValues; ++i)
		{
			array->operator[](mStartIndex + i*mArrayStride) = (T)arrayToCopy->operator[](mValuesStartIndex + i*mValuesStride);
		}
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
57 58
	}

59 60
private:

61 62 63 64 65
	const unsigned int mStartIndex;
	const unsigned int mValuesStartIndex;
	const unsigned int mNumValues;
	const unsigned int mArrayStride;
	const unsigned int mValuesStride;
66 67
};

68
class XdmfArray::Erase : public boost::static_visitor<void> {
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
public:

	Erase(const unsigned int index) :
		mIndex(index)
	{
	}

	template<typename T>
	void operator()(const boost::shared_ptr<std::vector<T> > & array) const
	{
		array->erase(array->begin() + mIndex);
	}

private:

	const unsigned int mIndex;
};

87
class XdmfArray::GetCapacity : public boost::static_visitor<unsigned int> {
88 89 90 91 92 93 94 95 96 97 98 99 100
public:

	GetCapacity()
	{
	}

	template<typename T>
	unsigned int operator()(const boost::shared_ptr<std::vector<T> > & array) const
	{
		return array->capacity();
	}
};

101
class XdmfArray::GetType : public boost::static_visitor<boost::shared_ptr<const XdmfArrayType> > {
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
102
public:
103

104
	GetType()
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
105 106 107
	{
	}

108
	boost::shared_ptr<const XdmfArrayType> getType(const char * const) const
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
109
	{
110
		return XdmfArrayType::Int8();
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
111 112
	}

113
	boost::shared_ptr<const XdmfArrayType> getType(const short * const) const
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
114
	{
115
		return XdmfArrayType::Int16();
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
116 117
	}

118
	boost::shared_ptr<const XdmfArrayType> getType(const int * const) const
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
119
	{
120
		return XdmfArrayType::Int32();
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
121 122
	}

123
	boost::shared_ptr<const XdmfArrayType> getType(const long * const) const
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
124
	{
125
		return XdmfArrayType::Int64();
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
126 127
	}

128
	boost::shared_ptr<const XdmfArrayType> getType(const float * const) const
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
129
	{
130
		return XdmfArrayType::Float32();
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
131 132
	}

133
	boost::shared_ptr<const XdmfArrayType> getType(const double * const) const
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
134
	{
135
		return XdmfArrayType::Float64();
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
136 137
	}

138
	boost::shared_ptr<const XdmfArrayType> getType(const unsigned char * const) const
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
139
	{
140
		return XdmfArrayType::UInt8();
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
141 142
	}

143
	boost::shared_ptr<const XdmfArrayType> getType(const unsigned short * const) const
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
144
	{
145
		return XdmfArrayType::UInt16();
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
146 147
	}

148
	boost::shared_ptr<const XdmfArrayType> getType(const unsigned int * const) const
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
149
	{
150
		return XdmfArrayType::UInt32();
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
151
	}
152 153

	template<typename T>
154
	boost::shared_ptr<const XdmfArrayType> operator()(const boost::shared_ptr<std::vector<T> > & array) const
155 156 157 158 159
	{
		return this->getType(&(array.get()->operator[](0)));
	}

	template<typename T>
160
	boost::shared_ptr<const XdmfArrayType> operator()(const boost::shared_array<const T> & array) const
161 162 163
	{
		return this->getType(array.get());
	}
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
164 165
};

166
class XdmfArray::GetSize : public boost::static_visitor<unsigned int> {
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
167 168
public:

169
	GetSize()
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
170 171 172
	{
	}

173
	template<typename T>
174
	unsigned int operator()(const boost::shared_ptr<std::vector<T> > & array) const
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
175
	{
176
		return array->size();
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
177 178 179
	}
};

180
class XdmfArray::GetValuesPointer : public boost::static_visitor<const void * const> {
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
181 182
public:

183
	GetValuesPointer()
184 185 186
	{
	}

187
	template<typename T>
188
	const void * const operator()(const boost::shared_ptr<std::vector<T> > & array) const
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
189
	{
190
		return &array->operator[](0);
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
191
	}
192 193

	template<typename T>
194
	const void * const operator()(const boost::shared_array<const T> & array) const
195 196 197
	{
		return array.get();
	}
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
198 199
};

200
class XdmfArray::GetValuesString : public boost::static_visitor<std::string> {
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
201 202
public:

203 204 205 206 207
	GetValuesString() :
		mArrayPointerNumValues(0)
	{
	}

208 209
	GetValuesString(const int arrayPointerNumValues) :
		mArrayPointerNumValues(arrayPointerNumValues)
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
210 211 212
	{
	}

213
	std::string getValuesString(const char * const array, const int numValues) const
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
214 215
	{
		std::stringstream toReturn;
216
		for(int i=0; i<numValues; ++i)
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
217
		{
218
			toReturn << (int)array[i] << " ";
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
219 220 221 222
		}
		return toReturn.str();
	}

223
	template<typename T>
224
	std::string getValuesString(const T * const array, const int numValues) const
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
225 226
	{
		std::stringstream toReturn;
227
		for(int i=0; i<numValues; ++i)
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
228
		{
229
			toReturn << array[i] << " ";
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
230 231 232
		}
		return toReturn.str();
	}
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247

	template<typename T>
	std::string operator()(const boost::shared_ptr<std::vector<T> > & array) const
	{
		return getValuesString(&(array->operator[](0)), array->size());
	}

	template<typename T>
	std::string operator()(const boost::shared_array<const T> & array) const
	{
		return getValuesString(array.get(), mArrayPointerNumValues);
	}

private:

248
	const unsigned int mArrayPointerNumValues;
249 250
};

251
class XdmfArray::InternalizeArrayPointer : public boost::static_visitor<void> {
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
public:

	InternalizeArrayPointer(XdmfArray * const array) :
		mArray(array)
	{
	}

	template<typename T>
	void operator()(const boost::shared_array<const T> & array) const
	{
		mArray->mHaveArrayPointer = false;
		mArray->copyValues(0, array.get(), mArray->mArrayPointerNumValues);
		mArray->mArrayPointer = boost::shared_array<const T>();
		mArray->mArrayPointerNumValues = 0;
	}

private:

	XdmfArray * const mArray;
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
271 272
};

273
class XdmfArray::NewArray : public boost::static_visitor<void> {
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
274 275
public:

276
	NewArray()
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
277 278 279
	{
	}

280 281
	template<typename T>
	void operator()(boost::shared_ptr<std::vector<T> > & array) const
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
282
	{
283 284
		boost::shared_ptr<std::vector<T> > newArray(new std::vector<T>());
		array = newArray;
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
285 286 287
	}
};

288
class XdmfArray::Reserve : public boost::static_visitor<void> {
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
public:

	Reserve(const unsigned int size):
		mSize(size)
	{
	}

	template<typename T>
	void operator()(boost::shared_ptr<std::vector<T> > & array) const
	{
		array->reserve(mSize);
	}

private:

	const unsigned int mSize;
};

Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
307
XdmfArray::XdmfArray() :
308 309
	mHaveArray(false),
	mHaveArrayPointer(false),
310
	mArrayPointerNumValues(0),
311
	mHDF5Controller(boost::shared_ptr<XdmfHDF5Controller>()),
312
	mTmpReserveSize(0)
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
313 314 315 316 317 318 319 320 321
{
	std::cout << "Created Array " << this << std::endl;
}

XdmfArray::~XdmfArray()
{
	std::cout << "Deleted Array " << this << std::endl;
}

322
const std::string XdmfArray::ItemTag = "DataItem";
323

324 325 326 327 328 329 330 331
void XdmfArray::clear()
{
	if(mHaveArray)
	{
		return boost::apply_visitor(Clear(), mArray);
	}
}

332
void XdmfArray::copyValues(const unsigned int startIndex, const boost::shared_ptr<const XdmfArray> values, const unsigned int valuesStartIndex, const unsigned int numValues, const unsigned int arrayStride, const unsigned int valuesStride)
333
{
334 335 336 337 338
	if(mHaveArrayPointer)
	{
		internalizeArrayPointer();
	}
	if(!mHaveArray)
339 340
	{
		// Copy the values variant in order to get the type (only taking smart pointer so no worries about large copies)
341
		mArray = values->mArray;
342
		// Reinitialize variant array to contain new array with same type.
343 344
		boost::apply_visitor(NewArray(), mArray);
		mHaveArray = true;
345
	}
346
	boost::apply_visitor(CopyArrayValues(startIndex, valuesStartIndex, numValues, arrayStride, valuesStride), mArray, values->mArray);
347 348
}

349
void XdmfArray::erase(const unsigned int index)
350
{
351 352
	if(mHaveArray)
	{
353
		return boost::apply_visitor(Erase(index), mArray);
354
	}
355 356
}

357 358 359 360 361 362 363 364 365
unsigned int XdmfArray::getCapacity() const
{
	if(mHaveArray)
	{
		return boost::apply_visitor(GetCapacity(), mArray);
	}
	return 0;
}

366 367 368 369 370
boost::shared_ptr<XdmfHDF5Controller> XdmfArray::getHDF5Controller()
{
	return mHDF5Controller;
}

371
boost::shared_ptr<const XdmfHDF5Controller> XdmfArray::getHDF5Controller() const
372 373 374 375
{
	return mHDF5Controller;
}

376 377 378
std::map<std::string, std::string> XdmfArray::getItemProperties() const
{
	std::map<std::string, std::string> arrayProperties;
379 380 381 382 383 384 385 386
	if(mHDF5Controller)
	{
		arrayProperties["Format"] = "HDF";
	}
	else
	{
		arrayProperties["Format"] = "XML";
	}
387
	boost::shared_ptr<const XdmfArrayType> type = this->getType();
388 389 390
	std::stringstream size;
	size <<  this->getSize();
	arrayProperties["Dimensions"] = size.str();
391
	type->getProperties(arrayProperties);
392 393 394
	return arrayProperties;
}

395 396
std::string XdmfArray::getItemTag() const
{
397
	return ItemTag;
398 399
}

400
unsigned int XdmfArray::getSize() const
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
401
{
402 403 404 405 406 407 408 409
	if(mHaveArray)
	{
		return boost::apply_visitor(GetSize(), mArray);
	}
	else if(mHaveArrayPointer)
	{
		return mArrayPointerNumValues;
	}
410 411 412 413
	else if(mHDF5Controller)
	{
		return mHDF5Controller->getSize();
	}
414
	return 0;
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
415 416
}

417
boost::shared_ptr<const XdmfArrayType> XdmfArray::getType() const
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
418
{
419 420 421 422 423 424 425 426
	if(mHaveArray)
	{
		return boost::apply_visitor(GetType(), mArray);
	}
	else if(mHaveArrayPointer)
	{
		return boost::apply_visitor(GetType(), mArrayPointer);
	}
427 428 429 430
	else if(mHDF5Controller)
	{
		return mHDF5Controller->getType();
	}
431
	return XdmfArrayType::Uninitialized();
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
432 433
}

434 435 436 437 438 439
void * XdmfArray::getValuesPointer()
{
	return const_cast<void *>(static_cast<const XdmfArray &>(*this).getValuesPointer());
}

const void * XdmfArray::getValuesPointer() const
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
440
{
441 442 443 444 445 446 447 448 449
	if(mHaveArray)
	{
		return boost::apply_visitor(GetValuesPointer(), mArray);
	}
	else if(mHaveArrayPointer)
	{
		return boost::apply_visitor(GetValuesPointer(), mArrayPointer);
	}
	return NULL;
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
450 451
}

452
std::string XdmfArray::getValuesString() const
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
453
{
454 455
	if(mHaveArray)
	{
456
		return boost::apply_visitor(GetValuesString(), mArray);
457 458 459 460 461 462 463 464
	}
	else if(mHaveArrayPointer)
	{
		return boost::apply_visitor(GetValuesString(mArrayPointerNumValues), mArrayPointer);
	}
	return "";
}

465
void XdmfArray::initialize(const boost::shared_ptr<const XdmfArrayType> arrayType)
466
{
467
	if(arrayType == XdmfArrayType::Int8())
468 469 470
	{
		this->initialize<char>();
	}
471
	else if(arrayType == XdmfArrayType::Int16())
472 473 474
	{
		this->initialize<short>();
	}
475
	else if(arrayType == XdmfArrayType::Int32())
476 477 478
	{
		this->initialize<int>();
	}
479
	else if(arrayType == XdmfArrayType::Int64())
480 481 482
	{
		this->initialize<long>();
	}
483
	else if(arrayType == XdmfArrayType::Float32())
484 485 486
	{
		this->initialize<float>();
	}
487
	else if(arrayType == XdmfArrayType::Float64())
488 489 490
	{
		this->initialize<double>();
	}
491
	else if(arrayType == XdmfArrayType::UInt8())
492 493 494
	{
		this->initialize<unsigned char>();
	}
495
	else if(arrayType == XdmfArrayType::UInt16())
496 497 498
	{
		this->initialize<unsigned short>();
	}
499
	else if(arrayType == XdmfArrayType::Int32())
500 501 502
	{
		this->initialize<unsigned int>();
	}
503
	else if(arrayType == XdmfArrayType::Uninitialized())
504
	{
505
		this->release();
506
	}
507 508 509 510 511 512
	else
	{
		assert(false);
	}
}

513 514 515 516 517
bool XdmfArray::isInitialized()
{
	return mHaveArray || mHaveArrayPointer;
}

518 519 520 521 522 523
void XdmfArray::internalizeArrayPointer()
{
	if(mHaveArrayPointer)
	{
		boost::apply_visitor(InternalizeArrayPointer(this), mArrayPointer);
	}
Ken Leiter (Civ ARL/CISD) kleiter's avatar
Ken Leiter (Civ ARL/CISD) kleiter committed
524 525
}

526 527 528
void XdmfArray::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems)
{
	std::string contentVal;
529
	unsigned int sizeVal;
530

531
	const boost::shared_ptr<const XdmfArrayType> arrayType = XdmfArrayType::New(itemProperties);
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
	std::map<std::string, std::string>::const_iterator content = itemProperties.find("Content");
	if(content != itemProperties.end())
	{
		contentVal = content->second;
	}
	else
	{
		assert(false);
	}
	std::map<std::string, std::string>::const_iterator size = itemProperties.find("Dimensions");
	if(size != itemProperties.end())
	{
		sizeVal = atoi(size->second.c_str());
	}
	else
	{
		assert(false);
	}
	std::map<std::string, std::string>::const_iterator format = itemProperties.find("Format");
	if(format != itemProperties.end())
	{
		if(format->second.compare("HDF") == 0)
		{
555
			mHDF5Controller = XdmfHDF5Controller::New(contentVal, sizeVal, arrayType);
556 557 558
		}
		else if(format->second.compare("XML") == 0)
		{
559
			this->initialize(arrayType);
560
			this->reserve(sizeVal);
561
			boost::char_separator<char> sep(" \t\n");
562
			boost::tokenizer<boost::char_separator<char> > tokens(contentVal, sep);
563
			for(boost::tokenizer<boost::char_separator<char> >::const_iterator iter = tokens.begin(); iter != tokens.end(); ++iter)
564
			{
565 566
				this->pushBack(atof((*iter).c_str()));

567 568 569 570 571 572 573 574 575 576 577 578 579
			}
		}
		else
		{
			assert(false);
		}
	}
	else
	{
		assert(false);
	}
}

580 581 582 583 584 585 586 587
void XdmfArray::read()
{
	if(mHDF5Controller)
	{
		mHDF5Controller->read(this);
	}
}

588 589 590 591 592 593
void XdmfArray::release()
{
	releaseArray();
	releaseArrayPointer();
}

594 595 596 597 598 599 600 601 602 603 604 605 606 607
void XdmfArray::releaseArray()
{
	boost::shared_ptr<std::vector<char> > emptyArray;
	mArray = emptyArray;
	mHaveArray = false;
}

void XdmfArray::releaseArrayPointer()
{
	boost::shared_array<const char> emptyArrayPointer;
	mArrayPointer = emptyArrayPointer;
	mHaveArrayPointer = false;
}

608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
void XdmfArray::reserve(const unsigned int size)
{
	if(mHaveArrayPointer)
	{
		internalizeArrayPointer();
	}
	if(!mHaveArray)
	{
		mTmpReserveSize = size;
	}
	else
	{
		boost::apply_visitor(Reserve(size), mArray);
	}
}

624
void XdmfArray::setHDF5Controller(const boost::shared_ptr<XdmfHDF5Controller> hdf5Controller)
625 626 627 628
{
	mHDF5Controller = hdf5Controller;
}

629
void XdmfArray::swap(const boost::shared_ptr<XdmfArray> array)
630
{
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
	ArrayVariant tmpArray = array->mArray;
	ArrayPointerVariant tmpArrayPointer = array->mArrayPointer;
	int tmpArrayPointerNumValues = array->mArrayPointerNumValues;
	bool tmpHaveArray = array->mHaveArray;
	bool tmpHaveArrayPointer = array->mHaveArrayPointer;

	array->mArray = mArray;
	array->mArrayPointer = mArrayPointer;
	array->mArrayPointerNumValues = mArrayPointerNumValues;
	array->mHaveArray = mHaveArray;
	array->mHaveArrayPointer = mHaveArrayPointer;

	mArray = tmpArray;
	mArrayPointer = tmpArrayPointer;
	mArrayPointerNumValues = tmpArrayPointerNumValues;
	mHaveArray = tmpHaveArray;
	mHaveArrayPointer = tmpHaveArrayPointer;
648
}