## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# csutil/eventhandlers.h

Go to the documentation of this file.

    00001 /*
    00002    Crystal Space 3D engine: Event and module naming interface
    00003    (C) 2005 by Adam D. Bradley <artdodge@cs.bu.edu>
    00004
    00005    This library is free software; you can redistribute it and/or
    00006    modify it under the terms of the GNU Library General Public
    00007    License as published by the Free Software Foundation; either
    00008    version 2 of the License, or (at your option) any later version.
    00009
    00010    This library is distributed in the hope that it will be useful,
    00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013    Library General Public License for more details.
    00014
    00015    You should have received a copy of the GNU Library General Public
    00016    License along with this library; if not, write to the Free
    00017    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00018 */
    00019
    00020 #ifndef __CS_UTIL_EVENTHNAMES_H__
    00021 #define __CS_UTIL_EVENTHNAMES_H__
    00022
    00023 #include "cssysdef.h" /* CS_DEBUG changes our definitions... */
    00024 #include "csextern.h"
    00025 #include "iutil/eventnames.h"
    00026 #include "iutil/eventhandlers.h"
    00027 #include "iutil/eventh.h"
    00028 #include "csutil/csstring.h"
    00029 #include "csutil/eventnames.h"
    00030 #include "csutil/scf_implementation.h"
    00031 #include "csutil/hash.h"
    00032 #include "csutil/strset.h"
    00033 #include "csutil/ref.h"
    00034
    00035 struct iObjectRegistry;
    00036
    00044 struct iEventHandler;
    00045
    00051 class CS_CRYSTALSPACE_EXPORT csEventHandlerRegistry :
    00052   public scfImplementation1<csEventHandlerRegistry, iEventHandlerRegistry>
    00053 {
    00054 public:
    00055   csEventHandlerRegistry(iObjectRegistry*);
    00056   ~csEventHandlerRegistry();
    00062   CS_CONST_METHOD csHandlerID GetGenericID (const char*);
    00063   static CS_CONST_METHOD csHandlerID GetGenericID (iObjectRegistry *reg,
    00064     const char* name)
    00065   {
    00066     return GetRegistry (reg)->GetGenericID (name);
    00067   }
    00068   CS_CONST_METHOD csHandlerID GetGenericPreBoundID (csHandlerID);
    00069   static CS_CONST_METHOD csHandlerID GetGenericPreBoundID (
    00070     iObjectRegistry *reg, csHandlerID id)
    00071   {
    00072     return GetRegistry (reg)->GetGenericPreBoundID (id);
    00073   }
    00074   CS_CONST_METHOD csHandlerID GetGenericPostBoundID (csHandlerID);
    00075   static CS_CONST_METHOD csHandlerID GetGenericPostBoundID (
    00076     iObjectRegistry *reg, csHandlerID id)
    00077   {
    00078     return GetRegistry (reg)->GetGenericPostBoundID (id);
    00079   }
    00080
    00085   csHandlerID GetID (iEventHandler *);
    00086   static CS_CONST_METHOD csHandlerID GetID (iObjectRegistry *reg,
    00087     iEventHandler *h)
    00088   {
    00089     return GetRegistry (reg)->GetID (h);
    00090   }
    00091
    00092   csHandlerID RegisterID (iEventHandler *);
    00093   static CS_CONST_METHOD csHandlerID RegisterID (iObjectRegistry *reg,
    00094     iEventHandler *h)
    00095   {
    00096     return GetRegistry (reg)->RegisterID (h);
    00097   }
    00098
    00105   csHandlerID GetID (const char*);
    00106   static CS_CONST_METHOD csHandlerID GetID (iObjectRegistry *reg,
    00107                                             const char* name)
    00108   {
    00109     return GetRegistry (reg)->GetID (name);
    00110   }
    00111
    00115   void ReleaseID (csHandlerID id);
    00116   static CS_CONST_METHOD void ReleaseID (iObjectRegistry *reg,
    00117     csHandlerID id)
    00118   {
    00119     GetRegistry (reg)->ReleaseID (id);
    00120   }
    00124   void ReleaseID (iEventHandler *);
    00125   static CS_CONST_METHOD void ReleaseID (iObjectRegistry *reg,
    00126     iEventHandler *h)
    00127   {
    00128     GetRegistry (reg)->ReleaseID (h);
    00129   }
    00135   CS_CONST_METHOD iEventHandler* GetHandler (csHandlerID id);
    00136   static inline CS_CONST_METHOD iEventHandler* GetHandler (
    00137     iObjectRegistry *reg, csHandlerID id)
    00138   {
    00139     return GetRegistry (reg)->GetHandler (id);
    00140   };
    00141
    00147   CS_CONST_METHOD bool const IsInstanceOf (csHandlerID instanceid,
    00148     csHandlerID genericid);
    00149   static inline CS_CONST_METHOD bool IsInstanceOf (iObjectRegistry *reg,
    00150     csHandlerID instanceid, csHandlerID genericid)
    00151   {
    00152     return GetRegistry (reg)->IsInstanceOf (instanceid, genericid);
    00153   };
    00154
    00158   CS_CONST_METHOD bool const IsInstance (csHandlerID id);
    00159   static inline CS_CONST_METHOD bool IsInstance (iObjectRegistry *reg,
    00160     csHandlerID id)
    00161   {
    00162     return GetRegistry (reg)->IsInstance (id);
    00163   };
    00164
    00168   CS_CONST_METHOD csHandlerID const GetGeneric (csHandlerID id);
    00169   static inline CS_CONST_METHOD csHandlerID GetGeneric (iObjectRegistry *reg,
    00170     csHandlerID id)
    00171   {
    00172     return GetRegistry (reg)->GetGeneric (id);
    00173   };
    00174
    00178   CS_CONST_METHOD const char* GetString (csHandlerID id);
    00179   static inline CS_CONST_METHOD const char* GetString (
    00180     iObjectRegistry *reg, csHandlerID id)
    00181   {
    00182     return GetRegistry (reg)->GetString (id);
    00183   };
    00184
    00185   static csRef<iEventHandlerRegistry> GetRegistry (
    00186     iObjectRegistry *object_reg);
    00187
    00188  private:
    00189   iObjectRegistry *object_reg;
    00190   csStringSet names;
    00191   csHash<csHandlerID, csHandlerID> instantiation;
    00192   struct KnownEventHandler
    00193   {
    00194     csRef<iEventHandler> handler;
    00195     int refcount;
    00196
    00197     KnownEventHandler (iEventHandler* handler) : handler (handler),
    00198       refcount (1) {}
    00199   };
    00200   csHash<KnownEventHandler, csHandlerID> idToHandler;
    00201   csHash<csHandlerID, csPtrKey<iEventHandler> > handlerToID;
    00202   csHash<csHandlerID, csHandlerID> handlerPres;
    00203   csHash<csHandlerID, csHandlerID> handlerPosts;
    00204   uint32 instanceCounter;
    00205 };
    00206
    00207 /* @} */
    00208
    00209
    00210
    00211
    00212
    00213 struct iFrameEventSignpost : public iEventHandler
    00214 {
    00215  public:
    00216   iFrameEventSignpost () { }
    00217   virtual ~iFrameEventSignpost () { }
    00218   CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS
    00219   virtual bool HandleEvent (iEvent&)
    00220   {
    00221     return false;
    00222   }
    00223 };
    00224
    00225
    00226 class FrameSignpost_Logic3D
    00227 : public scfImplementation2<FrameSignpost_Logic3D,
    00228   iFrameEventSignpost,
    00229   scfFakeInterface<iEventHandler> >
    00230 {
    00231  private:
    00232   FrameSignpost_Logic3D () : scfImplementationType (this) { }
    00233  public:
    00234   CS_EVENTHANDLER_NAMES("crystalspace.signpost.logic3d")
    00235   CS_CONST_METHOD virtual const csHandlerID * GenericPrec
    00236     (csRef<iEventHandlerRegistry> &,
    00237      csRef<iEventNameRegistry> &,
    00238      csEventID) const;
    00239   CS_CONST_METHOD virtual const csHandlerID * GenericSucc
    00240     (csRef<iEventHandlerRegistry> &r1,
    00241      csRef<iEventNameRegistry> &r2,
    00242      csEventID e) const;
    00243 };
    00244
    00245 class FrameSignpost_3D2D
    00246 : public scfImplementation2<FrameSignpost_3D2D,
    00247   iFrameEventSignpost,
    00248   scfFakeInterface<iEventHandler> >
    00249 {
    00250  private:
    00251   FrameSignpost_3D2D () : scfImplementationType (this) { }
    00252  public:
    00253   CS_EVENTHANDLER_NAMES("crystalspace.signpost.3d2d")
    00254   CS_CONST_METHOD virtual const csHandlerID * GenericPrec
    00255     (csRef<iEventHandlerRegistry> &,
    00256      csRef<iEventNameRegistry> &,
    00257      csEventID) const;
    00258   CS_CONST_METHOD virtual const csHandlerID * GenericSucc
    00259     (csRef<iEventHandlerRegistry> &r1,
    00260      csRef<iEventNameRegistry> &r2,
    00261      csEventID e) const;
    00262 };
    00263
    00264 class FrameSignpost_2DConsole
    00265 : public scfImplementation2<FrameSignpost_2DConsole,
    00266   iFrameEventSignpost,
    00267   scfFakeInterface<iEventHandler> >
    00268 {
    00269  private:
    00270   FrameSignpost_2DConsole () : scfImplementationType (this) { }
    00271  public:
    00272   CS_EVENTHANDLER_NAMES("crystalspace.signpost.2dconsole")
    00273   CS_CONST_METHOD virtual const csHandlerID * GenericPrec
    00274     (csRef<iEventHandlerRegistry> &,
    00275      csRef<iEventNameRegistry> &,
    00276      csEventID) const;
    00277   CS_CONST_METHOD virtual const csHandlerID * GenericSucc
    00278     (csRef<iEventHandlerRegistry> &r1,
    00279      csRef<iEventNameRegistry> &r2,
    00280      csEventID e) const;
    00281 };
    00282
    00283 class FrameSignpost_ConsoleDebug
    00284 : public scfImplementation2<FrameSignpost_ConsoleDebug,
    00285   iFrameEventSignpost,
    00286   scfFakeInterface<iEventHandler> >
    00287 {
    00288  private:
    00289   FrameSignpost_ConsoleDebug () : scfImplementationType (this) { }
    00290  public:
    00291   CS_EVENTHANDLER_NAMES("crystalspace.signpost.consoledebug")
    00292   CS_CONST_METHOD virtual const csHandlerID * GenericPrec
    00293     (csRef<iEventHandlerRegistry> &,
    00294      csRef<iEventNameRegistry> &,
    00295      csEventID) const;
    00296   CS_CONST_METHOD virtual const csHandlerID * GenericSucc
    00297     (csRef<iEventHandlerRegistry> &r1,
    00298      csRef<iEventNameRegistry> &r2,
    00299      csEventID e) const;
    00300 };
    00301
    00302 class FrameSignpost_DebugFrame
    00303 : public scfImplementation2<FrameSignpost_DebugFrame,
    00304   iFrameEventSignpost,
    00305   scfFakeInterface<iEventHandler> >
    00306 {
    00307  private:
    00308   FrameSignpost_DebugFrame () : scfImplementationType (this) { }
    00309  public:
    00310   CS_EVENTHANDLER_NAMES("crystalspace.signpost.debugframe")
    00311   CS_CONST_METHOD virtual const csHandlerID * GenericPrec
    00312     (csRef<iEventHandlerRegistry> &,
    00313      csRef<iEventNameRegistry> &,
    00314      csEventID) const;
    00315   CS_CONST_METHOD virtual const csHandlerID * GenericSucc
    00316     (csRef<iEventHandlerRegistry> &r1,
    00317      csRef<iEventNameRegistry> &r2,
    00318      csEventID e) const;
    00319 };
    00320
    00321
    00327 #define CS_EVENTHANDLER_PHASE_LOGIC(x)                                  \
    00328 CS_EVENTHANDLER_NAMES(x)                                                \
    00329 CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS                            \
    00330 CS_CONST_METHOD virtual const csHandlerID * GenericPrec                 \
    00331 (csRef<iEventHandlerRegistry> &, csRef<iEventNameRegistry> &,           \
    00332  csEventID) const {                                                     \
    00333   return 0;                                                             \
    00334 }                                                                       \
    00335 CS_CONST_METHOD virtual const csHandlerID * GenericSucc                 \
    00336 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2,       \
    00337  csEventID event) const {                                               \
    00338   static csHandlerID succConstraint[6];                                 \
    00339   if (event != csevFrame(r2))                                           \
    00340     return 0;                                                           \
    00341   succConstraint[0] = FrameSignpost_Logic3D::StaticID(r1);              \
    00342   succConstraint[1] = FrameSignpost_3D2D::StaticID(r1);                 \
    00343   succConstraint[2] = FrameSignpost_2DConsole::StaticID(r1);            \
    00344   succConstraint[3] = FrameSignpost_ConsoleDebug::StaticID(r1);         \
    00345   succConstraint[4] = FrameSignpost_DebugFrame::StaticID(r1);           \
    00346   succConstraint[5] = CS_HANDLERLIST_END;                               \
    00347   return succConstraint;                                                \
    00348 }
    00349
    00356 #define CS_EVENTHANDLER_PHASE_3D(x)                                     \
    00357 CS_EVENTHANDLER_NAMES(x)                                                \
    00358 CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS                            \
    00359 CS_CONST_METHOD virtual const csHandlerID * GenericPrec                 \
    00360 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2,       \
    00361  csEventID event) const {                                               \
    00362   static csHandlerID precConstraint[2];                                 \
    00363   if (event != csevFrame(r2))                                           \
    00364     return 0;                                                           \
    00365   precConstraint[0] = FrameSignpost_Logic3D::StaticID(r1);              \
    00366   precConstraint[1] = CS_HANDLERLIST_END;                               \
    00367   return precConstraint;                                                \
    00368 }                                                                       \
    00369 CS_CONST_METHOD virtual const csHandlerID * GenericSucc                 \
    00370 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2,       \
    00371  csEventID event) const {                                               \
    00372   static csHandlerID succConstraint[5];                                 \
    00373   if (event != csevFrame(r2))                                           \
    00374     return 0;                                                           \
    00375   succConstraint[0] = FrameSignpost_3D2D::StaticID(r1);                 \
    00376   succConstraint[1] = FrameSignpost_2DConsole::StaticID(r1);            \
    00377   succConstraint[2] = FrameSignpost_ConsoleDebug::StaticID(r1);         \
    00378   succConstraint[3] = FrameSignpost_DebugFrame::StaticID(r1);           \
    00379   succConstraint[4] = CS_HANDLERLIST_END;                               \
    00380   return succConstraint;                                                \
    00381 }
    00382
    00389 #define CS_EVENTHANDLER_PHASE_2D(x)                                     \
    00390 CS_EVENTHANDLER_NAMES(x)                                                \
    00391 CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS                            \
    00392 CS_CONST_METHOD virtual const csHandlerID * GenericPrec                 \
    00393 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2,       \
    00394  csEventID event) const {                                               \
    00395   static csHandlerID precConstraint[3];                                 \
    00396   if (event != csevFrame(r2))                                           \
    00397     return 0;                                                           \
    00398   precConstraint[0] = FrameSignpost_Logic3D::StaticID(r1);              \
    00399   precConstraint[1] = FrameSignpost_3D2D::StaticID(r1);                 \
    00400   precConstraint[2] = CS_HANDLERLIST_END;                               \
    00401   return precConstraint;                                                \
    00402 }                                                                       \
    00403 CS_CONST_METHOD virtual const csHandlerID * GenericSucc                 \
    00404 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2,       \
    00405  csEventID event) const {                                               \
    00406   static csHandlerID succConstraint[4];                                 \
    00407   if (event != csevFrame(r2))                                           \
    00408     return 0;                                                           \
    00409   succConstraint[0] = FrameSignpost_2DConsole::StaticID(r1);            \
    00410   succConstraint[1] = FrameSignpost_ConsoleDebug::StaticID(r1);         \
    00411   succConstraint[2] = FrameSignpost_DebugFrame::StaticID(r1);           \
    00412   succConstraint[3] = CS_HANDLERLIST_END;                               \
    00413   return succConstraint;                                                \
    00414 }
    00415
    00422 #define CS_EVENTHANDLER_PHASE_CONSOLE(x)                                \
    00423 CS_EVENTHANDLER_NAMES(x)                                                \
    00424 CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS                            \
    00425 CS_CONST_METHOD virtual const csHandlerID * GenericPrec                 \
    00426 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2,       \
    00427  csEventID event) const {                                               \
    00428   static csHandlerID precConstraint[4];                                 \
    00429   if (event != csevFrame(r2))                                           \
    00430     return 0;                                                           \
    00431   precConstraint[0] = FrameSignpost_Logic3D::StaticID(r1);              \
    00432   precConstraint[1] = FrameSignpost_3D2D::StaticID(r1);                 \
    00433   precConstraint[2] = FrameSignpost_2DConsole::StaticID(r1);            \
    00434   precConstraint[3] = CS_HANDLERLIST_END;                               \
    00435   return precConstraint;                                                \
    00436 }                                                                       \
    00437 CS_CONST_METHOD virtual const csHandlerID * GenericSucc                 \
    00438 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2,       \
    00439  csEventID event) const {                                               \
    00440   static csHandlerID succConstraint[3];                                 \
    00441   if (event != csevFrame(r2))                                           \
    00442     return 0;                                                           \
    00443   succConstraint[0] = FrameSignpost_ConsoleDebug::StaticID(r1);         \
    00444   succConstraint[1] = FrameSignpost_DebugFrame::StaticID(r1);           \
    00445   succConstraint[2] = CS_HANDLERLIST_END;                               \
    00446   return succConstraint;                                                \
    00447 }
    00448
    00455 #define CS_EVENTHANDLER_PHASE_DEBUG(x)                                  \
    00456 CS_EVENTHANDLER_NAMES(x)                                                \
    00457 CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS                            \
    00458 CS_CONST_METHOD virtual const csHandlerID * GenericPrec                 \
    00459 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2,       \
    00460  csEventID event) const {                                               \
    00461   static csHandlerID precConstraint[5];                                 \
    00462   if (event != csevFrame(r2))                                           \
    00463     return 0;                                                           \
    00464   precConstraint[0] = FrameSignpost_Logic3D::StaticID(r1);              \
    00465   precConstraint[0] = FrameSignpost_3D2D::StaticID(r1);                 \
    00466   precConstraint[0] = FrameSignpost_2DConsole::StaticID(r1);            \
    00467   precConstraint[0] = FrameSignpost_ConsoleDebug::StaticID(r1);         \
    00468   precConstraint[1] = CS_HANDLERLIST_END;                               \
    00469   return precConstraint;                                                \
    00470 }                                                                       \
    00471 CS_CONST_METHOD virtual const csHandlerID * GenericSucc                 \
    00472 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2,       \
    00473  csEventID event) const {                                               \
    00474   static csHandlerID succConstraint[2];                                 \
    00475   if (event != csevFrame(r2))                                           \
    00476     return 0;                                                           \
    00477   succConstraint[0] = FrameSignpost_DebugFrame::StaticID(r1);           \
    00478   succConstraint[1] = CS_HANDLERLIST_END;                               \
    00479   return succConstraint;                                                \
    00480 }
    00481
    00488 #define CS_EVENTHANDLER_PHASE_FRAME(x)                                  \
    00489 CS_EVENTHANDLER_NAMES(x)                                                \
    00490 CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS                            \
    00491 CS_CONST_METHOD virtual const csHandlerID * GenericPrec                 \
    00492 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2,       \
    00493  csEventID event) const {                                               \
    00494   static csHandlerID precConstraint[6];                                 \
    00495   if (event != csevFrame(r2))                                           \
    00496     return 0;                                                           \
    00497   precConstraint[0] = FrameSignpost_Logic3D::StaticID(r1);              \
    00498   precConstraint[0] = FrameSignpost_3D2D::StaticID(r1);                 \
    00499   precConstraint[0] = FrameSignpost_2DConsole::StaticID(r1);            \
    00500   precConstraint[0] = FrameSignpost_ConsoleDebug::StaticID(r1);         \
    00501   precConstraint[0] = FrameSignpost_DebugFrame::StaticID(r1);           \
    00502   precConstraint[1] = CS_HANDLERLIST_END;                               \
    00503   return precConstraint;                                                \
    00504 }                                                                       \
    00505 CS_CONST_METHOD virtual const csHandlerID * GenericSucc                 \
    00506 (csRef<iEventHandlerRegistry> &, csRef<iEventNameRegistry> &,           \
    00507  csEventID) const {                                                     \
    00508   return 0;                                                             \
    00509 }
    00510
    00511
    00512 #endif // __CS_UTIL_EVENTHNAMES_H__