gui/auxiliary/notifiee.hpp

Go to the documentation of this file.
00001 /* $Id: notifiee.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2010 - 2012 by Mark de Wever <koraq@xs4all.nl>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 #ifndef GUI_WIDGETS_AUXILIARY_NOTIFIEE_HPP_INCLUDED
00017 #define GUI_WIDGETS_AUXILIARY_NOTIFIEE_HPP_INCLUDED
00018 
00019 #include <cstdlib>
00020 
00021 namespace gui2 {
00022 
00023 template<class T>
00024 class tnotifier;
00025 
00026 /**
00027  * Helper class to implement callbacks with lifetime management.
00028  *
00029  * This part manages the lifetime off the callback.
00030  */
00031 template<class FUNCTOR>
00032 class tnotifiee
00033 {
00034 public:
00035     typedef FUNCTOR tfunctor;
00036     friend class tnotifier<tfunctor>;
00037 
00038     tnotifiee()
00039         : notifier_(NULL)
00040     {
00041     }
00042 
00043     ~tnotifiee()
00044     {
00045         if(notifier_) {
00046             notifier_->disconnect_notifiee(*this);
00047         }
00048     }
00049 
00050 private:
00051 
00052     /** Pointer the the tnotifier that's linked to us. */
00053     tnotifier<tfunctor> *notifier_;
00054 };
00055 
00056 } //namespace gui2
00057 
00058 #endif
00059 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:54 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs