From 7bcbfe72cbba51a52d2a51950d8599b7a0d7f281 Mon Sep 17 00:00:00 2001 From: Kenneth Leiter Date: Mon, 14 May 2012 14:16:00 -0400 Subject: [PATCH] ENH: Performance improvements for large reads/writes Eliminate getRealPath calls which are expensive and not necessary in many cases Parse XML node content only when necessary (parsing arrays) Fix cases where copies were made of strings instead of using references Use "map.insert()" rather than "map[] =" when adding properties to map --- XdmfAttribute.cpp | 11 +- XdmfAttribute.hpp | 2 +- XdmfAttributeCenter.cpp | 52 +++--- XdmfAttributeType.cpp | 66 +++---- XdmfCurvilinearGrid.cpp | 2 +- XdmfCurvilinearGrid.hpp | 2 +- XdmfDomain.cpp | 2 +- XdmfDomain.hpp | 2 +- XdmfGeometry.cpp | 4 +- XdmfGeometry.hpp | 2 +- XdmfGeometryType.cpp | 39 ++-- XdmfGrid.cpp | 5 +- XdmfGrid.hpp | 2 +- XdmfGridCollection.cpp | 5 +- XdmfGridCollection.hpp | 2 +- XdmfGridCollectionType.cpp | 42 +++-- XdmfItemFactory.cpp | 8 +- XdmfMap.cpp | 5 +- XdmfMap.hpp | 2 +- XdmfRectilinearGrid.cpp | 2 +- XdmfRectilinearGrid.hpp | 2 +- XdmfRegularGrid.cpp | 2 +- XdmfRegularGrid.hpp | 2 +- XdmfSet.cpp | 5 +- XdmfSet.hpp | 2 +- XdmfSetType.cpp | 52 +++--- XdmfTime.cpp | 9 +- XdmfTime.hpp | 2 +- XdmfTopology.cpp | 5 +- XdmfTopology.hpp | 2 +- XdmfTopologyType.cpp | 213 +++++++++++----------- core/XdmfArray.cpp | 140 +++++++------- core/XdmfArray.hpp | 2 +- core/XdmfArrayType.cpp | 87 ++++----- core/XdmfCoreReader.cpp | 55 +++--- core/XdmfHeavyDataController.cpp | 2 +- core/XdmfInformation.cpp | 7 +- core/XdmfInformation.hpp | 2 +- core/XdmfItem.cpp | 2 +- core/XdmfItem.hpp | 2 +- core/XdmfWriter.cpp | 16 +- core/tests/Cxx/TestXdmfHDF5Controller.cpp | 1 - utils/XdmfPartitioner.cpp | 2 +- 43 files changed, 450 insertions(+), 421 deletions(-) diff --git a/XdmfAttribute.cpp b/XdmfAttribute.cpp index 30e01512..c7bb5240 100644 --- a/XdmfAttribute.cpp +++ b/XdmfAttribute.cpp @@ -21,6 +21,7 @@ /* */ /*****************************************************************************/ +#include #include "XdmfAttribute.hpp" #include "XdmfAttributeCenter.hpp" #include "XdmfAttributeType.hpp" @@ -56,7 +57,7 @@ std::map XdmfAttribute::getItemProperties() const { std::map attributeProperties; - attributeProperties["Name"] = mName; + attributeProperties.insert(std::make_pair("Name", mName)); mType->getProperties(attributeProperties); mCenter->getProperties(attributeProperties); return attributeProperties; @@ -82,7 +83,7 @@ XdmfAttribute::getType() const void XdmfAttribute::populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader) { XdmfItem::populateItem(itemProperties, childItems, reader); @@ -93,7 +94,9 @@ XdmfAttribute::populateItem(const std::map & itemPrope mName = name->second; } else { - XdmfError::message(XdmfError::FATAL,"'Name' not found in itemProperties in XdmfAttribute::populateItem"); + XdmfError::message(XdmfError::FATAL, + "'Name' not found in itemProperties in " + "XdmfAttribute::populateItem"); } mCenter = XdmfAttributeCenter::New(itemProperties); @@ -104,8 +107,8 @@ XdmfAttribute::populateItem(const std::map & itemPrope ++iter) { if(shared_ptr array = shared_dynamic_cast(*iter)) { this->swap(array); + break; } - // TODO: If multiple dataitems. } } diff --git a/XdmfAttribute.hpp b/XdmfAttribute.hpp index e9713145..761b878b 100644 --- a/XdmfAttribute.hpp +++ b/XdmfAttribute.hpp @@ -109,7 +109,7 @@ protected: virtual void populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader); private: diff --git a/XdmfAttributeCenter.cpp b/XdmfAttributeCenter.cpp index bb903be1..4740268a 100644 --- a/XdmfAttributeCenter.cpp +++ b/XdmfAttributeCenter.cpp @@ -21,6 +21,7 @@ /* */ /*****************************************************************************/ +#include #include "XdmfAttributeCenter.hpp" #include "XdmfError.hpp" @@ -79,37 +80,38 @@ XdmfAttributeCenter::New(const std::map & itemProperti { std::map::const_iterator center = itemProperties.find("Center"); - if(center != itemProperties.end()) { - const std::string centerVal = center->second; - if(centerVal.compare("Grid") == 0) { - return Grid(); - } - else if(centerVal.compare("Cell") == 0) { - return Cell(); - } - else if(centerVal.compare("Face") == 0) { - return Face(); - } - else if(centerVal.compare("Edge") == 0) { - return Edge(); - } - else if(centerVal.compare("Node") == 0) { - return Node(); - } - else { - XdmfError::message(XdmfError::FATAL, - "Center not of 'Grid','Cell','Face','Edge','Node' " - "in XdmfAttributeCenter::New"); - } + if(center == itemProperties.end()) { + XdmfError::message(XdmfError::FATAL, + "'Center' not found in itemProperties in " + "XdmfAttributeCenter::New"); } + const std::string & centerVal = center->second; + + if(centerVal.compare("Node") == 0) { + return Node(); + } + else if(centerVal.compare("Cell") == 0) { + return Cell(); + } + else if(centerVal.compare("Grid") == 0) { + return Grid(); + } + else if(centerVal.compare("Face") == 0) { + return Face(); + } + else if(centerVal.compare("Edge") == 0) { + return Edge(); + } + XdmfError::message(XdmfError::FATAL, - "'Center' not found in itemProperties in " - "XdmfAttributeCenter::New"); + "Center not of 'Grid','Cell','Face','Edge','Node' " + "in XdmfAttributeCenter::New"); + return shared_ptr(); } void XdmfAttributeCenter::getProperties(std::map & collectedProperties) const { - collectedProperties["Center"] = mName; + collectedProperties.insert(std::make_pair("Center", mName)); } diff --git a/XdmfAttributeType.cpp b/XdmfAttributeType.cpp index 9fcdf35d..14bb687e 100644 --- a/XdmfAttributeType.cpp +++ b/XdmfAttributeType.cpp @@ -21,6 +21,7 @@ /* */ /*****************************************************************************/ +#include #include "XdmfAttributeType.hpp" #include "XdmfError.hpp" @@ -98,44 +99,45 @@ XdmfAttributeType::New(const std::map & itemProperties if(type == itemProperties.end()) { type = itemProperties.find("AttributeType"); } - if(type != itemProperties.end()) { - const std::string typeVal = type->second; - if(typeVal.compare("None") == 0) { - return NoAttributeType(); - } - else if(typeVal.compare("Scalar") == 0) { - return Scalar(); - } - else if(typeVal.compare("Vector") == 0) { - return Vector(); - } - else if(typeVal.compare("Tensor") == 0) { - return Tensor(); - } - else if(typeVal.compare("Matrix") == 0) { - return Matrix(); - } - else if(typeVal.compare("Tensor6") == 0) { - return Tensor6(); - } - else if(typeVal.compare("GlobalId") == 0) { - return GlobalId(); - } - else { - XdmfError::message(XdmfError::FATAL, - "Type not of 'None','Scalar','Vector','Tensor', " - "'Matrix','Tensor6', or 'GlobalId' in " - "XdmfAttributeType::New"); - } + if(type == itemProperties.end()) { + XdmfError::message(XdmfError::FATAL, + "Neither 'Type' nor 'AttributeType' found in " + "itemProperties in XdmfAttributeType::New"); + } + const std::string & typeVal = type->second; + + if(typeVal.compare("Scalar") == 0) { + return Scalar(); + } + else if(typeVal.compare("Vector") == 0) { + return Vector(); + } + else if(typeVal.compare("Tensor") == 0) { + return Tensor(); + } + else if(typeVal.compare("Matrix") == 0) { + return Matrix(); } + else if(typeVal.compare("Tensor6") == 0) { + return Tensor6(); + } + else if(typeVal.compare("GlobalId") == 0) { + return GlobalId(); + } + else if(typeVal.compare("None") == 0) { + return NoAttributeType(); + } + XdmfError::message(XdmfError::FATAL, - "Neither 'Type' nor 'AttributeType' found in " - "itemProperties in XdmfAttributeType::New"); + "Type not of 'None','Scalar','Vector','Tensor', " + "'Matrix','Tensor6', or 'GlobalId' in " + "XdmfAttributeType::New"); + return shared_ptr(); } void XdmfAttributeType::getProperties(std::map & collectedProperties) const { - collectedProperties["Type"] = mName; + collectedProperties.insert(std::make_pair("Type", mName)); } diff --git a/XdmfCurvilinearGrid.cpp b/XdmfCurvilinearGrid.cpp index 1e7b572e..00e37a49 100644 --- a/XdmfCurvilinearGrid.cpp +++ b/XdmfCurvilinearGrid.cpp @@ -244,7 +244,7 @@ XdmfCurvilinearGrid::getGeometry() void XdmfCurvilinearGrid::populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader) { XdmfGrid::populateItem(itemProperties, childItems, reader); diff --git a/XdmfCurvilinearGrid.hpp b/XdmfCurvilinearGrid.hpp index 716b5545..dc4fb729 100644 --- a/XdmfCurvilinearGrid.hpp +++ b/XdmfCurvilinearGrid.hpp @@ -131,7 +131,7 @@ protected: void populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader); private: diff --git a/XdmfDomain.cpp b/XdmfDomain.cpp index a6f61c23..d3af2cba 100644 --- a/XdmfDomain.cpp +++ b/XdmfDomain.cpp @@ -81,7 +81,7 @@ XdmfDomain::getItemTag() const void XdmfDomain::populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader) { XdmfItem::populateItem(itemProperties, childItems, reader); diff --git a/XdmfDomain.hpp b/XdmfDomain.hpp index e08de7de..758cad83 100644 --- a/XdmfDomain.hpp +++ b/XdmfDomain.hpp @@ -76,7 +76,7 @@ protected: XdmfDomain(); virtual void populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader); private: diff --git a/XdmfGeometry.cpp b/XdmfGeometry.cpp index cefcc3c6..e3e10f74 100644 --- a/XdmfGeometry.cpp +++ b/XdmfGeometry.cpp @@ -73,7 +73,7 @@ XdmfGeometry::getType() const void XdmfGeometry::populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader) { XdmfItem::populateItem(itemProperties, childItems, reader); @@ -84,8 +84,8 @@ XdmfGeometry::populateItem(const std::map & itemProper ++iter) { if(shared_ptr array = shared_dynamic_cast(*iter)) { this->swap(array); + break; } - // TODO: If multiple dataitems. } } diff --git a/XdmfGeometry.hpp b/XdmfGeometry.hpp index b3d73afb..2bf69c02 100644 --- a/XdmfGeometry.hpp +++ b/XdmfGeometry.hpp @@ -84,7 +84,7 @@ protected: virtual void populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader); private: diff --git a/XdmfGeometryType.cpp b/XdmfGeometryType.cpp index 4df4f48d..df4677a2 100644 --- a/XdmfGeometryType.cpp +++ b/XdmfGeometryType.cpp @@ -21,6 +21,7 @@ /* */ /*****************************************************************************/ +#include #include "XdmfGeometryType.hpp" #include "XdmfError.hpp" @@ -65,26 +66,26 @@ XdmfGeometryType::New(const std::map & itemProperties) if(type == itemProperties.end()) { type = itemProperties.find("GeometryType"); } + if(type == itemProperties.end()) { + XdmfError::message(XdmfError::FATAL, + "Neither 'Type' nor 'GeometryType' in itemProperties " + "in XdmfGeometryType::New"); + } + const std::string & typeVal = type->second; - if(type != itemProperties.end()) { - const std::string typeVal = type->second; - if(typeVal.compare("None") == 0) { - return NoGeometryType(); - } - else if(typeVal.compare("XYZ") == 0) { - return XYZ(); - } - else if(typeVal.compare("XY") == 0) { - return XY(); - } - else { - XdmfError::message(XdmfError::FATAL, "Type not 'None', 'XYZ', or 'XY' " - "in XdmfGeometryType::New"); - } + if(typeVal.compare("None") == 0) { + return NoGeometryType(); + } + else if(typeVal.compare("XYZ") == 0) { + return XYZ(); } - XdmfError::message(XdmfError::FATAL, - "Neither 'Type' nor 'GeometryType' in itemProperties in " - "XdmfGeometryType::New"); + else if(typeVal.compare("XY") == 0) { + return XY(); + } + + XdmfError::message(XdmfError::FATAL, "Type not 'None', 'XYZ', or 'XY' " + "in XdmfGeometryType::New"); + return shared_ptr(); } @@ -103,5 +104,5 @@ XdmfGeometryType::getName() const void XdmfGeometryType::getProperties(std::map & collectedProperties) const { - collectedProperties["Type"] = mName; + collectedProperties.insert(std::make_pair("Type", mName)); } diff --git a/XdmfGrid.cpp b/XdmfGrid.cpp index c4a0f276..1f5a2d5e 100644 --- a/XdmfGrid.cpp +++ b/XdmfGrid.cpp @@ -21,6 +21,7 @@ /* */ /*****************************************************************************/ +#include #include "XdmfAttribute.hpp" #include "XdmfGeometry.hpp" #include "XdmfGrid.hpp" @@ -59,7 +60,7 @@ std::map XdmfGrid::getItemProperties() const { std::map gridProperties; - gridProperties["Name"] = mName; + gridProperties.insert(std::make_pair("Name", mName)); return gridProperties; } @@ -96,7 +97,7 @@ XdmfGrid::getTopology() const void XdmfGrid::populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader) { XdmfItem::populateItem(itemProperties, childItems, reader); diff --git a/XdmfGrid.hpp b/XdmfGrid.hpp index 613aabde..67f372ff 100644 --- a/XdmfGrid.hpp +++ b/XdmfGrid.hpp @@ -130,7 +130,7 @@ protected: virtual void populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader); shared_ptr mGeometry; diff --git a/XdmfGridCollection.cpp b/XdmfGridCollection.cpp index a7970580..92bac104 100644 --- a/XdmfGridCollection.cpp +++ b/XdmfGridCollection.cpp @@ -21,6 +21,7 @@ /* */ /*****************************************************************************/ +#include #include "XdmfGeometry.hpp" #include "XdmfTopology.hpp" #include "XdmfGridCollection.hpp" @@ -51,7 +52,7 @@ XdmfGridCollection::getItemProperties() const { std::map collectionProperties = XdmfGrid::getItemProperties(); - collectionProperties["GridType"] = "Collection"; + collectionProperties.insert(std::make_pair("GridType", "Collection")); mType->getProperties(collectionProperties); return collectionProperties; } @@ -76,7 +77,7 @@ XdmfGridCollection::insert(const shared_ptr information) void XdmfGridCollection::populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader) { mType = XdmfGridCollectionType::New(itemProperties); diff --git a/XdmfGridCollection.hpp b/XdmfGridCollection.hpp index b2a945ce..d6af6d41 100644 --- a/XdmfGridCollection.hpp +++ b/XdmfGridCollection.hpp @@ -97,7 +97,7 @@ protected: virtual void populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader); private: diff --git a/XdmfGridCollectionType.cpp b/XdmfGridCollectionType.cpp index 3053b73f..aee619c7 100644 --- a/XdmfGridCollectionType.cpp +++ b/XdmfGridCollectionType.cpp @@ -21,8 +21,9 @@ /* */ /*****************************************************************************/ -#include "XdmfGridCollectionType.hpp" +#include #include "XdmfError.hpp" +#include "XdmfGridCollectionType.hpp" // Supported XdmfGridCollectionTypes shared_ptr @@ -63,31 +64,32 @@ XdmfGridCollectionType::New(const std::map & itemPrope { std::map::const_iterator type = itemProperties.find("CollectionType"); - if(type != itemProperties.end()) { - const std::string typeVal = type->second; - if(typeVal.compare("None") == 0) { - return NoCollectionType(); - } - else if(typeVal.compare("Spatial") == 0) { - return Spatial(); - } - else if(typeVal.compare("Temporal") == 0) { - return Temporal(); - } - else { - XdmfError::message(XdmfError::FATAL, - "'CollectionType' not of 'None', 'Spatial', or " - "'Temporal' in XdmfGridCollectionType::New"); - } + if(type == itemProperties.end()) { + XdmfError::message(XdmfError::FATAL, + "'CollectionType' not in itemProperties in " + "XdmfGridCollectionType::New"); + } + + const std::string & typeVal = type->second; + if(typeVal.compare("None") == 0) { + return NoCollectionType(); } + else if(typeVal.compare("Spatial") == 0) { + return Spatial(); + } + else if(typeVal.compare("Temporal") == 0) { + return Temporal(); + } + XdmfError::message(XdmfError::FATAL, - "'CollectionType' not in itemProperties in " - "XdmfGridCollectionType::New"); + "'CollectionType' not of 'None', 'Spatial', or " + "'Temporal' in XdmfGridCollectionType::New"); + return shared_ptr(); } void XdmfGridCollectionType::getProperties(std::map & collectedProperties) const { - collectedProperties["CollectionType"] = mName; + collectedProperties.insert(std::make_pair("CollectionType", mName)); } diff --git a/XdmfItemFactory.cpp b/XdmfItemFactory.cpp index b0a7ff8c..f2d572ed 100644 --- a/XdmfItemFactory.cpp +++ b/XdmfItemFactory.cpp @@ -80,13 +80,11 @@ XdmfItemFactory::createItem(const std::string & itemTag, } if(type != itemProperties.end()) { - const std::string typeVal = type->second; + const std::string & typeVal = type->second; if(typeVal.compare("ORIGIN_DXDY") == 0 || typeVal.compare("ORIGIN_DXDYDZ") == 0) { - shared_ptr origin = - shared_ptr(); - shared_ptr brickSize = - shared_ptr(); + shared_ptr origin = shared_ptr(); + shared_ptr brickSize = shared_ptr(); for(std::vector >::const_iterator iter = childItems.begin(); iter != childItems.end(); diff --git a/XdmfMap.cpp b/XdmfMap.cpp index a81c1841..dca20351 100644 --- a/XdmfMap.cpp +++ b/XdmfMap.cpp @@ -21,6 +21,7 @@ /* */ /*****************************************************************************/ +#include #include "XdmfAttribute.hpp" #include "XdmfError.hpp" #include "XdmfGridCollection.hpp" @@ -93,7 +94,7 @@ std::map XdmfMap::getItemProperties() const { std::map mapProperties; - mapProperties["Name"] = mName; + mapProperties.insert(std::make_pair("Name", mName)); return mapProperties; } @@ -142,7 +143,7 @@ bool XdmfMap::isInitialized() const void XdmfMap::populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader) { XdmfItem::populateItem(itemProperties, childItems, reader); diff --git a/XdmfMap.hpp b/XdmfMap.hpp index 9bc3c75a..6dbc3b44 100644 --- a/XdmfMap.hpp +++ b/XdmfMap.hpp @@ -186,7 +186,7 @@ protected: virtual void populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader); private: diff --git a/XdmfRectilinearGrid.cpp b/XdmfRectilinearGrid.cpp index 97bb0e16..35a5e571 100644 --- a/XdmfRectilinearGrid.cpp +++ b/XdmfRectilinearGrid.cpp @@ -373,7 +373,7 @@ XdmfRectilinearGrid::getDimensions() const void XdmfRectilinearGrid::populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader) { XdmfGrid::populateItem(itemProperties, childItems, reader); diff --git a/XdmfRectilinearGrid.hpp b/XdmfRectilinearGrid.hpp index 6cbb91d2..0f16769e 100644 --- a/XdmfRectilinearGrid.hpp +++ b/XdmfRectilinearGrid.hpp @@ -165,7 +165,7 @@ protected: XdmfRectilinearGrid(const std::vector > & axesCoordinates); void populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader); private: diff --git a/XdmfRegularGrid.cpp b/XdmfRegularGrid.cpp index e2d75188..cbecabc8 100644 --- a/XdmfRegularGrid.cpp +++ b/XdmfRegularGrid.cpp @@ -397,7 +397,7 @@ XdmfRegularGrid::getOrigin() const void XdmfRegularGrid::populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader) { XdmfGrid::populateItem(itemProperties, childItems, reader); diff --git a/XdmfRegularGrid.hpp b/XdmfRegularGrid.hpp index 0f1e6d95..288ba588 100644 --- a/XdmfRegularGrid.hpp +++ b/XdmfRegularGrid.hpp @@ -188,7 +188,7 @@ protected: const shared_ptr origin); void populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader); private: diff --git a/XdmfSet.cpp b/XdmfSet.cpp index 77bb8cfc..81ee9f2b 100644 --- a/XdmfSet.cpp +++ b/XdmfSet.cpp @@ -21,6 +21,7 @@ /* */ /*****************************************************************************/ +#include #include "XdmfAttribute.hpp" #include "XdmfHDF5Controller.hpp" #include "XdmfSet.hpp" @@ -52,7 +53,7 @@ std::map XdmfSet::getItemProperties() const { std::map setProperties; - setProperties["Name"] = mName; + setProperties.insert(std::make_pair("Name", mName)); mType->getProperties(setProperties); return setProperties; } @@ -77,7 +78,7 @@ XdmfSet::getType() const void XdmfSet::populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader) { XdmfItem::populateItem(itemProperties, childItems, reader); diff --git a/XdmfSet.hpp b/XdmfSet.hpp index ab0d3e88..d1ca7025 100644 --- a/XdmfSet.hpp +++ b/XdmfSet.hpp @@ -107,7 +107,7 @@ protected: virtual void populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader); private: diff --git a/XdmfSetType.cpp b/XdmfSetType.cpp index eb5894b0..d19b1198 100644 --- a/XdmfSetType.cpp +++ b/XdmfSetType.cpp @@ -21,6 +21,7 @@ /* */ /*****************************************************************************/ +#include #include "XdmfSetType.hpp" #include "XdmfError.hpp" @@ -77,37 +78,38 @@ XdmfSetType::New(const std::map & itemProperties) if(type == itemProperties.end()) { type = itemProperties.find("SetType"); } - if(type != itemProperties.end()) { - const std::string typeVal = type->second; - if(typeVal.compare("None") == 0) { - return NoSetType(); - } - else if(typeVal.compare("Node") == 0) { - return Node(); - } - else if(typeVal.compare("Cell") == 0) { - return Cell(); - } - else if(typeVal.compare("Face") == 0) { - return Face(); - } - else if(typeVal.compare("Edge") == 0) { - return Edge(); - } - else { - XdmfError::message(XdmfError::FATAL, - "Type not of 'None', 'Node', 'Cell', 'Face', or " - "'Edge' in XdmfSetType::New"); - } + if(type == itemProperties.end()) { + XdmfError::message(XdmfError::FATAL, + "Neither 'Type' nor 'SetType' found in itemProperties " + "in XdmfSetType::New"); + } + const std::string & typeVal = type->second; + + if(typeVal.compare("Node") == 0) { + return Node(); + } + else if(typeVal.compare("Cell") == 0) { + return Cell(); + } + else if(typeVal.compare("Face") == 0) { + return Face(); } + else if(typeVal.compare("Edge") == 0) { + return Edge(); + } + else if(typeVal.compare("None") == 0) { + return NoSetType(); + } + XdmfError::message(XdmfError::FATAL, - "Neither 'Type' nor 'SetType' found in itemProperties " - "in XdmfSetType::New"); + "Type not of 'None', 'Node', 'Cell', 'Face', or " + "'Edge' in XdmfSetType::New"); + return shared_ptr(); } void XdmfSetType::getProperties(std::map & collectedProperties) const { - collectedProperties["Type"] = this->mName; + collectedProperties.insert(std::make_pair("Type", mName)); } diff --git a/XdmfTime.cpp b/XdmfTime.cpp index 42243a1f..3a3da402 100644 --- a/XdmfTime.cpp +++ b/XdmfTime.cpp @@ -22,6 +22,7 @@ /*****************************************************************************/ #include +#include #include "XdmfTime.hpp" #include "XdmfError.hpp" @@ -49,7 +50,7 @@ XdmfTime::getItemProperties() const std::map timeProperties; std::stringstream value; value << mValue; - timeProperties["Value"] = value.str(); + timeProperties.insert(std::make_pair("Value", value.str())); return timeProperties; } @@ -67,7 +68,7 @@ XdmfTime::getValue() const void XdmfTime::populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader) { XdmfItem::populateItem(itemProperties, childItems, reader); @@ -77,7 +78,9 @@ XdmfTime::populateItem(const std::map & itemProperties mValue = atof(value->second.c_str()); } else { - XdmfError::message(XdmfError::FATAL, "'Value' not in itemProperties in XdmfTime::populateItem"); + XdmfError::message(XdmfError::FATAL, + "'Value' not in itemProperties in " + "XdmfTime::populateItem"); } } diff --git a/XdmfTime.hpp b/XdmfTime.hpp index 9e0058fa..a79faccc 100644 --- a/XdmfTime.hpp +++ b/XdmfTime.hpp @@ -74,7 +74,7 @@ protected: virtual void populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader); private: diff --git a/XdmfTopology.cpp b/XdmfTopology.cpp index d413349e..4ba5e65b 100644 --- a/XdmfTopology.cpp +++ b/XdmfTopology.cpp @@ -22,6 +22,7 @@ /*****************************************************************************/ #include +#include #include "XdmfError.hpp" #include "XdmfTopology.hpp" #include "XdmfTopologyType.hpp" @@ -58,7 +59,7 @@ XdmfTopology::getItemProperties() const if(mType->getCellType() != XdmfTopologyType::Structured) { std::stringstream numElements; numElements << this->getNumberElements(); - topologyProperties["Dimensions"] = numElements.str(); + topologyProperties.insert(std::make_pair("Dimensions", numElements.str())); } return topologyProperties; } @@ -116,7 +117,7 @@ XdmfTopology::getType() const void XdmfTopology::populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader) { XdmfItem::populateItem(itemProperties, childItems, reader); diff --git a/XdmfTopology.hpp b/XdmfTopology.hpp index d6c156ed..b970b8a2 100644 --- a/XdmfTopology.hpp +++ b/XdmfTopology.hpp @@ -99,7 +99,7 @@ protected: virtual void populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader); private: diff --git a/XdmfTopologyType.cpp b/XdmfTopologyType.cpp index bacd26bc..e9b7c034 100644 --- a/XdmfTopologyType.cpp +++ b/XdmfTopologyType.cpp @@ -23,6 +23,7 @@ #include #include +#include #include "XdmfError.hpp" #include "XdmfTopologyType.hpp" @@ -413,117 +414,118 @@ XdmfTopologyType::New(const std::map & itemProperties) if(type == itemProperties.end()) { type = itemProperties.find("TopologyType"); } + if(type == itemProperties.end()) { + XdmfError::message(XdmfError::FATAL, + "Neither 'Type' nor 'TopologyType' found in " + "itemProperties in XdmfTopologyType::New"); + } + std::string typeVal = type->second; + std::transform(typeVal.begin(), + typeVal.end(), + typeVal.begin(), + (int(*)(int))toupper); std::map::const_iterator nodesPerElement = itemProperties.find("NodesPerElement"); - if(type != itemProperties.end()) { - std::string typeVal = type->second; - std::transform(typeVal.begin(), - typeVal.end(), - typeVal.begin(), - (int(*)(int))toupper); - if(typeVal.compare("NOTOPOLOGY") == 0) { - return NoTopologyType(); - } - else if(typeVal.compare("POLYVERTEX") == 0) { - return Polyvertex(); - } - else if(typeVal.compare("POLYLINE") == 0) { - if(nodesPerElement != itemProperties.end()) { - return Polyline(atoi(nodesPerElement->second.c_str())); - } - XdmfError::message(XdmfError::FATAL, - "'NodesPerElement' not in itemProperties and type " - "'POLYLINE' selected in XdmfTopologyType::New"); + + if(typeVal.compare("NOTOPOLOGY") == 0) { + return NoTopologyType(); + } + else if(typeVal.compare("POLYVERTEX") == 0) { + return Polyvertex(); + } + else if(typeVal.compare("POLYLINE") == 0) { + if(nodesPerElement != itemProperties.end()) { + return Polyline(atoi(nodesPerElement->second.c_str())); } - else if(typeVal.compare("POLYGON") == 0) { - if(nodesPerElement != itemProperties.end()) { - return Polygon(atoi(nodesPerElement->second.c_str())); - } - XdmfError::message(XdmfError::FATAL, + XdmfError::message(XdmfError::FATAL, "'NodesPerElement' not in itemProperties and type " - "'POLYGON' selected in XdmfTopologyType::New"); - } - else if(typeVal.compare("TRIANGLE") == 0) { - return Triangle(); - } - else if(typeVal.compare("QUADRILATERAL") == 0) { - return Quadrilateral(); - } - else if(typeVal.compare("TETRAHEDRON") == 0) { - return Tetrahedron(); - } - else if(typeVal.compare("PYRAMID") == 0) { - return Pyramid(); - } - else if(typeVal.compare("WEDGE") == 0) { - return Wedge(); - } - else if(typeVal.compare("HEXAHEDRON") == 0) { - return Hexahedron(); - } - else if(typeVal.compare("EDGE_3") == 0) { - return Edge_3(); - } - else if(typeVal.compare("TRIANGLE_6") == 0) { - return Triangle_6(); - } - else if(typeVal.compare("QUADRILATERAL_8") == 0) { - return Quadrilateral_8(); - } - else if(typeVal.compare("TETRAHEDRON_10") == 0) { - return Tetrahedron_10(); - } - else if(typeVal.compare("PYRAMID_13") == 0) { - return Pyramid_13(); - } - else if(typeVal.compare("WEDGE_15") == 0) { - return Wedge_15(); - } - else if(typeVal.compare("HEXAHEDRON_20") == 0) { - return Hexahedron_20(); - } - else if(typeVal.compare("HEXAHEDRON_24") == 0) { - return Hexahedron_24(); - } - else if(typeVal.compare("HEXAHEDRON_27") == 0) { - return Hexahedron_27(); - } - else if(typeVal.compare("HEXAHEDRON_64") == 0) { - return Hexahedron_64(); - } - else if(typeVal.compare("HEXAHEDRON_125") == 0) { - return Hexahedron_125(); - } - else if(typeVal.compare("HEXAHEDRON_216") == 0) { - return Hexahedron_216(); - } - else if(typeVal.compare("HEXAHEDRON_343") == 0) { - return Hexahedron_343(); - } - else if(typeVal.compare("HEXAHEDRON_512") == 0) { - return Hexahedron_512(); - } - else if(typeVal.compare("HEXAHEDRON_729") == 0) { - return Hexahedron_729(); - } - else if(typeVal.compare("HEXAHEDRON_1000") == 0) { - return Hexahedron_1000(); - } - else if(typeVal.compare("HEXAHEDRON_1331") == 0) { - return Hexahedron_1331(); - } - else if(typeVal.compare("MIXED") == 0) { - return Mixed(); - } - else { - XdmfError::message(XdmfError::FATAL, - "Invalid Type selected in XdmfTopologyType::New"); + "'POLYLINE' selected in XdmfTopologyType::New"); + } + else if(typeVal.compare("POLYGON") == 0) { + if(nodesPerElement != itemProperties.end()) { + return Polygon(atoi(nodesPerElement->second.c_str())); } + XdmfError::message(XdmfError::FATAL, + "'NodesPerElement' not in itemProperties and type " + "'POLYGON' selected in XdmfTopologyType::New"); + } + else if(typeVal.compare("TRIANGLE") == 0) { + return Triangle(); + } + else if(typeVal.compare("QUADRILATERAL") == 0) { + return Quadrilateral(); + } + else if(typeVal.compare("TETRAHEDRON") == 0) { + return Tetrahedron(); + } + else if(typeVal.compare("PYRAMID") == 0) { + return Pyramid(); + } + else if(typeVal.compare("WEDGE") == 0) { + return Wedge(); + } + else if(typeVal.compare("HEXAHEDRON") == 0) { + return Hexahedron(); + } + else if(typeVal.compare("EDGE_3") == 0) { + return Edge_3(); + } + else if(typeVal.compare("TRIANGLE_6") == 0) { + return Triangle_6(); + } + else if(typeVal.compare("QUADRILATERAL_8") == 0) { + return Quadrilateral_8(); + } + else if(typeVal.compare("TETRAHEDRON_10") == 0) { + return Tetrahedron_10(); + } + else if(typeVal.compare("PYRAMID_13") == 0) { + return Pyramid_13(); } + else if(typeVal.compare("WEDGE_15") == 0) { + return Wedge_15(); + } + else if(typeVal.compare("HEXAHEDRON_20") == 0) { + return Hexahedron_20(); + } + else if(typeVal.compare("HEXAHEDRON_24") == 0) { + return Hexahedron_24(); + } + else if(typeVal.compare("HEXAHEDRON_27") == 0) { + return Hexahedron_27(); + } + else if(typeVal.compare("HEXAHEDRON_64") == 0) { + return Hexahedron_64(); + } + else if(typeVal.compare("HEXAHEDRON_125") == 0) { + return Hexahedron_125(); + } + else if(typeVal.compare("HEXAHEDRON_216") == 0) { + return Hexahedron_216(); + } + else if(typeVal.compare("HEXAHEDRON_343") == 0) { + return Hexahedron_343(); + } + else if(typeVal.compare("HEXAHEDRON_512") == 0) { + return Hexahedron_512(); + } + else if(typeVal.compare("HEXAHEDRON_729") == 0) { + return Hexahedron_729(); + } + else if(typeVal.compare("HEXAHEDRON_1000") == 0) { + return Hexahedron_1000(); + } + else if(typeVal.compare("HEXAHEDRON_1331") == 0) { + return Hexahedron_1331(); + } + else if(typeVal.compare("MIXED") == 0) { + return Mixed(); + } + XdmfError::message(XdmfError::FATAL, - "Neither 'Type' nor 'TopologyType' found in " - "itemProperties in XdmfTopologyType::New"); + "Invalid Type selected in XdmfTopologyType::New"); + return shared_ptr(); } @@ -566,10 +568,11 @@ XdmfTopologyType::getNodesPerElement() const void XdmfTopologyType::getProperties(std::map & collectedProperties) const { - collectedProperties["Type"] = this->getName(); + collectedProperties.insert(std::make_pair("Type", this->getName())); if(mName.compare("Polygon") == 0 || mName.compare("Polyline") == 0) { std::stringstream nodesPerElement; nodesPerElement << mNodesPerElement; - collectedProperties["NodesPerElement"] = nodesPerElement.str(); + collectedProperties.insert(std::make_pair("NodesPerElement", + nodesPerElement.str())); } } diff --git a/core/XdmfArray.cpp b/core/XdmfArray.cpp index 90139286..7712e156 100644 --- a/core/XdmfArray.cpp +++ b/core/XdmfArray.cpp @@ -23,11 +23,11 @@ #include #include +#include #include "XdmfArray.hpp" #include "XdmfArrayType.hpp" #include "XdmfHDF5Controller.hpp" #include "XdmfHeavyDataController.hpp" -#include "XdmfSystemUtils.hpp" #include "XdmfVisitor.hpp" #include "XdmfError.hpp" @@ -575,7 +575,7 @@ XdmfArray::getDimensions() const std::string XdmfArray::getDimensionsString() const { - const std::vector & dimensions = this->getDimensions(); + const std::vector dimensions = this->getDimensions(); return GetValuesString(dimensions.size()).getValuesString(&dimensions[0], dimensions.size()); } @@ -598,14 +598,16 @@ XdmfArray::getItemProperties() const { std::map arrayProperties; if(mHeavyDataController) { - arrayProperties["Format"] = mHeavyDataController->getName(); + arrayProperties.insert(std::make_pair("Format", + mHeavyDataController->getName())); } else { - arrayProperties["Format"] = "XML"; + arrayProperties.insert(std::make_pair("Format", "XML")); } - arrayProperties["Dimensions"] = this->getDimensionsString(); + arrayProperties.insert(std::make_pair("Dimensions", + this->getDimensionsString())); if(mName.compare("") != 0) { - arrayProperties["Name"] = mName; + arrayProperties.insert(std::make_pair("Name", mName)); } shared_ptr type = this->getArrayType(); type->getProperties(arrayProperties); @@ -744,46 +746,64 @@ XdmfArray::internalizeArrayPointer() void XdmfArray::populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader) { XdmfItem::populateItem(itemProperties, childItems, reader); - std::string contentVal; const shared_ptr arrayType = XdmfArrayType::New(itemProperties); std::map::const_iterator content = itemProperties.find("Content"); - if(content != itemProperties.end()) { - contentVal = content->second; - } - else { + if(content == itemProperties.end()) { XdmfError::message(XdmfError::FATAL, "'Content' not found in itemProperties in " "XdmfArray::populateItem"); } + const std::string & contentVal = content->second; std::map::const_iterator dimensions = itemProperties.find("Dimensions"); - if(dimensions != itemProperties.end()) { - boost::tokenizer<> tokens(dimensions->second); - for(boost::tokenizer<>::const_iterator iter = tokens.begin(); - iter != tokens.end(); - ++iter) { - mDimensions.push_back(atoi((*iter).c_str())); - } - } - else { + if(dimensions == itemProperties.end()) { XdmfError::message(XdmfError::FATAL, "'Dimensions' not found in itemProperties in " "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())); + } std::map::const_iterator format = itemProperties.find("Format"); - if(format != itemProperties.end()) { - if(format->second.compare("HDF") == 0) { + if(format == itemProperties.end()) { + XdmfError::message(XdmfError::FATAL, + "'Format' not found in itemProperties in " + "XdmfArray::populateItem"); + } + const std::string & formatVal = format->second; + + if(formatVal.compare("HDF") == 0) { + size_t colonLocation = contentVal.find(":"); + if(colonLocation == std::string::npos) { + XdmfError::message(XdmfError::FATAL, + "':' not found in content in " + "XdmfArray::populateItem -- double check an HDF5 " + "data set is specified for the file"); + } + + std::string hdf5Path = contentVal.substr(0, colonLocation); + const std::string dataSetPath = + contentVal.substr(colonLocation + 1, + contentVal.size() - colonLocation - 1); + + // FIXME: for other OS (e.g. windows) + if(hdf5Path.size() > 0 && hdf5Path[0] != '/') { + // Dealing with a relative path for hdf5 location std::map::const_iterator xmlDir = itemProperties.find("XMLDir"); if(xmlDir == itemProperties.end()) { @@ -791,58 +811,38 @@ XdmfArray::populateItem(const std::map & itemPropertie "'XMLDir' not found in itemProperties in " "XdmfArray::populateItem"); } - size_t colonLocation = contentVal.find(":"); - if(colonLocation != std::string::npos) { - std::string hdf5Path = contentVal.substr(0, colonLocation); - std::string dataSetPath = - contentVal.substr(colonLocation + 1, - contentVal.size() - colonLocation - 1); - if(hdf5Path.compare(XdmfSystemUtils::getRealPath(hdf5Path)) != 0) { - // Dealing with a relative path for hdf5 location - std::stringstream newHDF5Path; - newHDF5Path << xmlDir->second << hdf5Path; - hdf5Path = newHDF5Path.str(); - } - mHeavyDataController = - XdmfHDF5Controller::New(hdf5Path, - dataSetPath, - arrayType, - std::vector(mDimensions.size(), - 0), - std::vector(mDimensions.size(), - 1), - mDimensions); - } - else { - XdmfError::message(XdmfError::FATAL, - "':' not found in content in " - "XdmfArray::populateItem -- double check an HDF5 " - "data set is specified for the file"); - } - } - else if(format->second.compare("XML") == 0) { - this->initialize(arrayType, - mDimensions); - unsigned int index = 0; - boost::char_separator sep(" \t\n"); - boost::tokenizer > tokens(contentVal, sep); - for(boost::tokenizer >::const_iterator - iter = tokens.begin(); - iter != tokens.end(); - ++iter, ++index) { - this->insert(index, atof((*iter).c_str())); - } + + std::stringstream newHDF5Path; + newHDF5Path << xmlDir->second << hdf5Path; + hdf5Path = newHDF5Path.str(); } - else { - XdmfError::message(XdmfError::FATAL, - "Neither 'HDF' nor 'XML' specified as 'Format' " - "in XdmfArray::populateItem"); + mHeavyDataController = + XdmfHDF5Controller::New(hdf5Path, + dataSetPath, + arrayType, + std::vector(mDimensions.size(), + 0), + std::vector(mDimensions.size(), + 1), + mDimensions); + } + else if(formatVal.compare("XML") == 0) { + this->initialize(arrayType, + mDimensions); + unsigned int index = 0; + boost::char_separator sep(" \t\n"); + boost::tokenizer > tokens(contentVal, sep); + for(boost::tokenizer >::const_iterator + iter = tokens.begin(); + iter != tokens.end(); + ++iter, ++index) { + this->insert(index, atof((*iter).c_str())); } } else { XdmfError::message(XdmfError::FATAL, - "'Format' not found in itemProperties in " - "XdmfArray::populateItem"); + "Neither 'HDF' nor 'XML' specified as 'Format' " + "in XdmfArray::populateItem"); } std::map::const_iterator name = diff --git a/core/XdmfArray.hpp b/core/XdmfArray.hpp index ed75aebb..e7ecddb8 100644 --- a/core/XdmfArray.hpp +++ b/core/XdmfArray.hpp @@ -480,7 +480,7 @@ protected: virtual void populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader); private: diff --git a/core/XdmfArrayType.cpp b/core/XdmfArrayType.cpp index 22b661c8..e717a9e5 100644 --- a/core/XdmfArrayType.cpp +++ b/core/XdmfArrayType.cpp @@ -22,6 +22,7 @@ /*****************************************************************************/ #include +#include #include "XdmfArrayType.hpp" #include "XdmfError.hpp" @@ -115,54 +116,54 @@ XdmfArrayType::New(const std::map & itemProperties) if(type == itemProperties.end()) { type = itemProperties.find("NumberType"); } + if(type == itemProperties.end()) { + XdmfError::message(XdmfError::FATAL, + "Type unset because neither 'DataType' nor " + "'NumberType' found in itemProperties in " + "XdmfArrayType::New"); + } + const std::string & typeVal = type->second; + std::map::const_iterator precision = itemProperties.find("Precision"); - if(type != itemProperties.end()) { - const std::string typeVal = type->second; - unsigned int precisionVal = 0; - if(precision != itemProperties.end()) { - precisionVal = atoi(precision->second.c_str()); - } - if(typeVal.compare("None") == 0) { - return Uninitialized(); - } - else if(typeVal.compare("Char") == 0) { - return Int8(); - } - else if(typeVal.compare("Short") == 0) { - return Int16(); - } - else if(typeVal.compare("Int") == 0 && precisionVal == 8) { - return Int64(); - } - else if(typeVal.compare("Int") == 0) { - return Int32(); - } - else if(typeVal.compare("Float") == 0 && precisionVal == 8) { + const unsigned int precisionVal = + (precision == itemProperties.end()) ? 0 : atoi(precision->second.c_str()); + + if(typeVal.compare("Float") == 0) { + if(precisionVal == 8) { return Float64(); } - else if(typeVal.compare("Float") == 0) { - return Float32(); - } - else if(typeVal.compare("UChar") == 0) { - return UInt8(); - } - else if(typeVal.compare("UShort") == 0) { - return UInt16(); - } - else if(typeVal.compare("UInt") == 0) { - return UInt32(); - } - else { - XdmfError::message(XdmfError::FATAL, - "Type not one of accepted values: " + typeVal + - " in XdmfArrayType::New"); + return Float32(); + } + else if(typeVal.compare("Int") == 0) { + if(precisionVal == 8) { + return Int64(); } + return Int32(); + } + else if(typeVal.compare("Char") == 0) { + return Int8(); + } + else if(typeVal.compare("Short") == 0) { + return Int16(); } + else if(typeVal.compare("UChar") == 0) { + return UInt8(); + } + else if(typeVal.compare("UShort") == 0) { + return UInt16(); + } + else if(typeVal.compare("UInt") == 0) { + return UInt32(); + } + else if(typeVal.compare("None") == 0) { + return Uninitialized(); + } + XdmfError::message(XdmfError::FATAL, - "Type unset because neither 'DataType' nor " - "'NumberType' found in itemProperties in " - "XdmfArrayType::New"); + "Type not one of accepted values: " + typeVal + + " in XdmfArrayType::New"); + return shared_ptr(); } @@ -181,8 +182,8 @@ XdmfArrayType::getName() const void XdmfArrayType::getProperties(std::map & collectedProperties) const { - collectedProperties["DataType"] = mName; + collectedProperties.insert(std::make_pair("DataType", mName)); std::stringstream precision; precision << mPrecision; - collectedProperties["Precision"] = precision.str(); + collectedProperties.insert(std::make_pair("Precision", precision.str())); } diff --git a/core/XdmfCoreReader.cpp b/core/XdmfCoreReader.cpp index 78d6553b..e17e42e3 100644 --- a/core/XdmfCoreReader.cpp +++ b/core/XdmfCoreReader.cpp @@ -27,13 +27,13 @@ #include #include #include +#include +#include "XdmfArray.hpp" #include "XdmfCoreItemFactory.hpp" #include "XdmfCoreReader.hpp" +#include "XdmfError.hpp" #include "XdmfItem.hpp" #include "XdmfSystemUtils.hpp" -#include "XdmfError.hpp" - -#include /** * PIMPL @@ -101,6 +101,7 @@ public: " in XdmfCoreReader::XdmfCoreReaderImpl::parse"); } + mDocuments.insert(std::make_pair((char*)mDocument->URL, mDocument)); mXPathContext = xmlXPtrNewContext(mDocument, NULL, NULL); mXPathMap.clear(); } @@ -196,37 +197,40 @@ public: std::map itemProperties; xmlNodePtr childNode = currNode->children; - while(childNode != NULL) { - if(childNode->type == XML_TEXT_NODE && childNode->content) { - const char * content = (char*)childNode->content; - - // determine if content is whitespace - const size_t contentSize = std::strlen(content); - bool whitespace = true; - - for(size_t i=0; iname) == 0) { + while(childNode != NULL) { + if(childNode->type == XML_TEXT_NODE && childNode->content) { + const char * content = (char*)childNode->content; + + // determine if content is whitespace + bool whitespace = true; + + const char * contentPtr = content; + while(contentPtr != NULL) { + if(!isspace(*contentPtr++)) { + whitespace = false; + break; + } + } + + if(!whitespace) { + itemProperties.insert(std::make_pair("Content", content)); + itemProperties.insert(std::make_pair("XMLDir", mXMLDir)); break; } } - - if(!whitespace) { - itemProperties["Content"] = content; - itemProperties["XMLDir"] = mXMLDir; - break; - } + childNode = childNode->next; } - childNode = childNode->next; } + xmlAttrPtr currAttribute = currNode->properties; while(currAttribute != NULL) { - itemProperties[(const char *)currAttribute->name] = - (const char *)currAttribute->children->content; + itemProperties.insert(std::make_pair((char *)currAttribute->name, + (char *)currAttribute->children->content)); currAttribute = currAttribute->next; } - std::vector > childItems = + const std::vector > childItems = this->read(currNode->children); shared_ptr newItem = mItemFactory->createItem((const char *)currNode->name, @@ -240,7 +244,7 @@ public: newItem->populateItem(itemProperties, childItems, mCoreReader); myItems.push_back(newItem); - mXPathMap[currNode] = newItem; + mXPathMap.insert(std::make_pair(currNode, newItem)); } } @@ -262,7 +266,6 @@ public: std::map mDocuments; const XdmfCoreReader * const mCoreReader; const shared_ptr mItemFactory; - const std::string mRootItemTag; std::string mXMLDir; xmlXPathContextPtr mXPathContext; std::map > mXPathMap; diff --git a/core/XdmfHeavyDataController.cpp b/core/XdmfHeavyDataController.cpp index 1e2c48d8..345c5152 100644 --- a/core/XdmfHeavyDataController.cpp +++ b/core/XdmfHeavyDataController.cpp @@ -32,7 +32,7 @@ XdmfHeavyDataController::XdmfHeavyDataController(const std::string & filePath, const std::vector & dimensions) : mDataSetPath(dataSetPath), mDimensions(dimensions), - mFilePath(XdmfSystemUtils::getRealPath(filePath)), + mFilePath(filePath), mType(type) { } diff --git a/core/XdmfInformation.cpp b/core/XdmfInformation.cpp index 424a310c..c4e42151 100644 --- a/core/XdmfInformation.cpp +++ b/core/XdmfInformation.cpp @@ -21,6 +21,7 @@ /* */ /*****************************************************************************/ +#include #include "XdmfArray.hpp" #include "XdmfError.hpp" #include "XdmfInformation.hpp" @@ -59,8 +60,8 @@ std::map XdmfInformation::getItemProperties() const { std::map informationProperties; - informationProperties["Name"] = mKey; - informationProperties["Value"] = mValue; + informationProperties.insert(std::make_pair("Name", mKey)); + informationProperties.insert(std::make_pair("Value", mValue)); return informationProperties; } @@ -84,7 +85,7 @@ XdmfInformation::getValue() const void XdmfInformation::populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader) { XdmfItem::populateItem(itemProperties, childItems, reader); diff --git a/core/XdmfInformation.hpp b/core/XdmfInformation.hpp index dc37476a..eb733baa 100644 --- a/core/XdmfInformation.hpp +++ b/core/XdmfInformation.hpp @@ -111,7 +111,7 @@ protected: virtual void populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader); private: diff --git a/core/XdmfItem.cpp b/core/XdmfItem.cpp index c3b38d4b..6cba7d5d 100644 --- a/core/XdmfItem.cpp +++ b/core/XdmfItem.cpp @@ -36,7 +36,7 @@ XdmfItem::~XdmfItem() void XdmfItem::populateItem(const std::map &, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const) { for(std::vector >::const_iterator iter = diff --git a/core/XdmfItem.hpp b/core/XdmfItem.hpp index 40d4dc0b..0e48dfaf 100644 --- a/core/XdmfItem.hpp +++ b/core/XdmfItem.hpp @@ -239,7 +239,7 @@ protected: */ virtual void populateItem(const std::map & itemProperties, - std::vector > & childItems, + const std::vector > & childItems, const XdmfCoreReader * const reader); private: diff --git a/core/XdmfWriter.cpp b/core/XdmfWriter.cpp index be1fca48..3dafea78 100644 --- a/core/XdmfWriter.cpp +++ b/core/XdmfWriter.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "XdmfArray.hpp" #include "XdmfHeavyDataWriter.hpp" #include "XdmfHDF5Controller.hpp" @@ -259,7 +260,8 @@ XdmfWriter::visit(XdmfArray & array, } mImpl->mDepth++; - bool isSubclassed = array.getItemTag().compare(XdmfArray::ItemTag) != 0; + const bool isSubclassed = + array.getItemTag().compare(XdmfArray::ItemTag) != 0; if(isSubclassed) { this->visit(dynamic_cast(array), visitor); @@ -284,7 +286,7 @@ XdmfWriter::visit(XdmfArray & array, array.getHeavyDataController()->getFilePath(); size_t index = heavyDataPath.find_last_of("/\\"); if(index != std::string::npos) { - std::string heavyDataDir = heavyDataPath.substr(0, index + 1); + const std::string heavyDataDir = heavyDataPath.substr(0, index + 1); if(mImpl->mXMLFilePath.find(heavyDataDir) == 0) { heavyDataPath = heavyDataPath.substr(heavyDataDir.size(), @@ -347,7 +349,7 @@ XdmfWriter::visit(XdmfItem & item, if(mImpl->mWriteXPaths) { mImpl->mXPathCount++; - std::string parentXPathString = mImpl->mXPathString; + const std::string parentXPathString = mImpl->mXPathString; std::stringstream newXPathString; newXPathString << mImpl->mXPathString << "/" << mImpl->mXPathCount; @@ -374,16 +376,18 @@ XdmfWriter::visit(XdmfItem & item, NULL); std::stringstream xPathProp; xPathProp << "element(/1" << mImpl->mXPathString << ")"; - mImpl->mXPath[&item] = xPathProp.str(); + mImpl->mXPath.insert(std::make_pair(&item, xPathProp.str())); const std::map & itemProperties = item.getItemProperties(); for(std::map::const_iterator iter = itemProperties.begin(); iter != itemProperties.end(); ++iter) { - xmlNewProp(mImpl->mXMLCurrentNode, (xmlChar*)iter->first.c_str(), (xmlChar*)iter->second.c_str()); + xmlNewProp(mImpl->mXMLCurrentNode, + (xmlChar*)iter->first.c_str(), + (xmlChar*)iter->second.c_str()); } - unsigned int parentCount = mImpl->mXPathCount; + const unsigned int parentCount = mImpl->mXPathCount; mImpl->mXPathCount = 0; item.traverse(visitor); mImpl->mXPathCount = parentCount; diff --git a/core/tests/Cxx/TestXdmfHDF5Controller.cpp b/core/tests/Cxx/TestXdmfHDF5Controller.cpp index c8773365..46689a84 100644 --- a/core/tests/Cxx/TestXdmfHDF5Controller.cpp +++ b/core/tests/Cxx/TestXdmfHDF5Controller.cpp @@ -13,7 +13,6 @@ int main(int, char **) std::vector(1, 1), std::vector(1, 10)); assert(controller->getDataSetPath().compare("/foo/data1") == 0); - assert(controller->getFilePath().compare(XdmfSystemUtils::getRealPath("output.h5")) == 0); assert(controller->getSize() == 10); assert(controller->getType() == XdmfArrayType::Int8()); diff --git a/utils/XdmfPartitioner.cpp b/utils/XdmfPartitioner.cpp index 8108fe4c..3753a163 100644 --- a/utils/XdmfPartitioner.cpp +++ b/utils/XdmfPartitioner.cpp @@ -868,7 +868,7 @@ int main(int argc, char* argv[]) std::string inputFileName = ""; std::string outputFileName = ""; - unsigned int numPartitions; + unsigned int numPartitions = 0; XdmfPartitioner::MetisScheme metisScheme = XdmfPartitioner::DUAL_GRAPH; bool unpartition = false; -- GitLab