From d7c98ce00e9eb34f1eab0e439613b6d2542168ca Mon Sep 17 00:00:00 2001 From: Nicholas Sharp Date: Wed, 23 Aug 2023 01:35:44 -0400 Subject: [PATCH] reorder duplicate quantity adds to be sequential, rmeove PersistentValue destruct write --- include/polyscope/persistent_value.h | 7 +++--- include/polyscope/structure.h | 3 +-- include/polyscope/structure.ipp | 34 +++++++--------------------- src/curve_network.cpp | 6 +++++ src/point_cloud.cpp | 5 ++++ src/quantity.cpp | 2 +- src/surface_mesh.cpp | 17 ++++++++++++++ src/volume_grid.cpp | 2 ++ src/volume_mesh.cpp | 6 +++++ test/CMakeLists.txt | 1 + 10 files changed, 50 insertions(+), 33 deletions(-) diff --git a/include/polyscope/persistent_value.h b/include/polyscope/persistent_value.h index 222da6ff..96f08b8a 100644 --- a/include/polyscope/persistent_value.h +++ b/include/polyscope/persistent_value.h @@ -54,7 +54,7 @@ class PersistentValue { } // Ensure in cache on deletion (see not above reference conversion) - ~PersistentValue() { set(value); } + ~PersistentValue() {} // Don't want copy or move constructors, only operators PersistentValue(const PersistentValue&) = delete; @@ -82,8 +82,8 @@ class PersistentValue { return *this; } - // NOTE if you write via this reference, the value will not _actually_ be cached until destruction or - // manuallyChanged() is called, rather than immediately (ugly, but seems necessary to use with imgui)... + // NOTE if you write via this reference, the value will not _actually_ be cached until + // manuallyChanged() is called, rather than immediately (ugly, but seems necessary to use with imgui) T& get() { return value; } void manuallyChanged() { set(value); } @@ -107,7 +107,6 @@ class PersistentValue { template friend class PersistentValue; -private: const std::string name; T value; bool holdsDefaultValue = true; // True if the value was set on construction and never changed. False if it was pulled diff --git a/include/polyscope/structure.h b/include/polyscope/structure.h index 8401d4f6..1ea8d5fa 100644 --- a/include/polyscope/structure.h +++ b/include/polyscope/structure.h @@ -183,6 +183,7 @@ class QuantityStructure : public Structure { QuantityType* getQuantity(std::string name); // NOTE: will _not_ return floating quantities, must use other version below FloatingQuantity* getFloatingQuantity(std::string name); + void checkForQuantityWithNameAndDeleteOrError(std::string name, bool allowReplacement = true); void removeQuantity(std::string name, bool errorIfAbsent = false); void removeAllQuantities(); @@ -258,8 +259,6 @@ class QuantityStructure : public Structure { ImageOrigin imageOrigin, DataType type); protected: - // helper - bool checkForQuantityWithNameAndDeleteOrError(std::string name, bool allowReplacement); }; diff --git a/include/polyscope/structure.ipp b/include/polyscope/structure.ipp index 4381563c..5be25445 100644 --- a/include/polyscope/structure.ipp +++ b/include/polyscope/structure.ipp @@ -19,7 +19,7 @@ template QuantityStructure::~QuantityStructure(){}; template -bool QuantityStructure::checkForQuantityWithNameAndDeleteOrError(std::string name, bool allowReplacement) { +void QuantityStructure::checkForQuantityWithNameAndDeleteOrError(std::string name, bool allowReplacement) { // Look for an existing quantity with this name bool quantityExists = quantities.find(name) != quantities.end(); @@ -30,55 +30,32 @@ bool QuantityStructure::checkForQuantityWithNameAndDeleteOrError(std::string exception("Tried to add quantity with name: [" + name + "], but a quantity with that name already exists on the structure [" + name + "]. Use the allowReplacement option like addQuantity(..., true) to replace."); - return false; - } - - // Track if the previous quantity was enabled - // TODO why is isn't this handled by the persistence cache like everything else? - bool existingQuantityWasEnabled = false; - if (quantityExists) { - existingQuantityWasEnabled = quantities.find(name)->second->isEnabled(); - } - if (floatingQuantityExists) { - existingQuantityWasEnabled = floatingQuantities.find(name)->second->isEnabled(); } // Remove the old quantity if (quantityExists || floatingQuantityExists) { removeQuantity(name); } - - return existingQuantityWasEnabled; } template void QuantityStructure::addQuantity(QuantityType* q, bool allowReplacement) { // Check if a quantity with this name exists, remove it or throw and error if so - bool existingQuantityWasEnabled = checkForQuantityWithNameAndDeleteOrError(q->name, allowReplacement); + checkForQuantityWithNameAndDeleteOrError(q->name, allowReplacement); // Add the new quantity quantities[q->name] = std::unique_ptr(q); - - // Re-enable the quantity if we're replacing an enabled quantity - if (existingQuantityWasEnabled) { - q->setEnabled(true); - } } template void QuantityStructure::addQuantity(FloatingQuantity* q, bool allowReplacement) { // Check if a quantity with this name exists, remove it or throw and error if so - bool existingQuantityWasEnabled = checkForQuantityWithNameAndDeleteOrError(q->name, allowReplacement); + checkForQuantityWithNameAndDeleteOrError(q->name, allowReplacement); // Add the new quantity floatingQuantities[q->name] = std::unique_ptr(q); - - // Re-enable the quantity if we're replacing an enabled quantity - if (existingQuantityWasEnabled) { - q->setEnabled(true); - } } template @@ -330,6 +307,7 @@ template ScalarImageQuantity* QuantityStructure::addScalarImageQuantityImpl(std::string name, size_t dimX, size_t dimY, const std::vector& values, ImageOrigin imageOrigin, DataType type) { + checkForQuantityWithNameAndDeleteOrError(name); ScalarImageQuantity* q = createScalarImageQuantity(*this, name, dimX, dimY, values, imageOrigin, type); addQuantity(q); return q; @@ -339,6 +317,7 @@ template ColorImageQuantity* QuantityStructure::addColorImageQuantityImpl(std::string name, size_t dimX, size_t dimY, const std::vector& values, ImageOrigin imageOrigin) { + checkForQuantityWithNameAndDeleteOrError(name); ColorImageQuantity* q = createColorImageQuantity(*this, name, dimX, dimY, values, imageOrigin); addQuantity(q); return q; @@ -348,6 +327,7 @@ template DepthRenderImageQuantity* QuantityStructure::addDepthRenderImageQuantityImpl( std::string name, size_t dimX, size_t dimY, const std::vector& depthData, const std::vector& normalData, ImageOrigin imageOrigin) { + checkForQuantityWithNameAndDeleteOrError(name); DepthRenderImageQuantity* q = createDepthRenderImage(*this, name, dimX, dimY, depthData, normalData, imageOrigin); addQuantity(q); return q; @@ -357,6 +337,7 @@ template ColorRenderImageQuantity* QuantityStructure::addColorRenderImageQuantityImpl( std::string name, size_t dimX, size_t dimY, const std::vector& depthData, const std::vector& normalData, const std::vector& colorData, ImageOrigin imageOrigin) { + checkForQuantityWithNameAndDeleteOrError(name); ColorRenderImageQuantity* q = createColorRenderImage(*this, name, dimX, dimY, depthData, normalData, colorData, imageOrigin); addQuantity(q); @@ -368,6 +349,7 @@ ScalarRenderImageQuantity* QuantityStructure::addScalarRenderImageQuantityImp std::string name, size_t dimX, size_t dimY, const std::vector& depthData, const std::vector& normalData, const std::vector& scalarData, ImageOrigin imageOrigin, DataType type) { + checkForQuantityWithNameAndDeleteOrError(name); ScalarRenderImageQuantity* q = createScalarRenderImage(*this, name, dimX, dimY, depthData, normalData, scalarData, imageOrigin, type); addQuantity(q); diff --git a/src/curve_network.cpp b/src/curve_network.cpp index bca16952..9aa39cb0 100644 --- a/src/curve_network.cpp +++ b/src/curve_network.cpp @@ -497,6 +497,7 @@ void CurveNetworkQuantity::buildEdgeInfoGUI(size_t edgeInd) {} CurveNetworkNodeColorQuantity* CurveNetwork::addNodeColorQuantityImpl(std::string name, const std::vector& colors) { + checkForQuantityWithNameAndDeleteOrError(name); CurveNetworkNodeColorQuantity* q = new CurveNetworkNodeColorQuantity(name, colors, *this); addQuantity(q); return q; @@ -504,6 +505,7 @@ CurveNetworkNodeColorQuantity* CurveNetwork::addNodeColorQuantityImpl(std::strin CurveNetworkEdgeColorQuantity* CurveNetwork::addEdgeColorQuantityImpl(std::string name, const std::vector& colors) { + checkForQuantityWithNameAndDeleteOrError(name); CurveNetworkEdgeColorQuantity* q = new CurveNetworkEdgeColorQuantity(name, colors, *this); addQuantity(q); return q; @@ -512,6 +514,7 @@ CurveNetworkEdgeColorQuantity* CurveNetwork::addEdgeColorQuantityImpl(std::strin CurveNetworkNodeScalarQuantity* CurveNetwork::addNodeScalarQuantityImpl(std::string name, const std::vector& data, DataType type) { + checkForQuantityWithNameAndDeleteOrError(name); CurveNetworkNodeScalarQuantity* q = new CurveNetworkNodeScalarQuantity(name, data, *this, type); addQuantity(q); return q; @@ -519,6 +522,7 @@ CurveNetwork::addNodeScalarQuantityImpl(std::string name, const std::vector& data, DataType type) { + checkForQuantityWithNameAndDeleteOrError(name); CurveNetworkEdgeScalarQuantity* q = new CurveNetworkEdgeScalarQuantity(name, data, *this, type); addQuantity(q); return q; @@ -527,6 +531,7 @@ CurveNetwork::addEdgeScalarQuantityImpl(std::string name, const std::vector& vectors, VectorType vectorType) { + checkForQuantityWithNameAndDeleteOrError(name); CurveNetworkNodeVectorQuantity* q = new CurveNetworkNodeVectorQuantity(name, vectors, *this, vectorType); addQuantity(q); return q; @@ -535,6 +540,7 @@ CurveNetworkNodeVectorQuantity* CurveNetwork::addNodeVectorQuantityImpl(std::str CurveNetworkEdgeVectorQuantity* CurveNetwork::addEdgeVectorQuantityImpl(std::string name, const std::vector& vectors, VectorType vectorType) { + checkForQuantityWithNameAndDeleteOrError(name); CurveNetworkEdgeVectorQuantity* q = new CurveNetworkEdgeVectorQuantity(name, vectors, *this, vectorType); addQuantity(q); return q; diff --git a/src/point_cloud.cpp b/src/point_cloud.cpp index 324cd5de..4bb25084 100644 --- a/src/point_cloud.cpp +++ b/src/point_cloud.cpp @@ -371,6 +371,7 @@ void PointCloudQuantity::buildInfoGUI(size_t pointInd) {} PointCloudColorQuantity* PointCloud::addColorQuantityImpl(std::string name, const std::vector& colors) { + checkForQuantityWithNameAndDeleteOrError(name); PointCloudColorQuantity* q = new PointCloudColorQuantity(name, colors, *this); addQuantity(q); return q; @@ -378,6 +379,7 @@ PointCloudColorQuantity* PointCloud::addColorQuantityImpl(std::string name, cons PointCloudScalarQuantity* PointCloud::addScalarQuantityImpl(std::string name, const std::vector& data, DataType type) { + checkForQuantityWithNameAndDeleteOrError(name); PointCloudScalarQuantity* q = new PointCloudScalarQuantity(name, data, *this, type); addQuantity(q); return q; @@ -386,6 +388,7 @@ PointCloudScalarQuantity* PointCloud::addScalarQuantityImpl(std::string name, co PointCloudParameterizationQuantity* PointCloud::addParameterizationQuantityImpl(std::string name, const std::vector& param, ParamCoordsType type) { + checkForQuantityWithNameAndDeleteOrError(name); PointCloudParameterizationQuantity* q = new PointCloudParameterizationQuantity(name, *this, param, type, ParamVizStyle::CHECKER); addQuantity(q); @@ -395,6 +398,7 @@ PointCloudParameterizationQuantity* PointCloud::addParameterizationQuantityImpl( PointCloudParameterizationQuantity* PointCloud::addLocalParameterizationQuantityImpl(std::string name, const std::vector& param, ParamCoordsType type) { + checkForQuantityWithNameAndDeleteOrError(name); PointCloudParameterizationQuantity* q = new PointCloudParameterizationQuantity(name, *this, param, type, ParamVizStyle::LOCAL_CHECK); addQuantity(q); @@ -403,6 +407,7 @@ PointCloud::addLocalParameterizationQuantityImpl(std::string name, const std::ve PointCloudVectorQuantity* PointCloud::addVectorQuantityImpl(std::string name, const std::vector& vectors, VectorType vectorType) { + checkForQuantityWithNameAndDeleteOrError(name); PointCloudVectorQuantity* q = new PointCloudVectorQuantity(name, vectors, *this, vectorType); addQuantity(q); return q; diff --git a/src/quantity.cpp b/src/quantity.cpp index e0dbe654..7a70b9a5 100644 --- a/src/quantity.cpp +++ b/src/quantity.cpp @@ -13,7 +13,7 @@ namespace polyscope { // (subclasses could be a structure-specific quantity or a floating quantity) Quantity::Quantity(std::string name_, Structure& parentStructure_) - : parent(parentStructure_), name(name_), enabled(parent.typeName() + "#" + parent.name + "#" + name, false) { + : parent(parentStructure_), name(name_), enabled(uniquePrefix() + "enabled", false) { validateName(name); } diff --git a/src/surface_mesh.cpp b/src/surface_mesh.cpp index 4bd76542..31b19c35 100644 --- a/src/surface_mesh.cpp +++ b/src/surface_mesh.cpp @@ -1488,6 +1488,7 @@ MeshShadeStyle SurfaceMesh::getShadeStyle() { return shadeStyle.get(); } SurfaceVertexColorQuantity* SurfaceMesh::addVertexColorQuantityImpl(std::string name, const std::vector& colors) { + checkForQuantityWithNameAndDeleteOrError(name); SurfaceVertexColorQuantity* q = new SurfaceVertexColorQuantity(name, *this, colors); addQuantity(q); return q; @@ -1495,6 +1496,7 @@ SurfaceVertexColorQuantity* SurfaceMesh::addVertexColorQuantityImpl(std::string SurfaceFaceColorQuantity* SurfaceMesh::addFaceColorQuantityImpl(std::string name, const std::vector& colors) { + checkForQuantityWithNameAndDeleteOrError(name); SurfaceFaceColorQuantity* q = new SurfaceFaceColorQuantity(name, *this, colors); addQuantity(q); return q; @@ -1502,6 +1504,7 @@ SurfaceFaceColorQuantity* SurfaceMesh::addFaceColorQuantityImpl(std::string name SurfaceVertexScalarQuantity* SurfaceMesh::addVertexDistanceQuantityImpl(std::string name, const std::vector& data) { + checkForQuantityWithNameAndDeleteOrError(name); SurfaceVertexScalarQuantity* q = new SurfaceVertexScalarQuantity(name, data, *this, DataType::MAGNITUDE); q->setIsolinesEnabled(true); @@ -1513,6 +1516,7 @@ SurfaceVertexScalarQuantity* SurfaceMesh::addVertexDistanceQuantityImpl(std::str SurfaceVertexScalarQuantity* SurfaceMesh::addVertexSignedDistanceQuantityImpl(std::string name, const std::vector& data) { + checkForQuantityWithNameAndDeleteOrError(name); SurfaceVertexScalarQuantity* q = new SurfaceVertexScalarQuantity(name, data, *this, DataType::SYMMETRIC); q->setIsolinesEnabled(true); @@ -1525,6 +1529,7 @@ SurfaceVertexScalarQuantity* SurfaceMesh::addVertexSignedDistanceQuantityImpl(st SurfaceCornerParameterizationQuantity* SurfaceMesh::addParameterizationQuantityImpl(std::string name, const std::vector& coords, ParamCoordsType type) { + checkForQuantityWithNameAndDeleteOrError(name); SurfaceCornerParameterizationQuantity* q = new SurfaceCornerParameterizationQuantity(name, *this, coords, type, ParamVizStyle::CHECKER); addQuantity(q); @@ -1535,6 +1540,7 @@ SurfaceMesh::addParameterizationQuantityImpl(std::string name, const std::vector SurfaceVertexParameterizationQuantity* SurfaceMesh::addVertexParameterizationQuantityImpl(std::string name, const std::vector& coords, ParamCoordsType type) { + checkForQuantityWithNameAndDeleteOrError(name); SurfaceVertexParameterizationQuantity* q = new SurfaceVertexParameterizationQuantity(name, *this, coords, type, ParamVizStyle::CHECKER); addQuantity(q); @@ -1545,6 +1551,7 @@ SurfaceMesh::addVertexParameterizationQuantityImpl(std::string name, const std:: SurfaceVertexParameterizationQuantity* SurfaceMesh::addLocalParameterizationQuantityImpl(std::string name, const std::vector& coords, ParamCoordsType type) { + checkForQuantityWithNameAndDeleteOrError(name); SurfaceVertexParameterizationQuantity* q = new SurfaceVertexParameterizationQuantity(name, *this, coords, type, ParamVizStyle::LOCAL_CHECK); addQuantity(q); @@ -1554,6 +1561,7 @@ SurfaceMesh::addLocalParameterizationQuantityImpl(std::string name, const std::v SurfaceVertexScalarQuantity* SurfaceMesh::addVertexScalarQuantityImpl(std::string name, const std::vector& data, DataType type) { + checkForQuantityWithNameAndDeleteOrError(name); SurfaceVertexScalarQuantity* q = new SurfaceVertexScalarQuantity(name, data, *this, type); addQuantity(q); return q; @@ -1561,6 +1569,7 @@ SurfaceVertexScalarQuantity* SurfaceMesh::addVertexScalarQuantityImpl(std::strin SurfaceFaceScalarQuantity* SurfaceMesh::addFaceScalarQuantityImpl(std::string name, const std::vector& data, DataType type) { + checkForQuantityWithNameAndDeleteOrError(name); SurfaceFaceScalarQuantity* q = new SurfaceFaceScalarQuantity(name, data, *this, type); addQuantity(q); return q; @@ -1569,6 +1578,7 @@ SurfaceFaceScalarQuantity* SurfaceMesh::addFaceScalarQuantityImpl(std::string na SurfaceEdgeScalarQuantity* SurfaceMesh::addEdgeScalarQuantityImpl(std::string name, const std::vector& data, DataType type) { + checkForQuantityWithNameAndDeleteOrError(name); SurfaceEdgeScalarQuantity* q = new SurfaceEdgeScalarQuantity(name, data, *this, type); addQuantity(q); markEdgesAsUsed(); @@ -1577,6 +1587,7 @@ SurfaceEdgeScalarQuantity* SurfaceMesh::addEdgeScalarQuantityImpl(std::string na SurfaceHalfedgeScalarQuantity* SurfaceMesh::addHalfedgeScalarQuantityImpl(std::string name, const std::vector& data, DataType type) { + checkForQuantityWithNameAndDeleteOrError(name); SurfaceHalfedgeScalarQuantity* q = new SurfaceHalfedgeScalarQuantity(name, data, *this, type); addQuantity(q); markHalfedgesAsUsed(); @@ -1585,6 +1596,7 @@ SurfaceMesh::addHalfedgeScalarQuantityImpl(std::string name, const std::vector& data, DataType type) { + checkForQuantityWithNameAndDeleteOrError(name); SurfaceCornerScalarQuantity* q = new SurfaceCornerScalarQuantity(name, data, *this, type); addQuantity(q); markCornersAsUsed(); @@ -1594,6 +1606,7 @@ SurfaceCornerScalarQuantity* SurfaceMesh::addCornerScalarQuantityImpl(std::strin SurfaceVertexVectorQuantity* SurfaceMesh::addVertexVectorQuantityImpl(std::string name, const std::vector& vectors, VectorType vectorType) { + checkForQuantityWithNameAndDeleteOrError(name); SurfaceVertexVectorQuantity* q = new SurfaceVertexVectorQuantity(name, vectors, *this, vectorType); addQuantity(q); return q; @@ -1602,6 +1615,7 @@ SurfaceVertexVectorQuantity* SurfaceMesh::addVertexVectorQuantityImpl(std::strin SurfaceFaceVectorQuantity* SurfaceMesh::addFaceVectorQuantityImpl(std::string name, const std::vector& vectors, VectorType vectorType) { + checkForQuantityWithNameAndDeleteOrError(name); SurfaceFaceVectorQuantity* q = new SurfaceFaceVectorQuantity(name, vectors, *this, vectorType); addQuantity(q); return q; @@ -1613,6 +1627,7 @@ SurfaceFaceTangentVectorQuantity* SurfaceMesh::addFaceTangentVectorQuantityImpl( const std::vector& basisY, int nSym, VectorType vectorType) { + checkForQuantityWithNameAndDeleteOrError(name); SurfaceFaceTangentVectorQuantity* q = new SurfaceFaceTangentVectorQuantity(name, vectors, basisX, basisY, *this, nSym, vectorType); addQuantity(q); @@ -1624,6 +1639,7 @@ SurfaceVertexTangentVectorQuantity* SurfaceMesh::addVertexTangentVectorQuantityImpl(std::string name, const std::vector& vectors, const std::vector& basisX, const std::vector& basisY, int nSym, VectorType vectorType) { + checkForQuantityWithNameAndDeleteOrError(name); SurfaceVertexTangentVectorQuantity* q = new SurfaceVertexTangentVectorQuantity(name, vectors, basisX, basisY, *this, nSym, vectorType); addQuantity(q); @@ -1635,6 +1651,7 @@ SurfaceMesh::addVertexTangentVectorQuantityImpl(std::string name, const std::vec SurfaceOneFormTangentVectorQuantity* SurfaceMesh::addOneFormTangentVectorQuantityImpl(std::string name, const std::vector& data, const std::vector& orientations) { + checkForQuantityWithNameAndDeleteOrError(name); SurfaceOneFormTangentVectorQuantity* q = new SurfaceOneFormTangentVectorQuantity(name, data, orientations, *this); addQuantity(q); markEdgesAsUsed(); diff --git a/src/volume_grid.cpp b/src/volume_grid.cpp index 1201a983..8dbaea67 100644 --- a/src/volume_grid.cpp +++ b/src/volume_grid.cpp @@ -383,6 +383,7 @@ VolumeGridQuantity::VolumeGridQuantity(std::string name_, VolumeGrid& curveNetwo VolumeGridNodeScalarQuantity* VolumeGrid::addNodeScalarQuantityImpl(std::string name, const std::vector& data, DataType dataType_) { + checkForQuantityWithNameAndDeleteOrError(name); VolumeGridNodeScalarQuantity* q = new VolumeGridNodeScalarQuantity(name, *this, data, dataType_); addQuantity(q); markNodesAsUsed(); @@ -392,6 +393,7 @@ VolumeGridNodeScalarQuantity* VolumeGrid::addNodeScalarQuantityImpl(std::string VolumeGridCellScalarQuantity* VolumeGrid::addCellScalarQuantityImpl(std::string name, const std::vector& data, DataType dataType_) { + checkForQuantityWithNameAndDeleteOrError(name); VolumeGridCellScalarQuantity* q = new VolumeGridCellScalarQuantity(name, *this, data, dataType_); addQuantity(q); markCellsAsUsed(); diff --git a/src/volume_mesh.cpp b/src/volume_mesh.cpp index 648b292d..b4c525b0 100644 --- a/src/volume_mesh.cpp +++ b/src/volume_mesh.cpp @@ -1003,6 +1003,7 @@ double VolumeMesh::getEdgeWidth() { return edgeWidth.get(); } VolumeMeshVertexColorQuantity* VolumeMesh::addVertexColorQuantityImpl(std::string name, const std::vector& colors) { + checkForQuantityWithNameAndDeleteOrError(name); VolumeMeshVertexColorQuantity* q = new VolumeMeshVertexColorQuantity(name, *this, colors); addQuantity(q); return q; @@ -1010,6 +1011,7 @@ VolumeMeshVertexColorQuantity* VolumeMesh::addVertexColorQuantityImpl(std::strin VolumeMeshCellColorQuantity* VolumeMesh::addCellColorQuantityImpl(std::string name, const std::vector& colors) { + checkForQuantityWithNameAndDeleteOrError(name); VolumeMeshCellColorQuantity* q = new VolumeMeshCellColorQuantity(name, *this, colors); addQuantity(q); return q; @@ -1017,6 +1019,7 @@ VolumeMeshCellColorQuantity* VolumeMesh::addCellColorQuantityImpl(std::string na VolumeMeshVertexScalarQuantity* VolumeMesh::addVertexScalarQuantityImpl(std::string name, const std::vector& data, DataType type) { + checkForQuantityWithNameAndDeleteOrError(name); VolumeMeshVertexScalarQuantity* q = new VolumeMeshVertexScalarQuantity(name, data, *this, type); addQuantity(q); return q; @@ -1024,6 +1027,7 @@ VolumeMesh::addVertexScalarQuantityImpl(std::string name, const std::vector& data, DataType type) { + checkForQuantityWithNameAndDeleteOrError(name); VolumeMeshCellScalarQuantity* q = new VolumeMeshCellScalarQuantity(name, data, *this, type); addQuantity(q); return q; @@ -1032,6 +1036,7 @@ VolumeMeshCellScalarQuantity* VolumeMesh::addCellScalarQuantityImpl(std::string VolumeMeshVertexVectorQuantity* VolumeMesh::addVertexVectorQuantityImpl(std::string name, const std::vector& vectors, VectorType vectorType) { + checkForQuantityWithNameAndDeleteOrError(name); VolumeMeshVertexVectorQuantity* q = new VolumeMeshVertexVectorQuantity(name, vectors, *this, vectorType); addQuantity(q); return q; @@ -1040,6 +1045,7 @@ VolumeMeshVertexVectorQuantity* VolumeMesh::addVertexVectorQuantityImpl(std::str VolumeMeshCellVectorQuantity* VolumeMesh::addCellVectorQuantityImpl(std::string name, const std::vector& vectors, VectorType vectorType) { + checkForQuantityWithNameAndDeleteOrError(name); VolumeMeshCellVectorQuantity* q = new VolumeMeshCellVectorQuantity(name, vectors, *this, vectorType); addQuantity(q); return q; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f1fb454d..44b4c722 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -30,6 +30,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STR message("Setting gcc-specific options") SET(BASE_CXX_FLAGS "${BASE_CXX_FLAGS} -fmax-errors=5") SET(DISABLED_WARNINGS "${DISABLED_WARNINGS} -Wno-maybe-uninitialized -Wno-format-zero-length -Wno-unused-but-set-parameter -Wno-unused-but-set-variable") + SET(CMAKE_CXX_FLAGS_DEBUG "-fsanitize=address") endif() SET(CMAKE_CXX_FLAGS "${BASE_CXX_FLAGS} ${DISABLED_WARNINGS}")