singleton
fluxgen fluxgen
2 files changed,
25 insertions(+),
11 deletions(-)
M
src/FbAtoms.cc
→
src/FbAtoms.cc
@@ -19,24 +19,36 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// 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 <string> +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);
M
src/FbAtoms.hh
→
src/FbAtoms.hh
@@ -19,21 +19,21 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// 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 <X11/Xlib.h> #include <X11/Xatom.h> + /** 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 @@
#endif // NEWWMSPEC private: + void initAtoms(Display *disp); // NETAttributes Atom blackbox_attributes, blackbox_change_attributes, blackbox_hints;@@ -177,6 +178,7 @@ Atom xa_wm_colormap_windows, xa_wm_protocols, xa_wm_state,
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