Commit e2c1238a authored by Kenneth Leiter's avatar Kenneth Leiter

Remove shared_array from XdmfArray variant.

Replace with shared_ptr with custom deleter.
parent 2ae8ad35
......@@ -67,7 +67,7 @@ public:
template<typename T>
void
operator()(const boost::shared_array<const T> & array) const
operator()(const shared_ptr<const T> & array) const
{
mArray->internalizeArrayPointer();
boost::apply_visitor(*this,
......@@ -103,7 +103,7 @@ public:
template<typename T>
void
operator()(const boost::shared_array<const T> & array) const
operator()(const shared_ptr<const T> & array) const
{
mArray->internalizeArrayPointer();
boost::apply_visitor(*this,
......@@ -203,7 +203,7 @@ public:
template<typename T>
shared_ptr<const XdmfArrayType>
operator()(const boost::shared_array<const T> & array) const
operator()(const shared_ptr<const T> & array) const
{
return this->getArrayType(array.get());
}
......@@ -235,7 +235,7 @@ public:
template<typename T>
unsigned int
operator()(const boost::shared_array<const T> & array) const
operator()(const shared_ptr<const T> & array) const
{
return 0;
}
......@@ -264,7 +264,7 @@ public:
template<typename T>
const void *
operator()(const boost::shared_array<const T> & array) const
operator()(const shared_ptr<const T> & array) const
{
return array.get();
}
......@@ -335,7 +335,7 @@ public:
template<typename T>
std::string
operator()(const boost::shared_array<const T> & array) const
operator()(const shared_ptr<const T> & array) const
{
return getValuesString(array.get(), mArrayPointerNumValues);
}
......@@ -398,7 +398,7 @@ public:
template<typename T>
void
operator()(const boost::shared_array<const T> & array) const
operator()(const shared_ptr<const T> & array) const
{
mArray->internalizeArrayPointer();
boost::apply_visitor(*this,
......@@ -440,7 +440,7 @@ public:
template<typename T>
void
operator()(const boost::shared_array<const T> & array) const
operator()(const shared_ptr<const T> & array) const
{
const T * const pointer = array.get();
shared_ptr<std::vector<T> > newArray(new std::vector<T>(pointer,
......@@ -507,7 +507,7 @@ public:
template<typename T>
void
operator()(const boost::shared_array<const T> & array) const
operator()(const shared_ptr<const T> & array) const
{
mArray->internalizeArrayPointer();
boost::apply_visitor(*this,
......@@ -547,7 +547,7 @@ public:
template<typename T>
unsigned int
operator()(const boost::shared_array<const T> & array) const
operator()(const shared_ptr<const T> & array) const
{
return mArray->mArrayPointerNumValues;
}
......@@ -600,7 +600,7 @@ XdmfArray::erase(const unsigned int index)
shared_ptr<const XdmfArrayType>
XdmfArray::getArrayType() const
{
if (mHeavyDataControllers.size()>0) {
if (mHeavyDataControllers.size() > 0) {
return boost::apply_visitor(GetArrayType(mHeavyDataControllers[0]),
mArray);
}
......
......@@ -36,9 +36,11 @@
class XdmfArrayType;
class XdmfHeavyDataController;
#include <memory>
// Includes
#include <boost/shared_array.hpp>
#include <boost/variant.hpp>
using boost::variant;
/**
* @brief Provides storage for data values that are read in or will be
......@@ -1473,6 +1475,7 @@ private:
void operator=(const XdmfArray &); // Not implemented.
// Variant Visitor Operations
template <typename T> struct ArrayDeleter;
class Clear;
class Erase;
class GetArrayType;
......@@ -1501,7 +1504,7 @@ private:
*/
void internalizeArrayPointer();
typedef boost::variant<
typedef variant<
boost::blank,
shared_ptr<std::vector<char> >,
shared_ptr<std::vector<short> >,
......@@ -1513,15 +1516,15 @@ private:
shared_ptr<std::vector<unsigned short> >,
shared_ptr<std::vector<unsigned int> >,
shared_ptr<std::vector<std::string> >,
boost::shared_array<const char>,
boost::shared_array<const short>,
boost::shared_array<const int>,
boost::shared_array<const long>,
boost::shared_array<const float>,
boost::shared_array<const double>,
boost::shared_array<const unsigned char>,
boost::shared_array<const unsigned short>,
boost::shared_array<const unsigned int> > ArrayVariant;
shared_ptr<const char>,
shared_ptr<const short>,
shared_ptr<const int>,
shared_ptr<const long>,
shared_ptr<const float>,
shared_ptr<const double>,
shared_ptr<const unsigned char>,
shared_ptr<const unsigned short>,
shared_ptr<const unsigned int> > ArrayVariant;
unsigned int mArrayPointerNumValues;
std::vector<unsigned int> mDimensions;
......
......@@ -56,9 +56,9 @@ public:
template<typename U>
T
operator()(const boost::shared_array<const U> & array) const
operator()(const shared_ptr<const U> & array) const
{
return (T)array[mIndex];
return (T)array.get()[mIndex];
}
private:
......@@ -97,18 +97,12 @@ public:
return value.str();
}
std::string
operator()(const boost::shared_array<const std::string> & array) const
{
return array[mIndex];
}
template<typename U>
std::string
operator()(const boost::shared_array<const U> & array) const
operator()(const shared_ptr<const U> & array) const
{
std::stringstream value;
value << array[mIndex];
value << array.get()[mIndex];
return value.str();
}
......@@ -161,10 +155,12 @@ public:
template<typename U>
void
operator()(const boost::shared_array<const U> & array) const
operator()(const shared_ptr<const U> & array) const
{
const U * const arrayPtr = array.get();
for(unsigned int i=0; i<mNumValues; ++i) {
mValuesPointer[i*mValuesStride] = (T)array[mStartIndex + i*mArrayStride];
mValuesPointer[i*mValuesStride] =
(T)arrayPtr[mStartIndex + i*mArrayStride];
}
}
......@@ -213,11 +209,12 @@ public:
template<typename U>
void
operator()(const boost::shared_array<const U> & array) const
operator()(const shared_ptr<const U> & array) const
{
const U * const arrayPtr = array.get();
for(unsigned int i=0; i<mNumValues; ++i) {
std::stringstream value;
value << array[mStartIndex + i*mArrayStride];
value << arrayPtr[mStartIndex + i*mArrayStride];
mValuesPointer[i*mValuesStride] = value.str();
}
}
......@@ -292,7 +289,7 @@ public:
template<typename U>
void
operator()(boost::shared_array<const U> &) const
operator()(shared_ptr<const U> &) const
{
mArray->internalizeArrayPointer();
boost::apply_visitor(*this,
......@@ -370,7 +367,7 @@ public:
template<typename U>
void
operator()(boost::shared_array<const U> &) const
operator()(shared_ptr<const U> &) const
{
mArray->internalizeArrayPointer();
boost::apply_visitor(*this,
......@@ -426,7 +423,7 @@ public:
template<typename U>
void
operator()(const boost::shared_array<const U> &) const
operator()(const shared_ptr<const U> &) const
{
mArray->internalizeArrayPointer();
boost::apply_visitor(*this,
......@@ -475,7 +472,7 @@ public:
template<typename U>
void
operator()(const boost::shared_array<const U> &) const
operator()(const shared_ptr<const U> &) const
{
mArray->internalizeArrayPointer();
boost::apply_visitor(*this,
......@@ -528,7 +525,7 @@ public:
template<typename U>
void
operator()(const boost::shared_array<const U> &) const
operator()(const shared_ptr<const U> &) const
{
mArray->internalizeArrayPointer();
boost::apply_visitor(*this,
......@@ -580,7 +577,7 @@ public:
template<typename U>
void
operator()(const boost::shared_array<const U> &) const
operator()(const shared_ptr<const U> &) const
{
mArray->internalizeArrayPointer();
boost::apply_visitor(*this,
......@@ -594,12 +591,24 @@ private:
const std::string & mVal;
};
template <typename T>
struct XdmfArray::ArrayDeleter
{
void
operator()(T const * p) const
{
delete[] p;
}
};
struct XdmfArray::NullDeleter
{
void
operator()(void const *) const
{
}
};
template <typename T>
......@@ -709,7 +718,6 @@ XdmfArray::pushBack(const T & value)
return boost::apply_visitor(PushBack<T>(value,
this),
mArray);
}
template<typename T>
......@@ -722,7 +730,6 @@ XdmfArray::resize(const unsigned int numValues,
numValues,
value),
mArray);
}
template<typename T>
......@@ -745,13 +752,12 @@ XdmfArray::setValuesInternal(const T * const arrayPointer,
{
// Remove contents of internal array.
if(transferOwnership) {
const boost::shared_array<const T> newArrayPointer(arrayPointer);
mArray = newArrayPointer;
mArray = shared_ptr<const T>(arrayPointer,
ArrayDeleter<T>());
}
else {
const boost::shared_array<const T> newArrayPointer(arrayPointer,
NullDeleter());
mArray = newArrayPointer;
mArray = shared_ptr<const T>(arrayPointer,
NullDeleter());
}
mArrayPointerNumValues = numValues;
this->setIsChanged(true);
......
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