/*****************************************************************************
 * $Id: gfx_event.hh,v 1.5 2006/10/31 01:55:43 devel Exp $
 * @file
 * @author	Jim E. Brooks  http://www.jimbrooks.org
 * @brief	C++ template to call every registered listener function.
 * @verbatim
 *
 * Overview:
 * ---------
 * This is a C++ template to call every registered listener function.
 * When an event occurs, call Broadcast() to broadcast it to all of the
 * the listener functions, optionally propagating an object.
 *
 * Usage:
 * ------
 * If no object needs to be broadcast, this is how to declare an Event type:
 * Event<void> mEventHorizon;
 *
 * Notes:
 * ------
 * This template class is designed to survive a listener calling Ignore()
 * or Listen() while Call() is executing.  An example is an "exit" event
 * to which listeners may respond by calling Ignore() for that same event.
 * No STL container is used as Ignore()/Listen() would disrupt Call()'s iterator.
 * Instead, an ordinary C array is used.
 *
 * @endverbatim
 *//*
 * LEGAL:	COPYRIGHT (C) 2005 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE (GPL).
 *****************************************************************************/

#ifndef GFX_EVENT_HH
#define GFX_EVENT_HH 1

namespace gfx {

#ifndef GFX_EVENT_MAX_LISTENERS
#define GFX_EVENT_MAX_LISTENERS		16
#endif

////////////////////////////////////////////////////////////////////////////////
// Preprocess template class that passes an object to listeners.
#define GFX_EVENT_TEMPLATE_CLASS		template<typename T> class Event
#define GFX_EVENT_T_OBJ					T obj
#define GFX_EVENT_OBJ					obj
#define GFX_EVENT_TYPENAME				typename
#include "gfx_event2.hh"

#undef  GFX_EVENT_TEMPLATE_CLASS
#undef  GFX_EVENT_T_OBJ
#undef  GFX_EVENT_OBJ
#undef  GFX_EVENT_TYPENAME

////////////////////////////////////////////////////////////////////////////////
// Preprocess Event template class that passes nothing to listeners.
#define GFX_EVENT_TEMPLATE_CLASS		template<> class Event<void>
#define GFX_EVENT_T_OBJ					void
#define GFX_EVENT_OBJ
#define GFX_EVENT_TYPENAME
#include "gfx_event2.hh"

} // namespace gfx

#endif // GFX_EVENT_HH
