1
/////////////////////////////////////////////////////////////////////////////
3
// (C) Copyright Ion Gaztanaga 2006-2009
5
// Distributed under the Boost Software License, Version 1.0.
6
// (See accompanying file LICENSE_1_0.txt or copy at
7
// http://www.boost.org/LICENSE_1_0.txt)
9
// See http://www.boost.org/libs/intrusive for documentation.
11
/////////////////////////////////////////////////////////////////////////////
13
#include <boost/intrusive/list.hpp>
15
using namespace boost::intrusive;
17
//An abstract class that can be inserted in an intrusive list
18
class Window : public list_base_hook<>
21
//This is a container those value is an abstract class: you can't do this with std::list.
22
typedef list<Window> win_list;
24
//A static intrusive list declaration
25
static win_list all_windows;
27
//Constructor. Includes this window in the list
28
Window() { all_windows.push_back(*this); }
29
//Destructor. Removes this node from the list
30
virtual ~Window() { all_windows.erase(win_list::s_iterator_to(*this)); }
31
//Pure virtual function to be implemented by derived classes
32
virtual void Paint() = 0;
35
//The static intrusive list declaration
36
Window::win_list Window::all_windows;
38
//Some Window derived classes
39
class FrameWindow : public Window
40
{ void Paint(){/**/} };
42
class EditWindow : public Window
43
{ void Paint(){/**/} };
45
class CanvasWindow : public Window
46
{ void Paint(){/**/} };
48
//A function that prints all windows stored in the intrusive list
49
void paint_all_windows()
51
for(Window::win_list::iterator i(Window::all_windows.begin())
52
, e(Window::all_windows.end())
59
//A class derived from Window
60
class MainWindow : public Window
62
FrameWindow frame_; //these are derived from Window too
74
//When a Window class is created, is automatically registered in the global list
77
//Paint all the windows, sub-windows and so on
80
//All the windows are automatically unregistered in their destructors.