Commit e8274acc authored by Ken Leiter (Civ ARL/CISD) kleiter's avatar Ken Leiter (Civ ARL/CISD) kleiter
Browse files

ENH: Add initialize() method that allows user to specify the type of data to...

ENH: Add initialize() method that allows user to specify the type of data to store in an XdmfArray if desired.
parent 5e476e23
...@@ -135,6 +135,12 @@ public: ...@@ -135,6 +135,12 @@ public:
*/ */
virtual std::string getValuesString() const; virtual std::string getValuesString() const;
/**
* Initializes the array to contain an empty container of a particular type.
*/
template <typename T>
void initialize();
virtual std::string printSelf() const; virtual std::string printSelf() const;
/** /**
......
...@@ -45,10 +45,7 @@ void XdmfArray::copyValues(int startIndex, T * valuesPointer, int numValues, int ...@@ -45,10 +45,7 @@ void XdmfArray::copyValues(int startIndex, T * valuesPointer, int numValues, int
{ {
if(!mInitialized) if(!mInitialized)
{ {
// Set type of variant to type of pointer initialize<T>();
boost::shared_ptr<std::vector<T> > newArray(new std::vector<T>());
mArray = newArray;
mInitialized = true;
} }
boost::apply_visitor( XdmfArrayCopyValues<T>(startIndex, valuesPointer, numValues, arrayStride, valuesStride), mArray); boost::apply_visitor( XdmfArrayCopyValues<T>(startIndex, valuesPointer, numValues, arrayStride, valuesStride), mArray);
} }
...@@ -81,6 +78,15 @@ const boost::shared_ptr<const std::vector<T> > XdmfArray::getValues() const ...@@ -81,6 +78,15 @@ const boost::shared_ptr<const std::vector<T> > XdmfArray::getValues() const
} }
} }
template <typename T>
void XdmfArray::initialize()
{
// Set type of variant to type of pointer
boost::shared_ptr<std::vector<T> > newArray(new std::vector<T>());
mArray = newArray;
mInitialized = true;
}
template<typename T> template<typename T>
void XdmfArray::setValues(boost::shared_ptr<std::vector<T> > array) void XdmfArray::setValues(boost::shared_ptr<std::vector<T> > array)
{ {
...@@ -93,10 +99,7 @@ bool XdmfArray::swap(std::vector<T> & array) ...@@ -93,10 +99,7 @@ bool XdmfArray::swap(std::vector<T> & array)
{ {
if(!mInitialized) if(!mInitialized)
{ {
// Set type of variant to type of pointer initialize<T>();
boost::shared_ptr<std::vector<T> > newArray(new std::vector<T>());
mArray = newArray;
mInitialized = true;
} }
try try
{ {
......
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