Commit b71d08cb authored by Kenneth Leiter's avatar Kenneth Leiter

Remove boost::tokenizer

Replace with std::stringstream implementation put for convenience
in XdmfStringUtils.hpp. Added a test as well.
parent 75b8639b
......@@ -23,7 +23,6 @@
#include <numeric>
#include <functional>
#include <boost/tokenizer.hpp>
#include "XdmfArray.hpp"
#include "XdmfError.hpp"
#include "XdmfAggregate.hpp"
......
......@@ -21,11 +21,11 @@
/* */
/*****************************************************************************/
#include "XdmfGeometry.hpp"
#include "XdmfGeometryType.hpp"
#include "XdmfError.hpp"
#include "XdmfFunction.hpp"
#include <boost/tokenizer.hpp>
#include "XdmfGeometry.hpp"
#include "XdmfGeometryType.hpp"
#include "XdmfStringUtils.hpp"
shared_ptr<XdmfGeometry> XdmfGeometry::New()
{
......@@ -188,12 +188,7 @@ 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()) {
boost::tokenizer<> tokens(origin->second);
for(boost::tokenizer<>::const_iterator iter = tokens.begin();
iter != tokens.end();
++iter) {
mOrigin.push_back(atof((*iter).c_str()));
}
XdmfStringUtils::split(origin->second, mOrigin);
}
}
......
......@@ -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"
......@@ -41,6 +40,7 @@
#include "XdmfRegularGrid.hpp"
#include "XdmfSet.hpp"
#include "XdmfSparseMatrix.hpp"
#include "XdmfStringUtils.hpp"
#include "XdmfTemplate.hpp"
#include "XdmfTime.hpp"
#include "XdmfTopology.hpp"
......@@ -277,12 +277,11 @@ XdmfItemFactory::createItem(const std::string & itemTag,
if(dimensions != itemProperties.end()) {
dimensionsString = dimensions->second;
}
boost::tokenizer<> tokens(dimensionsString);
for(boost::tokenizer<>::const_iterator iter = tokens.begin();
iter != tokens.end();
++iter) {
dimensionsArray->pushBack<unsigned int>(atoi((*iter).c_str()));
}
std::vector<unsigned int> dimensionsVector;
XdmfStringUtils::split(dimensionsString, dimensionsVector);
dimensionsArray->insert(0,
&(dimensionsVector[0]),
dimensionsVector.size());
if(typeVal.compare("2DCORECTMESH") == 0 ||
typeVal.compare("3DCORECTMESH") == 0 ||
typeVal.compare("CORECTMESH") == 0) {
......
......@@ -26,20 +26,18 @@
#include <climits>
#include <set>
#include "XdmfArray.hpp"
#include "XdmfHDF5Controller.hpp"
#include "XdmfBinaryController.hpp"
#include "XdmfError.hpp"
#include "XdmfHDF5Controller.hpp"
#include "XdmfItem.hpp"
#include "XdmfItemFactory.hpp"
#include "XdmfReader.hpp"
#include "XdmfTemplate.hpp"
#include "XdmfError.hpp"
#include "XdmfStringUtils.hpp"
#include "XdmfSystemUtils.hpp"
#include "XdmfVisitor.hpp"
#include "XdmfWriter.hpp"
#include "XdmfSystemUtils.hpp"
#include <boost/tokenizer.hpp>
#include <stdio.h>
std::vector<shared_ptr<XdmfHeavyDataController> >
......@@ -1102,33 +1100,26 @@ XdmfTemplate::setStep(unsigned int stepId)
// Data is contained in the content
std::string content = mDataDescriptions[i+(stepId*mTrackedArrays.size())];
mTrackedArrays[i]->initialize(mTrackedArrayTypes[i], mTrackedArrayDims[i]);
mTrackedArrays[i]->initialize(mTrackedArrayTypes[i],
mTrackedArrayDims[i]);
unsigned int index = 0;
boost::char_separator<char> sep(" \t\n");
boost::tokenizer<boost::char_separator<char> > valtokens(content, sep);
if(mTrackedArrayTypes[i] == XdmfArrayType::String()) {
for(boost::tokenizer<boost::char_separator<char> >::const_iterator
iter = valtokens.begin();
iter != valtokens.end();
++iter, ++index) {
mTrackedArrays[i]->insert(index, *iter);
}
}
std::vector<std::string> tokens;
XdmfStringUtils::split(content, tokens);
mTrackedArrays[i]->insert(0, &(tokens[0]), tokens.size());
}
else {
for(boost::tokenizer<boost::char_separator<char> >::const_iterator
iter = valtokens.begin();
iter != valtokens.end();
++iter, ++index) {
mTrackedArrays[i]->insert(index, atof((*iter).c_str()));
}
std::vector<double> tokens;
XdmfStringUtils::split(content, tokens);
mTrackedArrays[i]->insert(0, &(tokens[0]), tokens.size());
}
}
}
}
}
else {
XdmfError::message(XdmfError::FATAL, "Error: Template attempting to load invalid step");
XdmfError::message(XdmfError::FATAL,
"Error: Template attempting to load invalid step");
}
mCurrentStep = stepId;
}
......
......@@ -21,7 +21,6 @@
/* */
/*****************************************************************************/
#include <boost/tokenizer.hpp>
#include <limits>
#include <sstream>
#include <utility>
......@@ -33,11 +32,12 @@
#include "XdmfArrayReference.hpp"
#include "XdmfBinaryController.hpp"
#include "XdmfCoreReader.hpp"
#include "XdmfError.hpp"
#include "XdmfFunction.hpp"
#include "XdmfSubset.hpp"
#include "XdmfHeavyDataController.hpp"
#include "XdmfSubset.hpp"
#include "XdmfStringUtils.hpp"
#include "XdmfVisitor.hpp"
#include "XdmfError.hpp"
XDMF_CHILDREN_IMPLEMENTATION(XdmfArray,
XdmfHeavyDataController,
......@@ -1092,20 +1092,17 @@ XdmfArray::populateItem(const std::map<std::string, std::string> & itemPropertie
unsigned int i = 0;
while (i < dimArray->getSize() / 3)
{
while (i < dimArray->getSize() / 3) {
start.push_back(dimArray->getValue<unsigned int>(i));
++i;
}
while (i < 2 * (dimArray->getSize() / 3))
{
while (i < 2 * (dimArray->getSize() / 3)) {
stride.push_back(dimArray->getValue<unsigned int>(i));
++i;
}
while (i < dimArray->getSize())
{
while (i < dimArray->getSize()) {
dimensions.push_back(dimArray->getValue<unsigned int>(i));
++i;
}
......@@ -1173,12 +1170,7 @@ XdmfArray::populateItem(const std::map<std::string, std::string> & itemPropertie
"XdmfArray::populateItem");
}
boost::tokenizer<> tokens(dimensions->second);
for(boost::tokenizer<>::const_iterator iter = tokens.begin();
iter != tokens.end();
++iter) {
mDimensions.push_back(atoi((*iter).c_str()));
}
XdmfStringUtils::split(dimensions->second, mDimensions);
std::map<std::string, std::string>::const_iterator format =
itemProperties.find("Format");
......@@ -1193,26 +1185,17 @@ XdmfArray::populateItem(const std::map<std::string, std::string> & itemPropertie
if(formatVal.compare("XML") == 0) {
this->initialize(arrayType,
mDimensions);
unsigned int index = 0;
boost::char_separator<char> sep(" \t\n");
for (contentIndex = 0; contentIndex < contentVals.size(); ++contentIndex)
{
boost::tokenizer<boost::char_separator<char> > tokens(contentVals[contentIndex], sep);
for (contentIndex = 0; contentIndex < contentVals.size();
++contentIndex) {
if(arrayType == XdmfArrayType::String()) {
for(boost::tokenizer<boost::char_separator<char> >::const_iterator
iter = tokens.begin();
iter != tokens.end();
++iter, ++index) {
this->insert(index, *iter);
}
std::vector<std::string> tokens;
XdmfStringUtils::split(contentVals[contentIndex], tokens);
this->insert(0, &(tokens[0]), tokens.size());
}
else {
for(boost::tokenizer<boost::char_separator<char> >::const_iterator
iter = tokens.begin();
iter != tokens.end();
++iter, ++index) {
this->insert(index, atof((*iter).c_str()));
}
std::vector<double> tokens;
XdmfStringUtils::split(contentVals[contentIndex], tokens);
this->insert(0, &(tokens[0]), tokens.size());
}
}
}
......
This diff is collapsed.
......@@ -34,8 +34,6 @@
#include "XdmfCoreItemFactory.hpp"
#include "XdmfCoreReader.hpp"
#include "XdmfError.hpp"
#include "XdmfFunction.hpp"
#include "XdmfSubset.hpp"
#include "XdmfItem.hpp"
#include "XdmfSystemUtils.hpp"
......
/*****************************************************************************/
/* XDMF */
/* eXtensible Data Model and Format */
/* */
/* Id : XdmfStringUtils.hpp */
/* */
/* Author: */
/* Kenneth Leiter */
/* kenneth.leiter@arl.army.mil */
/* US Army Research Laboratory */
/* Aberdeen Proving Ground, MD */
/* */
/* Copyright @ 2011 US Army Research Laboratory */
/* All Rights Reserved */
/* See Copyright.txt for details */
/* */
/* This software is distributed WITHOUT ANY WARRANTY; without */
/* even the implied warranty of MERCHANTABILITY or FITNESS */
/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
/* for more information. */
/* */
/*****************************************************************************/
#ifndef XDMFSTRINGUTILS_HPP_
#define XDMFSTRINGUTILS_HPP_
#include "XdmfCore.hpp"
#ifdef __cplusplus
#include <algorithm>
#include <iterator>
#include <sstream>
#include <vector>
/**
* @brief String parsing utilities
*
* Collects all string parsing utilities used by Xdmf
*/
class XDMFCORE_EXPORT XdmfStringUtils {
public:
/**
* Split a string by whitespace and insert into container
*
* @param stringToSplit a string to split by spaces.
* @param containerToInsert a container to insert the split string into.
*/
template <typename T>
static void split(const std::string & stringToSplit,
std::vector<T> & containerToInsert);
protected:
XdmfStringUtils();
~XdmfStringUtils();
private:
XdmfStringUtils(const XdmfStringUtils &); // Not implemented.
void operator=(const XdmfStringUtils &); // Not implemented.
};
template <typename T>
void
XdmfStringUtils::split(const std::string & stringToSplit,
std::vector<T> & containerToInsert)
{
std::istringstream stream(stringToSplit);
std::copy(std::istream_iterator<T>(stream),
std::istream_iterator<T>(),
std::back_inserter(containerToInsert));
}
#endif
#endif /* XDMFSTRINGUTILS_HPP_ */
......@@ -23,7 +23,6 @@
#include <numeric>
#include <functional>
#include <boost/tokenizer.hpp>
#include "string.h"
#include "XdmfArray.hpp"
#include "XdmfError.hpp"
......@@ -31,9 +30,9 @@
#include "XdmfWriter.hpp"
XdmfSubset::XdmfSubset(shared_ptr<XdmfArray> referenceArray,
std::vector<unsigned int> & start,
std::vector<unsigned int> & stride,
std::vector<unsigned int> & dimensions) :
const std::vector<unsigned int> & start,
const std::vector<unsigned int> & stride,
const std::vector<unsigned int> & dimensions) :
mParent(referenceArray),
mDimensions(dimensions),
mStart(start),
......@@ -55,11 +54,14 @@ const std::string XdmfSubset::ItemTag = "Subset";
shared_ptr<XdmfSubset>
XdmfSubset::New(shared_ptr<XdmfArray> referenceArray,
std::vector<unsigned int> & start,
std::vector<unsigned int> & stride,
std::vector<unsigned int> & dimensions)
const std::vector<unsigned int> & start,
const std::vector<unsigned int> & stride,
const std::vector<unsigned int> & dimensions)
{
shared_ptr<XdmfSubset> p(new XdmfSubset(referenceArray, start, stride, dimensions));
shared_ptr<XdmfSubset> p(new XdmfSubset(referenceArray,
start,
stride,
dimensions));
return p;
}
......@@ -88,36 +90,28 @@ XdmfSubset::getItemProperties() const
"one value contained within");
}
std::map<std::string, std::string> subsetMap = XdmfArrayReference::getItemProperties();
std::map<std::string, std::string> subsetMap =
XdmfArrayReference::getItemProperties();
std::stringstream vectorStream;
vectorStream << mStart[0];
for (unsigned int i = 1; i < mStart.size(); ++i) {
vectorStream << " " << mStart[i];
}
subsetMap["SubsetStarts"] = vectorStream.str();
vectorStream.str(std::string());
vectorStream << mStride[0];
for (unsigned int i = 1; i < mStride.size(); ++i) {
vectorStream << " " << mStride[i];
}
subsetMap["SubsetStrides"] = vectorStream.str();
vectorStream.str(std::string());
vectorStream << mDimensions[0];
for (unsigned int i = 1; i < mDimensions.size(); ++i) {
vectorStream << " " << mDimensions[i];
}
subsetMap["SubsetDimensions"] = vectorStream.str();
return subsetMap;
......@@ -161,44 +155,6 @@ XdmfSubset::getStride() const
return mStride;
}
void
XdmfSubset::populateItem(const std::map<std::string, std::string> & itemProperties,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader)
{
std::map<std::string, std::string>::const_iterator starts =
itemProperties.find("SubsetStarts");
boost::tokenizer<> tokens(starts->second);
for(boost::tokenizer<>::const_iterator iter = tokens.begin();
iter != tokens.end();
++iter) {
mStart.push_back(atoi((*iter).c_str()));
}
std::map<std::string, std::string>::const_iterator strides =
itemProperties.find("SubsetStrides");
boost::tokenizer<> stridetokens(strides->second);
for(boost::tokenizer<>::const_iterator iter = stridetokens.begin();
iter != stridetokens.end();
++iter) {
mStride.push_back(atoi((*iter).c_str()));
}
std::map<std::string, std::string>::const_iterator dimensions =
itemProperties.find("SubsetDimensions");
boost::tokenizer<> dimtokens(dimensions->second);
for(boost::tokenizer<>::const_iterator iter = dimtokens.begin();
iter != dimtokens.end();
++iter) {
mDimensions.push_back(atoi((*iter).c_str()));
}
mParent = shared_dynamic_cast<XdmfArray>(childItems[0]);
}
shared_ptr<XdmfArray>
XdmfSubset::read() const
{
......
......@@ -75,9 +75,9 @@ public:
*/
static shared_ptr<XdmfSubset>
New(shared_ptr<XdmfArray> referenceArray,
std::vector<unsigned int> & start,
std::vector<unsigned int> & stride,
std::vector<unsigned int> & dimensions);
const std::vector<unsigned int> & start,
const std::vector<unsigned int> & stride,
const std::vector<unsigned int> & dimensions);
virtual ~XdmfSubset();
......@@ -369,14 +369,9 @@ public:
protected:
XdmfSubset(shared_ptr<XdmfArray> referenceArray,
std::vector<unsigned int> & start,
std::vector<unsigned int> & stride,
std::vector<unsigned int> & dimensions);
void
populateItem(const std::map<std::string, std::string> & itemProperties,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader);
const std::vector<unsigned int> & start,
const std::vector<unsigned int> & stride,
const std::vector<unsigned int> & dimensions);
shared_ptr<XdmfArray> mParent;
std::vector<unsigned int> mDimensions;
......
......@@ -30,6 +30,7 @@ ADD_TEST_CXX(TestXdmfHDF5Writer)
ADD_TEST_CXX(TestXdmfHDF5WriterTree)
ADD_TEST_CXX(TestXdmfInformation)
ADD_TEST_CXX(TestXdmfSparseMatrix)
ADD_TEST_CXX(TestXdmfStringUtils)
ADD_TEST_CXX(TestXdmfVersion)
# Add any cxx cleanup here:
......@@ -56,4 +57,5 @@ CLEAN_TEST_CXX(TestXdmfHDF5WriterTree
CLEAN_TEST_CXX(TestXdmfInformation)
CLEAN_TEST_CXX(TestXdmfSparseMatrix
TestXdmfSparseMatrix.xmf)
CLEAN_TEST_CXX(TestXdmfStringUtils)
CLEAN_TEST_CXX(TestXdmfVersion)
#include "XdmfStringUtils.hpp"
#include <cassert>
#include <vector>
int main() {
std::vector<int> split;
XdmfStringUtils::split("1 2 3", split);
assert(split.size() == 3);
assert(split[0] == 1);
assert(split[1] == 2);
assert(split[2] == 3);
split.clear();
XdmfStringUtils::split(" 1 2 3 ", split);
assert(split.size() == 3);
assert(split[0] == 1);
assert(split[1] == 2);
assert(split[2] == 3);
split.clear();
XdmfStringUtils::split("1\t2\t3", split);
assert(split.size() == 3);
assert(split[0] == 1);
assert(split[1] == 2);
assert(split[2] == 3);
split.clear();
XdmfStringUtils::split("1\n2\n3", split);
assert(split.size() == 3);
assert(split[0] == 1);
assert(split[1] == 2);
assert(split[2] == 3);
split.clear();
XdmfStringUtils::split("1\n\t 2\n\t 3", split);
assert(split.size() == 3);
assert(split[0] == 1);
assert(split[1] == 2);
assert(split[2] == 3);
return 0;
}
......@@ -9,123 +9,105 @@
int main(int, char **)
{
shared_ptr<XdmfArray> referenceArray = XdmfArray::New();
shared_ptr<XdmfArray> referenceArray = XdmfArray::New();
for (unsigned int i = 0; i < 27; ++i)
{
referenceArray->pushBack(i);
}
for (unsigned int i = 0; i < 27; ++i){
referenceArray->pushBack(i);
}
std::vector<unsigned int> initDimensions;
initDimensions.push_back(3);
initDimensions.push_back(3);
initDimensions.push_back(3);
std::vector<unsigned int> initDimensions;
initDimensions.push_back(3);
initDimensions.push_back(3);
initDimensions.push_back(3);
referenceArray->resize(initDimensions, 0);
referenceArray->resize(initDimensions, 0);
std::vector<unsigned int> newStarts;
newStarts.push_back(0);
newStarts.push_back(0);
newStarts.push_back(0);
std::vector<unsigned int> newStrides;
newStrides.push_back(2);
newStrides.push_back(2);
newStrides.push_back(2);
std::vector<unsigned int> newDimensions;
newDimensions.push_back(2);
newDimensions.push_back(2);
newDimensions.push_back(2);
std::vector<unsigned int> newStarts;
newStarts.push_back(0);
newStarts.push_back(0);
newStarts.push_back(0);
std::vector<unsigned int> newStrides;
newStrides.push_back(2);
newStrides.push_back(2);
newStrides.push_back(2);
std::vector<unsigned int> newDimensions;
newDimensions.push_back(2);
newDimensions.push_back(2);
newDimensions.push_back(2);
shared_ptr<XdmfSubset> testSubset = XdmfSubset::New(referenceArray,
newStarts,
newStrides,
newDimensions);
shared_ptr<XdmfSubset> testSubset = XdmfSubset::New(referenceArray,
newStarts,
newStrides,
newDimensions);
shared_ptr<XdmfAttribute> subsetHolder = XdmfAttribute::New();
shared_ptr<XdmfAttribute> subsetHolder = XdmfAttribute::New();
subsetHolder->setReference(testSubset);
subsetHolder->setReadMode(XdmfArray::Reference);
subsetHolder->setReference(testSubset);
shared_ptr<XdmfWriter> subsetWriter = XdmfWriter::New("subset.xmf");
subsetHolder->accept(subsetWriter);
subsetHolder->setReadMode(XdmfArray::Reference);
subsetHolder->readReference();
std::cout << subsetHolder->getValuesString() << std::endl;
shared_ptr<XdmfReader> subsetReader = XdmfReader::New();
shared_ptr<XdmfItem> readItem = subsetReader->read("subset.xmf");
std::cout << readItem->getItemTag() << " ?= Attribute" << std::endl;
assert(readItem->getItemTag().compare("Attribute") == 0);
shared_ptr<XdmfWriter> subsetWriter = XdmfWriter::New("subset.xmf");
shared_ptr<XdmfAttribute> readSubsetHolder =
shared_dynamic_cast<XdmfAttribute>(readItem);
subsetHolder->accept(subsetWriter);
readSubsetHolder->readReference();
std::cout << shared_dynamic_cast<XdmfSubset>(readSubsetHolder->getReference())->getReferenceArray()->getValuesString() << std::endl;
std::cout << readSubsetHolder->getValuesString() << std::endl;
assert(readSubsetHolder->getValuesString().compare(subsetHolder->getValuesString()) == 0);
subsetHolder->readReference();
shared_ptr<XdmfArray> referenceArray2 = XdmfArray::New();
std::cout << subsetHolder->getValuesString() << std::endl;
for (unsigned int i = 10; i < 37; ++i) {
referenceArray2->pushBack(i);
}
shared_ptr<XdmfReader> subsetReader = XdmfReader::New();
referenceArray2->resize(initDimensions, 0);
shared_ptr<XdmfItem> readItem = subsetReader->read("subset.xmf");
testSubset->setReferenceArray(referenceArray2);
std::cout << readItem->getItemTag() << " ?= Attribute" << std::endl;
std::string changedSubsetOutput = testSubset->read()->getValuesString();
assert(readItem->getItemTag().compare("Attribute") == 0);
std::cout << "after changing reference Array: " << changedSubsetOutput
<< std::endl;
shared_ptr<XdmfAttribute> readSubsetHolder = shared_dynamic_cast<XdmfAttribute>(readItem);
assert(changedSubsetOutput.compare("10 12 16 18 28 30 34 36") == 0);
readSubsetHolder->readReference();
shared_ptr<XdmfArray> subsetHolder2 = XdmfArray::New();
subsetHolder2->setReference(testSubset);
subsetHolder2->setReadMode(XdmfArray::Reference);
subsetHolder2->accept(subsetWriter);
subsetHolder2->readReference();
std::cout << shared_dynamic_cast<XdmfSubset>(readSubsetHolder->getReference())->getReferenceArray()->getValuesString() << std::endl;
std::cout << subsetHolder2->getValuesString() << std::endl;
std::cout << readSubsetHolder->getValuesString() << std::endl;
readItem = subsetReader->read("subset.xmf");
assert(readSubsetHolder->getValuesString().compare(subsetHolder->getValuesString()) == 0);
std::cout << readItem->getItemTag() << " ?= DataItem" << std::endl;
shared_ptr<XdmfArray> referenceArray2 = XdmfArray::New();
assert(readItem->getItemTag().compare("DataItem") == 0);
for (unsigned int i = 10; i < 37; ++i)
{
referenceArray2->pushBack(i);
}
shared_ptr<XdmfArray> readSubsetHolder2 =
shared_dynamic_cast<XdmfArray>(readItem);
readSubsetHolder2->readReference();
std::cout <<
shared_dynamic_cast<XdmfSubset>(readSubsetHolder2->getReference())->getReferenceArray()->getValuesString()
<< std::endl;
referenceArray2->resize(initDimensions, 0);
std::cout << readSubsetHolder2->getValuesString() << std::endl;
testSubset->setReferenceArray(referenceArray2);
assert(readSubsetHolder2->getValuesString().compare(subsetHolder2->getValuesString()) == 0);
std::string changedSubsetOutput = testSubset->read()->getValuesString();
std::cout << "after changing reference Array: " << changedSubsetOutput << std::endl;
assert(changedSubsetOutput.compare("10 12 16 18 28 30 34 36") == 0);
shared_ptr<XdmfArray> subsetHolder2 = XdmfArray::New();
subsetHolder2->setReference(testSubset);
subsetHolder2->setReadMode(XdmfArray::Reference);