ENH: Remove XdmfPython.cpp and Xdmf.py from repository. Modify CMake build...

ENH: Remove XdmfPython.cpp and Xdmf.py from repository.  Modify CMake build script to generate wrappers automagically with swig (this will ensure that users always have swig wrapper tailored to their version of python and prevents us from having to regenerate and commit every time something in Xdmf changes).  Add a couple extra methods to XdmfArray.cpp --- still need to figure out the rest of XdmfArray functionality.
parent e8274acc
......@@ -21,12 +21,15 @@ if(LIBXML2_FOUND)
include_directories(${LIBXML2_INCLUDE_DIR})
endif(LIBXML2_FOUND)
option(XDMF_WRAP_PYTHON ON)
option(XDMF_WRAP_PYTHON OFF)
if(XDMF_WRAP_PYTHON)
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
find_package(PythonLibs REQUIRED)
if(PYTHONLIBS_FOUND)
include_directories(${PYTHON_INCLUDE_DIRS})
endif(PYTHONLIBS_FOUND)
include_directories(${PYTHON_INCLUDE_DIRS})
set_source_files_properties(Xdmf.i PROPERTIES CPLUSPLUS ON)
swig_add_module(Xdmf python Xdmf.i)
swig_link_libraries(Xdmf Xdmf ${PYTHON_LIBRARIES})
endif(XDMF_WRAP_PYTHON)
set(XdmfSources
......@@ -49,17 +52,6 @@ set(XdmfSources
add_library(Xdmf ${XdmfSources})
target_link_libraries(Xdmf ${HDF5_LIBRARIES} ${LIBXML2_LIBRARIES})
if(XDMF_WRAP_PYTHON)
add_library(_Xdmf MODULE XdmfPython)
set_target_properties(_Xdmf PROPERTIES PREFIX "")
target_link_libraries(_Xdmf Xdmf)
if(WIN32 OR APPLE)
target_link_libraries(_Xdmf ${PYTHON_LIBRARY})
endif(WIN32 OR APPLE)
endif(XDMF_WRAP_PYTHON)
configure_file(Xdmf.py Xdmf.py COPYONLY)
option(BUILD_DOCUMENTATION OFF)
if(BUILD_DOCUMENTATION)
add_subdirectory(doc)
......
This diff is collapsed.
......@@ -349,7 +349,7 @@ std::string XdmfArray::printSelf() const
return "";
}
void XdmfArray::swap(boost::shared_ptr<XdmfArray> & array)
void XdmfArray::swap(boost::shared_ptr<XdmfArray> array)
{
array->mArray.swap(mArray);
bool initialized = array->mInitialized;
......
......@@ -106,17 +106,17 @@ public:
virtual std::string getType() const;
/**
* Get a smart pointer to the values stored in this array
* Get a smart pointer to the values stored in this array.
*
* @return a smart pointer to the internal vector of values stored in this array
* @return a smart pointer to the internal vector of values stored in this array.
*/
template <typename T>
boost::shared_ptr<std::vector<T> > getValues();
/**
* Get a smart pointer to the values stored in this array (const version)
* Get a smart pointer to the values stored in this array (const version).
*
* @return a smart pointer to the internal vector of values stored in this array
* @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;
......@@ -137,12 +137,23 @@ public:
/**
* Initializes the array to contain an empty container of a particular type.
*
* @return a smart pointer to the internal vector of values initialized in this array.
*/
template <typename T>
void initialize();
boost::shared_ptr<std::vector<T> > initialize();
virtual std::string printSelf() const;
/**
* Sets the values of this array to the values stored in the vector. No copy is made. The caller of this method retains
* ownership of the data and must ensure that the array is still valid for the entire time Xdmf needs it.
*
* @param array a vector to store in this array.
*/
template<typename T>
void setValues(std::vector<T> & array);
/**
* Sets the values of this array to the values stored in the vector. No copy is made. This array shares ownership with
* other references to the smart pointer.
......@@ -175,7 +186,7 @@ public:
* @param array a smart pointer to a vector to exchange values with.
* @return bool whether the swap was successful.
*/
void swap(boost::shared_ptr<XdmfArray> & array);
void swap(boost::shared_ptr<XdmfArray> array);
/**
*
......
......@@ -40,6 +40,13 @@ private:
int mValuesStride;
};
struct XdmfArrayNullDeleter
{
void operator()(void const *) const
{
}
};
template<typename T>
void XdmfArray::copyValues(int startIndex, T * valuesPointer, int numValues, int arrayStride, int valuesStride)
{
......@@ -79,12 +86,21 @@ const boost::shared_ptr<const std::vector<T> > XdmfArray::getValues() const
}
template <typename T>
void XdmfArray::initialize()
boost::shared_ptr<std::vector<T> > 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;
return newArray;
}
template<typename T>
void XdmfArray::setValues(std::vector<T> & array)
{
boost::shared_ptr<std::vector<T> > newArray(&array, XdmfArrayNullDeleter());
mArray = newArray;
mInitialized = true;
}
template<typename T>
......
This diff is collapsed.
......@@ -93,19 +93,29 @@ int main(int argc, char* argv[])
}
/**
* Swap values from a vector
* Set values from vector
*/
std::vector<short> values4;
values4.push_back(-1);
values4.push_back(0);
values4.push_back(1);
boost::shared_ptr<XdmfArray> array5 = XdmfArray::New();
array5->swap(values4);
assert(values4.size() == 0);
assert(array5->getSize() == 3);
assert(array5->getType().compare("Short") == 0);
assert(array5->getPrecision() == 2);
boost::shared_ptr<std::vector<short> > storedValues5 = array5->getValues<short>();
std::vector<long> values4;
values4.push_back(-100);
values4.push_back(0);
values4.push_back(500);
array5->setValues(values4);
/**
* Swap values from a vector
*/
std::vector<short> values5;
values5.push_back(-1);
values5.push_back(0);
values5.push_back(1);
boost::shared_ptr<XdmfArray> array6 = XdmfArray::New();
array6->swap(values5);
assert(values5.size() == 0);
assert(array6->getSize() == 3);
assert(array6->getType().compare("Short") == 0);
assert(array6->getPrecision() == 2);
boost::shared_ptr<std::vector<short> > storedValues5 = array6->getValues<short>();
assert((*storedValues5)[0] == -1);
assert((*storedValues5)[1] == 0);
assert((*storedValues5)[2] == 1);
......@@ -113,30 +123,30 @@ int main(int argc, char* argv[])
/**
* Swap values from a shared vector
*/
array5->clear();
array5->swap(storedValues3);
array6->clear();
array6->swap(storedValues3);
assert(storedValues3->size() == 0);
assert(array5->getSize() == 6);
assert(array6->getSize() == 6);
/**
* Swap values from an XdmfArray
*/
array5->clear();
array5->swap(array4);
array6->clear();
array6->swap(array4);
assert(array4->getSize() == 0);
assert(array5->getSize() == 4);
assert(array6->getSize() == 4);
/**
* Get values via swap
*/
std::vector<int> valsInt;
bool success = array5->swap(valsInt);
bool success = array6->swap(valsInt);
assert(success == false);
std::vector<double> valsDouble;
success = array5->swap(valsDouble);
success = array6->swap(valsDouble);
assert(success == true);
assert(valsDouble.size() == 4);
assert(array5->getSize() == 0);
assert(array6->getSize() == 0);
return 0;
}
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