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

fixes to handle boost not being available

parent 44d1df0e
......@@ -25,6 +25,7 @@
#include "XdmfGeometryType.hpp"
#include "XdmfError.hpp"
#include "XdmfFunction.hpp"
#include <cstring>
shared_ptr<XdmfGeometry> XdmfGeometry::New()
{
......
......@@ -23,6 +23,7 @@
#include <algorithm>
#include <cctype>
#include <cstring>
#include "XdmfAttribute.hpp"
#include "XdmfCurvilinearGrid.hpp"
#include "XdmfDomain.hpp"
......
......@@ -24,6 +24,7 @@
#include <sstream>
#include <utility>
#include <climits>
#include <cstring>
#include <set>
#include "XdmfArray.hpp"
#include "XdmfHDF5Controller.hpp"
......
......@@ -35,7 +35,7 @@ if(XDMF_BUILD_DSM)
endif()
mark_as_advanced(CLEAR Boost_INCLUDE_DIR)
find_package(Boost REQUIRED)
find_package(Boost)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
mark_as_advanced(FORCE Boost_INCLUDE_DIR)
......@@ -113,7 +113,6 @@ endif()
TEST_BIG_ENDIAN(XDMF_BIG_ENDIAN)
unset(HAVE_BOOST_SHARED_DYNAMIC_CAST CACHE)
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${Boost_INCLUDE_DIRS})
unset(HAVE_CXX11_SHARED_PTR CACHE)
check_cxx_source_compiles("
......@@ -291,14 +290,24 @@ if (XDMF_STATIC_AND_SHARED AND BUILD_SHARED_LIBS)
ARCHIVE DESTINATION lib)
endif ()
set(XdmfCore_INCLUDE_DIRS
${Boost_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${HDF5_INCLUDE_DIR}
${LIBXML2_INCLUDE_DIR}
${PYTHON_INCLUDE_DIRS}
CACHE INTERNAL "")
if (Boost_FOUND)
set(XdmfCore_INCLUDE_DIRS
${Boost_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${HDF5_INCLUDE_DIR}
${LIBXML2_INCLUDE_DIR}
${PYTHON_INCLUDE_DIRS}
CACHE INTERNAL "")
else ()
set(XdmfCore_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${HDF5_INCLUDE_DIR}
${LIBXML2_INCLUDE_DIR}
${PYTHON_INCLUDE_DIRS}
CACHE INTERNAL "")
endif ()
set(XDMF_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/include PARENT_SCOPE)
set(XDMF_LIBRARIES ${XDMF_LIBRARIES} ${CMAKE_INSTALL_PREFIX}/lib)
......
......@@ -26,7 +26,7 @@
#include <utility>
#include <stack>
#include <math.h>
#include <string.h>
#include <cstring>
#include "XdmfArray.hpp"
#include "XdmfArrayType.hpp"
#include "XdmfArrayReference.hpp"
......@@ -133,6 +133,7 @@ XdmfArray::XdmfArray() :
mName(""),
mTmpReserveSize(256),
mReadMode(XdmfArray::Controller),
mHasArrayOwnership(true),
mArray(NULL)
{
// Most intances use at most 3 dimensions
......@@ -146,6 +147,8 @@ XdmfArray::XdmfArray(XdmfArray & refArray):
mDimensions(refArray.getDimensions()),
mName(refArray.getName()),
mReadMode(refArray.getReadMode()),
mHasArrayOwnership(true),
mArray(NULL),
mArrayType(refArray.mArrayType)
{
if (refArray.getArrayType() != XdmfArrayType::Uninitialized()) {
......@@ -167,6 +170,7 @@ XdmfArray::XdmfArray(XdmfArray & refArray):
XdmfArray::~XdmfArray()
{
this->release();
}
const std::string XdmfArray::ItemTag = "DataItem";
......@@ -1022,7 +1026,7 @@ XdmfArray::readReference()
void
XdmfArray::release()
{
if (mArray)
if (mArray && mHasArrayOwnership)
{
free(mArray);
mArray = NULL;
......@@ -1115,6 +1119,14 @@ XdmfArray::setArrayType<long>()
mArrayType = XdmfArrayType::Int64();
}
template <>
XDMFCORE_EXPORT
void
XdmfArray::setArrayType<long long>()
{
mArrayType = XdmfArrayType::Int64();
}
#ifdef WIN32
template <>
XDMFCORE_EXPORT
......
......@@ -1537,6 +1537,7 @@ private:
shared_ptr<const XdmfArrayType> mArrayType;
std::vector<unsigned int> mCapacity;
std::vector<unsigned long> mAllocation;
bool mHasArrayOwnership;
void * mArray;
};
......
......@@ -429,10 +429,6 @@ public:
U copyValue = array[mStartIndex + i*mArrayStride];
T setValue = (T)copyValue;
mValuesPointer[i*mValuesStride] = setValue;
/*
mValuesPointer[i*mValuesStride] =
(T)array[mStartIndex + i*mArrayStride];
*/
}
}
}
......@@ -595,15 +591,12 @@ public:
{
// TODO STRING
unsigned int size = mStartIndex + (mNumValues - 1) * mArrayStride + 1;
// TODO resize pointer
if(array->size() < size) {
array->resize(size);
mDimensions.clear();
}
for(unsigned int i=0; i<mNumValues; ++i) {
std::stringstream value;
// TODO
// value << mValuesPointer[i*mValuesStride];
array[mStartIndex + i*mArrayStride] = value.str();
}
}
......@@ -613,7 +606,6 @@ public:
operator()(U * array) const
{
unsigned int size = mStartIndex + (mNumValues - 1) * mArrayStride + 1;
// TODO resize pointer
if(mArray->getSize() < size) {
T resizeValue = 0;
mArray->resize(size, resizeValue);
......@@ -622,10 +614,6 @@ public:
for(unsigned int i=0; i<mNumValues; ++i) {
T copyValue = mValuesPointer[i*mValuesStride];
array[mStartIndex + i*mArrayStride] = (U)copyValue;
/*
array[mStartIndex + i*mArrayStride] =
((U *)mValuesPointer)[i*mValuesStride];
*/
}
}
......@@ -677,7 +665,6 @@ public:
operator()(std::string * array) const
{
unsigned int size = mStartIndex + (mNumValues - 1) * mArrayStride + 1;
// TODO resize pointer
if(array->size() < size) {
array->resize(size);
mDimensions.clear();
......@@ -693,10 +680,7 @@ public:
operator()(U * array) const
{
unsigned int size = mStartIndex + (mNumValues - 1) * mArrayStride + 1;
// TODO resize pointer
if(mArray->getSize() < size) {
// TODO resize for std::string needs to be fixed
// mArray->resize(size, std::string(""));
mDimensions.clear();
}
for(unsigned int i=0; i<mNumValues; ++i) {
......@@ -960,118 +944,10 @@ template<>
std::string
XdmfArray::GetValuesString<std::string>::getValuesString<void, void>(const void * const array,
const int numValues) const;
/*
{
const int lastIndex = numValues - 1;
if(lastIndex < 0) {
return "";
}
std::stringstream toReturn;
toReturn.precision(std::numeric_limits<char>::digits10 + 2);
for(int i=0; i<lastIndex; ++i) {
toReturn << (char)((char *)array)[i] << " ";
}
toReturn << (char)((char *)array)[lastIndex];
return toReturn.str();
}
*/
/*
template <>
class XdmfArray::Insert<std::string> : public XdmfArray::XdmfVisitor<void> {
public:
Insert(XdmfArray * const array,
const unsigned int startIndex,
const std::string * const valuesPointer,
const unsigned int numValues,
const unsigned int arrayStride,
const unsigned int valuesStride,
std::vector<unsigned int> & dimensions) :
mArray(array),
mStartIndex(startIndex),
mValuesPointer(valuesPointer),
mNumValues(numValues),
mArrayStride(arrayStride),
mValuesStride(valuesStride),
mDimensions(dimensions)
{
mName = "Insert";
}
void
operator()(void * array) const
{
mArray->initialize<std::string>();
ApplyVisitor(mArray,
this),
mArray->mArray,
(std::string *) array);
}
void
operator()(std::string * array) const
{
unsigned int size = mStartIndex + (mNumValues - 1) * mArrayStride + 1;
// TODO resize pointer
if(array->size() < size) {
array->resize(size);
mDimensions.clear();
}
for(unsigned int i=0; i<mNumValues; ++i) {
array[mStartIndex + i*mArrayStride] =
mValuesPointer[i*mValuesStride].c_str();
}
}
template<typename U>
void
operator()(U * array) const
{
unsigned int size = mStartIndex + (mNumValues - 1) * mArrayStride + 1;
// TODO resize pointer
if(mArray->getSize() < size) {
mArray->resize(size, std::string(""));
mDimensions.clear();
}
for(unsigned int i=0; i<mNumValues; ++i) {
array[mStartIndex + i*mArrayStride] =
(U)atof(mValuesPointer[i*mValuesStride].c_str());
}
}
private:
XdmfArray * const mArray;
const unsigned int mStartIndex;
const std::string * const mValuesPointer;
const unsigned int mNumValues;
const unsigned int mArrayStride;
const unsigned int mValuesStride;
std::vector<unsigned int> & mDimensions;
};
*/
template<>
void
XdmfArray::Insert<std::string>::operator()<void>(void * array) const;
/*
{
unsigned int size = mStartIndex + (mNumValues - 1) * mArrayStride + 1;
// TODO resize pointer
if(mArray->getSize() < size) {
mArray->resize(size, std::string(""));
mDimensions.clear();
}
for(unsigned int i=0; i<mNumValues; ++i) {
((char *)array)[mStartIndex + i*mArrayStride] =
(char)atof(mValuesPointer[i*mValuesStride].c_str());
}
}
*/
class XdmfArray::InsertArray : public XdmfArray::XdmfVisitor<void> {
public:
......@@ -1162,17 +1038,6 @@ public:
operator()(std::string * array) const
{
mArray->insert(mArray->getSize(), mVal);
/*
//resize if outside capacity
std::stringstream value;
value << mVal;
unsigned int endpoint = mArray->getSize();// TODO
mArray->resize<T>(endpoint + 1);
array = (std::string *) mArray->mArray;
array[endpoint + 1] = value.str();
mArray->mDimensions.clear();
mArray->mDimensions.push_back(endpoint + 1);
*/
}
template<typename U>
......@@ -1180,14 +1045,6 @@ public:
operator()(U * array) const
{
mArray->insert(mArray->getSize(), mVal);
/*
unsigned int endpoint = mArray->getSize();// TODO
mArray->resize<T>(endpoint + 1);
array = (U *) mArray->mArray;
array[endpoint]=(U)mVal;
mArray->mDimensions.clear();
mArray->mDimensions.push_back(endpoint + 1);
*/
}
private:
......@@ -1476,14 +1333,14 @@ public:
}
void
operator()(const void * array) const
operator()(void * array) const
{
mArray->mTmpReserveSize = mSize;
}
template<typename T>
void
operator()(T * & array) const
operator()(T * array) const
{
mArray->initialize<T>(mSize);
}
......@@ -1764,13 +1621,9 @@ XdmfArray::setValuesInternal(T * const arrayPointer,
{
// Remove contents of internal array.
// Free old internal array if required
if(transferOwnership) {
// In this case Xdmf will free the pointer when done with it
mArray = arrayPointer;
}
else {
// The user has to free the pointer
mArray = arrayPointer;
mArray = arrayPointer;
if(!transferOwnership) {
mHasArrayOwnership = false;
}
mArrayPointerNumValues = numValues;
mDimensions.clear();
......@@ -1784,13 +1637,9 @@ void
XdmfArray::setValuesInternal(std::vector<T> & array,
const bool transferOwnership)
{
if(transferOwnership) {
// Extract the vector's internal pointer, but leave control to original source
mArray = *(array[0]);
}
else {
// Completely extract the internal pointer
mArray = *(array[0]);
mArray = *(array[0]);
if(!transferOwnership) {
mHasArrayOwnership = false;
}
mDimensions.clear();
mDimensions.push_back(array.size());
......
......@@ -27,7 +27,6 @@
#include "XdmfArrayReference.hpp"
#include <stack>
#include <math.h>
#include <boost/assign.hpp>
#include "XdmfError.hpp"
XdmfArrayReference::XdmfArrayReference():
......
......@@ -23,7 +23,6 @@
#include <sstream>
#include <utility>
#include <boost/assign.hpp>
#include "string.h"
#include "XdmfArrayType.hpp"
#include "XdmfError.hpp"
......
......@@ -25,6 +25,7 @@
#define XDMFCONFIG_HPP_
#cmakedefine HAVE_BOOST_SHARED_DYNAMIC_CAST
#cmakedefine HAVE_CXX11_SHARED_PTR
#cmakedefine HAVE_CXX11_ENABLE_IF
#cmakedefine XDMF_BIG_ENDIAN
......
......@@ -33,5 +33,6 @@
#endif
#cmakedefine XDMF_NO_REALPATH
#cmakedefine HAVE_CXX11_SHARED_PTR
#endif /* XDMFCORECONFIG_HPP_ */
......@@ -32,7 +32,7 @@
#include "XdmfTIFFController.hpp"
#include "XdmfInformation.hpp"
#include "XdmfSparseMatrix.hpp"
#include <string.h>
#include <cstring>
std::string
XdmfCoreItemFactory::getFullHeavyDataPath(const std::string & filePath,
......
......@@ -22,6 +22,40 @@
/*****************************************************************************/
#include "XdmfItemProperty.hpp"
#ifdef HAVE_CXX11_SHARED_PTR
const std::map<const char, const char> XdmfItemProperty::UpperConversionMap =
{
{'a', 'A'},
{'b', 'B'},
{'c', 'C'},
{'d', 'D'},
{'e', 'E'},
{'f', 'F'},
{'g', 'G'},
{'h', 'H'},
{'i', 'I'},
{'j', 'J'},
{'k', 'K'},
{'l', 'L'},
{'m', 'M'},
{'n', 'N'},
{'o', 'O'},
{'p', 'P'},
{'q', 'Q'},
{'r', 'R'},
{'s', 'S'},
{'t', 'T'},
{'u', 'U'},
{'v', 'V'},
{'w', 'W'},
{'x', 'X'},
{'y', 'Y'},
{'z', 'Z'}
};
#else
#include <boost/assign.hpp>
const std::map<const char, const char> XdmfItemProperty::UpperConversionMap =
......@@ -51,6 +85,7 @@ const std::map<const char, const char> XdmfItemProperty::UpperConversionMap =
('x', 'X')
('y', 'Y')
('z', 'Z');
#endif
// Using this method because ANSI and std transform aren't guarenteed
std::string
......
......@@ -24,7 +24,7 @@
#ifndef XDMFSHAREDPTR_HPP_
#define XDMFSHAREDPTR_HPP_
#include "XdmfConfig.hpp"
#include "XdmfCoreConfig.hpp"
#ifdef HAVE_CXX11_SHARED_PTR
......@@ -42,17 +42,6 @@ using boost::const_pointer_cast;
#endif /* */
/*
#ifdef HAVE_CXX11_VARIANT
using std::variant;
#else
*/
//#include <boost/variant.hpp>
//using boost::variant;
//#endif
// Tokenizer
// http://en.cppreference.com/w/cpp/string/byte/strtok
......@@ -73,31 +62,6 @@ shared_ptr<T> shared_dynamic_cast(shared_ptr<U> const & r)
#endif /* HAVE_BOOST_SHARED_DYNAMIC_CAST */
#ifdef HAVE_CXX11_ENABLE_IF
#include <type_traits>
using std::is_floating_point;
using std::is_signed;
using std::is_unsigned;
using std::is_same;
#define enable_if_c std::enable_if
using std::remove_const;
#else
#include "boost/utility.hpp"
#include "boost/type_traits.hpp"
using boost::enable_if_c;
using boost::is_floating_point;
using boost::is_signed;
using boost::is_unsigned;
using boost::is_same;
using boost::remove_const;
#endif /* HAVE_CXX11_ENABLE_IF */
// Used by C wrappers to prevent shared pointers from prematurely deleting objects
// Normally this would be completely against the point of shared pointers,
// but the C wrapping requires that objects be seperated from the shared pointers.
......
......@@ -23,7 +23,7 @@
#include <numeric>
#include <functional>
#include "string.h"
#include <cstring>
#include "XdmfArray.hpp"
#include "XdmfError.hpp"
#include "XdmfSubset.hpp"
......
......@@ -33,9 +33,11 @@ if (HAVE_CXX11_SHARED_PTR AND NOT XDMF_WRAP_PYTHON)
add_definitions(-DHAVE_CXX11_SHARED_PTR)
endif ()
mark_as_advanced(Boost_INCLUDE_DIR)
include_directories(${Boost_INCLUDE_DIRS})
mark_as_advanced(FORCE Boost_INCLUDE_DIR)
if (Boost_FOUND)
mark_as_advanced(Boost_INCLUDE_DIR)
include_directories(${Boost_INCLUDE_DIRS})
mark_as_advanced(FORCE Boost_INCLUDE_DIR)
endif()
#mark_as_advanced(CLEAR HDF5_C_INCLUDE_DIR)
#mark_as_advanced(CLEAR HDF5_hdf5_LIBRARY_DEBUG)
......@@ -214,7 +216,6 @@ endif (BUILD_SHARED_LIBS)
if(XDMF_BUILD_DSM_THREADS)
set(XdmfDSM_INCLUDE_DIRS
${Boost_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}
${HDF5_INCLUDE_DIR}
${H5FDdsm_INCLUDE_DIR}
......@@ -223,7 +224,6 @@ set(XdmfDSM_INCLUDE_DIRS
CACHE INTERNAL "")
else()
set(XdmfDSM_INCLUDE_DIRS
${Boost_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}
${HDF5_INCLUDE_DIR}
${LIBXML2_INCLUDE_DIR}
......@@ -231,6 +231,12 @@ set(XdmfDSM_INCLUDE_DIRS
CACHE INTERNAL "")
endif()
if (Boost_FOUND)
set(XdmfDSM_INCLUDE_DIRS
${XdmfDSM_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS})
endif ()
include_directories(${XdmfCore_INCLUDE_DIRS} ${XdmfDSM_INCLUDE_DIRS})
if(XDMF_BUILD_TESTING)
......
......@@ -123,12 +123,16 @@ int main()
printf("%d ?= %d\n", XdmfArrayGetNumberDimensions(array), 2);
printf("%d ?= %d\n", XdmfArrayGetSize(array), 20);
int capacity = XdmfArrayGetCapacity(array);
printf("Capacity Prior to Reserve = %d\n", capacity);
assert(XdmfArrayGetNumberDimensions(array) == 2);
assert(XdmfArrayGetSize(array) == 20);
XdmfArrayReserve(array, 50);
int capacity = XdmfArrayGetCapacity(array);
capacity = XdmfArrayGetCapacity(array);
printf("%d ?>= %d\n", capacity, 50);
......
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