From 238526bd48a9318672f8e2c20e8a3b3dbf16927d Mon Sep 17 00:00:00 2001 From: fluxgen Date: Wed, 14 Aug 2002 21:53:07 +0000 Subject: singleton --- src/FbAtoms.cc | 26 +++++++++++++++++++------- src/FbAtoms.hh | 10 ++++++---- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/FbAtoms.cc b/src/FbAtoms.cc index e19ba21..4e2c7f5 100644 --- a/src/FbAtoms.cc +++ b/src/FbAtoms.cc @@ -19,24 +19,36 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: FbAtoms.cc,v 1.2 2002/03/18 20:29:16 fluxgen Exp $ +// $Id: FbAtoms.cc,v 1.3 2002/08/14 21:53:07 fluxgen Exp $ #include "FbAtoms.hh" +#include +using namespace std; + +FbAtoms *FbAtoms::s_singleton = 0; + FbAtoms::FbAtoms(Display *display):m_init(false) { - if (display) - initAtoms(display); + if (s_singleton != 0) + throw string("You can only create one instance of FbAtoms"); + + if (display == 0) + throw string("Must supply FbAtoms with an valid display connection"); + + s_singleton = this; + initAtoms(display); } FbAtoms::~FbAtoms() { } +FbAtoms *FbAtoms::instance() { + assert(s_singleton); + return s_singleton; +} + void FbAtoms::initAtoms(Display *display) { - if (m_init) //already done init? - return; - else - m_init = true; xa_wm_colormap_windows = XInternAtom(display, "WM_COLORMAP_WINDOWS", False); diff --git a/src/FbAtoms.hh b/src/FbAtoms.hh index 63882e2..3fb8b2b 100644 --- a/src/FbAtoms.hh +++ b/src/FbAtoms.hh @@ -19,21 +19,21 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: FbAtoms.hh,v 1.5 2002/08/12 19:25:35 fluxgen Exp $ +// $Id: FbAtoms.hh,v 1.6 2002/08/14 21:53:07 fluxgen Exp $ #ifndef FBATOMS_HH #define FBATOMS_HH #include #include + /** atom handler, should probably be a singleton */ -class FbAtoms -{ +class FbAtoms { public: explicit FbAtoms(Display *display); virtual ~FbAtoms(); - void initAtoms(Display *display); + static FbAtoms *instance(); #ifdef GNOME inline Atom getGnomeProtAtom() const { return gnome_wm_prot; } @@ -125,6 +125,7 @@ public: #endif // NEWWMSPEC private: + void initAtoms(Display *disp); // NETAttributes Atom blackbox_attributes, blackbox_change_attributes, blackbox_hints; @@ -177,6 +178,7 @@ private: xa_wm_delete_window, xa_wm_take_focus, xa_wm_change_state, motif_wm_hints; bool m_init; + static FbAtoms *s_singleton; }; #endif //FBATOMS_HH -- cgit v0.11.2