This shows you the differences between two versions of the page.

Link to this comparison view

hobject [2009/03/20 15:04] (current)
hadrien created
Line 1: Line 1:
 +===== Overview =====
 +HObject intents to gather common features of most classes from HBot. It looks like Qt's QObject, it tastes like it, but it is not a QObject. For the moment the only feature of HObject is related to signal/slot communication.
 +===== Signal/Slot =====
 +The principle is to declare signals in classes that may raise events, to declare slots in classes that may act when an event is raised, and to connect signals and slots that correspond to the same event. This connection is not automatic, since it may be dynamically modified depending on algorithmic needs.
 +==== Technics ====
 +The signal/slot mechanism is implemented with templates and hash tables. Each object has a table for declaring signals, and an object list to send the signal to, and a table for declaring slots, and the method pointer associated to this slot. Templates are used because method pointers in C++ need the Class to be known, and this can be done with template function and template classes for wrapping slots.
 +==== Use ====
 +  - declareSignal(eventname) is used when a class declares it may raise a signal for an event
 +  - declareSlot(eventname,​ method pointer) is used when a class declares the slot method to be used on reception of an event
 +  - connect(eventname,​ slot) is used to connect the current object to slot object, for a given event
 +  - sendSignal(eventname,​ parameter) is used to actually emit an event, with a generic parameter
 +  - listSignals and listSlots are used to list signals and slots currently declared
 +  - disconnect(eventname,​ slot) reverts a previous connect()
 +Declarations are usually made in constructors,​ but since all the signal/slot mechanism is dynamic, everything can be done at any moment. Beware of multi-threading though, hash tables are absolutely not thread-safe.
hobject.txt ยท Last modified: 2009/03/20 15:04 by hadrien
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS La rache Driven by DokuWiki