Commit 24ea357e authored by Andrew J. Burns (Cont's avatar Andrew J. Burns (Cont

std::string compatibility

parent b21b735a
...@@ -887,6 +887,8 @@ XdmfTemplate::preallocateSteps(unsigned int numSteps) ...@@ -887,6 +887,8 @@ XdmfTemplate::preallocateSteps(unsigned int numSteps)
//printf("allocating subsection %u\n", allocateIteration); //printf("allocating subsection %u\n", allocateIteration);
//*/ //*/
//printf("initializing base array\n"); //printf("initializing base array\n");
std::vector<unsigned int> preallocatedSizeVector;
preallocatedSizeVector.push_back(preallocatedSize);
tempArray->initialize(mTrackedArrays[i]->getArrayType(), preallocatedSize); tempArray->initialize(mTrackedArrays[i]->getArrayType(), preallocatedSize);
//printf("writing subsection"); //printf("writing subsection");
tempArray->accept(mHeavyWriter); tempArray->accept(mHeavyWriter);
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include <utility> #include <utility>
#include <stack> #include <stack>
#include <math.h> #include <math.h>
#include <cstring> #include <string.h>
#include "XdmfArray.hpp" #include "XdmfArray.hpp"
#include "XdmfArrayType.hpp" #include "XdmfArrayType.hpp"
#include "XdmfArrayReference.hpp" #include "XdmfArrayReference.hpp"
...@@ -43,6 +43,10 @@ XDMF_CHILDREN_IMPLEMENTATION(XdmfArray, ...@@ -43,6 +43,10 @@ XDMF_CHILDREN_IMPLEMENTATION(XdmfArray,
HeavyDataController, HeavyDataController,
Name) Name)
template<>
void
XdmfArray::setArrayType<std::string>();
template<> template<>
XDMFCORE_EXPORT XDMFCORE_EXPORT
std::string std::string
...@@ -70,7 +74,7 @@ std::string ...@@ -70,7 +74,7 @@ std::string
XdmfArray::getValue<std::string>(const unsigned int index) const XdmfArray::getValue<std::string>(const unsigned int index) const
{ {
std::string * internalRef = NULL; std::string * internalRef = NULL;
XdmfArray::GetValue<std::string> visitor = GetValue<std::string>(index); XdmfArray::GetValue<std::string> visitor = GetValue<std::string>(this, index);
return ApplyVisitor(this, return ApplyVisitor(this,
visitor, visitor,
mArray, mArray,
...@@ -85,6 +89,63 @@ XdmfArray::initialize<void>(const unsigned int size) ...@@ -85,6 +89,63 @@ XdmfArray::initialize<void>(const unsigned int size)
return this->initialize<char>(size); return this->initialize<char>(size);
} }
template <>
XDMFCORE_EXPORT
std::string *
XdmfArray::initialize<std::string>(const unsigned int size)
{
// Set type of variant to type of pointer
if (mCapacity.size() == 0)
{
mCapacity.push_back(0);
}
if (size * mStringSize > mCapacity[0] * getArrayType()->getElementSize())
{
if (size >= mTmpReserveSize)
{
if (mArray)
{
void * newArray = calloc(size, mStringSize);
memcpy(newArray, mArray, mCapacity[0] * getArrayType()->getElementSize());
std::swap(mArray, newArray);
free(newArray);
}
else
{
void * newArray = calloc(size, mStringSize);
std::swap(mArray, newArray);
}
if (mArray == NULL)
{
XdmfError::message(XdmfError::FATAL,
"Error: Allocation Failed.");
}
mCapacity[0] = size;
}
else
{
if (mArray)
{
void * newArray = calloc(mTmpReserveSize, mStringSize);
memcpy(newArray, mArray, mCapacity[0] * getArrayType()->getElementSize());
std::swap(mArray, newArray);
free(newArray);
}
else
{
void * newArray = calloc(mTmpReserveSize, mStringSize);
std::swap(mArray, newArray);
}
mCapacity[0] = mTmpReserveSize;
mTmpReserveSize = 0;
}
}
this->setArrayType<std::string>();
this->setIsChanged(true);
return (std::string *)mArray;
}
//These void calls should never be called
template<> template<>
XDMFCORE_EXPORT XDMFCORE_EXPORT
void void
...@@ -120,7 +181,6 @@ XdmfArray::GetValues<std::string>::operator()<void>(const void * array) const ...@@ -120,7 +181,6 @@ XdmfArray::GetValues<std::string>::operator()<void>(const void * array) const
} }
} }
shared_ptr<XdmfArray> shared_ptr<XdmfArray>
XdmfArray::New() XdmfArray::New()
{ {
...@@ -130,6 +190,7 @@ XdmfArray::New() ...@@ -130,6 +190,7 @@ XdmfArray::New()
XdmfArray::XdmfArray() : XdmfArray::XdmfArray() :
mArrayPointerNumValues(0), mArrayPointerNumValues(0),
mStringSize(256),
mName(""), mName(""),
mTmpReserveSize(256), mTmpReserveSize(256),
mReadMode(XdmfArray::Controller), mReadMode(XdmfArray::Controller),
...@@ -145,6 +206,7 @@ XdmfArray::XdmfArray() : ...@@ -145,6 +206,7 @@ XdmfArray::XdmfArray() :
XdmfArray::XdmfArray(XdmfArray & refArray): XdmfArray::XdmfArray(XdmfArray & refArray):
XdmfItem(refArray), XdmfItem(refArray),
mDimensions(refArray.getDimensions()), mDimensions(refArray.getDimensions()),
mStringSize(refArray.mStringSize),
mName(refArray.getName()), mName(refArray.getName()),
mReadMode(refArray.getReadMode()), mReadMode(refArray.getReadMode()),
mHasArrayOwnership(true), mHasArrayOwnership(true),
...@@ -271,7 +333,8 @@ XdmfArray::getDimensionsString() const ...@@ -271,7 +333,8 @@ XdmfArray::getDimensionsString() const
if (mHeavyDataControllers.size() > 0) if (mHeavyDataControllers.size() > 0)
{ {
std::vector<unsigned int> dimensions = this->getDimensions(); std::vector<unsigned int> dimensions = this->getDimensions();
return GetValuesString<std::string>(dimensions.size()).getValuesString(&dimensions[0], return GetValuesString<std::string>(this,
dimensions.size()).getValuesString(&dimensions[0],
dimensions.size()); dimensions.size());
} }
else else
...@@ -281,7 +344,8 @@ XdmfArray::getDimensionsString() const ...@@ -281,7 +344,8 @@ XdmfArray::getDimensionsString() const
} }
else else
{ {
return GetValuesString<std::string>(mDimensions.size()).getValuesString(&mDimensions[0], return GetValuesString<std::string>(this,
mDimensions.size()).getValuesString(&mDimensions[0],
mDimensions.size()); mDimensions.size());
} }
} }
...@@ -380,7 +444,7 @@ XdmfArray::getValuesString() const ...@@ -380,7 +444,7 @@ XdmfArray::getValuesString() const
{ {
if (isInitialized()) if (isInitialized())
{ {
XdmfArray::GetValuesString<std::string> visitor = GetValuesString<std::string>(getSize()); XdmfArray::GetValuesString<std::string> visitor = GetValuesString<std::string>(this, getSize());
return ApplyVisitor<std::string>(this, return ApplyVisitor<std::string>(this,
visitor, visitor,
mArray, mArray,
...@@ -1010,7 +1074,15 @@ XdmfArray::readController() ...@@ -1010,7 +1074,15 @@ XdmfArray::readController()
shared_ptr<XdmfArray> tempArray = XdmfArray::New(); shared_ptr<XdmfArray> tempArray = XdmfArray::New();
mHeavyDataControllers[0]->read(tempArray.get()); mHeavyDataControllers[0]->read(tempArray.get());
this->insert(mHeavyDataControllers[0]->getArrayOffset(), tempArray, 0, mHeavyDataControllers[0]->getSize(), 1, 1); this->insert(mHeavyDataControllers[0]->getArrayOffset(), tempArray, 0, mHeavyDataControllers[0]->getSize(), 1, 1);
mDimensions = mHeavyDataControllers[0]->getDimensions(); std::vector<unsigned int> initDims;
unsigned int initSize = 1;
for (unsigned int i = 0; i < mHeavyDataControllers[0]->getDimensions().size(); ++i)
{
initSize *= mHeavyDataControllers[0]->getDimensions()[i];
}
initSize += mHeavyDataControllers[0]->getArrayOffset();
initDims.push_back(initSize);
mDimensions = initDims;
} }
this->setIsChanged(true); this->setIsChanged(true);
} }
...@@ -2328,109 +2400,6 @@ XdmfArraySwapWithXdmfArray(XDMFARRAY * array, XDMFARRAY * swapArray) ...@@ -2328,109 +2400,6 @@ XdmfArraySwapWithXdmfArray(XDMFARRAY * array, XDMFARRAY * swapArray)
((XdmfArray *)array)->swap(pointerToSwap); ((XdmfArray *)array)->swap(pointerToSwap);
} }
void
XdmfArraySwapWithArray(XDMFARRAY * array, void ** pointer, int numValues, int arrayType, int * status)
{
XDMF_ERROR_WRAP_START(status)
switch (arrayType) {
case XDMF_ARRAY_TYPE_UINT8: {
std::vector<unsigned char> swapVector((unsigned char *)(*pointer), (unsigned char *)(*pointer) + numValues);
((XdmfArray *)array)->swap(swapVector);
*pointer = new unsigned char[swapVector.size()];
for (unsigned int i = 0; i < swapVector.size(); ++i)
{
((unsigned char *) (*pointer))[i] = swapVector[i];
}
break;
}
case XDMF_ARRAY_TYPE_UINT16: {
std::vector<unsigned short> swapVector((unsigned short *)(*pointer), (unsigned short *)(*pointer) + numValues);
((XdmfArray *)array)->swap(swapVector);
*pointer = new unsigned short[swapVector.size()];
for (unsigned int i = 0; i < swapVector.size(); ++i)
{
((unsigned short *) (*pointer))[i] = swapVector[i];
}
break;
}
case XDMF_ARRAY_TYPE_UINT32: {
std::vector<unsigned int> swapVector((unsigned int *)(*pointer), (unsigned int *)(*pointer) + numValues);
((XdmfArray *)array)->swap(swapVector);
*pointer = new unsigned int[swapVector.size()];
for (unsigned int i = 0; i < swapVector.size(); ++i)
{
((unsigned int *) (*pointer))[i] = swapVector[i];
}
break;
}
case XDMF_ARRAY_TYPE_INT8: {
std::vector<char> swapVector((char *)(*pointer), (char *)(*pointer) + numValues);
((XdmfArray *)array)->swap(swapVector);
*pointer = new char[swapVector.size()];
for (unsigned int i = 0; i < swapVector.size(); ++i)
{
((char *) (*pointer))[i] = swapVector[i];
}
break;
}
case XDMF_ARRAY_TYPE_INT16: {
std::vector<short> swapVector((short *)(*pointer), (short *)(*pointer) + numValues);
((XdmfArray *)array)->swap(swapVector);
*pointer = new short[swapVector.size()];
for (unsigned int i = 0; i < swapVector.size(); ++i)
{
((short *) (*pointer))[i] = swapVector[i];
}
break;
}
case XDMF_ARRAY_TYPE_INT32: {
std::vector<int> swapVector((int *)(*pointer), (int *)(*pointer) + numValues);
((XdmfArray *)array)->swap(swapVector);
*pointer = new int[swapVector.size()];
for (unsigned int i = 0; i < swapVector.size(); ++i)
{
((int *) (*pointer))[i] = swapVector[i];
}
break;
}
case XDMF_ARRAY_TYPE_INT64: {
std::vector<long> swapVector((long *)(*pointer), (long *)(*pointer) + numValues);
((XdmfArray *)array)->swap(swapVector);
*pointer = new long[swapVector.size()];
for (unsigned int i = 0; i < swapVector.size(); ++i)
{
((long *) (*pointer))[i] = swapVector[i];
}
break;
}
case XDMF_ARRAY_TYPE_FLOAT32: {
std::vector<float> swapVector((float *)(*pointer), (float *)(*pointer) + numValues);
((XdmfArray *)array)->swap(swapVector);
*pointer = new float[swapVector.size()];
for (unsigned int i = 0; i < swapVector.size(); ++i)
{
((float *) (*pointer))[i] = swapVector[i];
}
break;
}
case XDMF_ARRAY_TYPE_FLOAT64: {
std::vector<double> swapVector((double *)(*pointer), (double *)(*pointer) + numValues);
((XdmfArray *)array)->swap(swapVector);
*pointer = new double[swapVector.size()];
for (unsigned int i = 0; i < swapVector.size(); ++i)
{
((double *) (*pointer))[i] = swapVector[i];
}
break;
}
default:
XdmfError::message(XdmfError::FATAL,
"Error: Invalid ArrayType.");
break;
}
XDMF_ERROR_WRAP_END(status)
}
// C Wrappers for parent classes are generated by macros // C Wrappers for parent classes are generated by macros
XDMF_ITEM_C_CHILD_WRAPPER(XdmfArray, XDMFARRAY) XDMF_ITEM_C_CHILD_WRAPPER(XdmfArray, XDMFARRAY)
...@@ -108,6 +108,11 @@ public: ...@@ -108,6 +108,11 @@ public:
Reference Reference
}; };
friend class XdmfHeavyDataWriter;
friend class XdmfHDF5Writer;
friend class XdmfHeavyDataController;
friend class XdmfHDF5Controller;
/** /**
* Create a new XdmfArray. * Create a new XdmfArray.
* *
...@@ -1375,56 +1380,6 @@ public: ...@@ -1375,56 +1380,6 @@ public:
template<typename T> template<typename T>
void setValuesInternal(const shared_ptr<std::vector<T> > array); void setValuesInternal(const shared_ptr<std::vector<T> > array);
/**
* Exchange the contents of the vector with the contents of this
* array. No copy is made. The internal arrays are swapped.
*
* Example of use
*
* C++
*
* @dontinclude ExampleXdmfArray.cpp
* @skipline //#initialization
* @until //#initialization
* @skipline //#initinternalvector
* @until //#initinternalvector
* @skipline //#swapvector
* @until //#swapvector
*
* Python: The Python version only supports swapping XdmfArrays
*
* @param array A vector to exchange values with.
* @return bool whether the swap was successful.
*/
template<typename T>
bool swap(std::vector<T> & array);
/**
* Exchange the contents of the vector with the contents of this
* array. No copy is made. The internal arrays are swapped.
*
* Example of use
*
* C++
*
* @dontinclude ExampleXdmfArray.cpp
* @skipline //#initialization
* @until //#initialization
* @skipline //#initinternalvector
* @until //#initinternalvector
* @skipline //#initsharedvector
* @until //#initsharedvector
* @skipline //#swapsharedvector
* @until //#swapsharedvector
*
* Python: The Python version only supports swapping XdmfArrays
*
* @param array A smart pointer to a vector to exchange values with.
* @return bool whether the swap was successful.
*/
template<typename T>
bool swap(const shared_ptr<std::vector<T> > array);
/** /**
* Exchange the contents of an XdmfArray with the contents of this * Exchange the contents of an XdmfArray with the contents of this
* array. No copy is made. The internal arrays are swapped. * array. No copy is made. The internal arrays are swapped.
...@@ -1472,6 +1427,8 @@ protected: ...@@ -1472,6 +1427,8 @@ protected:
const std::vector<shared_ptr<XdmfItem> > & childItems, const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader); const XdmfCoreReader * const reader);
unsigned int mStringSize;
private: private:
XdmfArray(const XdmfArray &); // Not implemented. XdmfArray(const XdmfArray &); // Not implemented.
...@@ -1525,7 +1482,7 @@ private: ...@@ -1525,7 +1482,7 @@ private:
void internalizeArrayPointer(); void internalizeArrayPointer();
unsigned int mArrayPointerNumValues; unsigned int mArrayPointerNumValues;
// unsigned int mStringSize;
unsigned int mTmpReserveSize; unsigned int mTmpReserveSize;
ReadMode mReadMode; ReadMode mReadMode;
shared_ptr<XdmfArrayReference> mReference; shared_ptr<XdmfArrayReference> mReference;
...@@ -1631,8 +1588,6 @@ XDMFCORE_EXPORT void XdmfArraySetValuesInternal(XDMFARRAY * array, void * pointe ...@@ -1631,8 +1588,6 @@ XDMFCORE_EXPORT void XdmfArraySetValuesInternal(XDMFARRAY * array, void * pointe
XDMFCORE_EXPORT void XdmfArraySwapWithXdmfArray(XDMFARRAY * array, XDMFARRAY * swapArray); XDMFCORE_EXPORT void XdmfArraySwapWithXdmfArray(XDMFARRAY * array, XDMFARRAY * swapArray);
XDMFCORE_EXPORT void XdmfArraySwapWithArray(XDMFARRAY * array, void ** pointer, int numValues, int arrayType, int * status);
// C Wrappers for parent classes are generated by macros // C Wrappers for parent classes are generated by macros
XDMF_ITEM_C_CHILD_DECLARE(XdmfArray, XDMFARRAY, XDMFCORE) XDMF_ITEM_C_CHILD_DECLARE(XdmfArray, XDMFARRAY, XDMFCORE)
...@@ -1721,12 +1676,7 @@ Level##_EXPORT void ClassName##SetValuesInternal( CClassName * array, ...@@ -1721,12 +1676,7 @@ Level##_EXPORT void ClassName##SetValuesInternal( CClassName * array,
int arrayType, \ int arrayType, \
int transferOwnership, \ int transferOwnership, \
int * status); \ int * status); \
Level##_EXPORT void ClassName##SwapWithXdmfArray( CClassName * array, XDMFARRAY * swapArray); \ Level##_EXPORT void ClassName##SwapWithXdmfArray( CClassName * array, XDMFARRAY * swapArray);
Level##_EXPORT void ClassName##SwapWithArray( CClassName * array, \
void ** pointer, \
int numValues, \
int arrayType, \
int * status);
#define XDMF_ARRAY_C_CHILD_WRAPPER(ClassName, CClassName) \ #define XDMF_ARRAY_C_CHILD_WRAPPER(ClassName, CClassName) \
...@@ -1996,16 +1946,6 @@ void ...@@ -1996,16 +1946,6 @@ void
ClassName##SwapWithXdmfArray( CClassName * array, XDMFARRAY * swapArray) \ ClassName##SwapWithXdmfArray( CClassName * array, XDMFARRAY * swapArray) \
{ \ { \
XdmfArraySwapWithXdmfArray((XDMFARRAY *)((void *)array), swapArray); \ XdmfArraySwapWithXdmfArray((XDMFARRAY *)((void *)array), swapArray); \
} \
\
void \
ClassName##SwapWithArray( CClassName * array, \
void ** pointer, \
int numValues, \
int arrayType, \
int * status) \
{ \
XdmfArraySwapWithArray((XDMFARRAY *)((void *)array), pointer, numValues, arrayType, status); \
} }
#ifdef __cplusplus #ifdef __cplusplus
......
This diff is collapsed.
...@@ -285,7 +285,7 @@ XdmfHDF5Controller::read(XdmfArray * const array, const int fapl) ...@@ -285,7 +285,7 @@ XdmfHDF5Controller::read(XdmfArray * const array, const int fapl)
} }
else if(mType == XdmfArrayType::String()) { else if(mType == XdmfArrayType::String()) {
datatype = H5Tcopy(H5T_C_S1); datatype = H5Tcopy(H5T_C_S1);
H5Tset_size(datatype, H5T_VARIABLE); H5Tset_size(datatype, array->mStringSize);
closeDatatype = true; closeDatatype = true;
} }
else { else {
...@@ -304,7 +304,7 @@ XdmfHDF5Controller::read(XdmfArray * const array, const int fapl) ...@@ -304,7 +304,7 @@ XdmfHDF5Controller::read(XdmfArray * const array, const int fapl)
errOut.str()); errOut.str());
} }
if(closeDatatype) { if(closeDatatype) {
char ** data = new char*[numVals]; char * data = new char[numVals * array->mStringSize];
status = H5Dread(dataset, status = H5Dread(dataset,
datatype, datatype,
memspace, memspace,
...@@ -312,7 +312,7 @@ XdmfHDF5Controller::read(XdmfArray * const array, const int fapl) ...@@ -312,7 +312,7 @@ XdmfHDF5Controller::read(XdmfArray * const array, const int fapl)
H5P_DEFAULT, H5P_DEFAULT,
data); data);
for(hssize_t i=0; i<numVals; ++i) { for(hssize_t i=0; i<numVals; ++i) {
array->insert<std::string>(i, data[i]); array->insert<std::string>(i, std::string(&(data[i * array->mStringSize])));
} }
status = H5Dvlen_reclaim(datatype, status = H5Dvlen_reclaim(datatype,
dataspace, dataspace,
......
...@@ -1123,7 +1123,7 @@ XdmfHDF5Writer::write(XdmfArray & array) ...@@ -1123,7 +1123,7 @@ XdmfHDF5Writer::write(XdmfArray & array)
else if(array.getArrayType() == XdmfArrayType::String()) { else if(array.getArrayType() == XdmfArrayType::String()) {
// Strings are a special case as they have mutable size // Strings are a special case as they have mutable size
datatype = H5Tcopy(H5T_C_S1); datatype = H5Tcopy(H5T_C_S1);
H5Tset_size(datatype, H5T_VARIABLE); H5Tset_size(datatype, array.mStringSize);
closeDatatype = true; closeDatatype = true;
} }
else { else {
......
...@@ -304,44 +304,5 @@ int main() ...@@ -304,44 +304,5 @@ int main()
free(valueString); free(valueString);
int * swapArray = valArray;
XdmfArraySwapWithArray(secondaryArray, ((void **)&(swapArray)), 3, XDMF_ARRAY_TYPE_INT32, &status);
valueString = XdmfArrayGetValuesString(secondaryArray);
printf("%s ?= %s\n", "5 6 7", valueString);
assert(strcmp("5 6 7", valueString) == 0);
for (i = 0; i < 10; ++i)
{
printf("swapArray[%d] = %d\n", i, swapArray[i]);
}
assert(swapArray[0] == 0);
assert(swapArray[1] == 1);
assert(swapArray[2] == 2);
assert(swapArray[3] == 4);
assert(swapArray[4] == 5);
assert(swapArray[5] == 6);
assert(swapArray[6] == 7);
assert(swapArray[7] == 8);
assert(swapArray[8] == 9);
assert(swapArray[9] == 90);
free(valueString);
int *returnArray = (int *)XdmfArrayGetValues(secondaryArray, 0, XDMF_ARRAY_TYPE_INT32, 3, 1, 1, &status);
for (i = 0; i < 3; ++i)
{
printf("returnArray[%d] = %d\n", i, returnArray[i]);
}
assert(returnArray[0] == 5);
assert(returnArray[1] == 6);
assert(returnArray[2] == 7);
return 0; return 0;
} }
...@@ -246,34 +246,6 @@ int main(int, char **) ...@@ -246,34 +246,6 @@ int main(int, char **)
assert(array6->getArrayType() == XdmfArrayType::Int8()); assert(array6->getArrayType() == XdmfArrayType::Int8());
assert(array6->getValuesString().compare("-2 -1 0 1 2") == 0); assert(array6->getValuesString().compare("-2 -1 0 1 2") == 0);
// Assert we have the same values! // Assert we have the same values!
shared_ptr<std::vector<char> > storedValues2 =
array6->getValuesInternal<char>();
int i = 0;
for(std::vector<char>::const_iterator iter = storedValues2->begin();
iter != storedValues2->end();
++iter, ++i) {
std::cout << *iter << " ?= " << values2->operator[](i) << std::endl;
assert(*iter == values2->operator[](i));
}
// Now modify original array
values2->push_back(8);
std::cout << array6->getSize() << " ?= " << 6 << std::endl;
std::cout << array6->getValuesString() << " ?= " << "-2 -1 0 1 2 8" << std::endl;
assert(array6->getSize() == 6);
assert(array6->getValuesString().compare("-2 -1 0 1 2 8") == 0);
// Assert we have the same values!
i = 0;
for(std::vector<char>::const_iterator iter = storedValues2->begin();
iter != storedValues2->end();
++iter, ++i) {
std::cout << *iter << " ?= " << values2->operator[](i) << std::endl;
assert(*iter == values2->operator[](i));
}
// Assert we can't get an int vector out of our array.
shared_ptr<std::vector<int> > storedValues2Int =
array6->getValuesInternal<int>();
std::cout << storedValues2Int << " ?= " << "NULL" << std::endl;
assert(storedValues2Int == NULL);
// //
// SWAPS // SWAPS
...@@ -282,38 +254,7 @@ int main(int, char **) ...@@ -282,38 +254,7 @@ int main(int, char **)
/** /**
* Swap values from a vector * Swap values from a vector
*/ */
std::vector<short> values3;
values3.push_back(-1);
values3.push_back(0);
values3.push_back(1);
shared_ptr<XdmfArray> array7 = XdmfArray::New(); shared_ptr<XdmfArray> array7 = XdmfArray::New();
array7->swap(values3);
std::cout << values3.size() << " ?= " << 0 << std::endl;
std::cout << array7->getSize() << " ?= " << 3 << std::endl;
std::cout << array7->getArrayType() << " ?= " << XdmfArrayType::Int16() << std::endl;
assert(values3.size() == 0);
assert(array7->getSize() == 3);
assert(array7->getArrayType() == XdmfArrayType::Int16());
shared_ptr<std::vector<short> > storedValues3 =
array7->getValuesInternal<short>();
std::cout << (*storedValues3)[0] << " ?= " << -1 << std::endl;
std::cout << (*storedValues3)[1] << " ?= " << 0 << std::endl;
std::cout << (*storedValues3)[2] << " ?= " << 1 << std::endl;
assert((*storedValues3)[0] == -1);
assert((*storedValues3)[1] == 0);
assert((*storedValues3)[2] == 1);
/**
* Swap values from a shared vector
*/
array7->release();
array7->swap(values2);
std::cout << storedValues2->size() << " ?= " << 0 << std::endl;
std::cout << array7->getSize() << " ?= " << 6 << std::endl;
std::cout << array7->getArrayType() << " ?= " << XdmfArrayType::Int8() << std::endl;
assert(storedValues2->size() == 0);
assert(array7->getSize() == 6);
assert(array7->getArrayType() == XdmfArrayType::Int8());
/** /**
* Swap values from an XdmfArray (with copy) * Swap values from an XdmfArray (with copy)
......
...@@ -10,7 +10,7 @@ int main(int, char **) ...@@ -10,7 +10,7 @@ int main(int, char **)
// Create 1D arrays // Create 1D arrays
// //
shared_ptr<XdmfArray> array = XdmfArray::New(); shared_ptr<XdmfArray> array = XdmfArray::New();
array->initialize(XdmfArrayType::UInt32(), 2); array->resize<unsigned int>(2);
std::cout << array->getArrayType() << " ?= " << XdmfArrayType::UInt32() << std::endl; std::cout << array->getArrayType() << " ?= " << XdmfArrayType::UInt32() << std::endl;
assert(array->getArrayType() == XdmfArrayType::UInt32()); assert(array->getArrayType() == XdmfArrayType::UInt32());
std::cout << array->getSize() << " ?= " << 2 << std::endl; std::cout << array->getSize() << " ?= " << 2 << std::endl;
......
...@@ -6,7 +6,7 @@ if __name__ == "__main__": ...@@ -6,7 +6,7 @@ if __name__ == "__main__":
# Create 1D arrays # Create 1D arrays
# #
array1 = XdmfArray.New() array1 = XdmfArray.New()
array1.initialize(XdmfArrayType.UInt32(), 2) array1.resizeAsUInt32(2)
print str(array1.getArrayType()) + " ?= " + str(XdmfArrayType.UInt32()) print str(array1.getArrayType()) + " ?= " + str(XdmfArrayType.UInt32())
print str(array1.getSize()) + " ?= " + str(2) print str(array1.getSize()) + " ?= " + str(2)
assert array1.getArrayType() == XdmfArrayType.UInt32() assert array1.getArrayType() == XdmfArrayType.UInt32()
......
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