VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gxwindowmap.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Graeme Walker
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 ///
18 /// \file gxwindowmap.h
19 ///
20 
21 #ifndef GX_WINDOW_MAP_H
22 #define GX_WINDOW_MAP_H
23 
24 #include "gdef.h"
25 #include "gxdef.h"
26 #include "gxwindow.h"
27 #include "gxerror.h"
28 #include <map>
29 #include <exception>
30 
31 namespace GX
32 {
33  class WindowMap ;
34 }
35 
36 /// \class GX::WindowMap
37 /// A class that can locate a GX::Window object based on a Xlib window handle.
38 ///
40 {
41 public:
42  struct NotFound : public GX::Error /// Exception class for GX::WindowMap.
43  {
44  virtual const char * what() const g__noexcept override { return "window not found" ; }
45  } ;
46 
47  WindowMap() ;
48  ///< Constructor.
49 
50  ~WindowMap() ;
51  ///< Destructor.
52 
53  static WindowMap * instance() ;
54  ///< Singleton access. Returns nullptr if none.
55 
56  void add( GX::Window & w ) ;
57  ///< Adds a window.
58 
59  void remove( GX::Window & w ) ;
60  ///< Removes a window.
61 
62  GX::Window & find( ::Window w ) const ;
63  ///< Finds a window. Throws if not found.
64 
65 private:
66  WindowMap( const WindowMap & ) ;
67  void operator=( const WindowMap & ) ;
68 
69 private:
70  typedef ::Window XlibWindow ;
71  typedef std::map<XlibWindow,GX::Window*> Map ;
72  Map m_map ;
73  static WindowMap * m_this ;
74 } ;
75 
76 #endif
A window class that is-a GX::Drawable and a GX::EventHandler.
Definition: gxwindow.h:47
~WindowMap()
Destructor.
Definition: gxwindowmap.cpp:34
An exception class for GX classes.
Definition: gxerror.h:37
void add(GX::Window &w)
Adds a window.
Definition: gxwindowmap.cpp:45
GX::Window & find(::Window w) const
Finds a window. Throws if not found.
Definition: gxwindowmap.cpp:55
Exception class for GX::WindowMap.
Definition: gxwindowmap.h:42
A class that can locate a GX::Window object based on a Xlib window handle.
Definition: gxwindowmap.h:39
static WindowMap * instance()
Singleton access. Returns nullptr if none.
Definition: gxwindowmap.cpp:40
WindowMap()
Constructor.
Definition: gxwindowmap.cpp:28