Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

DataEvent.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_DataEvent_h_
00003 #define INCLUDED_DataEvent_h_
00004 
00005 #include "Events/EventBase.h"
00006 
00007 //! for passing around data (or pointers to data)
00008 template<class T, int TID=-1>
00009 class DataEvent : public EventBase {
00010 public:
00011   //!@name Constructors
00012   //!
00013   DataEvent() : EventBase(), data() {}
00014   DataEvent(const T& d, EventGeneratorID_t gid, size_t sid, EventTypeID_t tid, unsigned int dur=0) : EventBase(gid,sid,tid,dur), data(d) {}
00015   DataEvent(const T& d, EventGeneratorID_t gid, size_t sid, EventTypeID_t tid, unsigned int dur, const std::string& n, float mag) : EventBase(gid,sid,tid,dur,n,mag), data(d) {}
00016 
00017   //! copy constructor
00018   DataEvent(const DataEvent& evt) : EventBase(evt), data(evt.data) {}
00019   
00020   //! assignment
00021   const DataEvent& operator=(const DataEvent& evt) { EventBase::operator=(evt); data=evt.data; return *this; }
00022 
00023   virtual EventBase* clone() const { return new DataEvent<T>(*this); }
00024   //@}
00025 
00026   void setData(const T& d) { data=d; } //!< assigns @a d to the internal #data
00027   const T& getData() const { return data; } //!< returns #data
00028   T& getData() { return data; } //!< returns #data
00029 
00030   virtual classTypeID_t getClassTypeID() const { return autoRegisterDataEvent; }
00031 
00032 protected:
00033   T data; //!< the data being communicated
00034   
00035   //! this silliness is to work around parsing issue in gcc 3.3 branch
00036   static EventBase::classTypeID_t registerDataType(EventBase::classTypeID_t classid) {
00037 #if !defined(__GNUC__) || __GNUC__>3 || __GNUC__==3 && __GNUC_MINOR__>3
00038     // if here, using gcc 3.4 or later...
00039     // gcc 3.3 won't let me call this templated member function?!?!
00040     return getTypeRegistry().registerType< DataEvent<T,TID> >(classid);
00041 #else // using gcc 3.3.x or prior
00042     // instead I have to wind up registering my own instance instead of using the FamilyFactory's instance generation
00043     return getTypeRegistry().registerFactory(classid,new EventBase::registry_t::FactoryType< DataEvent<T,TID> >);
00044 #endif
00045   }
00046   static const EventBase::classTypeID_t autoRegisterDataEvent; //!< causes class type id to automatically be regsitered with EventBase's FamilyFactory (getTypeRegistry())
00047 };
00048 
00049 template<class T,int TID>
00050 const EventBase::classTypeID_t DataEvent<T,TID>::autoRegisterDataEvent=DataEvent<T,TID>::registerDataType(makeClassTypeID("DATA")+(TID<0?getTypeRegistry().getNumTypes():TID));
00051 
00052 
00053 /*! @file
00054  * @brief Defines DataEvent, for passing around data (or pointers to data)
00055  * @author ejt (Creator)
00056  *
00057  * $Author: ejt $
00058  * $Name: tekkotsu-4_0 $
00059  * $Revision: 1.6 $
00060  * $State: Exp $
00061  * $Date: 2007/11/13 04:16:02 $
00062  */
00063 
00064 #endif

Tekkotsu v4.0
Generated Thu Nov 22 00:54:52 2007 by Doxygen 1.5.4