STYLE: Split XdmfArray.tpp from XdmfArray.hpp --- this will hold template...

STYLE: Split XdmfArray.tpp from XdmfArray.hpp --- this will hold template implementations for XdmfArray instead of stuffing them all in XdmfArray.hpp (merely a style difference).  Do some minor formatting on some other files.
parent 63368adb
......@@ -303,11 +303,6 @@ void XdmfArray::copyValues(int startIndex, boost::shared_ptr<XdmfArray> values,
mArray = values->getVariant();
// Reinitialize variant array to contain new array with same type.
boost::apply_visitor( XdmfArrayNewArray(), mArray);
//boost::shared_ptr<std::vector<double> > newArray(new std::vector<double>());
//mArray = newArray;
//std::cout << boost::get<boost::shared_ptr<std::vector<double> > >(mArray)->operator[](0) << std::endl;
//std::cout << this->getValuesString() << std::endl;
}
boost::apply_visitor( XdmfArrayCopyArrayValues(startIndex, valuesStartIndex, numValues, arrayStride, valuesStride), mArray, values->getVariant());
}
......
......@@ -7,85 +7,6 @@
#include <hdf5.h>
#include <vector>
template<typename T>
class XdmfArrayCopyValues : public boost::static_visitor <void> {
public:
XdmfArrayCopyValues(int startIndex, T * valuesPointer, int numValues = 1, int arrayStride = 1, int valuesStride = 1) :
mStartIndex(startIndex),
mValuesPointer(valuesPointer),
mNumValues(numValues),
mArrayStride(arrayStride),
mValuesStride(valuesStride)
{
}
template<typename U> void operator()(boost::shared_ptr<std::vector<U> > & array) const
{
int size = mStartIndex + mNumValues;
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) = (U)mValuesPointer[i*mValuesStride];
}
}
private:
int mStartIndex;
T* mValuesPointer;
int mNumValues;
int mArrayStride;
int mValuesStride;
};
template <typename T>
class XdmfArrayGetValues : public boost::static_visitor <boost::shared_ptr<std::vector<T> > > {
public:
XdmfArrayGetValues()
{
}
boost::shared_ptr<std::vector<T> > operator()(const boost::shared_ptr<std::vector<T> > & array) const
{
return array;
}
template <typename U>
boost::shared_ptr<std::vector<T> > operator()(const boost::shared_ptr<std::vector<U> > & array) const
{
return boost::shared_ptr<std::vector<T> >();
}
};
template <typename T>
class XdmfArrayGetValuesConst : public boost::static_visitor <const boost::shared_ptr<const std::vector<T> > > {
public:
XdmfArrayGetValuesConst()
{
}
const boost::shared_ptr<const std::vector<T> > operator()(const boost::shared_ptr<const std::vector<T> > & array) const
{
return array;
}
template <typename U>
const boost::shared_ptr<const std::vector<T> > operator()(const boost::shared_ptr<const std::vector<U> > & array) const
{
return boost::shared_ptr<std::vector<T> >();
}
};
/**
* @brief Provides a single interface for storing a wide variety of data types.
*
......@@ -147,17 +68,8 @@ public:
* @param arrayStride number of values to stride in this array between each copy.
* @param valuesStride number of values to stride in the pointer between each copy.
*/
template<typename T> void copyValues(int startIndex, T * valuesPointer, int numValues = 1, int arrayStride = 1, int valuesStride = 1)
{
if(!mInitialized)
{
// Set type of variant to type of pointer
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);
}
template<typename T>
void copyValues(int startIndex, T * valuesPointer, int numValues = 1, int arrayStride = 1, int valuesStride = 1);
/**
* Remove all values from this array
......@@ -199,10 +111,7 @@ public:
* @return a smart pointer to the internal vector of values stored in this array
*/
template <typename T>
boost::shared_ptr<std::vector<T> > getValues()
{
return boost::apply_visitor( XdmfArrayGetValues<T>(), mArray);
}
boost::shared_ptr<std::vector<T> > getValues();
/**
* Get a smart pointer to the values stored in this array (const version)
......@@ -210,10 +119,7 @@ public:
* @return a smart pointer to the internal vector of values stored in this array
*/
template <typename T>
const boost::shared_ptr<const std::vector<T> > getValues() const
{
return boost::apply_visitor( XdmfArrayGetValuesConst<T>(), mArray);
}
const boost::shared_ptr<const std::vector<T> > getValues() const;
/**
* Get a pointer to the values stored in this array.
......@@ -237,10 +143,8 @@ public:
*
* @param array a smart pointer to a vector to store in this array.
*/
template<typename T> void setValues(boost::shared_ptr<std::vector<T> > array)
{
mArray = array;
}
template<typename T>
void setValues(boost::shared_ptr<std::vector<T> > array);
virtual void write(boost::shared_ptr<XdmfVisitor>) const;
......@@ -271,4 +175,6 @@ private:
bool mInitialized;
};
#include "XdmfArray.tpp"
#endif /* XDMFARRAY_HPP_ */
// Includes
#include "XdmfArray.hpp"
template<typename T>
class XdmfArrayCopyValues : public boost::static_visitor <void> {
public:
XdmfArrayCopyValues(int startIndex, T * valuesPointer, int numValues = 1, int arrayStride = 1, int valuesStride = 1) :
mStartIndex(startIndex),
mValuesPointer(valuesPointer),
mNumValues(numValues),
mArrayStride(arrayStride),
mValuesStride(valuesStride)
{
}
template<typename U> void operator()(boost::shared_ptr<std::vector<U> > & array) const
{
int size = mStartIndex + mNumValues;
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) = (U)mValuesPointer[i*mValuesStride];
}
}
private:
int mStartIndex;
T* mValuesPointer;
int mNumValues;
int mArrayStride;
int mValuesStride;
};
template <typename T>
class XdmfArrayGetValues : public boost::static_visitor <boost::shared_ptr<std::vector<T> > > {
public:
XdmfArrayGetValues()
{
}
boost::shared_ptr<std::vector<T> > operator()(const boost::shared_ptr<std::vector<T> > & array) const
{
return array;
}
template <typename U>
boost::shared_ptr<std::vector<T> > operator()(const boost::shared_ptr<std::vector<U> > & array) const
{
return boost::shared_ptr<std::vector<T> >();
}
};
template <typename T>
class XdmfArrayGetValuesConst : public boost::static_visitor <const boost::shared_ptr<const std::vector<T> > > {
public:
XdmfArrayGetValuesConst()
{
}
const boost::shared_ptr<const std::vector<T> > operator()(const boost::shared_ptr<const std::vector<T> > & array) const
{
return array;
}
template <typename U>
const boost::shared_ptr<const std::vector<T> > operator()(const boost::shared_ptr<const std::vector<U> > & array) const
{
return boost::shared_ptr<std::vector<T> >();
}
};
template<typename T>
void XdmfArray::copyValues(int startIndex, T * valuesPointer, int numValues, int arrayStride, int valuesStride)
{
if(!mInitialized)
{
// Set type of variant to type of pointer
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);
}
template <typename T>
boost::shared_ptr<std::vector<T> > XdmfArray::getValues()
{
return boost::apply_visitor( XdmfArrayGetValues<T>(), mArray);
}
template <typename T>
const boost::shared_ptr<const std::vector<T> > XdmfArray::getValues() const
{
return boost::apply_visitor( XdmfArrayGetValuesConst<T>(), mArray);
}
template<typename T>
void XdmfArray::setValues(boost::shared_ptr<std::vector<T> > array)
{
mArray = array;
}
#ifndef XDMFOBJECT_HPP_
#define XDMFOBJECT_HPP_
// Includes
#include "boost/shared_ptr.hpp"
#include <iostream>
#include <ostream>
......
......@@ -117,7 +117,7 @@ protected:
* by Xdmf should be accessed through more specific static methods that construct XdmfTopologyType -
* i.e. XdmfTopologyType::Tetrahedron()
*/
XdmfTopologyType(const int& nodesPerElement, const std::string& name, const CellType& cellType);
XdmfTopologyType(const int & nodesPerElement, const std::string & name, const CellType & cellType);
private:
......
......@@ -22,7 +22,6 @@ class XdmfTopology;
* XdmfVisitor visits each node of an Xdmf graph structure and writes the data to disk. Xdmf files are written to disk
* by performing a visitor operation. Writing begins by calling the write() operation on any XdmfItem and supplying an
* XdmfVisitor as the parameter. The XdmfItem as well as all children attached to the XdmfItem are written to disk.
*
*/
class XdmfVisitor : public XdmfObject {
......
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