From 35c16d75c177509b7ca6198f75c13ad5d6f9294c Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 25 Oct 2009 17:00:19 +0000 Subject: [PATCH] Add a template version of ILayout::get --- include/gui2/ILayout.hpp | 6 ++++++ src/UIDemo.cpp | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/gui2/ILayout.hpp b/include/gui2/ILayout.hpp index 86efa57..ee751d2 100644 --- a/include/gui2/ILayout.hpp +++ b/include/gui2/ILayout.hpp @@ -31,6 +31,12 @@ namespace gui { struct ILayout { virtual ~ILayout() {} + template + T& get_cast(const string& path) const + { + return dynamic_cast(get(path)); + } + virtual Widget& get(const string& path) const = 0; virtual void render() const = 0; diff --git a/src/UIDemo.cpp b/src/UIDemo.cpp index 6f6cebf..3e88e8b 100644 --- a/src/UIDemo.cpp +++ b/src/UIDemo.cpp @@ -60,7 +60,7 @@ void UIDemo::btn1_click(gui::Widget& w) static int cnt = 0; debug() << "Clicked button 1!"; - dynamic_cast(layout->get("/wnd1/cntlabel")).text( + layout->get_cast("/wnd1/cntlabel").text( boost::lexical_cast(++cnt)); } -- 2.39.2