00001 // Filename: event.h 00002 // Created by: drose (08Feb99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #ifndef EVENT_H 00020 #define EVENT_H 00021 00022 #include <pandabase.h> 00023 00024 #include "eventParameter.h" 00025 00026 #include <typedReferenceCount.h> 00027 00028 class EventReceiver; 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Class : Event 00032 // Description : A named event, possibly with parameters. Anyone in 00033 // any thread may throw an event at any time; there will 00034 // be one process responsible for reading and dispacting 00035 // on the events (but not necessarily immediately). 00036 // 00037 // This function use to inherit from Namable, but that 00038 // makes it too expensive to get its name the Python 00039 // code. Now it just copies the Namable interface in. 00040 //////////////////////////////////////////////////////////////////// 00041 class EXPCL_PANDAEXPRESS Event : public TypedReferenceCount { 00042 PUBLISHED: 00043 Event(const string &event_name, EventReceiver *receiver = NULL); 00044 Event(const Event ©); 00045 void operator = (const Event ©); 00046 ~Event(); 00047 00048 INLINE void set_name(const string &name); 00049 INLINE void clear_name(); 00050 INLINE bool has_name() const; 00051 INLINE const string &get_name() const; 00052 00053 void add_parameter(const EventParameter &obj); 00054 00055 int get_num_parameters() const; 00056 EventParameter get_parameter(int n) const; 00057 00058 bool has_receiver() const; 00059 EventReceiver *get_receiver() const; 00060 void set_receiver(EventReceiver *receiver); 00061 void clear_receiver(); 00062 00063 void output(ostream &out) const; 00064 00065 protected: 00066 typedef pvector<EventParameter> ParameterList; 00067 ParameterList _parameters; 00068 EventReceiver *_receiver; 00069 00070 private: 00071 string _name; 00072 00073 public: 00074 static TypeHandle get_class_type() { 00075 return _type_handle; 00076 } 00077 static void init_type() { 00078 TypedReferenceCount::init_type(); 00079 register_type(_type_handle, "Event", 00080 TypedReferenceCount::get_class_type()); 00081 } 00082 virtual TypeHandle get_type() const { 00083 return get_class_type(); 00084 } 00085 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00086 00087 private: 00088 static TypeHandle _type_handle; 00089 }; 00090 00091 INLINE ostream &operator << (ostream &out, const Event &n); 00092 00093 #include "event.I" 00094 00095 #endif