event.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Filename: event.h
  2. // Created by: drose (08Feb99)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. // Apparently some OSX system header defines EVENT_H. Go figure.
  15. #ifndef __EVENT_H__
  16. #define __EVENT_H__
  17. #include "pandabase.h"
  18. #include "eventParameter.h"
  19. #include "typedReferenceCount.h"
  20. class EventReceiver;
  21. ////////////////////////////////////////////////////////////////////
  22. // Class : Event
  23. // Description : A named event, possibly with parameters. Anyone in
  24. // any thread may throw an event at any time; there will
  25. // be one process responsible for reading and dispacting
  26. // on the events (but not necessarily immediately).
  27. //
  28. // This function use to inherit from Namable, but that
  29. // makes it too expensive to get its name the Python
  30. // code. Now it just copies the Namable interface in.
  31. ////////////////////////////////////////////////////////////////////
  32. class EXPCL_PANDA_EVENT Event : public TypedReferenceCount {
  33. PUBLISHED:
  34. Event(const string &event_name, EventReceiver *receiver = NULL);
  35. Event(const Event &copy);
  36. void operator = (const Event &copy);
  37. ~Event();
  38. INLINE void set_name(const string &name);
  39. INLINE void clear_name();
  40. INLINE bool has_name() const;
  41. INLINE const string &get_name() const;
  42. void add_parameter(const EventParameter &obj);
  43. int get_num_parameters() const;
  44. EventParameter get_parameter(int n) const;
  45. MAKE_SEQ(get_parameters, get_num_parameters, get_parameter);
  46. bool has_receiver() const;
  47. EventReceiver *get_receiver() const;
  48. void set_receiver(EventReceiver *receiver);
  49. void clear_receiver();
  50. void output(ostream &out) const;
  51. protected:
  52. typedef pvector<EventParameter> ParameterList;
  53. ParameterList _parameters;
  54. EventReceiver *_receiver;
  55. private:
  56. string _name;
  57. public:
  58. static TypeHandle get_class_type() {
  59. return _type_handle;
  60. }
  61. static void init_type() {
  62. TypedReferenceCount::init_type();
  63. register_type(_type_handle, "Event",
  64. TypedReferenceCount::get_class_type());
  65. }
  66. virtual TypeHandle get_type() const {
  67. return get_class_type();
  68. }
  69. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  70. private:
  71. static TypeHandle _type_handle;
  72. };
  73. INLINE ostream &operator << (ostream &out, const Event &n);
  74. #include "event.I"
  75. #endif