core/vgui/vgui_text_graph.cxx
Go to the documentation of this file.
00001 // This is core/vgui/vgui_text_graph.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \author fsm
00008 // \brief  See vgui_text_graph.h for a description of this file.
00009 
00010 #include "vgui_text_graph.h"
00011 
00012 #include <vcl_iostream.h>
00013 #include <vgui/vgui_tableau.h>
00014 
00015 //-----------------------------------------------------------------------------
00016 //: Sends a text description of the tableau hierarchy beneath the given tableau.
00017 static
00018 void vgui_text_graph(vcl_ostream &s, vcl_string const &prefix,
00019                      vgui_tableau_sptr const &t)
00020 {
00021   s << prefix << t/*->type_name()*/ << vcl_endl;
00022 
00023   vcl_vector<vgui_tableau_sptr> tmp;
00024   t->get_children(&tmp);
00025 
00026   for (unsigned int i=0; i<tmp.size(); ++i) {
00027     if (i+1 < tmp.size())
00028       vgui_text_graph(s, prefix + "| ", tmp[i]);
00029     else
00030       vgui_text_graph(s, prefix + "  ", tmp[i]);
00031   }
00032 }
00033 
00034 //-----------------------------------------------------------------------------
00035 //: Sends a text description of the tableau hierarchy beneath the given tableau.
00036 void vgui_text_graph(vcl_ostream &s, vgui_tableau_sptr const &t)
00037 {
00038   vgui_text_graph(s, "", t);
00039 }
00040 
00041 //-----------------------------------------------------------------------------
00042 //: Sends a text description of the whole tableau hierarchy to the given stream.
00043 void vgui_text_graph(vcl_ostream &s)
00044 {
00045   s << "All tableaux in the world:\n";
00046   vcl_vector<vgui_tableau_sptr> all;
00047   vgui_tableau::get_all(&all);
00048 
00049   // find those tableaux with no parents.
00050   vcl_vector<vgui_tableau_sptr> top;
00051   for (unsigned int i=0; i<all.size(); ++i)
00052   {
00053     vcl_vector<vgui_tableau_sptr> tmp;
00054     all[i]->get_parents(&tmp);
00055     if (tmp.empty())
00056       top.push_back(all[i]);
00057   }
00058 
00059   for (unsigned int i=0; i<top.size(); ++i)
00060   {
00061     if (i > 0)
00062       s << vcl_endl;
00063     vgui_text_graph(s, top[i]);
00064   }
00065   s << vcl_endl;
00066 }