Commit 3eb2d342 authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Simplify XdmfArray class.

Slightly improves compile time on gcc.
Get rid of mHaveArray and mHaveArrayPointer - rely on blank in variant.
This reduces code and makes logic easier to understand.
parent d5ebbc9f
This diff is collapsed.
......@@ -500,7 +500,6 @@ private:
template <typename T> class Insert;
class InsertArray;
class InternalizeArrayPointer;
class NewArray;
struct NullDeleter;
template <typename T> class PushBack;
class Reserve;
......@@ -517,17 +516,8 @@ private:
*/
void internalizeArrayPointer();
/**
* Release references to internal data.
*/
void releaseArray();
/**
* Release references to held array pointer internal data;
*/
void releaseArrayPointer();
typedef boost::variant<
boost::blank,
shared_ptr<std::vector<char> >,
shared_ptr<std::vector<short> >,
shared_ptr<std::vector<int> >,
......@@ -536,9 +526,7 @@ private:
shared_ptr<std::vector<double> >,
shared_ptr<std::vector<unsigned char> >,
shared_ptr<std::vector<unsigned short> >,
shared_ptr<std::vector<unsigned int> > > ArrayVariant;
typedef boost::variant<
shared_ptr<std::vector<unsigned int> >,
boost::shared_array<const char>,
boost::shared_array<const short>,
boost::shared_array<const int>,
......@@ -547,14 +535,11 @@ private:
boost::shared_array<const double>,
boost::shared_array<const unsigned char>,
boost::shared_array<const unsigned short>,
boost::shared_array<const unsigned int> > ArrayPointerVariant;
boost::shared_array<const unsigned int> > ArrayVariant;
ArrayVariant mArray;
ArrayPointerVariant mArrayPointer;
unsigned int mArrayPointerNumValues;
std::vector<unsigned int> mDimensions;
bool mHaveArray;
bool mHaveArrayPointer;
shared_ptr<XdmfHeavyDataController> mHeavyDataController;
std::string mName;
unsigned int mTmpReserveSize;
......
This diff is collapsed.
#include <XdmfError.hpp>
#include <cstdlib>
#include <iostream>
XdmfError::XdmfError()
{}
......
#ifndef XDMFERROR_HPP_
#define XDMFERROR_HPP_
#include <iostream>
#include <iosfwd>
#include <sstream>
#include "XdmfCore.hpp"
......
#include "XdmfArray.hpp"
#include "XdmfArrayType.hpp"
#include <iostream>
int main(int, char **)
{
......@@ -90,9 +92,20 @@ int main(int, char **)
shared_ptr<XdmfArray> array5 = XdmfArray::New();
array5->insert(0, array, 1, 3);
assert(array5->getSize() == 3);
assert(array5->getArrayType() == array->getArrayType());
storedValues = array5->getValuesInternal<int>();
assert(array5->getSize() == 3);
assert(array->getSize() == 4);
assert(array5->getValuesString().compare("2 3 4") == 0);
array5->insert(1, array, 1, 3);
assert(array5->getValuesString().compare("2 2 3 4") == 0);
array5->clear();
assert(array5->getSize() == 0);
array5->insert(0, array, 1, 3, 2, 1);
assert(array5->getValuesString().compare("2 0 3 0 4") == 0);
array5->clear();
array5->insert(0, array, 1, 2, 2, 2);
assert(array5->getValuesString().compare("2 0 4") == 0);
/**
* Single Insertion
......@@ -135,8 +148,8 @@ int main(int, char **)
array5->setValuesInternal(&values[1], 3, 0);
assert(array5->getSize() == 3);
assert(array5->getValuesString().compare("2 3 4") == 0);
int zero = 0;
array5->insert(3, &zero, 1, 1, 0);
int zero = 0;
array5->insert(3, &zero, 1, 1, 0);
assert(array5->getSize() == 4);
assert(array5->getValuesString().compare("2 3 4 0") == 0);
......@@ -260,6 +273,12 @@ int main(int, char **)
array8->resize(8, 1.1);
assert(array8->getValuesString().compare("1 2 3 1 1 1 1 1") == 0);
/**
* Erase
*/
array8->erase(0);
assert(array8->getValuesString().compare("2 3 1 1 1 1 1") == 0);
/**
* Reserve / Capacity
*/
......@@ -270,5 +289,19 @@ int main(int, char **)
array8->setName("BLAH");
assert(array8->getName().compare("BLAH") == 0);
/**
* Dimensions
*/
dimensions.resize(2);
dimensions[0] = 3;
dimensions[1] = 3;
shared_ptr<XdmfArray> array9 = XdmfArray::New();
array9->initialize(XdmfArrayType::Float64(),
dimensions);
assert(array9->getDimensionsString() == "3 3");
assert(array9->getSize() == 9);
array9->insert<double>(9, 1.0);
assert(array9->getDimensionsString() == "10");
return 0;
}
......@@ -112,7 +112,7 @@ int main(int, char **)
// 7 8
//
const std::vector<unsigned int> start(2, 1);
const std::vector<unsigned int> stride(2,1);
const std::vector<unsigned int> stride(2, 1);
const std::vector<unsigned int> count(2, 2);
shared_ptr<XdmfHeavyDataController> controller =
......
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