Author: mordante
Date: Sun Apr 19 16:52:22 2009
New Revision: 35048
URL: http://svn.gna.org/viewcvs/wesnoth?rev=35048&view=rev
Log:
Templatize another find_widget function.
Modified:
trunk/src/gui/widgets/grid.cpp
trunk/src/gui/widgets/grid_private.hpp
Modified: trunk/src/gui/widgets/grid.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/grid.cpp?rev=35048&r1=35047&r2=35048&view=diff
==============================================================================
--- trunk/src/gui/widgets/grid.cpp (original)
+++ trunk/src/gui/widgets/grid.cpp Sun Apr 19 16:52:22 2009
@@ -809,55 +809,15 @@
twidget* tgrid::find_widget(const std::string& id, const bool must_be_active)
{
- // Inherited.
- twidget* widget = twidget::find_widget(id, must_be_active);
- if(widget) {
- return widget;
- }
-
- for(std::vector<tchild>::iterator itor = children_.begin();
- itor != children_.end(); ++itor) {
-
- widget = itor->widget();
- if(!widget) {
- continue;
- }
-
- widget = widget->find_widget(id, must_be_active);
- if(widget) {
- return widget;
- }
-
- }
-
- return 0;
+ return tgrid_implementation::find_widget<twidget>(
+ *this, id, must_be_active);
}
const twidget* tgrid::find_widget(const std::string& id,
const bool must_be_active) const
{
- // Inherited.
- const twidget* widget = twidget::find_widget(id, must_be_active);
- if(widget) {
- return widget;
- }
-
- for(std::vector<tchild>::const_iterator itor = children_.begin();
- itor != children_.end(); ++itor) {
-
- widget = itor->widget();
- if(!widget) {
- continue;
- }
-
- widget = widget->find_widget(id, must_be_active);
- if(widget) {
- return widget;
- }
-
- }
-
- return 0;
+ return tgrid_implementation::find_widget<const twidget>(
+ *this, id, must_be_active);
}
bool tgrid::has_widget(const twidget* widget) const
Modified: trunk/src/gui/widgets/grid_private.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/grid_private.hpp?rev=35048&r1=35047&r2=35048&view=diff
==============================================================================
--- trunk/src/gui/widgets/grid_private.hpp (original)
+++ trunk/src/gui/widgets/grid_private.hpp Sun Apr 19 16:52:22 2009
@@ -92,6 +92,41 @@
return 0;
}
+
+ /**
+ * Implementation for the wrappers for
+ * [const] twidget* tgrid::find_widget(const std::string&,
+ * const bool) [const].
+ *
+ * @param W twidget or const twidget.
+ */
+ template<class W>
+ static W* find_widget(typename tconst_duplicator<W, tgrid>::type& grid,
+ const std::string& id, const bool
must_be_active)
+ {
+ // Inherited.
+ W* widget = grid.twidget::find_widget(id, must_be_active);
+ if(widget) {
+ return widget;
+ }
+
+ typedef typename tconst_duplicator<W, tgrid::tchild>::type hack;
+ foreach(hack& child, grid.children_) {
+
+ widget = child.widget();
+ if(!widget) {
+ continue;
+ }
+
+ widget = widget->find_widget(id, must_be_active);
+ if(widget) {
+ return widget;
+ }
+
+ }
+
+ return 0;
+ }
};
} // namespace gui2
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits