Author: ilor
Date: Wed Aug 13 09:33:22 2008
New Revision: 28528

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28528&view=rev
Log:
add a template helper for find_widget in twidget

Modified:
    trunk/src/gui/widgets/widget.hpp

Modified: trunk/src/gui/widgets/widget.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/widget.hpp?rev=28528&r1=28527&r2=28528&view=diff
==============================================================================
--- trunk/src/gui/widgets/widget.hpp (original)
+++ trunk/src/gui/widgets/widget.hpp Wed Aug 13 09:33:22 2008
@@ -17,6 +17,7 @@
 
 #include "gui/widgets/helper.hpp"
 #include "sdl_utils.hpp"
+#include "wml_exception.hpp"
 
 #include "SDL.h"
 
@@ -432,6 +433,33 @@
        virtual const twidget* find_widget(const std::string& id, 
                        const bool /*must_be_active*/) const
                { return id_ == id ? this : 0; }
+               
+       /** 
+        * The template counterpart of find_widget(id) with automatic 
dynamic_cast 
+        * and error checking.
+        */
+       template <class T>
+       T* get_widget(const std::string& id,
+                                  const bool must_be_active)
+       {
+               T* result = dynamic_cast<T*>(find_widget(id, must_be_active));
+               VALIDATE(result, missing_widget(id));
+               return result;
+       }
+
+       /** 
+        * The template counterpart of find_widget(id) with automatic 
dynamic_cast 
+        * and error checking - const version.
+        */
+       template <class T>
+       T* get_widget(const std::string& id,
+                                  const bool must_be_active) const
+       {
+               T* result = dynamic_cast<T*>(find_widget(id, must_be_active));
+               VALIDATE(result, missing_widget(id));
+               return result;
+       }
+       
        /** 
         * Does the widget contain the widget.
         *


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to