소스 검색

Merge branch '26-CTK-windows-configuration-error-dgraph-related'

Fixes issue #26

* 26-CTK-windows-configuration-error-dgraph-related:
  Fixed memory leak
  26 dgraph in STL, compile and unit test pass
  26 dgraph in STL, compile and unit test pass

Conflicts:
	Utilities/DGraph/CMakeLists.txt
Sascha Zelzer 13 년 전
부모
커밋
9457adbf3b

+ 0 - 1
CMakeLists.txt

@@ -503,7 +503,6 @@ endforeach()
 try_compile(RESULT_VAR ${CTK_BINARY_DIR}/Utilities/DGraph ${CTK_SOURCE_DIR}/Utilities/DGraph
               DGraph
               CMAKE_FLAGS
-                -DQT_QMAKE_EXECUTABLE:FILE=${QT_QMAKE_EXECUTABLE}
                 -DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES}
                 -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${CMAKE_OSX_DEPLOYMENT_TARGET}
                 -DCMAKE_OSX_SYSROOT:STRING=${CMAKE_OSX_SYSROOT}

+ 74 - 49
Libs/Core/Testing/Cpp/ctkDependencyGraphTest1.cpp

@@ -20,32 +20,19 @@
 
 // CTK includes
 #include "ctkDependencyGraph.h"
+#include "ctkDependencyGraphTestHelper.h"
 
 // STL includes
 #include <cstdlib>
 #include <iostream>
 
-namespace
-{
-void printIntegerList(const char* msg, const QList<int>& list, bool endl = true)
-{
-  std::cerr << msg; 
-  foreach(int l, list)
-    {
-    std::cerr << l << " "; 
-    }
-  if (endl)
-    {
-    std::cerr << std::endl;
-    }
-}
-}
-
 //-----------------------------------------------------------------------------
 int ctkDependencyGraphTest1(int argc, char * argv [] )
 {
-  Q_UNUSED(argc);
-  Q_UNUSED(argv);  
+  if (argc > 1)
+    {
+    std::cerr << argv[0] << " expects zero arguments" << std::endl;
+    }
 
   const int numberOfVertices = 14;
 
@@ -82,9 +69,8 @@ int ctkDependencyGraphTest1(int argc, char * argv [] )
 
   int expectedNumberOfEdge = 15;
   
-
   graph.printAdditionalInfo();
-  graph.printGraph();
+//  graph.printGraph();  // printAdditionalInfo also prints graph.
   
   int nov = graph.numberOfVertices();
 
@@ -117,11 +103,14 @@ int ctkDependencyGraphTest1(int argc, char * argv [] )
 
   //int cend = graph.cycleEnd();
 
-  QList<int> path;
-  QList<int> expectedPath;
+  std::list<int> path;
+  std::list<int> expectedPath;
 
   graph.findPath( 8, 7, path );
-  expectedPath << 8 << 6 << 7;
+  expectedPath.push_back(8);
+  expectedPath.push_back(6);
+  expectedPath.push_back(7);
+
   if (path != expectedPath)
     {
     std::cerr << "Problem with findPath()" << std::endl;
@@ -134,7 +123,10 @@ int ctkDependencyGraphTest1(int argc, char * argv [] )
   expectedPath.clear();
   
   graph.findPath( 1, 7, path );
-  expectedPath << 1 << 5 << 7;
+  expectedPath.push_back(1);
+  expectedPath.push_back(5);
+  expectedPath.push_back(7);
+
   if (path != expectedPath)
     {
     std::cerr << "Problem with findPath()" << std::endl;
@@ -147,7 +139,12 @@ int ctkDependencyGraphTest1(int argc, char * argv [] )
   expectedPath.clear();
   
   graph.findPath( 3, 7, path );
-  expectedPath << 3 << 4 << 1 << 5 << 7;
+  expectedPath.push_back(3);
+  expectedPath.push_back(4);
+  expectedPath.push_back(1);
+  expectedPath.push_back(5);
+  expectedPath.push_back(7);
+
   if (path != expectedPath)
     {
     std::cerr << "Problem with findPath()" << std::endl;
@@ -160,7 +157,10 @@ int ctkDependencyGraphTest1(int argc, char * argv [] )
   expectedPath.clear();
   
   graph.findPath( 2, 5, path );
-  expectedPath << 2 << 1 << 5;
+  expectedPath.push_back(2);
+  expectedPath.push_back(1);
+  expectedPath.push_back(5);
+
   if (path != expectedPath)
     {
     std::cerr << "Problem with findPath()" << std::endl;
@@ -172,19 +172,32 @@ int ctkDependencyGraphTest1(int argc, char * argv [] )
   path.clear();
   expectedPath.clear();
 
-  QList<QList<int>* > paths;
-  QList<int> expectedPath1;
-  QList<int> expectedPath2;
-  QList<int> expectedPath3;
+  std::list<std::list<int>* > paths;
+  std::list<int> expectedPath1;
+  std::list<int> expectedPath2;
+  std::list<int> expectedPath3;
 
   graph.findPaths(14, 5, paths);
-  expectedPath1 << 14 << 9 << 3 << 4 << 1 << 5;
-  expectedPath2 << 14 << 9 << 2 << 1 << 5;
-  foreach(QList<int>* p, paths)
+
+  expectedPath1.push_back(14);
+  expectedPath1.push_back(9);
+  expectedPath1.push_back(3);
+  expectedPath1.push_back(4);
+  expectedPath1.push_back(1);
+  expectedPath1.push_back(5);
+
+  expectedPath2.push_back(14);
+  expectedPath2.push_back(9);
+  expectedPath2.push_back(2);
+  expectedPath2.push_back(1);
+  expectedPath2.push_back(5);
+
+  std::list<std::list<int>* >::const_iterator pathsIterator;
+  for(pathsIterator = paths.begin(); pathsIterator != paths.end(); pathsIterator++)
     {
-    if (*p != expectedPath1 && *p != expectedPath2)
+    if (*(*pathsIterator) != expectedPath1 && *(*pathsIterator) != expectedPath2)
       {
-      printIntegerList("current:", *p);
+      printIntegerList("current:", *(*pathsIterator));
       printIntegerList("expected:", expectedPath1, false);
       printIntegerList(" or ", expectedPath2);
       return EXIT_FAILURE;
@@ -195,14 +208,34 @@ int ctkDependencyGraphTest1(int argc, char * argv [] )
   expectedPath2.clear();
 
   graph.findPaths(14, 7, paths);
-  expectedPath1 << 14 << 9 << 3 << 4 << 1 << 5 << 7;
-  expectedPath2 << 14 << 9 << 2 << 1 << 5 << 7;
-  expectedPath3 << 14 << 13 << 12 << 11 << 10 << 7;
-  foreach(QList<int>* p, paths)
+
+  expectedPath1.push_back(14);
+  expectedPath1.push_back(9);
+  expectedPath1.push_back(3);
+  expectedPath1.push_back(4);
+  expectedPath1.push_back(1);
+  expectedPath1.push_back(5);
+  expectedPath1.push_back(7);
+
+  expectedPath2.push_back(14);
+  expectedPath2.push_back(9);
+  expectedPath2.push_back(2);
+  expectedPath2.push_back(1);
+  expectedPath2.push_back(5);
+  expectedPath2.push_back(7);
+
+  expectedPath3.push_back(14);
+  expectedPath3.push_back(13);
+  expectedPath3.push_back(12);
+  expectedPath3.push_back(11);
+  expectedPath3.push_back(10);
+  expectedPath3.push_back(7);
+
+  for(pathsIterator = paths.begin(); pathsIterator != paths.end(); pathsIterator++)
     {
-    if (*p != expectedPath1 && *p != expectedPath2 && *p != expectedPath3)
+    if (*(*pathsIterator) != expectedPath1 && *(*pathsIterator) != expectedPath2 && *(*pathsIterator) != expectedPath3)
       {
-      printIntegerList("current:", *p);
+      printIntegerList("current:", *(*pathsIterator));
       printIntegerList("expected:", expectedPath1, false);
       printIntegerList(" or ", expectedPath2, false);
       printIntegerList(" or ", expectedPath3);
@@ -210,13 +243,5 @@ int ctkDependencyGraphTest1(int argc, char * argv [] )
       }
     }
 
-//   QList<int> list;
-//   graph.setEdgeListToExclude( list );
-// 
-//   graph.shouldExcludeEdge(2);
-// 
-//   QList<int> sortedlist;
-//   graph.topologicalSort( sortedlist );
-
   return EXIT_SUCCESS;
 }

+ 138 - 74
Libs/Core/Testing/Cpp/ctkDependencyGraphTest2.cpp

@@ -21,19 +21,18 @@
 
 // CTK includes
 #include "ctkDependencyGraph.h"
+#include "ctkDependencyGraphTestHelper.h"
 
 // STL includes
 #include <cstdlib>
 #include <iostream>
 
-// Qt includes
-#include <QDebug>
-
-
 int ctkDependencyGraphTest2(int argc, char * argv [] )
 {
-  Q_UNUSED(argc);
-  Q_UNUSED(argv);  
+  if (argc > 1)
+    {
+    std::cerr << argv[0] << " expects zero arguments" << std::endl;
+    }
 
   // check that cycle detection works
   {
@@ -55,14 +54,14 @@ int ctkDependencyGraphTest2(int argc, char * argv [] )
 
   if( nov != numberOfVertices )
     {
-    qCritical() << "Number of vertices does not match (expected" << numberOfVertices << "got" << nov << ")";
+    std::cerr << "Number of vertices does not match (expected" << numberOfVertices << " got " << nov << ")" << std::endl;
     return EXIT_FAILURE;
     }
 
   int noe = graph.numberOfEdges();
   if( noe != expectedNumberOfEdge )
     {
-    qCritical() << "Number of edges does not match (expected" << expectedNumberOfEdge << "got" << noe << ")";
+    std::cerr << "Number of edges does not match (expected" << expectedNumberOfEdge << " got " << noe << ")" << std::endl;
     return EXIT_FAILURE;
     }
 
@@ -70,7 +69,7 @@ int ctkDependencyGraphTest2(int argc, char * argv [] )
   
   if( cfc == false )
     {
-    qCritical() << "Cycle detection failed";
+    std::cerr << "Cycle detection failed" << std::endl;
     return EXIT_FAILURE;
     }
 
@@ -78,7 +77,7 @@ int ctkDependencyGraphTest2(int argc, char * argv [] )
 
   if( cdtd == false )
     {
-    qCritical() << "Cycle detected flag wrong";
+    std::cerr << "Cycle detected flag wrong" << std::endl;
     return EXIT_FAILURE;
     }
 
@@ -87,13 +86,13 @@ int ctkDependencyGraphTest2(int argc, char * argv [] )
 
   if (co != 2)
     {
-    qCritical() << "Wrong cycle origin (expected" << 2 << "got" << co << ")";
+    std::cerr << "Wrong cycle origin (expected" << 2 << " got " << co << " )" << std::endl;
     return EXIT_FAILURE;
     }
 
   if (ce != 1)
     {
-    qCritical() << "Wrong cycle end (expected" << 1 << "got" << ce << ")";
+    std::cerr << "Wrong cycle end (expected" << 1 << " got " << ce << " )" << std::endl;
     return EXIT_FAILURE;
     }
 
@@ -121,14 +120,14 @@ int ctkDependencyGraphTest2(int argc, char * argv [] )
 
   if( nov != numberOfVertices )
     {
-    qCritical() << "Number of vertices does not match (expected" << numberOfVertices << "got" << nov << ")";
+    std::cerr << "Number of vertices does not match (expected" << numberOfVertices << " got " << nov << ")" << std::endl;
     return EXIT_FAILURE;
     }
 
   int noe = graph.numberOfEdges();
   if( noe != expectedNumberOfEdge )
     {
-    qCritical() << "Number of edges does not match (expected" << expectedNumberOfEdge << "got" << noe << ")";
+    std::cerr << "Number of edges does not match (expected" << expectedNumberOfEdge << " got " << noe << ")" << std::endl;
     return EXIT_FAILURE;
     }
 
@@ -136,7 +135,7 @@ int ctkDependencyGraphTest2(int argc, char * argv [] )
 
   if( cfc == false )
     {
-    qCritical() << "Cycle detection failed";
+    std::cerr << "Cycle detection failed" << std::endl;
     return EXIT_FAILURE;
     }
 
@@ -144,7 +143,7 @@ int ctkDependencyGraphTest2(int argc, char * argv [] )
 
   if( cdtd == false )
     {
-    qCritical() << "Cycle detected flag wrong";
+    std::cerr << "Cycle detected flag wrong" << std::endl;
     return EXIT_FAILURE;
     }
 
@@ -153,13 +152,13 @@ int ctkDependencyGraphTest2(int argc, char * argv [] )
 
   if (co != 2)
     {
-    qCritical() << "Wrong cycle origin (expected" << 2 << "got" << co << ")";
+    std::cerr << "Wrong cycle origin (expected" << 2 << " got " << co << ")" << std::endl;
     return EXIT_FAILURE;
     }
 
   if (ce != 4)
     {
-    qCritical() << "Wrong cycle end (expected" << 4 << "got" << ce << ")";
+    std::cerr << "Wrong cycle end (expected" << 4 << " got " << ce << ")" << std::endl;
     return EXIT_FAILURE;
     }
 
@@ -195,14 +194,14 @@ int ctkDependencyGraphTest2(int argc, char * argv [] )
 
   if( nov != numberOfVertices )
     {
-    qCritical() << "Number of vertices does not match (expected" << numberOfVertices << "got" << nov << ")";
+    std::cerr << "Number of vertices does not match (expected" << numberOfVertices << " got " << nov << ")" << std::endl;
     return EXIT_FAILURE;
     }
 
   int noe = graph.numberOfEdges();
   if( noe != expectedNumberOfEdge )
     {
-    qCritical() << "Number of edges does not match (expected" << expectedNumberOfEdge << "got" << noe << ")";
+    std::cerr << "Number of edges does not match (expected" << expectedNumberOfEdge << " got " << noe << ")" << std::endl;
     return EXIT_FAILURE;
     }
 
@@ -210,7 +209,7 @@ int ctkDependencyGraphTest2(int argc, char * argv [] )
 
   if( cfc == false )
     {
-    qCritical() << "Cycle detection failed";
+    std::cerr << "Cycle detection failed" << std::endl;
     return EXIT_FAILURE;
     }
 
@@ -218,7 +217,7 @@ int ctkDependencyGraphTest2(int argc, char * argv [] )
 
   if( cdtd == false )
     {
-    qCritical() << "Cycle detected flag wrong";
+    std::cerr << "Cycle detected flag wrong" << std::endl;
     return EXIT_FAILURE;
     }
 
@@ -259,14 +258,14 @@ int ctkDependencyGraphTest2(int argc, char * argv [] )
 
   if( nov != numberOfVertices )
     {
-    qCritical() << "Number of vertices does not match (expected" << numberOfVertices << "got" << nov << ")";
+    std::cerr << "Number of vertices does not match (expected" << numberOfVertices << " got " << nov << ")" << std::endl;
     return EXIT_FAILURE;
     }
 
   int noe = graph.numberOfEdges();
   if( noe != expectedNumberOfEdge )
     {
-    qCritical() << "Number of edges does not match (expected" << expectedNumberOfEdge << "got" << noe << ")";
+    std::cerr << "Number of edges does not match (expected" << expectedNumberOfEdge << " got " << noe << ")" << std::endl;
     return EXIT_FAILURE;
     }
 
@@ -274,7 +273,7 @@ int ctkDependencyGraphTest2(int argc, char * argv [] )
 
   if( cfc == true )
     {
-    qCritical() << "Cycle detection failed";
+    std::cerr << "Cycle detection failed" << std::endl;
     return EXIT_FAILURE;
     }
 
@@ -282,41 +281,65 @@ int ctkDependencyGraphTest2(int argc, char * argv [] )
 
   if( cdtd == true )
     {
-    qCritical() << "Cycle detected flag wrong";
+    std::cerr << "Cycle detected flag wrong" << std::endl;
     return EXIT_FAILURE;
     }
 
-  QList<int> sources;
+  std::list<int> sources;
   graph.sourceVertices(sources);
 
-  QList<int> expectedSources;
-  expectedSources << 1 << 5 << 10;
+  std::list<int> expectedSources;
+  expectedSources.push_back(1);
+  expectedSources.push_back(5);
+  expectedSources.push_back(10);
 
   if (sources != expectedSources)
     {
-    qCritical() << "Source vertices do not match (expected" << expectedSources << "got" << sources << ")";
+    std::cerr << "Problem with sourceVertices()" << std::endl;
+    printIntegerList("sources:", sources);
+    printIntegerList("expectedSources:", expectedSources);
     return EXIT_FAILURE;
     }
 
-  QList<int> globalSort;
+  std::list<int> globalSort;
   graph.topologicalSort(globalSort);
 
-  QList<int> expectedGlobalSort;
-  expectedGlobalSort << 1 << 5 << 10 << 2 << 6 << 11 << 3 << 4 << 7 << 8 << 9;
+  std::list<int> expectedGlobalSort;
+
+  expectedGlobalSort.push_back(1);
+  expectedGlobalSort.push_back(5);
+  expectedGlobalSort.push_back(10);
+  expectedGlobalSort.push_back(2);
+  expectedGlobalSort.push_back(6);
+  expectedGlobalSort.push_back(11);
+  expectedGlobalSort.push_back(3);
+  expectedGlobalSort.push_back(4);
+  expectedGlobalSort.push_back(7);
+  expectedGlobalSort.push_back(8);
+  expectedGlobalSort.push_back(9);
+
   if (globalSort != expectedGlobalSort)
   {
-    qCritical() << "Topological sort error (expected" << expectedGlobalSort << "got" << globalSort << ")";
+    std::cerr << "Problem with topologicalSort(globalSort)" << std::endl;
+    printIntegerList("globalSort:", globalSort);
+    printIntegerList("expectedGlobalSort:", expectedGlobalSort);
     return EXIT_FAILURE;
   }
 
-  QList<int> subSort10;
+  std::list<int> subSort10;
   graph.topologicalSort(subSort10, 10);
 
-  QList<int> expectedSubSort10;
-  expectedSubSort10 << 10 << 8 << 11 << 9;
+  std::list<int> expectedSubSort10;
+  expectedSubSort10.push_back(10);
+  expectedSubSort10.push_back(8);
+  expectedSubSort10.push_back(11);
+  expectedSubSort10.push_back(9);
+
   if (subSort10 != expectedSubSort10)
   {
-    qCritical() << "Topological subgraph sort error (expected" << expectedSubSort10 << "got" << subSort10 << ")";
+    std::cerr << "Problem with topologicalSort(subSort10, 10)" << std::endl;
+    printIntegerList("subSort10:", subSort10);
+    printIntegerList("expectedSubSort10:", expectedSubSort10);
     return EXIT_FAILURE;
   }
 
@@ -359,14 +382,14 @@ int ctkDependencyGraphTest2(int argc, char * argv [] )
 
   if( nov != numberOfVertices )
     {
-    qCritical() << "Number of vertices does not match (expected" << numberOfVertices << "got" << nov << ")";
+    std::cerr << "Number of vertices does not match (expected" << numberOfVertices << " got " << nov << ")" << std::endl;
     return EXIT_FAILURE;
     }
 
   int noe = graph.numberOfEdges();
   if( noe != expectedNumberOfEdge )
     {
-    qCritical() << "Number of edges does not match (expected" << expectedNumberOfEdge << "got" << noe << ")";
+    std::cerr << "Number of edges does not match (expected" << expectedNumberOfEdge << " got " << noe << ")" << std::endl;
     return EXIT_FAILURE;
     }
 
@@ -374,7 +397,7 @@ int ctkDependencyGraphTest2(int argc, char * argv [] )
 
   if( cfc == true )
     {
-    qCritical() << "Cycle detection failed";
+    std::cerr << "Cycle detection failed" << std::endl;
     return EXIT_FAILURE;
     }
 
@@ -382,52 +405,82 @@ int ctkDependencyGraphTest2(int argc, char * argv [] )
 
   if( cdtd == true )
     {
-    qCritical() << "Cycle detected flag wrong";
+    std::cerr << "Cycle detected flag wrong" << std::endl;
     return EXIT_FAILURE;
     }
 
-  QList<int> sources;
+  std::list<int> sources;
   graph.sourceVertices(sources);
 
-  QList<int> expectedSources;
-  expectedSources << 1 << 5 << 10 << 12 << 13;
+  std::list<int> expectedSources;
+  expectedSources.push_back(1);
+  expectedSources.push_back(5);
+  expectedSources.push_back(10);
+  expectedSources.push_back(12);
+  expectedSources.push_back(13);
 
   if (sources != expectedSources)
     {
-    qCritical() << "Source vertices do not match (expected" << expectedSources << "got" << sources << ")";
+    std::cerr << "Problem with sourceVertices(sources)" << std::endl;
+    printIntegerList("sources:", sources);
+    printIntegerList("expectedSources:", expectedSources);
     return EXIT_FAILURE;
     }
 
-  QList<int> globalSort;
+  std::list<int> globalSort;
   graph.topologicalSort(globalSort);
 
-  QList<int> expectedGlobalSort;
-  expectedGlobalSort << 1 << 5 << 10 << 12 << 13 << 2 << 6 << 11 << 3 << 4 << 7 << 8 << 9;
+  std::list<int> expectedGlobalSort;
+  expectedGlobalSort.push_back(1);
+  expectedGlobalSort.push_back(5);
+  expectedGlobalSort.push_back(10);
+  expectedGlobalSort.push_back(12);
+  expectedGlobalSort.push_back(13);
+  expectedGlobalSort.push_back(2);
+  expectedGlobalSort.push_back(6);
+  expectedGlobalSort.push_back(11);
+  expectedGlobalSort.push_back(3);
+  expectedGlobalSort.push_back(4);
+  expectedGlobalSort.push_back(7);
+  expectedGlobalSort.push_back(8);
+  expectedGlobalSort.push_back(9);
+
   if (globalSort != expectedGlobalSort)
   {
-    qCritical() << "Topological sort error (expected" << expectedGlobalSort << "got" << globalSort << ")";
+    std::cerr << "Problem with topologicalSort(globalSort)" << std::endl;
+    printIntegerList("globalSort:", globalSort);
+    printIntegerList("expectedGlobalSort:", expectedGlobalSort);
     return EXIT_FAILURE;
   }
 
-  QList<int> subSort10;
+  std::list<int> subSort10;
   graph.topologicalSort(subSort10, 10);
 
-  QList<int> expectedSubSort10;
-  expectedSubSort10 << 10 << 8 << 11 << 9;
+  std::list<int> expectedSubSort10;
+  expectedSubSort10.push_back(10);
+  expectedSubSort10.push_back(8);
+  expectedSubSort10.push_back(11);
+  expectedSubSort10.push_back(9);
+
   if (subSort10 != expectedSubSort10)
   {
-    qCritical() << "Topological subgraph sort error (expected" << expectedSubSort10 << "got" << subSort10 << ")";
+    std::cerr << "Problem with topologicalSort(subSort10, 10)" << std::endl;
+    printIntegerList("subSort10:", subSort10);
+    printIntegerList("expectedSubSort10:", expectedSubSort10);
     return EXIT_FAILURE;
   }
 
-  QList<int> subSort12;
+  std::list<int> subSort12;
   graph.topologicalSort(subSort12, 12);
 
-  QList<int> expectedSubSort12;
-  expectedSubSort12 << 12;
+  std::list<int> expectedSubSort12;
+  expectedSubSort12.push_back(12);
+
   if (subSort12 != expectedSubSort12)
   {
-    qCritical() << "Topological subgraph sort error (expected" << expectedSubSort12 << "got" << subSort12 << ")";
+    std::cerr << "Problem with topologicalSort(subSort12, 12)" << std::endl;
+    printIntegerList("subSort12:", subSort12);
+    printIntegerList("expectedSubSort12:", expectedSubSort12);
     return EXIT_FAILURE;
   }
 
@@ -450,14 +503,14 @@ int ctkDependencyGraphTest2(int argc, char * argv [] )
 
   if( nov != numberOfVertices )
     {
-    qCritical() << "Number of vertices does not match (expected" << numberOfVertices << "got" << nov << ")";
+    std::cerr << "Number of vertices does not match (expected" << numberOfVertices << " got " << nov << ")" << std::endl;
     return EXIT_FAILURE;
     }
 
   int noe = graph.numberOfEdges();
   if( noe != expectedNumberOfEdge )
     {
-    qCritical() << "Number of edges does not match (expected" << expectedNumberOfEdge << "got" << noe << ")";
+    std::cerr << "Number of edges does not match (expected" << expectedNumberOfEdge << " got " << noe << ")" << std::endl;
     return EXIT_FAILURE;
     }
 
@@ -465,7 +518,7 @@ int ctkDependencyGraphTest2(int argc, char * argv [] )
 
   if( cfc == true )
     {
-    qCritical() << "Cycle detection failed";
+    std::cerr << "Cycle detection failed" << std::endl;
     return EXIT_FAILURE;
     }
 
@@ -473,41 +526,52 @@ int ctkDependencyGraphTest2(int argc, char * argv [] )
 
   if( cdtd == true )
     {
-    qCritical() << "Cycle detected flag wrong";
+    std::cerr << "Cycle detected flag wrong" << std::endl;
     return EXIT_FAILURE;
     }
 
-  QList<int> sources;
+  std::list<int> sources;
   graph.sourceVertices(sources);
 
-  QList<int> expectedSources;
-  expectedSources << 1 << 2 << 3;
+  std::list<int> expectedSources;
+  expectedSources.push_back(1);
+  expectedSources.push_back(2);
+  expectedSources.push_back(3);
 
   if (sources != expectedSources)
     {
-    qCritical() << "Source vertices do not match (expected" << expectedSources << "got" << sources << ")";
+    std::cerr << "Problem with sourceVertices(sources)" << std::endl;
+    printIntegerList("sources:", sources);
+    printIntegerList("expectedSources:", expectedSources);
     return EXIT_FAILURE;
     }
 
-  QList<int> globalSort;
+  std::list<int> globalSort;
   graph.topologicalSort(globalSort);
 
-  QList<int> expectedGlobalSort;
-  expectedGlobalSort << 1 << 2 << 3;
+  std::list<int> expectedGlobalSort;
+  expectedGlobalSort.push_back(1);
+  expectedGlobalSort.push_back(2);
+  expectedGlobalSort.push_back(3);
+
   if (globalSort != expectedGlobalSort)
   {
-    qCritical() << "Topological sort error (expected" << expectedGlobalSort << "got" << globalSort << ")";
+    std::cerr << "Problem with topologicalSort(globalSort)" << std::endl;
+    printIntegerList("globalSort:", globalSort);
+    printIntegerList("expectedGlobalSort:", expectedGlobalSort);
     return EXIT_FAILURE;
   }
 
-  QList<int> subSort2;
+  std::list<int> subSort2;
   graph.topologicalSort(subSort2, 2);
 
-  QList<int> expectedSubSort2;
-  expectedSubSort2 << 2;
+  std::list<int> expectedSubSort2;
+  expectedSubSort2.push_back(2);
   if (subSort2 != expectedSubSort2)
   {
-    qCritical() << "Topological subgraph sort error (expected" << expectedSubSort2 << "got" << subSort2 << ")";
+    std::cerr << "Problem with topologicalSort(subSort2, 2)" << std::endl;
+    printIntegerList("subSort2:", subSort2);
+    printIntegerList("expectedSubSort2:", expectedSubSort2);
     return EXIT_FAILURE;
   }
 

+ 46 - 0
Libs/Core/Testing/Cpp/ctkDependencyGraphTestHelper.h

@@ -0,0 +1,46 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0.txt
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+#ifndef __ctkDependencyGraphTestHelper_h
+#define __ctkDependencyGraphTestHelper_h
+
+#include <list>
+#include <iostream>
+
+namespace
+{
+
+void printIntegerList(const char* msg, const std::list<int>& list, bool endl = true)
+{
+  std::cerr << msg;
+  std::list<int>::const_iterator iter;
+  for (iter = list.begin(); iter != list.end(); iter++)
+    {
+    std::cerr << *iter << " ";
+    }
+  if (endl)
+    {
+    std::cerr << std::endl;
+    }
+}
+
+}
+
+#endif // end __ctkDependencyGraphTestHelper_h

+ 260 - 189
Libs/Core/ctkDependencyGraph.cpp

@@ -18,16 +18,19 @@
 
 =========================================================================*/
 
-// Qt includes
-#include <QQueue>
-#include <QVarLengthArray>
-#include <QDebug>
-
 // CTK includes
 #include "ctkDependencyGraph.h"
 
 // STD includes
 #include <iostream>
+#include <sstream>
+#include <algorithm>
+#include <vector>
+#include <set>
+#include <map>
+#include <list>
+#include <queue>
+#include <cassert>
 
 #define MAXV 100
 #define MAXDEGREE 50
@@ -35,16 +38,16 @@
 //----------------------------------------------------------------------------
 class ctkDependencyGraphPrivate
 {
-  Q_DECLARE_PUBLIC(ctkDependencyGraph);
 
 public:
 
   ctkDependencyGraph* const q_ptr;
 
   ctkDependencyGraphPrivate(ctkDependencyGraph& p);
+  ~ctkDependencyGraphPrivate();
   
   /// Compute outdegree
-  void computeOutdegrees(QVarLengthArray<int, MAXV>& computedOutdegrees);
+  void computeOutdegrees(std::vector<int>& computedOutdegrees);
   
   /// Traverse tree using Depth-first_search
   void traverseUsingDFS(int v);
@@ -56,38 +59,38 @@ public:
   void processVertex(int v);
 
   /// Retrieve the path between two vertices
-  void findPathDFS(int from, int to, QList<int>& path);
+  void findPathDFS(int from, int to, std::list<int>& path);
 
   /// Recursive function used by findPaths to retrieve the path between two vertices
-  void findPathsRec(int from, int to, QList<int>* path, QList<QList<int>* >& paths);
+  void findPathsRec(int from, int to, std::list<int>* path, std::list<std::list<int>* >& paths);
   
   void setEdge(int vertice, int degree, int value);
   int edge(int vertice, int degree)const;
 
-  void verticesWithIndegree(int indegree, QList<int>& list);
+  void verticesWithIndegree(int indegree, std::list<int>& list);
 
   int subgraphSize(int rootId);
-  void subgraphSizeRec(int rootId, QSet<int>& uniqueVertices);
+  void subgraphSizeRec(int rootId, std::set<int>& uniqueVertices);
 
   void subgraphInsert(ctkDependencyGraph& subgraph, int rootId,
-                      QHash<int,int>& subgraphIdToGlobal, QHash<int,int>& globalIdToSubgraph);
+                      std::map<int,int>& subgraphIdToGlobal, std::map<int,int>& globalIdToSubgraph);
 
-  int getOrGenerateSubgraphId(QHash<int, int>& subgraphIdToGlobal,
-                      QHash<int, int>& globalIdToSubgraph,
+  int getOrGenerateSubgraphId(std::map<int, int>& subgraphIdToGlobal,
+                      std::map<int, int>& globalIdToSubgraph,
                       int globalId);
 
   /// See http://en.wikipedia.org/wiki/Adjacency_list
-  QVarLengthArray<QVarLengthArray<int,MAXDEGREE>*, MAXV+1> Edges;
-  QVarLengthArray<int, MAXV+1> OutDegree;
-  QVarLengthArray<int, MAXV+1> InDegree;
+  std::vector<std::vector<int>* > Edges;
+  std::vector<int> OutDegree;
+  std::vector<int> InDegree;
   int NVertices;
   int NEdges;
   
   /// Structure used by DFS
   /// See http://en.wikipedia.org/wiki/Depth-first_search
-  QVarLengthArray<bool, MAXV> Processed;	// processed vertices
-  QVarLengthArray<bool, MAXV> Discovered; // discovered vertices
-  QVarLengthArray<int, MAXV>  Parent;	    // relation discovered
+  std::vector<bool> Processed;	// processed vertices
+  std::vector<bool> Discovered; // discovered vertices
+  std::vector<int>  Parent;	    // relation discovered
   
   bool    Abort;	// Flag indicating if traverse should be aborted
   bool    Verbose; 
@@ -95,11 +98,61 @@ public:
   int     CycleOrigin; 
   int     CycleEnd;
   
-  QList<int> ListOfEdgeToExclude;
-  
+  std::list<int> ListOfEdgeToExclude;
+
 };
 
 //----------------------------------------------------------------------------
+// Returns a space separated string of T.
+template<class T>
+std::string listToString(const std::list<T>& list)
+{
+  std::stringstream outputString;
+
+  typename std::list<T>::const_iterator iter;
+  for (iter = list.begin(); iter != list.end(); iter++)
+    {
+    outputString << *iter << " ";
+    }
+
+  return outputString.str();
+}
+
+//----------------------------------------------------------------------------
+// Returns true if the map contains the key and false otherwise.
+template<class T1, class T2>
+bool mapContainsKey(const std::map<T1, T2>& map, const T1& key)
+{
+  bool result = false;
+
+  if (map.find(key) != map.end())
+    {
+    result = true;
+    }
+
+  return result;
+}
+
+//----------------------------------------------------------------------------
+// Returns true if the list contains the value and false otherwise.
+template<class T>
+bool listContainsValue(const std::list<T>& list, const T& value)
+{
+  bool result = false;
+
+  typename std::list<T>::const_iterator iter;
+  for (iter = list.begin(); iter != list.end(); iter++)
+    {
+    if ((*iter) == value)
+      {
+      result = true;
+      break;
+      }
+    }
+  return result;
+}
+
+//----------------------------------------------------------------------------
 // ctkInternal methods
 
 //----------------------------------------------------------------------------
@@ -115,8 +168,20 @@ ctkDependencyGraphPrivate::ctkDependencyGraphPrivate(ctkDependencyGraph& object)
   this->CycleEnd = 0;
 }
 
+ctkDependencyGraphPrivate::~ctkDependencyGraphPrivate()
+{
+  std::vector<std::vector<int>* >::iterator edgesIterator;
+  for (edgesIterator = this->Edges.begin(); edgesIterator != this->Edges.end(); edgesIterator++)
+    {
+    if (*edgesIterator != NULL)
+      {
+      delete *edgesIterator;
+      }
+    }
+}
+
 //----------------------------------------------------------------------------
-void ctkDependencyGraphPrivate::computeOutdegrees(QVarLengthArray<int, MAXV>& computedOutdegrees)
+void ctkDependencyGraphPrivate::computeOutdegrees(std::vector<int>& computedOutdegrees)
 {
 	for (int i=1; i <= this->NVertices; i++)
 	  {
@@ -135,7 +200,6 @@ void ctkDependencyGraphPrivate::computeOutdegrees(QVarLengthArray<int, MAXV>& co
 //----------------------------------------------------------------------------
 void ctkDependencyGraphPrivate::traverseUsingDFS(int v)
 {
-  Q_Q(ctkDependencyGraph);
   // allow for search termination
 	if (this->Abort)
 	  {
@@ -149,7 +213,7 @@ void ctkDependencyGraphPrivate::traverseUsingDFS(int v)
   for (int i=0; i<this->OutDegree[v]; i++)
 	  {
 		y = this->edge(v, i);
-		if (q->shouldExcludeEdge(this->edge(v, i)) == false)
+		if (q_ptr->shouldExcludeEdge(this->edge(v, i)) == false)
 		  {
       this->Parent[y] = v;
 			if (this->Discovered[y] == false)
@@ -183,13 +247,13 @@ void ctkDependencyGraphPrivate::processEdge(int from, int to)
     this->CycleEnd = from;
     if (this->Verbose)
       {
-      QList<int> path;
+      std::list<int> path;
       this->findPathDFS(from, to, path);
-      qWarning() << "Cycle detected from " << to << " to " << from;
-      qWarning() << " " << path;
+      std::cerr << "ERROR: Cycle detected from " << to << " to " << from << std::endl;
+      std::cerr << " " << listToString<int>(path) << std::endl;
       path.clear();
       this->findPathDFS(to, from, path);
-      qWarning() << " " << path;
+      std::cerr << " " << listToString<int>(path) << std::endl;
       }
     this->Abort = true;
     }
@@ -200,109 +264,115 @@ void ctkDependencyGraphPrivate::processVertex(int v)
 {
 	if (this->Verbose)
 	  {
-	  qDebug() << "processed vertex " << v;
+	  std::cout << "processed vertex " << v << std::endl;
 	  }
 }
 
 //----------------------------------------------------------------------------
 void ctkDependencyGraphPrivate::setEdge(int vertice, int degree, int value)
 {
-  Q_ASSERT(vertice <= this->NVertices);
-  Q_ASSERT(degree < MAXDEGREE);
+  assert(vertice <= this->NVertices);
+  assert(degree < MAXDEGREE);
   (*this->Edges[vertice])[degree] = value; 
 }
 
 //----------------------------------------------------------------------------
 int ctkDependencyGraphPrivate::edge(int vertice, int degree)const
 {
-  Q_ASSERT(vertice <= this->NVertices);
-  Q_ASSERT(degree < MAXDEGREE);
+  assert(vertice <= this->NVertices);
+  assert(degree < MAXDEGREE);
   return (*this->Edges[vertice])[degree];
 }
 
 //----------------------------------------------------------------------------
-void ctkDependencyGraphPrivate::findPathDFS(int from, int to, QList<int>& path)
+void ctkDependencyGraphPrivate::findPathDFS(int from, int to, std::list<int>& path)
 {
   if ((from == to) || (to == -1))
     {
-    path << from;
+    path.push_back(from);
     }
   else 
     {
     this->findPathDFS(from, this->Parent[to], path);
-    path << to;
+    path.push_back(to);
     }
 }
 
 //----------------------------------------------------------------------------
 void ctkDependencyGraphPrivate::findPathsRec(
-  int from, int to, QList<int>* path, QList<QList<int>* >& paths)
+  int from, int to, std::list<int>* path, std::list<std::list<int>* >& paths)
 {
   if (from == to)
     {
     return;
     }
   
-  QList<int> branch(*path);
+  std::list<int> branch;
+  branch = *path;
+
   int child = from;
   for (int j=0; j < this->OutDegree[child]; j++)
     {
     if (j == 0)
       {
       int parent = this->edge(child, j);
-      *path << parent;
+      (*path).push_back(parent);
       this->findPathsRec(parent, to, path, paths);
       }
     else
       {
       int parent = this->edge(child, j);
       // Copy path and add it to the list
-      QList<int>* pathCopy = new QList<int>(branch);
-      paths << pathCopy;
-      *pathCopy << parent;
+      std::list<int>* pathCopy = new std::list<int>();
+      *pathCopy = branch;
+      paths.push_back(pathCopy);
+      (*pathCopy).push_back(parent);
       this->findPathsRec(parent, to, pathCopy, paths);
       }
     }
 }
 
-void ctkDependencyGraphPrivate::verticesWithIndegree(int indegree, QList<int>& list)
+//----------------------------------------------------------------------------
+void ctkDependencyGraphPrivate::verticesWithIndegree(int indegree, std::list<int>& list)
 {
-  Q_ASSERT(indegree >= 0);
+  assert(indegree >= 0);
 
   for (int i=1; i <= this->NVertices; i++)
     {
     if (this->InDegree[i] == indegree)
       {
-      list << i;
+      list.push_back(i);
       }
     }
 }
 
-void ctkDependencyGraphPrivate::subgraphSizeRec(int rootId, QSet<int>& uniqueVertices)
+//----------------------------------------------------------------------------
+void ctkDependencyGraphPrivate::subgraphSizeRec(int rootId, std::set<int>& uniqueVertices)
 {
-  Q_ASSERT(rootId > 0);
+  assert(rootId > 0);
 
   for (int i = 0; i < this->OutDegree[rootId]; ++i)
     {
     int child = this->edge(rootId, i);
-    uniqueVertices << child;
+    uniqueVertices.insert(child);
     subgraphSizeRec(child, uniqueVertices);
     }
 }
 
+//----------------------------------------------------------------------------
 int ctkDependencyGraphPrivate::subgraphSize(int rootId)
 {
-  Q_ASSERT(rootId > 0);
+  assert(rootId > 0);
 
-  QSet<int> vertices;
-  vertices << rootId;
+  std::set<int> vertices;
+  vertices.insert(rootId);
   this->subgraphSizeRec(rootId, vertices);
   return vertices.size();
 }
 
 void ctkDependencyGraphPrivate::subgraphInsert(
     ctkDependencyGraph& subgraph, int rootId,
-    QHash<int,int>& subgraphIdToGlobal, QHash<int,int>& globalIdToSubgraph)
+    std::map<int,int>& subgraphIdToGlobal, std::map<int,int>& globalIdToSubgraph)
 {
   int from = this->getOrGenerateSubgraphId(subgraphIdToGlobal, globalIdToSubgraph, rootId);
   for (int i = 0; i < this->OutDegree[rootId]; ++i)
@@ -316,16 +386,17 @@ void ctkDependencyGraphPrivate::subgraphInsert(
   }
 }
 
+//----------------------------------------------------------------------------
 int ctkDependencyGraphPrivate::getOrGenerateSubgraphId(
-    QHash<int, int>& subgraphIdToGlobal,
-    QHash<int, int>& globalIdToSubgraph,
+    std::map<int, int>& subgraphIdToGlobal,
+    std::map<int, int>& globalIdToSubgraph,
     int globalId)
 {
   // If needed, generate vertex id
   int subgraphId = -1;
-  if (!globalIdToSubgraph.keys().contains(globalId))
+  if (!mapContainsKey<int, int>(globalIdToSubgraph,globalId))
     {
-    subgraphId = globalIdToSubgraph.keys().size() + 1;
+    subgraphId = globalIdToSubgraph.size() + 1;
     globalIdToSubgraph[globalId] = subgraphId;
     subgraphIdToGlobal[subgraphId] = globalId;
     }
@@ -335,7 +406,7 @@ int ctkDependencyGraphPrivate::getOrGenerateSubgraphId(
     }
   return subgraphId;
 }
-    
+
 //----------------------------------------------------------------------------
 // ctkDependencyGraph methods
 
@@ -343,88 +414,83 @@ int ctkDependencyGraphPrivate::getOrGenerateSubgraphId(
 ctkDependencyGraph::ctkDependencyGraph(int nvertices)
   :d_ptr(new ctkDependencyGraphPrivate(*this))
 {
-  Q_D(ctkDependencyGraph);
-  d->NVertices = nvertices; 
+  d_ptr->NVertices = nvertices;
   
   // Resize internal array
-  d->Processed.resize(nvertices + 1);
-  d->Discovered.resize(nvertices + 1);
-  d->Parent.resize(nvertices + 1);
-  d->Edges.resize(nvertices + 1);
-  d->OutDegree.resize(nvertices + 1);
-  d->InDegree.resize(nvertices + 1);
+  d_ptr->Processed.resize(nvertices + 1);
+  d_ptr->Discovered.resize(nvertices + 1);
+  d_ptr->Parent.resize(nvertices + 1);
+  d_ptr->Edges.resize(nvertices + 1);
+  d_ptr->OutDegree.resize(nvertices + 1);
+  d_ptr->InDegree.resize(nvertices + 1);
 
   for (int i=1; i <= nvertices; i++)
     {
-    d->OutDegree[i] = 0;
-    d->InDegree[i] = 0;
+    d_ptr->OutDegree[i] = 0;
+    d_ptr->InDegree[i] = 0;
     }
     
   // initialize Edge adjacency list
   for (int i=0; i <= nvertices; i++)
     {
-    d->Edges[i] = new QVarLengthArray<int, MAXDEGREE>();
-    d->Edges[i]->resize(MAXDEGREE);
+    d_ptr->Edges[i] = new std::vector<int>();
+    d_ptr->Edges[i]->resize(MAXDEGREE);
     }
     
   // initialize search
   for (int i=1; i <= nvertices; i++)
     {
-    d->Processed[i] = false;
-    d->Discovered[i] = false;
-    d->Parent[i] = -1;
+    d_ptr->Processed[i] = false;
+    d_ptr->Discovered[i] = false;
+    d_ptr->Parent[i] = -1;
     }
 }
 
 //----------------------------------------------------------------------------
 ctkDependencyGraph::~ctkDependencyGraph()
 {
-  Q_D(ctkDependencyGraph);
-  // Clean memory
-  for (int i=0; i <= d->NVertices; i++)
+  if (d_ptr != NULL)
     {
-    delete d->Edges[i];
+    delete d_ptr;
     }
 }
 
 //----------------------------------------------------------------------------
 void ctkDependencyGraph::printAdditionalInfo()const
 {
-  Q_D(const ctkDependencyGraph);
-  qDebug() << "ctkDependencyGraph (" << this << ")" << endl
-           << " NVertices:" << this->numberOfVertices() << endl
-           << " NEdges:" << this->numberOfEdges() << endl
-           << " Abort:" << d->Abort;
-           
-  qDebug() << " [Processed]";
-  for(int i=1; i < d->Processed.size(); i++)
+  std::cout << "ctkDependencyGraph (" << this << ")" << std::endl
+            << " NVertices:" << this->numberOfVertices() << std::endl
+            << " NEdges:" << this->numberOfEdges() << std::endl
+            << " Abort:" << d_ptr->Abort << std::endl;
+
+  std::cout << " [Processed]" << std::endl;
+  for(unsigned int i=1; i < d_ptr->Processed.size(); i++)
     {
-    qDebug() << i << "->" << d->Processed[i];
+    std::cout << i << "->" << d_ptr->Processed[i] << std::endl;
     }
-  qDebug() << " [Discovered]";
-  for(int i=1; i < d->Discovered.size(); i++)
+  std::cout << " [Discovered]" << std::endl;
+  for(unsigned int i=1; i < d_ptr->Discovered.size(); i++)
     {
-    qDebug() << i << "->" << d->Discovered[i];
+    std::cout << i << "->" << d_ptr->Discovered[i] << std::endl;
     }
-  qDebug() << " [Parent]";
-  for(int i=1; i < d->Parent.size(); i++)
+  std::cout << " [Parent]" << std::endl;
+  for(unsigned int i=1; i < d_ptr->Parent.size(); i++)
     {
-    qDebug() << i << "->" << d->Parent[i];
+    std::cout << i << "->" << d_ptr->Parent[i] << std::endl;
     }
-  qDebug() << " [Graph]"; 
+  std::cout << " [Graph]" << std::endl;
   this->printGraph();
 }
 
 //----------------------------------------------------------------------------
 void ctkDependencyGraph::printGraph()const
 {
-  Q_D(const ctkDependencyGraph);
-  for(int i=1; i <= d->NVertices; i++)
+  for(int i=1; i <= d_ptr->NVertices; i++)
     {
     std::cout << i << ":";
-    for (int j=0; j < d->OutDegree[i]; j++)
+    for (int j=0; j < d_ptr->OutDegree[i]; j++)
       {
-      std::cout << " " << d->edge(i, j);
+      std::cout << " " << d_ptr->edge(i, j);
       }
     std::cout << std::endl;
     }
@@ -433,68 +499,63 @@ void ctkDependencyGraph::printGraph()const
 //----------------------------------------------------------------------------
 int ctkDependencyGraph::numberOfVertices()const
 {
-  Q_D(const ctkDependencyGraph);
-  return d->NVertices;
+  return d_ptr->NVertices;
 }
 
 //----------------------------------------------------------------------------
 int ctkDependencyGraph::numberOfEdges()const
 {
-  Q_D(const ctkDependencyGraph);
-  return d->NEdges;
+  return d_ptr->NEdges;
 }
 
 //----------------------------------------------------------------------------
 void ctkDependencyGraph::setVerbose(bool verbose)
 {
-  Q_D(ctkDependencyGraph);
-  d->Verbose = verbose;
+  d_ptr->Verbose = verbose;
 }
 
 //----------------------------------------------------------------------------
-void ctkDependencyGraph::setEdgeListToExclude(const QList<int>& list)
+void ctkDependencyGraph::setEdgeListToExclude(const std::list<int>& list)
 {
-  Q_D(ctkDependencyGraph);
-  d->ListOfEdgeToExclude = list;
+  d_ptr->ListOfEdgeToExclude = list;
 }
 
 //----------------------------------------------------------------------------
 bool ctkDependencyGraph::shouldExcludeEdge(int edge)const
 {
-  Q_D(const ctkDependencyGraph);
-  return d->ListOfEdgeToExclude.contains(edge);
+  return listContainsValue(d_ptr->ListOfEdgeToExclude, edge);
 }
 
 //----------------------------------------------------------------------------
 bool ctkDependencyGraph::checkForCycle()
 {
-  Q_D(ctkDependencyGraph);
-  if (d->NEdges > 0)
+  if (d_ptr->NEdges > 0)
     {
     // Store unprocessed vertex ids
-    QList<int> uncheckedVertices;
-    for (int i = 1; i <= d->NVertices; ++i)
+    std::list<int> uncheckedVertices;
+    for (int i = 1; i <= d_ptr->NVertices; ++i)
       {
-        uncheckedVertices << i;
+        uncheckedVertices.push_back(i);
       }
 
     // Start the cycle detection on the source vertices
-    QList<int> sources;
+    std::list<int> sources;
     this->sourceVertices(sources);
-    foreach(int sourceId, sources)
+    std::list<int>::const_iterator sourcesIterator;
+    for (sourcesIterator = sources.begin(); sourcesIterator != sources.end(); sourcesIterator++)
       {
-      d->traverseUsingDFS(sourceId);
+      d_ptr->traverseUsingDFS(*sourcesIterator);
       if (this->cycleDetected()) return true;
 
-      for (int i=0; i < d->Processed.size(); i++)
+      for (unsigned int i=0; i < d_ptr->Processed.size(); i++)
         {
-          if (d->Processed[i] == true)
+          if (d_ptr->Processed[i] == true)
             {
-            uncheckedVertices.removeOne(i);
+            uncheckedVertices.remove(i);
             }
 
-          d->Discovered[i] = false;
-          d->Processed[i] = false;
+          d_ptr->Discovered[i] = false;
+          d_ptr->Processed[i] = false;
         }
       }
 
@@ -503,18 +564,18 @@ bool ctkDependencyGraph::checkForCycle()
     // processed vertices.
     while (!uncheckedVertices.empty())
       {
-      d->traverseUsingDFS(uncheckedVertices.last());
+      d_ptr->traverseUsingDFS((*uncheckedVertices.rbegin()));
       if (this->cycleDetected()) return true;
 
-      for (int i=0; i < d->Processed.size(); i++)
+      for (unsigned int i=0; i < d_ptr->Processed.size(); i++)
         {
-          if (d->Processed[i] == true)
+          if (d_ptr->Processed[i] == true)
             {
-            uncheckedVertices.removeOne(i);
+            uncheckedVertices.remove(i);
             }
 
-          d->Discovered[i] = false;
-          d->Processed[i] = false;
+          d_ptr->Discovered[i] = false;
+          d_ptr->Processed[i] = false;
         }
       }
     }
@@ -524,125 +585,134 @@ bool ctkDependencyGraph::checkForCycle()
 //----------------------------------------------------------------------------
 bool ctkDependencyGraph::cycleDetected()const
 {
-  Q_D(const ctkDependencyGraph);
-  return d->CycleDetected;
+  return d_ptr->CycleDetected;
 }
 
 //----------------------------------------------------------------------------
 int ctkDependencyGraph::cycleOrigin()const
 {
-  Q_D(const ctkDependencyGraph);
-  return d->CycleOrigin;
+  return d_ptr->CycleOrigin;
 }
 
 //----------------------------------------------------------------------------
 int ctkDependencyGraph::cycleEnd()const
 {
-  Q_D(const ctkDependencyGraph);
-  return d->CycleEnd;
+  return d_ptr->CycleEnd;
 }
 
 //----------------------------------------------------------------------------
 void ctkDependencyGraph::insertEdge(int from, int to)
 {
-  Q_D(ctkDependencyGraph);
-  Q_ASSERT(from > 0 && from <= d->NVertices);
-  Q_ASSERT(to > 0 && to <= d->NVertices);
+  assert(from > 0 && from <= d_ptr->NVertices);
+  assert(to > 0 && to <= d_ptr->NVertices);
   
   // resize if needed
-  int capacity = d->Edges[from]->capacity(); 
-  if (d->OutDegree[from] > capacity)
+  int capacity = d_ptr->Edges[from]->capacity();
+  if (d_ptr->OutDegree[from] > capacity)
     {
-    d->Edges[from]->resize(capacity + capacity * 0.3);
+    d_ptr->Edges[from]->resize(capacity + capacity * 0.3);
     }
 
-  d->setEdge(from, d->OutDegree[from], to);
-  d->OutDegree[from]++;
-  d->InDegree[to]++;
+  d_ptr->setEdge(from, d_ptr->OutDegree[from], to);
+  d_ptr->OutDegree[from]++;
+  d_ptr->InDegree[to]++;
 
-  d->NEdges++;
+  d_ptr->NEdges++;
 }
 
 //----------------------------------------------------------------------------
-void ctkDependencyGraph::findPaths(int from, int to, QList<QList<int>* >& paths)
+void ctkDependencyGraph::findPaths(int from, int to, std::list<std::list<int>* >& paths)
 {
-  Q_D(ctkDependencyGraph);
-  QList<int>* path = new QList<int>;
-  *path << from; 
-  paths << path;
-  d->findPathsRec(from, to, path, paths);
+  std::list<int>* path = new std::list<int>;
+  (*path).push_back(from);
+  (paths).push_back(path);
+  d_ptr->findPathsRec(from, to, path, paths);
+
+  // Remove lists not ending with the requested element
+  std::list<std::list<int>* >::iterator pathsIterator;
+  pathsIterator = paths.begin();
 
-  QList<int> pathToRemove;
-  // Remove list no ending with the requested element
-  int i = 0; 
-  while (!paths.isEmpty() && i < paths.size())
+  while (paths.size() > 0 && pathsIterator != paths.end())
     {
-    QList<int>* path = paths[i];
-    Q_ASSERT(path);
-    if (path->last() != to)
+    std::list<int>* pathToCheck = (*pathsIterator);
+    assert(pathToCheck);
+
+    if (*(pathToCheck->rbegin()) != to)
       {
-      paths.removeAt(i);
-      delete path; 
+      pathsIterator = paths.erase(pathsIterator);
       }
     else
       {
-      i++;
+      pathsIterator++;
       }
     }
 }
 
 //----------------------------------------------------------------------------
-void ctkDependencyGraph::findPath(int from, int to, QList<int>& path)
+void ctkDependencyGraph::findPath(int from, int to, std::list<int>& path)
 {
-  QList<QList<int>* > paths;
+  std::list<std::list<int>* > paths;
   this->findPaths(from, to, paths);
+
   if (!paths.empty())
     {
-    path << *(paths.first());
+    std::list<int>::iterator pathIterator;
+    for (pathIterator = (*(paths.begin()))->begin(); pathIterator != (*(paths.begin()))->end(); pathIterator++)
+      {
+      path.push_back(*pathIterator);
+      }
     }
 
-  qDeleteAll(paths);
+  std::list<std::list<int>* >::iterator pathsIterator;
+  for(pathsIterator = paths.begin(); pathsIterator != paths.end(); pathsIterator++)
+  {
+    if (*pathsIterator != NULL)
+    {
+      delete *pathsIterator;
+    }
+  }
 }
 
 //----------------------------------------------------------------------------
-bool ctkDependencyGraph::topologicalSort(QList<int>& sorted, int rootId)
+bool ctkDependencyGraph::topologicalSort(std::list<int>& sorted, int rootId)
 {
-  Q_D(ctkDependencyGraph);
   if (rootId > 0)
     {
-    ctkDependencyGraph subgraph(d->subgraphSize(rootId));
-    QHash<int,int> subgraphIdToGlobal;
-    QHash<int,int> globalIdToSubgraph;
-    d->subgraphInsert(subgraph, rootId, subgraphIdToGlobal, globalIdToSubgraph);
+    ctkDependencyGraph subgraph(d_ptr->subgraphSize(rootId));
+    std::map<int,int> subgraphIdToGlobal;
+    std::map<int,int> globalIdToSubgraph;
+    d_ptr->subgraphInsert(subgraph, rootId, subgraphIdToGlobal, globalIdToSubgraph);
 
-    QList<int> subgraphSorted;
+    std::list<int> subgraphSorted;
     bool result = subgraph.topologicalSort(subgraphSorted);
-    foreach(int subgraphId, subgraphSorted)
+    std::list<int>::const_iterator subgraphSortedIterator;
+    for (subgraphSortedIterator = subgraphSorted.begin(); subgraphSortedIterator != subgraphSorted.end(); subgraphSortedIterator++)
       {
-      sorted << subgraphIdToGlobal[subgraphId];
+      sorted.push_back(subgraphIdToGlobal[*subgraphSortedIterator]);
       }
     return result;
     }
 
-  QVarLengthArray<int, MAXV> outdegree; // outdegree of each vertex
-  QQueue<int> zeroout;	  // vertices of outdegree 0
+  std::vector<int> outdegree; // outdegree of each vertex
+  outdegree.resize(MAXV);
+  std::queue<int> zeroout;	  // vertices of outdegree 0
 	int x, y;			        // current and next vertex
   
-  outdegree.resize(d->NVertices + 1);
+  outdegree.resize(d_ptr->NVertices + 1);
 	
 	// resize if needed
-	if (d->NVertices > MAXV)
+	if (d_ptr->NVertices > MAXV)
 	  {
-    outdegree.resize(d->NVertices);
+    outdegree.resize(d_ptr->NVertices);
 	  }
 
-  d->computeOutdegrees(outdegree);
+	d_ptr->computeOutdegrees(outdegree);
 	
-	for (int i=1; i <= d->NVertices; i++)
+	for (int i=1; i <= d_ptr->NVertices; i++)
 	  {
     if (outdegree[i] == 0)
 		  {
-      zeroout.enqueue(i);
+      zeroout.push(i);
 		  }
 		}
 
@@ -650,20 +720,21 @@ bool ctkDependencyGraph::topologicalSort(QList<int>& sorted, int rootId)
   while (zeroout.empty() == false)
 	  {
 		j = j+1;
-    x = zeroout.dequeue();
-		sorted << x;
-    for (int i=0; i < d->OutDegree[x]; i++)
+    x = zeroout.front();
+    zeroout.pop();
+		sorted.push_back(x);
+    for (int i=0; i < d_ptr->OutDegree[x]; i++)
 		  {
-			y = d->edge(x, i);
+			y = d_ptr->edge(x, i);
       outdegree[y] --;
       if (outdegree[y] == 0)
 			  {
-        zeroout.enqueue(y);
+        zeroout.push(y);
 			  }
 		  }
 	  }
 
-	if (j != d->NVertices)
+	if (j != d_ptr->NVertices)
 	  {
 		return false;
 		}
@@ -671,8 +742,8 @@ bool ctkDependencyGraph::topologicalSort(QList<int>& sorted, int rootId)
   return true;
 }
 
-void ctkDependencyGraph::sourceVertices(QList<int>& sources)
+//----------------------------------------------------------------------------
+void ctkDependencyGraph::sourceVertices(std::list<int>& sources)
 {
-  Q_D(ctkDependencyGraph);
-  d->verticesWithIndegree(0, sources);
+  d_ptr->verticesWithIndegree(0, sources);
 }

+ 15 - 14
Libs/Core/ctkDependencyGraph.h

@@ -21,21 +21,20 @@
 #ifndef __ctkDependencyGraph_h
 #define __ctkDependencyGraph_h
 
-// Qt includes
-#include <QScopedPointer>
-#include <QString>
-#include <QList>
-#include <QtGlobal>
-
 // CTK includes
 #if !defined(NO_SYMBOL_EXPORT)
 #include "ctkCoreExport.h"
 #else
 #define CTK_CORE_EXPORT
 #endif
+
+#include <list>
+
 class ctkDependencyGraphPrivate;
 
 /// \ingroup Core
+/// \class ctkDependencyGraph
+/// \brief Class to implement a dependency graph, converted to STL instead of Qt.
 class CTK_CORE_EXPORT ctkDependencyGraph
 {
 public:
@@ -73,14 +72,14 @@ public:
 
   /// Retrieve the paths between two vertices
   /// Caller is responsible to clear paths list
-  void findPaths(int from, int to, QList<QList<int>* >& paths);
+  void findPaths(int from, int to, std::list<std::list<int>* >& paths);
   
   /// Retrieve the path between two vertices
-  void findPath(int from, int to, QList<int>& path);
+  void findPath(int from, int to, std::list<int>& path);
   
   /// List of edge to exclude
   /// An edge is specified using its extremity
-  void setEdgeListToExclude(const QList<int>& list);
+  void setEdgeListToExclude(const std::list<int>& list);
   
   /// The default implementation check if 'edge' is in the list of edge to exclude
   /// See setEdgeListToExclude
@@ -93,17 +92,19 @@ public:
   /// Return false if the graph contains cycles
   /// If a rootId is given, the subgraph starting at the root id is sorted
   /// See cycleDetected, cycleOrigin, cycleEnd
-  bool topologicalSort(QList<int>& sorted, int rootId = -1);
+  bool topologicalSort(std::list<int>& sorted, int rootId = -1);
 
   /// Retrieve all vertices with indegree 0
-  void sourceVertices(QList<int>& sources);
+  void sourceVertices(std::list<int>& sources);
 
 protected:
-  QScopedPointer<ctkDependencyGraphPrivate> d_ptr;
+  ctkDependencyGraphPrivate* d_ptr;
 
 private:
-  Q_DECLARE_PRIVATE(ctkDependencyGraph);
-  Q_DISABLE_COPY(ctkDependencyGraph);
+
+  // Intentionally disable copy semantics
+  ctkDependencyGraph(const ctkDependencyGraph &);
+  ctkDependencyGraph &operator=(const ctkDependencyGraph &);
 };
 
 #endif

+ 0 - 6
Utilities/DGraph/CMakeLists.txt

@@ -30,10 +30,6 @@ project(DGraph)
 
 set(CTK_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../)
 
-set(QT_DONT_USE_QTGUI TRUE)
-find_package(Qt4 4.6 REQUIRED)
-include(${QT_USE_FILE})
-
 include_directories(
   ${CMAKE_CURRENT_SOURCE_DIR}
   ${CMAKE_CURRENT_BINARY_DIR}
@@ -56,7 +52,5 @@ add_executable(${PROJECT_NAME}
   DGraph.cpp
   ${CTK_SOURCE_DIR}/Libs/Core/ctkDependencyGraph.h
   ${CTK_SOURCE_DIR}/Libs/Core/ctkDependencyGraph.cpp)
-  
-target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES} )
 
   

+ 227 - 114
Utilities/DGraph/DGraph.cpp

@@ -18,45 +18,103 @@
 
 =========================================================================*/
 
-// Qt includes
-#include <QFile>
-#include <QTextStream>
-#include <QRegExp>
-#include <QStringList>
-#include <QDebug>
-
 // CTK includes
 #include <ctkDependencyGraph.h>
 
 // STD includes
 #include <cstdlib>
 #include <iostream>
+#include <fstream>
+#include <sstream>
+#include <map>
+#include <list>
+#include <vector>
+#include <cassert>
+
+using namespace std;
 
 //----------------------------------------------------------------------------
-QString help(const QString& progName)
+std::string help(const std::string& progName)
 {
-  QString msg = "Usage: %1 <graphfile> [-paths Label | -sort Label]";
-  return msg.arg(progName);
+  std::string msg = std::string("Usage: ") + progName + std::string(" <graphfile> [-paths Label | -sort Label]");
+  return msg;
 }
 
 //----------------------------------------------------------------------------
-void displayError(const QString& progName, const QString& msg)
+void displayError(const std::string& progName, const std::string& msg)
+{
+  std::cerr << progName << std::endl << msg << std::endl << help(progName) << std::endl;
+}
+
+std::vector< std::string > splitString(const std::string& string)
 {
-  std::cerr << qPrintable(QString("%1\n%2\n%3\n").arg(progName).
-                                                 arg(msg).
-                                                 arg(help(progName)));
+  std::vector<std::string> results;
+  std::stringstream stringStream;
+  stringStream << string;
+  do
+    {
+    std::string nextString;
+    stringStream >> nextString;
+    size_t found = nextString.find_first_not_of(" ");
+    if (found != string::npos)
+      {
+      results.push_back(nextString.substr(found));
+      }
+    } while (!stringStream.eof());
+
+  return results;
+}
+
+std::string listToString(const std::list<int>& list)
+{
+  std::stringstream stream;
+
+  if (list.size() == 0)
+    {
+    stream << "empty";
+    }
+  else
+  {
+    unsigned int counter = 0;
+    std::list<int>::const_iterator iterator;
+    for (iterator = list.begin(); iterator != list.end(); iterator++)
+      {
+      stream << *iterator;
+      counter++;
+
+      if (counter != list.size())
+        {
+        stream << " ";
+        }
+      }
+  }
+  return stream.str();
+}
+
+int getLastElement(const std::list<int>& list)
+{
+  int result = -1;
+
+  if (list.size() > 0)
+    {
+    std::list<int>::const_reverse_iterator iterator;
+    iterator = list.rend();
+    result = *iterator;
+    }
+
+  return result;
 }
 
 //----------------------------------------------------------------------------
-int getOrGenerateId(QHash<int, QString>& vertexIdToLabel,
-                    QHash<QString, int>& vertexLabelToId,
-                    const QString& label)
+int getOrGenerateId(std::map<int, std::string>& vertexIdToLabel,
+                    std::map<std::string, int>& vertexLabelToId,
+                    const std::string& label)
 {
   // If needed, generate vertex id
   int vertexId = -1;
-  if (!vertexLabelToId.keys().contains(label))
+  if (vertexLabelToId.find(label) == vertexLabelToId.end())
     {
-    vertexId = vertexLabelToId.keys().size() + 1;
+    vertexId = vertexLabelToId.size() + 1;
     vertexLabelToId[label] = vertexId;
     vertexIdToLabel[vertexId] = label;
     }
@@ -72,31 +130,31 @@ int main(int argc, char** argv)
 {
   bool verbose = false;
   bool outputTopologicalOrder = true;
-  
+
   // a graph file is expected
   if (argc < 2)
     {
-    displayError(argv[0], QLatin1String("Missing one argument"));
+    displayError(argv[0], std::string("Missing one argument"));
     return EXIT_FAILURE;
     }
 
   bool outputPath = false;
   bool outputSort = false;
-  QString label;
+  std::string label;
   if (argc == 3)
     {
-    displayError(argv[0], QLatin1String("Wrong argument"));
+    displayError(argv[0], std::string("Wrong argument"));
     return EXIT_FAILURE;
     }
   if (argc == 4)
     {
-    QString arg2 = QString::fromLatin1(argv[2]);
+    std::string arg2 = std::string(argv[2]);
     if (arg2.compare("-paths")!=0 && arg2.compare("-sort")!=0)
       {
-      displayError(argv[0], QString("Wrong argument: %1").arg(arg2));
+      displayError(argv[0], std::string("Wrong argument: ") + arg2);
       return EXIT_FAILURE;
       }
-    label = QLatin1String(argv[3]);
+    label = std::string(argv[3]);
     outputTopologicalOrder = false;
     if (arg2.compare("-paths") == 0)
       {
@@ -109,97 +167,112 @@ int main(int argc, char** argv)
 
     if (verbose)
       {
-      qDebug() << "label:" << label; 
+      std::cout << "label:" << label << std::endl;
       }
     }
-    
-  QString filepath = QString::fromLatin1(argv[1]);
-  if (!QFile::exists(filepath))
+
+  // Open File.
+
+  std::string filepath = std::string(argv[1]);
+  if (verbose)
+    {
+    std::cout << "filename:" << filepath << std::endl;
+    }
+
+  std::ifstream data;
+  data.open(filepath.c_str(), ifstream::in);
+
+  if (!data.is_open())
     {
-    displayError(argv[0], QString("File '%1' doesn't exists !").arg(filepath));
+    displayError(argv[0], std::string("Failed to open file '") + filepath + "' !");
     return EXIT_FAILURE;
     }
 
-  QFile data(filepath);
-  if (!data.open(QFile::ReadOnly))
+  // Read first line, called the header.
+
+  std::string header;
+  std::getline (data, header);
+  if (verbose)
     {
-    displayError(argv[0], QString("Failed to open file '%1' !").arg(filepath));
-    return EXIT_FAILURE; 
+    std::cout << "header:" << header << std::endl;
     }
-    
-  QTextStream in(&data);
-  QString header = in.readLine();
-  if (header.isNull())
+  if (header.length() == 0)
     {
-    displayError(argv[0], QString("Failed to read Header line in file '%1' !").arg(filepath));
+    displayError(argv[0], std::string("Failed to read Header line in file '") + filepath + "' !");
     return EXIT_FAILURE;
     }
 
-  // Regular expression to extract two integers
-  QRegExp twoint_re("^([0-9]+)\\s+([0-9]+)");
+  // Extract two integers
+
+  int numberOfVertices = -1;
+  int numberOfEdges = -1;
+
+  std::stringstream stringStream;
+  stringStream << header;
+  stringStream >> numberOfVertices;
+  stringStream >> numberOfEdges;
   
-  // Extract numberOfVertices and numberOfEdges
-  int pos = twoint_re.indexIn(header.trimmed());
-  if (pos != 0)
+  if (numberOfVertices == -1 || numberOfEdges == -1)
     {
-    displayError(argv[0], QString("Error in file '%1' - First line should look like: <#Vertices> <#Edges>")
-      .arg(filepath));
+    displayError(argv[0], std::string("Error in file '") + filepath + "' - First line should look like: <#Vertices> <#Edges>");
     return EXIT_FAILURE;
     }
-  QStringList list = twoint_re.capturedTexts();
-  Q_ASSERT(list.size() == 3);
-
-  int numberOfVertices = list[1].toInt();
-  int numberOfEdges = list[2].toInt();
 
   if (verbose)
     {
-    qDebug() << "#Vertices:" << numberOfVertices << "#Edges:" << numberOfEdges;
+    std::cout << "#Vertices:" << numberOfVertices << " #Edges:" << numberOfEdges << std::endl;
     }
 
-  // Init
+  // Init dependency graph, and maps.
+
   ctkDependencyGraph mygraph(numberOfVertices);
   mygraph.setVerbose(verbose);
+  std::map<int, std::string> vertexIdToLabel;
+  std::map<std::string, int> vertexLabelToId;
 
-  // Map between vertex label and vertex id
-  QHash<int, QString> vertexIdToLabel;
-  QHash<QString, int> vertexLabelToId;
-  
-  // Regular expression to extract two label
-  QRegExp twolabel_re("^\\s*(\\S+)\\s*$|^\\s*(\\S+)\\s*(\\S+)\\s*$");
+  // Repeatedly read lines containing labels.
   
-  // Read vertex connection
+  std::string line;
   int lineNumber = 2;
-  QString line = in.readLine();
+  std::getline(data, line);
+
   do
     {
     // Skip empty line or commented line
-    if (line.isEmpty() || line.startsWith("#"))
+    if (line.length() == 0 || line[0] == '#')
       {
-      line = in.readLine();
+      std::getline(data, line);
       continue;
       }
 
-    // Extract vertex points
-    
-    int pos = twolabel_re.indexIn(line.trimmed());
-    if (pos != 0)
+    // Extract two strings
+    stringStream.clear();
+    stringStream << line;
+
+    std::vector<std::string> strings = splitString(line);
+
+    if (strings.size() < 1 || strings.size() > 2)
       {
-      displayError(argv[0], QString("Error in file '%1' - line:%2 - Expected format is: <label> [<label>]")
-        .arg(filepath).arg(lineNumber));
-      return EXIT_FAILURE;
+      stringStream << "Error in file '" << filepath << "' - line:" << lineNumber << " - Expected format is: <label> [<label>]" << std::endl;
+      std::string message;
+      stringStream >> message;
+      displayError(argv[0], message);
       }
+    
     lineNumber++;
 
-    QStringList list = twolabel_re.capturedTexts();
-    Q_ASSERT(list.size() == 4);
-
     int from = -1;
     int to = -1;
-    if (list[1].isEmpty())
+
+    if (strings.size() == 2)
       {
-      from = getOrGenerateId(vertexIdToLabel, vertexLabelToId, list[2]);
-      to = getOrGenerateId(vertexIdToLabel, vertexLabelToId, list[3]);
+      from = getOrGenerateId(vertexIdToLabel, vertexLabelToId, strings[0]);
+      to = getOrGenerateId(vertexIdToLabel, vertexLabelToId, strings[1]);
+
+      if (verbose)
+        {
+        std::cout << "Line='" << line << "', line number " << lineNumber << ", from (" << strings[0] << ", " << from << ") to (" << strings[1] << ", " << to << ")"  << std::endl;
+        }
       }
 
     if (to > -1)
@@ -210,19 +283,19 @@ int main(int argc, char** argv)
     else
       {
       // Just generate an entry in the vertexIdToLabel map
-      getOrGenerateId(vertexIdToLabel, vertexLabelToId, list[1]);
+      getOrGenerateId(vertexIdToLabel, vertexLabelToId, "");
       }
 
-    line = in.readLine();
+    std::getline(data, line);
     }
-  while (!line.isNull());
+  while (!data.eof());
 
-  Q_ASSERT(numberOfEdges == mygraph.numberOfEdges());
+  assert(numberOfEdges == mygraph.numberOfEdges());
 
   if (verbose)
     {
     mygraph.printGraph();
-    qDebug() << "> Check for cycle ...";
+    std::cout << "> Check for cycle ..." << std::endl;
     }
    
   mygraph.checkForCycle();
@@ -230,26 +303,32 @@ int main(int argc, char** argv)
   if (mygraph.cycleDetected())
     {
     std::cerr << "Cycle detected !" << std::endl;
-    QList<int> path;
+
+    std::list<int> path;
+    std::list<int>::iterator pathIterator;
+    unsigned int pathIteratorCounter = 0;
+
     mygraph.findPath(mygraph.cycleOrigin(), mygraph.cycleEnd(), path);
     
-    for(int i = 0; i < path.size(); ++i)
+    for (pathIterator = path.begin(); pathIterator != path.end(); pathIterator++)
       {
-      std::cerr << qPrintable(vertexIdToLabel[path[i]]);
-      if (i != path.size() - 1)
+      std::cerr << vertexIdToLabel[*pathIterator];
+      if (pathIteratorCounter != path.size() - 1)
         {
         std::cerr << " -> ";
         }
+      pathIteratorCounter++;
       }
     std::cerr << std::endl;
     
     path.clear();
     mygraph.findPath(mygraph.cycleEnd(), mygraph.cycleOrigin(), path);
 
-    for(int i = 0; i < path.size(); ++i)
+    pathIteratorCounter = 0;
+    for (pathIterator = path.begin(); pathIterator != path.end(); pathIterator++)
       {
-      std::cerr << qPrintable(vertexIdToLabel[path[i]]);
-      if (i != path.size() - 1)
+      std::cerr << vertexIdToLabel[*pathIterator];
+      if (pathIteratorCounter != path.size() - 1)
         {
         std::cerr << " -> ";
         }
@@ -263,15 +342,19 @@ int main(int argc, char** argv)
     {
     if (verbose)
       {
-      qDebug() << "> Topological order ...";
+      std::cerr << "> Topological order ..." << std::endl;
       }
-    QList<int> out;
+    std::list<int> out;
+    std::list<int>::reverse_iterator outIterator;
+    unsigned int outIteratorCounter = 0;
+
     if (mygraph.topologicalSort(out))
       {
-      for(int i=out.size() - 1; i >= 0; --i)
+      outIteratorCounter = 0;
+      for (outIterator = out.rbegin(); outIterator != out.rend(); outIterator++)
         {
-        std::cout << qPrintable(vertexIdToLabel[out[i]]);
-        if (i != 0)
+        std::cout << vertexIdToLabel[*outIterator];
+        if (outIteratorCounter != out.size() - 1)
           {
           std::cout << " ";
           }
@@ -282,44 +365,69 @@ int main(int argc, char** argv)
 
   if (verbose)
     {
-    QList<int> sources;
+    std::list<int> sources;
     mygraph.sourceVertices(sources);
-    qDebug() << "Source vertices: " << sources;
+    std::cout << "Source vertices: " << listToString(sources) << std::endl;
     }
     
   if (outputPath)
     {
     // TODO Make sure label is valid
-    QList<int> out;
+    std::list<int> out;
     if (mygraph.topologicalSort(out))
       {
-      for(int i=0; i < out.size(); i++)
+      std::list<int>::iterator outIterator;
+      for (outIterator = out.begin(); outIterator != out.end(); outIterator++)
         {
         // Assume all targets depend on the first lib
         // We could get all sinks and find all paths
         // from the rootId to the sink vertices.
-        int rootId = out.last();
+        int rootId = getLastElement(out);
         int labelId = vertexLabelToId[label];
-        QList<QList<int>*> paths;
+
+        std::list<std::list<int>*> paths;
         mygraph.findPaths(labelId, rootId, paths);
-        for(int i=0; i < paths.size(); i++)
+
+        std::list<std::list<int>*>::iterator pathsIterator;
+        std::list<std::list<int>*>::iterator pathsIteratorPlus1;
+
+        for (pathsIterator = paths.begin(); pathsIterator != paths.end(); pathsIterator++)
           {
-          QList<int>* p = paths[i];
-          Q_ASSERT(p);
-          for(int j=0; j < p->size(); j++)
+          std::list<int>* p = *pathsIterator;
+          assert(p);
+
+          std::list<int>::iterator pIterator;
+          std::list<int>::iterator pIteratorPlus1;
+          for (pIterator = p->begin(); pIterator != p->end(); pIterator++)
             {
-            int id = p->at(j);
-            std::cout << qPrintable(vertexIdToLabel[id]);
-            if (j != p->size() - 1)
+            int id = *pIterator;
+            std::cout << vertexIdToLabel[id];
+
+            pIteratorPlus1 = pIterator;
+            pIteratorPlus1++;
+
+            if (pIteratorPlus1 != p->end())
               {
               std::cout << " ";
               }
             }
-          if (i != paths.size() - 1)
+
+          pathsIteratorPlus1 = pathsIterator;
+          pathsIteratorPlus1++;
+
+          if (pathsIteratorPlus1 != paths.end())
             {
             std::cout << ";";
             }
           }
+
+        for (pathsIterator = paths.begin(); pathsIterator != paths.end(); pathsIterator++)
+          {
+            if (*pathsIterator != NULL)
+              {
+              delete *pathsIterator;
+              }
+          }
         }
       }
     }
@@ -327,22 +435,27 @@ int main(int argc, char** argv)
   if (outputSort)
     {
     // TODO Make sure label is valid
-    QList<int> out;
+    std::list<int> out;
     int labelId = vertexLabelToId[label];
     if (mygraph.topologicalSort(out, labelId))
       {
-      for(int i=0; i < out.size(); i++)
+      std::list<int>::iterator outIterator;
+      std::list<int>::iterator outIteratorPlus1;
+
+      for (outIterator = out.begin(); outIterator != out.end(); outIterator++)
         {
-        int id = out.at(i);
-        std::cout << qPrintable(vertexIdToLabel[id]);
+        int id = *outIterator;
+        std::cout << vertexIdToLabel[id];
 
-        if (i != out.size() - 1)
+        outIteratorPlus1 = outIterator;
+        outIteratorPlus1++;
+
+        if (outIteratorPlus1 != out.end())
           {
           std::cout << " ";
           }
         }
       }
     }
-    
   return EXIT_SUCCESS;
 }