(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
--- a/src/window.cpp Sun Feb 11 22:57:24 2007 +0000
+++ b/src/window.cpp Mon Feb 12 23:12:02 2007 +0000
@@ -55,17 +55,14 @@
if (it != m_list.end()) m_list.erase(it);
}
+static bool MatchWindow(WindowList::Iterator it, Window *w)
+{
+ return (*it).w == w;
+}
+
WindowList::Iterator WindowList::Find(Window *w)
{
- struct Match {
- Window *m_w;
- bool EnumProc(Iterator it)
- {
- return (*it).w == m_w;
- }
- } match = {w};
-
- Iterator it = EnumT(match);
+ Iterator it = EnumT(&MatchWindow, w);
if (it == m_list.end()) {
DEBUG(misc, 3, "Window (cls %d, number %d) is not open, probably removed by recursive calls",
w->window_class, w->window_number);
@@ -73,50 +70,37 @@
return it;
}
+static bool MatchNonVitalWindow(WindowList::Iterator it)
+{
+ return !(*it).w->IsVital();
+}
+
WindowList::Iterator WindowList::FindFirstVitalWindow()
{
- struct MatchNonVital {
- bool EnumProc(Iterator it)
- {
- return !(*it).w->IsVital();
- }
- } match;
-
- Iterator it = ReverseEnumT(match);
+ Iterator it = ReverseEnumT(&MatchNonVitalWindow);
/* we have stopped on last non-vital window. Move one step forward to locate first vital window. */
if (it != m_list.end()) ++it;
return it;
}
+static bool MatchClass(WindowList::Iterator it, WindowClass cls)
+{
+ return (*it).w->window_class == cls;
+}
+
WindowList::Iterator WindowList::FindByClass(WindowClass cls)
{
- struct MatchCls {
- WindowClass m_cls;
- bool EnumProc(Iterator it)
- {
- Window *w = (*it).w;
- return w->window_class == m_cls;
- }
- } match = {cls};
+ return EnumT(&MatchClass, cls);
+}
- Iterator it = EnumT(match);
- return it;
+static bool MatchClassAndId(WindowList::Iterator it, WindowClass cls, WindowNumber num)
+{
+ return (*it).w->window_class == cls && (*it).w->window_number == num;
}
WindowList::Iterator WindowList::FindById(WindowClass cls, WindowNumber num)
{
- struct MatchClsAndId {
- WindowClass m_cls;
- WindowNumber m_num;
- bool EnumProc(Iterator it)
- {
- Window *w = (*it).w;
- return w->window_class == m_cls && w->window_number == m_num;
- }
- } match = {cls, num};
-
- Iterator it = EnumT(match);
- return it;
+ return EnumT(&MatchClassAndId, cls, num);
}
/* Open a new window.
--- a/src/window.h Sun Feb 11 22:57:24 2007 +0000
+++ b/src/window.h Mon Feb 12 23:12:02 2007 +0000
@@ -287,19 +287,44 @@
Iterator FindByClass(WindowClass cls);
Iterator FindById(WindowClass cls, WindowNumber num);
- template <class Tmatch> Iterator EnumT(Tmatch match)
+ Iterator EnumT(bool (*enum_proc)(Iterator))
{
for (Iterator it = m_list.begin(); it != m_list.end(); ++it) {
- if (match.EnumProc(it)) return it;
+ if (enum_proc(it)) return it;
}
return m_list.end();
}
- template <class Tmatch> Iterator ReverseEnumT(Tmatch match)
+ template <class Tmatch_1> Iterator EnumT(bool (*enum_proc)(Iterator, Tmatch_1), Tmatch_1 match)
+ {
+ for (Iterator it = m_list.begin(); it != m_list.end(); ++it) {
+ if (enum_proc(it, match)) return it;
+ }
+ return m_list.end();
+ }
+
+ template <class Tmatch_1, class Tmatch_2> Iterator EnumT(bool (*enum_proc)(Iterator, Tmatch_1, Tmatch_2), Tmatch_1 match_1, Tmatch_2 match_2)
+ {
+ for (Iterator it = m_list.begin(); it != m_list.end(); ++it) {
+ if (enum_proc(it, match_1, match_2)) return it;
+ }
+ return m_list.end();
+ }
+
+ Iterator ReverseEnumT(bool (*enum_proc)(Iterator))
{
for (Iterator it = m_list.end(); it != m_list.begin(); ) {
--it;
- if (match.EnumProc(it)) return it;
+ if (enum_proc(it)) return it;
+ }
+ return m_list.end();
+ }
+
+ template <class Tmatch_1> Iterator ReverseEnumT(bool (*enum_proc)(Iterator, Tmatch_1), Tmatch_1 match)
+ {
+ for (Iterator it = m_list.end(); it != m_list.begin(); ) {
+ --it;
+ if (enum_proc(it, match)) return it;
}
return m_list.end();
}
@@ -401,17 +426,17 @@
}
};
- template <class Tmatch> Window* EnumT(Tmatch m)
- {
- WindowList::Iterator it = Window::s_list.EnumT(EnumMatch(m));
- return (it == Window::s_list.m_list.end()) ? NULL : (*it).w;
- }
+ //template <class Tmatch> Window* EnumT(Tmatch m)
+ //{
+ // WindowList::Iterator it = Window::s_list.EnumT(EnumMatch<Tmatch>(m));
+ // return (it == Window::s_list.m_list.end()) ? NULL : (*it).w;
+ //}
- template <class Tmatch> Window* ReverseEnumT(Tmatch m)
- {
- WindowList::Iterator it = Window::s_list.ReverseEnumT(EnumMatch(m));
- return (it == Window::s_list.m_list.end()) ? NULL : (*it).w;
- }
+ //template <class Tmatch> Window* ReverseEnumT(Tmatch m)
+ //{
+ // WindowList::Iterator it = Window::s_list.ReverseEnumT(EnumMatch<Tmatch>(m));
+ // return (it == Window::s_list.m_list.end()) ? NULL : (*it).w;
+ //}
};