]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2092] Add support for showing pointers in Graphviz output
authorMukund Sivaraman <muks@isc.org>
Fri, 20 Jul 2012 07:27:52 +0000 (12:57 +0530)
committerMukund Sivaraman <muks@isc.org>
Tue, 24 Jul 2012 06:15:12 +0000 (11:45 +0530)
src/lib/datasrc/rbtree.h

index 2a6c8b46560e79dc0bf12cdf93f3ad6c920aac65..4bf8f0b1e7a9c7821db46a748fe49fc45519295c 100644 (file)
@@ -1055,7 +1055,8 @@ public:
     /// Graphviz's dot.
     ///
     /// \param os A \c std::ostream object to which the tree is printed.
-    void dumpDot(std::ostream& os) const;
+    /// \param show_pointers Show node and parent pointers in the node
+    void dumpDot(std::ostream& os, bool show_pointers = false) const;
     //@}
 
     /// \name Modify functions
@@ -1124,7 +1125,7 @@ private:
 
     /// \brief Print the information of given RBNode for dot.
     int dumpDotHelper(std::ostream& os, const RBNode<T>* node,
-                      int* nodecount) const;
+                      int* nodecount, bool show_pointers) const;
 
     /// \brief Indentation helper function for dumpTree
     static void indent(std::ostream& os, unsigned int depth);
@@ -1731,33 +1732,37 @@ RBTree<T>::indent(std::ostream& os, unsigned int depth) {
 
 template <typename T>
 void
-RBTree<T>::dumpDot(std::ostream& os) const {
+RBTree<T>::dumpDot(std::ostream& os, bool show_pointers) const {
     int nodecount = 0;
 
     os << "digraph g {\n";
     os << "node [shape = record,height=.1];\n";
-    dumpDotHelper(os, root_, &nodecount);
+    dumpDotHelper(os, root_, &nodecount, show_pointers);
     os << "}\n";
 }
 
 template <typename T>
 int
 RBTree<T>::dumpDotHelper(std::ostream& os, const RBNode<T>* node,
-                         int* nodecount) const
+                         int* nodecount, bool show_pointers) const
 {
     if (node == NULLNODE) {
         return 0;
     }
 
-    int l = dumpDotHelper(os, node->left_, nodecount);
-    int r = dumpDotHelper(os, node->right_, nodecount);
-    int d = dumpDotHelper(os, node->down_, nodecount);
+    int l = dumpDotHelper(os, node->left_, nodecount, show_pointers);
+    int r = dumpDotHelper(os, node->right_, nodecount, show_pointers);
+    int d = dumpDotHelper(os, node->down_, nodecount, show_pointers);
 
     *nodecount += 1;
 
     os << "node" << *nodecount <<
           "[label = \"<f0> |<f1> " << node->name_.toText() <<
-          "|<f2>\"] [";
+          "|<f2>";
+    if (show_pointers) {
+        os << "|<f3> n=" << node << "|<f4> p=" << node->parent_;
+    }
+    os << "\"] [";
 
     if (node->getColor() == RBNode<T>::RED) {
         os << "color=red";