From 1c43db9259c12f17c9a3388933752fef308f62f9 Mon Sep 17 00:00:00 2001 From: Brian Wylie <bnwylie@sandia.gov> Date: Mon, 14 Jul 2008 17:30:35 -0400 Subject: [PATCH] BUG: vtkVariantCompare had a serious bug in it. Deleted all instances of it and replacing with vtkVariantLessThan which now properly supports heterogeneous types. --- Common/vtkVariant.cxx | 7 ++++++ Infovis/vtkGraphHierarchicalBundle.cxx | 31 +++----------------------- Infovis/vtkGroupLeafVertices.cxx | 28 ++--------------------- Infovis/vtkTableToGraph.cxx | 28 ++--------------------- 4 files changed, 14 insertions(+), 80 deletions(-) diff --git a/Common/vtkVariant.cxx b/Common/vtkVariant.cxx index 4aa76f63e53..ff03b323da3 100644 --- a/Common/vtkVariant.cxx +++ b/Common/vtkVariant.cxx @@ -39,6 +39,13 @@ vtkVariantLessThan::vtkVariantLessThan() // Implementation of vtkVariant's less than operation bool vtkVariantLessThan::operator()(const vtkVariant& s1, const vtkVariant& s2) const { + // First sort on type if they are different + if (s1.Type != s2.Type) + { + return s1.Type < s2.Type; + } + + // Okay they must be of the same type if (s1.IsString() && s2.IsString()) { return *s1.Data.String < *s2.Data.String; diff --git a/Infovis/vtkGraphHierarchicalBundle.cxx b/Infovis/vtkGraphHierarchicalBundle.cxx index cd1832362a1..448a1d3bb03 100644 --- a/Infovis/vtkGraphHierarchicalBundle.cxx +++ b/Infovis/vtkGraphHierarchicalBundle.cxx @@ -38,31 +38,6 @@ #include <vtksys/stl/map> using vtksys_stl::map; - -//--------------------------------------------------------------------------- -class vtkVariantCompare -{ -public: - bool operator()( - const vtkVariant& a, - const vtkVariant& b) const - { - if (a.GetType() == VTK_STRING) - { - return a.ToString() < b.ToString(); - } - else if (a.IsNumeric()) - { - return a.ToDouble() < b.ToDouble(); - } - else - { - // Punt, just do pointer difference. - return &a < &b; - } - } -}; - //--------------------------------------------------------------------------- template <typename T> vtkVariant vtkGetValue(T* arr, vtkIdType index) @@ -83,7 +58,7 @@ vtkVariant vtkGetVariantValue(vtkAbstractArray* arr, vtkIdType i) } -vtkCxxRevisionMacro(vtkGraphHierarchicalBundle, "1.9"); +vtkCxxRevisionMacro(vtkGraphHierarchicalBundle, "1.10"); vtkStandardNewMacro(vtkGraphHierarchicalBundle); vtkGraphHierarchicalBundle::vtkGraphHierarchicalBundle() @@ -182,7 +157,7 @@ int vtkGraphHierarchicalBundle::RequestData( } } - map<vtkVariant,vtkIdType,vtkVariantCompare> graphIdMap; + map<vtkVariant,vtkIdType,vtkVariantLessThan> graphIdMap; // Create a map from graph id to graph index for (int i=0; i<graph->GetNumberOfVertices(); ++i) @@ -194,7 +169,7 @@ int vtkGraphHierarchicalBundle::RequestData( for (int i=0; i<tree->GetNumberOfVertices(); ++i) { vtkVariant id = vtkGetVariantValue(treeIdArray,i); - if (graphIdMap.count(id) > 0) + if (graphIdMap.count(id)) { graphIndexToTreeIndex[graphIdMap[id]] = i; } diff --git a/Infovis/vtkGroupLeafVertices.cxx b/Infovis/vtkGroupLeafVertices.cxx index bd78bbb9469..882c1a16108 100644 --- a/Infovis/vtkGroupLeafVertices.cxx +++ b/Infovis/vtkGroupLeafVertices.cxx @@ -37,33 +37,9 @@ #include <vtksys/stl/utility> #include <vtksys/stl/vector> -vtkCxxRevisionMacro(vtkGroupLeafVertices, "1.7"); +vtkCxxRevisionMacro(vtkGroupLeafVertices, "1.8"); vtkStandardNewMacro(vtkGroupLeafVertices); -//--------------------------------------------------------------------------- -class vtkVariantCompare -{ -public: - bool operator()( - const vtkVariant& a, - const vtkVariant& b) const - { - if (a.GetType() == VTK_STRING) - { - return a.ToString() < b.ToString(); - } - else if (a.IsNumeric()) - { - return a.ToDouble() < b.ToDouble(); - } - else - { - // Punt, just do pointer difference. - return &a < &b; - } - } -}; - //--------------------------------------------------------------------------- class vtkGroupLeafVerticesCompare { @@ -76,7 +52,7 @@ public: { return a.first < b.first; } - return vtkVariantCompare()(a.second, b.second); + return vtkVariantLessThan()(a.second, b.second); } }; diff --git a/Infovis/vtkTableToGraph.cxx b/Infovis/vtkTableToGraph.cxx index a28e4b86cfa..b1d5936fdb0 100644 --- a/Infovis/vtkTableToGraph.cxx +++ b/Infovis/vtkTableToGraph.cxx @@ -51,7 +51,7 @@ #define VTK_CREATE(type, name) \ vtkSmartPointer<type> name = vtkSmartPointer<type>::New() -vtkCxxRevisionMacro(vtkTableToGraph, "1.14"); +vtkCxxRevisionMacro(vtkTableToGraph, "1.15"); vtkStandardNewMacro(vtkTableToGraph); vtkCxxSetObjectMacro(vtkTableToGraph, LinkGraph, vtkMutableDirectedGraph); //--------------------------------------------------------------------------- @@ -298,30 +298,6 @@ int vtkTableToGraph::FillInputPortInformation(int port, vtkInformation* info) return 0; } -//--------------------------------------------------------------------------- -class vtkVariantCompare -{ -public: - bool operator()( - const vtkVariant& a, - const vtkVariant& b) const - { - if (a.GetType() == VTK_STRING) - { - return a.ToString() < b.ToString(); - } - else if (a.IsNumeric()) - { - return a.ToDouble() < b.ToDouble(); - } - else - { - // Punt, just do pointer difference. - return &a < &b; - } - } -}; - //--------------------------------------------------------------------------- class vtkTableToGraphCompare { @@ -334,7 +310,7 @@ public: { return a.first < b.first; } - return vtkVariantCompare()(a.second, b.second); + return vtkVariantLessThan()(a.second, b.second); } }; -- GitLab