home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / include / k3d / k3dsdk / signal_slots.h < prev    next >
C/C++ Source or Header  |  2008-07-03  |  2KB  |  79 lines

  1. #ifndef K3DSDK_SIGNAL_SLOTS_H
  2. #define K3DSDK_SIGNAL_SLOTS_H
  3.  
  4. // K-3D
  5. // Copyright (c) 1995-2005, Timothy M. Shead
  6. //
  7. // Contact: tshead@k-3d.com
  8. //
  9. // This program is free software; you can redistribute it and/or
  10. // modify it under the terms of the GNU General Public
  11. // License as published by the Free Software Foundation; either
  12. // version 2 of the License, or (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. // General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public
  20. // License along with this program; if not, write to the Free Software
  21. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  22.  
  23. namespace k3d
  24. {
  25.  
  26. class ihint;
  27.  
  28. namespace signal
  29. {
  30.  
  31. template<typename SignalT>
  32. class loop_safe_slot
  33. {
  34. public:
  35.     loop_safe_slot(SignalT& Signal) :
  36.         signal(Signal),
  37.         emitting(false)
  38.     {
  39.     }
  40.  
  41.     void operator()()
  42.     {
  43.         if(emitting)
  44.             return;
  45.  
  46.         emitting = true;
  47.         signal.emit();
  48.         emitting = false;
  49.     }
  50.  
  51.     void operator()(ihint* const Hint)
  52.     {
  53.         if(emitting)
  54.             return;
  55.  
  56.         emitting = true;
  57.         signal.emit(Hint);
  58.         emitting = false;
  59.     }
  60.  
  61. private:
  62.     SignalT& signal;
  63.     bool emitting;
  64. };
  65.  
  66. template<typename SignalT>
  67. loop_safe_slot<SignalT> make_loop_safe_slot(SignalT& Signal)
  68. {
  69.     return loop_safe_slot<SignalT>(Signal);
  70. }
  71.  
  72. } // namespace signal
  73.  
  74. } // namespace k3d
  75.  
  76. #endif // !K3DSDK_SIGNAL_SLOTS_H
  77.  
  78.  
  79.