core/vgui/vgui_find.cxx
Go to the documentation of this file.
00001 // This is core/vgui/vgui_find.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \author fsm
00008 // \brief  See vgui_find.h for a description of this file.
00009 
00010 #include "vgui_find.h"
00011 #include <vgui/vgui_tableau.h>
00012 
00013 // Does a depth-first search for the first tableau whose type_name()
00014 // method returns the given vcl_string. Returns 0 if no tableau is found.
00015 vgui_tableau_sptr vgui_find_by_type_name(vgui_tableau_sptr const& start, vcl_string const &tn, bool direction_down)
00016 {
00017   if (!start)
00018     return 0;
00019 
00020   if (start->type_name() == tn)
00021     return start;
00022 
00023   vcl_vector<vgui_tableau_sptr> tt;
00024   if (direction_down)
00025     start->get_children(&tt); // get all children.
00026   else
00027     start->get_parents (&tt); // get all parents.
00028 
00029   for (unsigned int i=0; i<tt.size(); ++i) {
00030     vgui_tableau_sptr t = vgui_find_by_type_name(tt[i], tn, direction_down);
00031     if (t)
00032       return t; // found one.
00033   }
00034   return 0; // not found.
00035 }
00036 
00037 
00038 vgui_tableau_sptr
00039 vgui_find_by_name(vgui_tableau_sptr const& start, vcl_string const &name, bool direction_down)
00040 {
00041   if (!start)
00042     return 0;
00043 
00044   if (start->name() == name)
00045     return start;
00046 
00047   vcl_vector<vgui_tableau_sptr> tt;
00048   if (direction_down)
00049     start->get_children(&tt); // get all children.
00050   else
00051     start->get_parents (&tt); // get all parents.
00052 
00053   for (unsigned int i=0; i<tt.size(); ++i) {
00054     vgui_tableau_sptr t = vgui_find_by_name(tt[i], name, direction_down);
00055     if (t)
00056       return t; // found one.
00057   }
00058   return 0; // not found.
00059 }