Panda3D

event.h

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