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

Changes to remove boost dependency and add Cxx11 as an alternate

parent aff6b1fa
......@@ -12,6 +12,8 @@ if(MSVC10)
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
endif()
include(CheckCXXSourceCompiles)
set(XDMF_LIBNAME "Xdmf" CACHE STRING "Name for this xdmf library to avoid collision")
option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
if(BUILD_SHARED_LIBS)
......@@ -94,6 +96,29 @@ endif (TIFF_FOUND)
option(XDMF_BUILD_DSM OFF)
mark_as_advanced(XDMF_BUILD_DSM)
# Test for Cxx11
unset(HAVE_CXX11_SHARED_PTR CACHE)
check_cxx_source_compiles("
#include <memory>
using namespace std;
struct Base { virtual ~Base(){} };
int main(int ac, char * av[])
{
shared_ptr<Base> ptr(new Base());
}
"
HAVE_CXX11_SHARED_PTR)
# Cxx11 does not work with swig due to an issue with swig
if (HAVE_CXX11_SHARED_PTR AND NOT XDMF_WRAP_PYTHON)
set(HAVE_CXX11_SHARED_PTR ${HAVE_CXX11_SHARED_PTR} PARENT_SCOPE)
add_definitions(-DHAVE_CXX11_SHARED_PTR)
endif ()
if(XDMF_BUILD_DSM)
find_package(MPI REQUIRED)
if(MPI_FOUND)
......
......@@ -23,7 +23,6 @@
#include <numeric>
#include <functional>
#include <boost/tokenizer.hpp>
#include "XdmfArray.hpp"
#include "XdmfError.hpp"
#include "XdmfAggregate.hpp"
......
......@@ -114,11 +114,7 @@ XdmfAttribute::populateItem(const std::map<std::string, std::string> & itemPrope
iter != childItems.end();
++iter) {
if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
this->swap(array);
if (array->getReference()) {
this->setReference(array->getReference());
this->setReadMode(XdmfArray::Reference);
}
this->populateArray(array);
break;
}
}
......
......@@ -276,7 +276,7 @@ XdmfCurvilinearGrid::copyGrid(shared_ptr<XdmfGrid> sourceGrid)
shared_ptr<XdmfArray>
XdmfCurvilinearGrid::getDimensions()
{
return boost::const_pointer_cast<XdmfArray>
return const_pointer_cast<XdmfArray>
(static_cast<const XdmfCurvilinearGrid &>(*this).getDimensions());
}
......@@ -289,7 +289,7 @@ XdmfCurvilinearGrid::getDimensions() const
shared_ptr<XdmfGeometry>
XdmfCurvilinearGrid::getGeometry()
{
return boost::const_pointer_cast<XdmfGeometry>
return const_pointer_cast<XdmfGeometry>
(static_cast<const XdmfGrid &>(*this).getGeometry());
}
......
......@@ -25,7 +25,6 @@
#include "XdmfGeometryType.hpp"
#include "XdmfError.hpp"
#include "XdmfFunction.hpp"
#include <boost/tokenizer.hpp>
shared_ptr<XdmfGeometry> XdmfGeometry::New()
{
......@@ -176,11 +175,7 @@ XdmfGeometry::populateItem(const std::map<std::string, std::string> & itemProper
iter != childItems.end();
++iter) {
if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
this->swap(array);
if (array->getReference()) {
this->setReference(array->getReference());
this->setReadMode(XdmfArray::Reference);
}
this->populateArray(array);
break;
}
}
......@@ -195,12 +190,25 @@ XdmfGeometry::populateItem(const std::map<std::string, std::string> & itemProper
std::map<std::string, std::string>::const_iterator origin =
itemProperties.find("Origin");
if (origin != itemProperties.end()) {
#ifdef HAVE_CXX11_SHARED_PTR
char * originString = strdup(origin->second.c_str());
char * token = std::strtok(originString, " ");
while (token != NULL)
{
mOrigin.push_back(atoi(token));
token = std::strtok(NULL, " ");
}
free(originString);
originString = NULL;
#else
boost::tokenizer<> tokens(origin->second);
for(boost::tokenizer<>::const_iterator iter = tokens.begin();
iter != tokens.end();
++iter) {
mOrigin.push_back(atof((*iter).c_str()));
}
#endif
}
}
......
......@@ -62,7 +62,7 @@ XdmfGraph::getItemTag() const
shared_ptr<XdmfTime>
XdmfGraph::getTime()
{
return boost::const_pointer_cast<XdmfTime>
return const_pointer_cast<XdmfTime>
(static_cast<const XdmfGraph &>(*this).getTime());
}
......
......@@ -141,7 +141,7 @@ XdmfGrid::getName() const
shared_ptr<XdmfTime>
XdmfGrid::getTime()
{
return boost::const_pointer_cast<XdmfTime>
return const_pointer_cast<XdmfTime>
(static_cast<const XdmfGrid &>(*this).getTime());
}
......
......@@ -42,8 +42,6 @@
#include "XdmfSystemUtils.hpp"
#include <boost/tokenizer.hpp>
#include <stdio.h>
shared_ptr<XdmfGridTemplate>
......
......@@ -22,7 +22,6 @@
/*****************************************************************************/
#include <cctype>
#include <boost/tokenizer.hpp>
#include "XdmfAttribute.hpp"
#include "XdmfCurvilinearGrid.hpp"
#include "XdmfDomain.hpp"
......@@ -277,12 +276,25 @@ XdmfItemFactory::createItem(const std::string & itemTag,
if(dimensions != itemProperties.end()) {
dimensionsString = dimensions->second;
}
#ifdef HAVE_CXX11_SHARED_PTR
char * dimString = strdup(dimensionsString);
char * token = std::strtok(dimString, " ");
while (token != NULL)
{
dimensionsArray.push_back(atoi(token));
token = std::strtok(NULL, " ");
}
free(dimString);
dimString = NULL;
#else
boost::tokenizer<> tokens(dimensionsString);
for(boost::tokenizer<>::const_iterator iter = tokens.begin();
iter != tokens.end();
++iter) {
dimensionsArray->pushBack<unsigned int>(atoi((*iter).c_str()));
}
#endif
if(typeVal.compare("2DCORECTMESH") == 0 ||
typeVal.compare("3DCORECTMESH") == 0 ||
typeVal.compare("CORECTMESH") == 0) {
......
......@@ -333,7 +333,7 @@ XdmfRectilinearGrid::copyGrid(shared_ptr<XdmfGrid> sourceGrid)
shared_ptr<XdmfArray>
XdmfRectilinearGrid::getCoordinates(const unsigned int axisIndex)
{
return boost::const_pointer_cast<XdmfArray>
return const_pointer_cast<XdmfArray>
(static_cast<const XdmfRectilinearGrid &>
(*this).getCoordinates(axisIndex));
}
......@@ -362,7 +362,7 @@ XdmfRectilinearGrid::getCoordinates() const
shared_ptr<XdmfArray>
XdmfRectilinearGrid::getDimensions()
{
return boost::const_pointer_cast<XdmfArray>
return const_pointer_cast<XdmfArray>
(static_cast<const XdmfRectilinearGrid &>(*this).getDimensions());
}
......
......@@ -373,7 +373,7 @@ XdmfRegularGrid::copyGrid(shared_ptr<XdmfGrid> sourceGrid)
shared_ptr<XdmfArray>
XdmfRegularGrid::getBrickSize()
{
return boost::const_pointer_cast<XdmfArray>
return const_pointer_cast<XdmfArray>
(static_cast<const XdmfRegularGrid &>(*this).getBrickSize());
}
......@@ -386,7 +386,7 @@ XdmfRegularGrid::getBrickSize() const
shared_ptr<XdmfArray>
XdmfRegularGrid::getDimensions()
{
return boost::const_pointer_cast<XdmfArray>
return const_pointer_cast<XdmfArray>
(static_cast<const XdmfRegularGrid &>(*this).getDimensions());
}
......@@ -399,7 +399,7 @@ XdmfRegularGrid::getDimensions() const
shared_ptr<XdmfArray>
XdmfRegularGrid::getOrigin()
{
return boost::const_pointer_cast<XdmfArray>
return const_pointer_cast<XdmfArray>
(static_cast<const XdmfRegularGrid &>(*this).getOrigin());
}
......
......@@ -107,7 +107,7 @@ XdmfSet::populateItem(const std::map<std::string, std::string> & itemProperties,
else if(shared_ptr<XdmfArray> array =
shared_dynamic_cast<XdmfArray>(*iter)) {
if (!filled) {
this->swap(array);
this->populateArray(array);
filled = true;
}
if (array->getReference()) {
......
......@@ -38,8 +38,6 @@
#include "XdmfSystemUtils.hpp"
#include <boost/tokenizer.hpp>
#include <stdio.h>
std::vector<shared_ptr<XdmfHeavyDataController> >
......@@ -1114,6 +1112,26 @@ XdmfTemplate::setStep(unsigned int stepId)
mTrackedArrays[i]->initialize(mTrackedArrayTypes[i], mTrackedArrayDims[i]);
unsigned int index = 0;
#ifdef HAVE_CXX11_SHARED_PTR
char * trackedString = strdup(content);
char * token = std::strtok(trackedString, " \t\n");
if(mTrackedArrayTypes[i] == XdmfArrayType::String()) {
while (token != NULL)
{
mTrackedArrays[i]->insert(index, std::string(token));
token = std::strtok(NULL, " \t\n");
}
}
else {
while (token != NULL)
{
mTrackedArrays[i]->insert(index, atof(token));
token = std::strtok(NULL, " \t\n");
}
}
free(trackedString);
trackedString = NULL;
#else
boost::char_separator<char> sep(" \t\n");
boost::tokenizer<boost::char_separator<char> > valtokens(content, sep);
if(mTrackedArrayTypes[i] == XdmfArrayType::String()) {
......@@ -1132,6 +1150,7 @@ XdmfTemplate::setStep(unsigned int stepId)
mTrackedArrays[i]->insert(index, atof((*iter).c_str()));
}
}
#endif
}
}
}
......
......@@ -158,11 +158,7 @@ XdmfTopology::populateItem(const std::map<std::string, std::string> & itemProper
iter != childItems.end();
++iter) {
if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
this->swap(array);
if (array->getReference()) {
this->setReference(array->getReference());
this->setReadMode(XdmfArray::Reference);
}
this->populateArray(array);
break;
}
}
......
......@@ -259,7 +259,7 @@ XdmfUnstructuredGrid::copyGrid(shared_ptr<XdmfGrid> sourceGrid)
shared_ptr<XdmfGeometry>
XdmfUnstructuredGrid::getGeometry()
{
return boost::const_pointer_cast<XdmfGeometry>
return const_pointer_cast<XdmfGeometry>
(static_cast<const XdmfGrid &>(*this).getGeometry());
}
......@@ -272,7 +272,7 @@ XdmfUnstructuredGrid::getItemTag() const
shared_ptr<XdmfTopology>
XdmfUnstructuredGrid::getTopology()
{
return boost::const_pointer_cast<XdmfTopology>
return const_pointer_cast<XdmfTopology>
(static_cast<const XdmfGrid &>(*this).getTopology());
}
......
......@@ -114,6 +114,8 @@ 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("
#include <boost/shared_ptr.hpp>
......@@ -127,6 +129,26 @@ int main(int ac, char * av[])
}
"
HAVE_BOOST_SHARED_DYNAMIC_CAST)
check_cxx_source_compiles("
#include <memory>
using namespace std;
struct Base { virtual ~Base(){} };
int main(int ac, char * av[])
{
shared_ptr<Base> ptr(new Base());
}
"
HAVE_CXX11_SHARED_PTR)
if (HAVE_CXX11_SHARED_PTR AND NOT XDMF_WRAP_PYTHON)
set(HAVE_CXX11_SHARED_PTR ${HAVE_CXX11_SHARED_PTR} PARENT_SCOPE)
add_definitions(-DHAVE_CXX11_SHARED_PTR)
endif ()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/XdmfCoreConfig.hpp.in
${CMAKE_CURRENT_BINARY_DIR}/XdmfCoreConfig.hpp)
......
This diff is collapsed.
......@@ -37,8 +37,6 @@ class XdmfArrayType;
class XdmfHeavyDataController;
// Includes
#include <boost/shared_array.hpp>
#include <boost/variant.hpp>
/**
* @brief Provides storage for data values that are read in or will be
......@@ -600,7 +598,7 @@ public:
* initialized in this array.
*/
template <typename T>
shared_ptr<std::vector<T> > initialize(const unsigned int size = 0);
T * initialize(const unsigned int size = 0);
/**
* Initialize the array to specific dimensions.
......@@ -625,8 +623,7 @@ public:
* initialized in this array.
*/
template <typename T>
shared_ptr<std::vector<T> >
initialize(const std::vector<unsigned int> & dimensions);
T * initialize(const std::vector<unsigned int> & dimensions);
/**
* Initialize the array to contain a specified amount of a particular type.
......@@ -1320,7 +1317,7 @@ public:
* deletion of the array to XdmfArray.
*/
template<typename T>
void setValuesInternal(const T * const arrayPointer,
void setValuesInternal(T * const arrayPointer,
const unsigned int numValues,
const bool transferOwnership = 0);
......@@ -1464,6 +1461,12 @@ protected:
XdmfArray();
template <typename T>
void setArrayType();
virtual void
populateArray(const shared_ptr<XdmfArray> array);
virtual void
populateItem(const std::map<std::string, std::string> & itemProperties,
const std::vector<shared_ptr<XdmfItem> > & childItems,
......@@ -1474,16 +1477,34 @@ private:
XdmfArray(const XdmfArray &); // Not implemented.
void operator=(const XdmfArray &); // Not implemented.
template <typename T>
class XdmfVisitor;
template <typename T, typename U>
static
T
ApplyVisitor(const XdmfArray * const source, XdmfVisitor<T> & visitor, void * array, U * internal);
template<typename T, typename U, typename V>
static
T
ApplyVisitorFunction(XdmfVisitor<T> & visitor, U * array, V * internal);
// Variant Visitor Operations
class Clear;
class Erase;
class GetArrayType;
class GetCapacity;
template <typename T> class GetValue;
template <typename T> class GetValues;
template <typename T>
class GetValue;
template <typename T>
class GetValues;
class GetValuesPointer;
template <typename T>
class GetValuesString;
template <typename T> class Insert;
template <typename T>
class Insert;
class InsertArray;
class InternalizeArrayPointer;
class IsInitialized;
......@@ -1503,35 +1524,20 @@ private:
*/
void internalizeArrayPointer();
typedef boost::variant<
boost::blank,
shared_ptr<std::vector<char> >,
shared_ptr<std::vector<short> >,
shared_ptr<std::vector<int> >,
shared_ptr<std::vector<long> >,
shared_ptr<std::vector<float> >,
shared_ptr<std::vector<double> >,
shared_ptr<std::vector<unsigned char> >,
shared_ptr<std::vector<unsigned short> >,
shared_ptr<std::vector<unsigned int> >,
shared_ptr<std::vector<std::string> >,
boost::shared_array<const char>,
boost::shared_array<const short>,
boost::shared_array<const int>,
boost::shared_array<const long>,
boost::shared_array<const float>,
boost::shared_array<const double>,
boost::shared_array<const unsigned char>,
boost::shared_array<const unsigned short>,
boost::shared_array<const unsigned int> > ArrayVariant;
unsigned int mArrayPointerNumValues;
std::vector<unsigned int> mDimensions;
std::string mName;
unsigned int mTmpReserveSize;
ReadMode mReadMode;
shared_ptr<XdmfArrayReference> mReference;
ArrayVariant mArray;
std::vector<unsigned int> mDimensions;
std::string mName;
std::string mRequestedHeavyDataset;
// Internal Array Data
// This will need to be expanded as T** or further to handle multiple dimensions
shared_ptr<const XdmfArrayType> mArrayType;
std::vector<unsigned int> mCapacity;
std::vector<unsigned long> mAllocation;
void * mArray;
};
#include "XdmfArray.tpp"
......
This diff is collapsed.
......@@ -32,7 +32,6 @@
#include "XdmfTIFFController.hpp"
#include "XdmfInformation.hpp"
#include "XdmfSparseMatrix.hpp"
#include <boost/tokenizer.hpp>
#include <string.h>
std::string
......@@ -76,11 +75,11 @@ XdmfCoreItemFactory::createItem(const std::string & itemTag,
const std::vector<shared_ptr<XdmfItem> > & childItems) const
{
if(itemTag.compare(XdmfArray::ItemTag) == 0) {
return XdmfArray::New();
return shared_dynamic_cast<XdmfItem>(XdmfArray::New());
}
else if(itemTag.compare("DataStructure") == 0) {
// to support old xdmf DataStructure tag
return XdmfArray::New();
return shared_dynamic_cast<XdmfItem>(XdmfArray::New());
}
else if (itemTag.compare(XdmfFunction::ItemTag) == 0) {
std::map<std::string, std::string>::const_iterator type =
......@@ -198,6 +197,49 @@ XdmfCoreItemFactory::createItem(const std::string & itemTag,
std::vector<unsigned int> dimensionVector;
shared_ptr<XdmfArray> referenceArray;
#ifdef HAVE_CXX11_SHARED_PTR
std::map<std::string, std::string>::const_iterator starts =
itemProperties.find("SubsetStarts");
char * startsString = strdup(starts->second.c_str());
char * token = std::strtok(startsString, " ");
while (token != NULL)
{
startVector.push_back(atoi(token));
token = std::strtok(NULL, " ");
}
free(startsString);
startsString = NULL;
std::map<std::string, std::string>::const_iterator strides =
itemProperties.find("SubsetStrides");
char * stridesString = strdup(strides->second.c_str());
token = std::strtok(stridesString, " ");
while (token != NULL)
{
strideVector.push_back(atoi(token));
token = std::strtok(NULL, " ");
}
free(stridesString);
stridesString = NULL;
std::map<std::string, std::string>::const_iterator dimensions =
itemProperties.find("SubsetDimensions");
char * dimsString = strdup(dimensions->second.c_str());
token = std::strtok(dimsString, " ");
while (token != NULL)
{
dimensionVector.push_back(atoi(token));
token = std::strtok(NULL, " ");
}
free(dimsString);
dimsString = NULL;
#else
std::map<std::string, std::string>::const_iterator starts =
itemProperties.find("SubsetStarts");
......@@ -227,6 +269,7 @@ XdmfCoreItemFactory::createItem(const std::string & itemTag,
++iter) {
dimensionVector.push_back(atoi((*iter).c_str()));
}
#endif
bool foundspacer = false;
......@@ -334,13 +377,25 @@ XdmfCoreItemFactory::generateHeavyDataControllers(const std::map<std::string, st
"'Dimensions' not found in generateHeavyControllers in "
"XdmfCoreItemFactory");
}
#ifdef HAVE_CXX11_SHARED_PTR
char * dimsString = strdup(dimensions->second.c_str());
char * token = std::strtok(dimsString, " ");
while (token != NULL)
{
dimVector.push_back(atoi(token));
token = std::strtok(NULL, " ");
}
free(dimsString);
dimsString = NULL;
#else
boost::tokenizer<> tokens(dimensions->second);
for(boost::tokenizer<>::const_iterator iter = tokens.begin();
iter != tokens.end();
++iter) {
dimVector.push_back(atoi((*iter).c_str()));
}
#endif
}
shared_ptr<const XdmfArrayType> arrayType;
......@@ -415,6 +470,61 @@ XdmfCoreItemFactory::generateHeavyDataControllers(const std::map<std::string, st
}
// split the description based on tokens
#ifdef HAVE_CXX11_SHARED_PTR
char * dimsString;
if (dataspaceVector.size() == 1) {
dimsString = strdup(dataspaceDescription.c_str());
}
else if (dataspaceVector.size() == 5) {
dimsString = strdup(dataspaceVector[3].c_str());
}
char * token = std::strtok(dimsString, " ");
while (token != NULL)
{
contentDims.push_back(atoi(token));
token = std::strtok(NULL, " ");
}
free(dimsString);
dimsString = NULL;
if (dataspaceVector.size() == 5) {
seek = atoi(dataspaceVector[0].c_str());
dimsString = strdup(dataspaceVector[1].c_str());
token = std::strtok(dimsString, " ");
while (token != NULL)
{
contentStarts.push_back(atoi(token));
token = std::strtok(NULL, " ");
}
free(dimsString);
dimsString = NULL;
dimsString = strdup(dataspaceVector[2].c_str());
token = std::strtok(dimsString, " ");
while (token != NULL)
{
contentStrides.push_back(atoi(token));
token = std::strtok(NULL, " ");
}
free(dimsString);
dimsString = NULL;
dimsString = strdup(dataspaceVector[4].c_str());
token = std::strtok(dimsString, " ");
while (token != NULL)
{
contentDataspaces.push_back(atoi(token));
token = std::strtok(NULL, " ");
}
free(dimsString);
dimsString = NULL;
}
#else
boost::tokenizer<> dimtokens(std::string(""));
if (dataspaceVector.size() == 1) {
dimtokens = boost::tokenizer<>(dataspaceDescription);
......@@ -449,6 +559,7 @@ XdmfCoreItemFactory::generateHeavyDataControllers(const std::map<std::string, st
contentDataspaces.push_back(atoi((*iter).c_str()));
}
}
#endif
contentStep = 2;
// If this works then the dimension content should be skipped over
......@@ -529,6 +640,59 @@ XdmfCoreItemFactory::generateHeavyDataControllers(const std::map<std::string, st
}
// split the description based on tokens
#ifdef HAVE_CXX11_SHARED_PTR
char * dimsString;
if (dataspaceVector.size() == 1) {
dimsString = strdup(dataspaceDescription.c_str());
}
else if (dataspaceVector.size() == 4) {
dimsString = strdup(dataspaceVector[2].c_str());
}
char * token = std::strtok(dimsString, " ");
while (token != NULL)
{
contentDims.push_back(atoi(token));
token = std::strtok(NULL, " ");
}
free(dimsString);
dimsString = NULL;
if (dataspaceVector.size() == 4) {
dimsString = strdup(dataspaceVector[0].c_str());
token = std::strtok(dimsString, " ");
while (token != NULL)
{
contentStarts.push_back(atoi(token));
token = std::strtok(NULL, " ");
}
free(dimsString);
dimsString = NULL;
dimsString = strdup(dataspaceVector[1].c_str());
token = std::strtok(dimsString, " ");
while (token != NULL)
{
contentStrides.push_back(atoi(token));
token = std::strtok(NULL, " ");
}
free(dimsString);
dimsString = NULL;
dimsString = strdup(dataspaceVector[3].c_str());
token = std::strtok(dimsString, " ");
while (token != NULL)
{
contentDataspace.push_back(atoi(token));
token = std::strtok(NULL, " ");
}
free(dimsString);
dimsString = NULL;
}
#else
boost::tokenizer<> dimtokens(std::string(""));
if (dataspaceVector.size() == 1) {
dimtokens = boost::tokenizer<>(dataspaceDescription);
......@@ -562,6 +726,7 @@ XdmfCoreItemFactory::generateHeavyDataControllers(const std::map<std::string, st
contentDataspaces.push_back(atoi((*iter).c_str()));
}
}
#endif
contentStep = 2;
// If this works then the dimension con