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" 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 struct iFrameEventSignpost : public iEventHandler 00212 { 00213 public: 00214 iFrameEventSignpost () { } 00215 virtual ~iFrameEventSignpost () { } 00216 CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS 00217 virtual bool HandleEvent (iEvent&) 00218 { 00219 return false; 00220 } 00221 }; 00222 00223 00224 class FrameSignpost_Logic3D 00225 : public scfImplementation2<FrameSignpost_Logic3D, 00226 iFrameEventSignpost, 00227 scfFakeInterface<iEventHandler> > 00228 { 00229 private: 00230 FrameSignpost_Logic3D () : scfImplementationType (this) { } 00231 public: 00232 CS_EVENTHANDLER_NAMES("crystalspace.signpost.logic3d") 00233 CS_CONST_METHOD virtual const csHandlerID * GenericPrec 00234 (csRef<iEventHandlerRegistry> &, 00235 csRef<iEventNameRegistry> &, 00236 csEventID) const; 00237 CS_CONST_METHOD virtual const csHandlerID * GenericSucc 00238 (csRef<iEventHandlerRegistry> &r1, 00239 csRef<iEventNameRegistry> &r2, 00240 csEventID e) const; 00241 }; 00242 00243 class FrameSignpost_3D2D 00244 : public scfImplementation2<FrameSignpost_3D2D, 00245 iFrameEventSignpost, 00246 scfFakeInterface<iEventHandler> > 00247 { 00248 private: 00249 FrameSignpost_3D2D () : scfImplementationType (this) { } 00250 public: 00251 CS_EVENTHANDLER_NAMES("crystalspace.signpost.3d2d") 00252 CS_CONST_METHOD virtual const csHandlerID * GenericPrec 00253 (csRef<iEventHandlerRegistry> &, 00254 csRef<iEventNameRegistry> &, 00255 csEventID) const; 00256 CS_CONST_METHOD virtual const csHandlerID * GenericSucc 00257 (csRef<iEventHandlerRegistry> &r1, 00258 csRef<iEventNameRegistry> &r2, 00259 csEventID e) const; 00260 }; 00261 00262 class FrameSignpost_2DConsole 00263 : public scfImplementation2<FrameSignpost_2DConsole, 00264 iFrameEventSignpost, 00265 scfFakeInterface<iEventHandler> > 00266 { 00267 private: 00268 FrameSignpost_2DConsole () : scfImplementationType (this) { } 00269 public: 00270 CS_EVENTHANDLER_NAMES("crystalspace.signpost.2dconsole") 00271 CS_CONST_METHOD virtual const csHandlerID * GenericPrec 00272 (csRef<iEventHandlerRegistry> &, 00273 csRef<iEventNameRegistry> &, 00274 csEventID) const; 00275 CS_CONST_METHOD virtual const csHandlerID * GenericSucc 00276 (csRef<iEventHandlerRegistry> &r1, 00277 csRef<iEventNameRegistry> &r2, 00278 csEventID e) const; 00279 }; 00280 00281 class FrameSignpost_ConsoleDebug 00282 : public scfImplementation2<FrameSignpost_ConsoleDebug, 00283 iFrameEventSignpost, 00284 scfFakeInterface<iEventHandler> > 00285 { 00286 private: 00287 FrameSignpost_ConsoleDebug () : scfImplementationType (this) { } 00288 public: 00289 CS_EVENTHANDLER_NAMES("crystalspace.signpost.consoledebug") 00290 CS_CONST_METHOD virtual const csHandlerID * GenericPrec 00291 (csRef<iEventHandlerRegistry> &, 00292 csRef<iEventNameRegistry> &, 00293 csEventID) const; 00294 CS_CONST_METHOD virtual const csHandlerID * GenericSucc 00295 (csRef<iEventHandlerRegistry> &r1, 00296 csRef<iEventNameRegistry> &r2, 00297 csEventID e) const; 00298 }; 00299 00300 class FrameSignpost_DebugFrame 00301 : public scfImplementation2<FrameSignpost_DebugFrame, 00302 iFrameEventSignpost, 00303 scfFakeInterface<iEventHandler> > 00304 { 00305 private: 00306 FrameSignpost_DebugFrame () : scfImplementationType (this) { } 00307 public: 00308 CS_EVENTHANDLER_NAMES("crystalspace.signpost.debugframe") 00309 CS_CONST_METHOD virtual const csHandlerID * GenericPrec 00310 (csRef<iEventHandlerRegistry> &, 00311 csRef<iEventNameRegistry> &, 00312 csEventID) const; 00313 CS_CONST_METHOD virtual const csHandlerID * GenericSucc 00314 (csRef<iEventHandlerRegistry> &r1, 00315 csRef<iEventNameRegistry> &r2, 00316 csEventID e) const; 00317 }; 00318 00319 00325 #define CS_EVENTHANDLER_PHASE_LOGIC(x) \ 00326 CS_EVENTHANDLER_NAMES(x) \ 00327 CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS \ 00328 CS_CONST_METHOD virtual const csHandlerID * GenericPrec \ 00329 (csRef<iEventHandlerRegistry> &, csRef<iEventNameRegistry> &, \ 00330 csEventID) const { \ 00331 return 0; \ 00332 } \ 00333 CS_CONST_METHOD virtual const csHandlerID * GenericSucc \ 00334 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2, \ 00335 csEventID event) const { \ 00336 static csHandlerID succConstraint[6]; \ 00337 if (event != csevFrame(r2)) \ 00338 return 0; \ 00339 succConstraint[0] = FrameSignpost_Logic3D::StaticID(r1); \ 00340 succConstraint[1] = FrameSignpost_3D2D::StaticID(r1); \ 00341 succConstraint[2] = FrameSignpost_2DConsole::StaticID(r1); \ 00342 succConstraint[3] = FrameSignpost_ConsoleDebug::StaticID(r1); \ 00343 succConstraint[4] = FrameSignpost_DebugFrame::StaticID(r1); \ 00344 succConstraint[5] = CS_HANDLERLIST_END; \ 00345 return succConstraint; \ 00346 } 00347 00354 #define CS_EVENTHANDLER_PHASE_3D(x) \ 00355 CS_EVENTHANDLER_NAMES(x) \ 00356 CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS \ 00357 CS_CONST_METHOD virtual const csHandlerID * GenericPrec \ 00358 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2, \ 00359 csEventID event) const { \ 00360 static csHandlerID precConstraint[2]; \ 00361 if (event != csevFrame(r2)) \ 00362 return 0; \ 00363 precConstraint[0] = FrameSignpost_Logic3D::StaticID(r1); \ 00364 precConstraint[1] = CS_HANDLERLIST_END; \ 00365 return precConstraint; \ 00366 } \ 00367 CS_CONST_METHOD virtual const csHandlerID * GenericSucc \ 00368 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2, \ 00369 csEventID event) const { \ 00370 static csHandlerID succConstraint[5]; \ 00371 if (event != csevFrame(r2)) \ 00372 return 0; \ 00373 succConstraint[0] = FrameSignpost_3D2D::StaticID(r1); \ 00374 succConstraint[1] = FrameSignpost_2DConsole::StaticID(r1); \ 00375 succConstraint[2] = FrameSignpost_ConsoleDebug::StaticID(r1); \ 00376 succConstraint[3] = FrameSignpost_DebugFrame::StaticID(r1); \ 00377 succConstraint[4] = CS_HANDLERLIST_END; \ 00378 return succConstraint; \ 00379 } 00380 00387 #define CS_EVENTHANDLER_PHASE_2D(x) \ 00388 CS_EVENTHANDLER_NAMES(x) \ 00389 CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS \ 00390 CS_CONST_METHOD virtual const csHandlerID * GenericPrec \ 00391 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2, \ 00392 csEventID event) const { \ 00393 static csHandlerID precConstraint[3]; \ 00394 if (event != csevFrame(r2)) \ 00395 return 0; \ 00396 precConstraint[0] = FrameSignpost_Logic3D::StaticID(r1); \ 00397 precConstraint[1] = FrameSignpost_3D2D::StaticID(r1); \ 00398 precConstraint[2] = CS_HANDLERLIST_END; \ 00399 return precConstraint; \ 00400 } \ 00401 CS_CONST_METHOD virtual const csHandlerID * GenericSucc \ 00402 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2, \ 00403 csEventID event) const { \ 00404 static csHandlerID succConstraint[4]; \ 00405 if (event != csevFrame(r2)) \ 00406 return 0; \ 00407 succConstraint[0] = FrameSignpost_2DConsole::StaticID(r1); \ 00408 succConstraint[1] = FrameSignpost_ConsoleDebug::StaticID(r1); \ 00409 succConstraint[2] = FrameSignpost_DebugFrame::StaticID(r1); \ 00410 succConstraint[3] = CS_HANDLERLIST_END; \ 00411 return succConstraint; \ 00412 } 00413 00420 #define CS_EVENTHANDLER_PHASE_CONSOLE(x) \ 00421 CS_EVENTHANDLER_NAMES(x) \ 00422 CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS \ 00423 CS_CONST_METHOD virtual const csHandlerID * GenericPrec \ 00424 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2, \ 00425 csEventID event) const { \ 00426 static csHandlerID precConstraint[4]; \ 00427 if (event != csevFrame(r2)) \ 00428 return 0; \ 00429 precConstraint[0] = FrameSignpost_Logic3D::StaticID(r1); \ 00430 precConstraint[1] = FrameSignpost_3D2D::StaticID(r1); \ 00431 precConstraint[2] = FrameSignpost_2DConsole::StaticID(r1); \ 00432 precConstraint[3] = CS_HANDLERLIST_END; \ 00433 return precConstraint; \ 00434 } \ 00435 CS_CONST_METHOD virtual const csHandlerID * GenericSucc \ 00436 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2, \ 00437 csEventID event) const { \ 00438 static csHandlerID succConstraint[3]; \ 00439 if (event != csevFrame(r2)) \ 00440 return 0; \ 00441 succConstraint[0] = FrameSignpost_ConsoleDebug::StaticID(r1); \ 00442 succConstraint[1] = FrameSignpost_DebugFrame::StaticID(r1); \ 00443 succConstraint[2] = CS_HANDLERLIST_END; \ 00444 return succConstraint; \ 00445 } 00446 00453 #define CS_EVENTHANDLER_PHASE_DEBUG(x) \ 00454 CS_EVENTHANDLER_NAMES(x) \ 00455 CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS \ 00456 CS_CONST_METHOD virtual const csHandlerID * GenericPrec \ 00457 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2, \ 00458 csEventID event) const { \ 00459 static csHandlerID precConstraint[5]; \ 00460 if (event != csevFrame(r2)) \ 00461 return 0; \ 00462 precConstraint[0] = FrameSignpost_Logic3D::StaticID(r1); \ 00463 precConstraint[0] = FrameSignpost_3D2D::StaticID(r1); \ 00464 precConstraint[0] = FrameSignpost_2DConsole::StaticID(r1); \ 00465 precConstraint[0] = FrameSignpost_ConsoleDebug::StaticID(r1); \ 00466 precConstraint[1] = CS_HANDLERLIST_END; \ 00467 return precConstraint; \ 00468 } \ 00469 CS_CONST_METHOD virtual const csHandlerID * GenericSucc \ 00470 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2, \ 00471 csEventID event) const { \ 00472 static csHandlerID succConstraint[2]; \ 00473 if (event != csevFrame(r2)) \ 00474 return 0; \ 00475 succConstraint[0] = FrameSignpost_DebugFrame::StaticID(r1); \ 00476 succConstraint[1] = CS_HANDLERLIST_END; \ 00477 return succConstraint; \ 00478 } 00479 00485 #define CS_EVENTHANDLER_PHASE_FRAME(x) \ 00486 CS_EVENTHANDLER_NAMES(x) \ 00487 CS_EVENTHANDLER_DEFAULT_INSTANCE_CONSTRAINTS \ 00488 CS_CONST_METHOD virtual const csHandlerID * GenericPrec \ 00489 (csRef<iEventHandlerRegistry> &r1, csRef<iEventNameRegistry> &r2, \ 00490 csEventID event) const { \ 00491 static csHandlerID precConstraint[6]; \ 00492 if (event != csevFrame(r2)) \ 00493 return 0; \ 00494 precConstraint[0] = FrameSignpost_Logic3D::StaticID(r1); \ 00495 precConstraint[0] = FrameSignpost_3D2D::StaticID(r1); \ 00496 precConstraint[0] = FrameSignpost_2DConsole::StaticID(r1); \ 00497 precConstraint[0] = FrameSignpost_ConsoleDebug::StaticID(r1); \ 00498 precConstraint[0] = FrameSignpost_DebugFrame::StaticID(r1); \ 00499 precConstraint[1] = CS_HANDLERLIST_END; \ 00500 return precConstraint; \ 00501 } \ 00502 CS_CONST_METHOD virtual const csHandlerID * GenericSucc \ 00503 (csRef<iEventHandlerRegistry> &, csRef<iEventNameRegistry> &, \ 00504 csEventID) const { \ 00505 return 0; \ 00506 } 00507 00508 #endif // __CS_UTIL_EVENTHNAMES_H__
Generated for Crystal Space 1.2 by doxygen 1.4.7