HowTo Add a new Event

  • In BasicEvent, add new entry to EventTypes enum (say, EVENT_DISPLAY), always at the end of the list
  • Add the new class to LibEvents project (say, DisplayEvent), in namespace events
  • Add public enheritance of BasicEvent
  • In all constructors of DisplayEvent, add to initialization list: BasicEvent(BasicEvent::EVENT_DISPLAY)
  • Define and implement following functions:
   virtual void saveToStream(std::ostream &os) const;
   virtual void readFromStream(std::istream &is);
   virtual void writeDebugInfo(std::ostream &os) const; 
  • Add include to new class in AllEvents.h
  • In EventsAllocationRegistry.cpp: add registerAllocator<DisplayEvent>(BasicEvent::EVENT_DISPLAY);

Notes

Of cause, you can use any data members for your class, but for simple types it's recommended to use GenericDataType template class - it generally behaves like provided type, but also has default implementation of all serialization functions. See, for example, the way HANDLE type is implemented in FileEvent (it also demonstrates adding a custom operator<< for std::ostream)

Last edited Jul 16, 2008 at 8:56 PM by migo, version 3

Comments

No comments yet.