[Aptitude-svn-commit] r4023 - in branches/aptitude-0.3/aptitude: . src/generic

Daniel Burrows dburrows at costa.debian.org
Wed Aug 31 22:32:14 UTC 2005


Author: dburrows
Date: Wed Aug 31 22:32:12 2005
New Revision: 4023

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/generic/immset.h
Log:
Add an operator<< to display tree structure.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Wed Aug 31 22:32:12 2005
@@ -1,3 +1,10 @@
+2005-08-31  Daniel Burrows  <dburrows at debian.org>
+
+	* src/generic/immset.h:
+
+	  Add operator<< implementations that show the structure of each
+	  set/map.
+
 2005-08-31 Sorin Batariuc <sorin at bonbon.net>
 
 	* Update Romanian translation

Modified: branches/aptitude-0.3/aptitude/src/generic/immset.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/immset.h	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/immset.h	Wed Aug 31 22:32:12 2005
@@ -333,6 +333,26 @@
 	  realNode->getRightChild().for_each(o);
 	}
     }
+
+    void dump(std::ostream &out,
+	      int indent = 2,
+	      int level = 0,
+	      int mode = -1) const
+    {
+      for(int i = 0; i < indent; ++i)
+	for(int j = 0; j < level; ++j)
+	  out << " ";
+
+      if(mode == 0)
+	out << "L-> ";
+      else if(mode == 1)
+	out << "R-> ";
+
+      out << getVal() << std::endl;
+
+      getLeft().dump(out, indent, level+1, 0);
+      getLeft().dump(out, indent, level+1, 1);
+    }
   };
 
   /** An entire weighted tree.
@@ -617,6 +637,11 @@
       return const_iterator();
     }
 
+    node get_root() const
+    {
+      return root;
+    }
+
     size_type size() const
     {
       return root.size();
@@ -828,4 +853,27 @@
   };
 };
 
+template<typename T, int w>
+std::ostream &operator<<(std::ostream &out,
+			 const imm::wtree_node<T, w> &n)
+{
+  n.dump(out);
+  return out;
+}
+
+template<typename Val, typename Compare, int w>
+std::ostream &operator<<(std::ostream &out,
+			 const imm::set<Val, Compare, w> &s)
+{
+  s.get_root().dump(out);
+  return out;
+}
+
+template<typename Key, typename Val, typename Compare>
+std::ostream &operator<<(std::ostream &out,
+			 const imm::map<Key, Val, Compare> &m)
+{
+  return out << m.get_contents();
+}
+
 #endif



More information about the Aptitude-svn-commit mailing list