Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8035 in orxonox.OLD for trunk/src/lib/gui/gl_gui/signal_connector.h


Ignore:
Timestamp:
May 31, 2006, 4:20:51 PM (18 years ago)
Author:
bensch
Message:

gui: merged the gui back to the trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/gui/gl_gui/signal_connector.h

    r7919 r8035  
    1212{
    1313
    14 #define DeclareSignal(name, params) \
     14  //////////////// TO BE IGNORED BY YOU /////
     15#define DeclareSignalBegin(SignalName) \
    1516  public: \
    16    void signal_ ##connect ##name(const SignalConnector& connector) { \
    17      name ## connected.push_back(connector); \
     17   void signal_ ## connect ## SignalName(const SignalConnector& connector) { \
     18     SignalName ## connected.push_back(connector); \
     19}\
     20   Signal& getSignalVector_##SignalName () { return this->SignalName ## connected; }; \
     21  private:
     22
     23#define DeclareSignalEnd(SignalName) \
     24  Signal SignalName ## connected
     25  /////////////////////////////////////////////
     26
     27
     28  /**
     29   * @brief declares a new Signal.
     30   * @param SignalName the Name of the Signal.
     31   */
     32#define DeclareSignal0(SignalName) \
     33  DeclareSignalBegin(SignalName) \
     34   void  SignalName () { \
     35     for (unsigned int i = 0; i < SignalName ## connected .size(); i++) \
     36       SignalName ## connected[i] (); \
    1837   }\
    19   private: \
    20    void  signal_ ## name params { \
    21      for (unsigned int i = 0; i < name ## connected . size(); i++) \
    22        name ## connected[i] ("TEST"); \
    23    }\
    24    std::vector<SignalConnector> name ## connected
     38     DeclareSignalEnd(SignalName)
    2539
    26   //! A class for Conncting Signals to Objects, inside of the GUI
     40
     41  /**
     42   * @brief declares a new Signal.
     43   * @param SignalName the Name of the Signal.
     44   * @param param0 the first Parameter the Function takes
     45   */
     46#define DeclareSignal1(SignalName, param0) \
     47  DeclareSignalBegin(SignalName) \
     48   void  SignalName (param0 val0) { \
     49     for (unsigned int i = 0; i < SignalName ## connected .size(); i++) \
     50       SignalName ## connected[i] (val0); \
     51    }\
     52    DeclareSignalEnd(SignalName)
     53
     54  /**
     55   * @brief declares a new Signal.
     56   * @param SignalName the Name of the Signal.
     57   * @param param0 the first Parameter the Function takes
     58   * @param param1 the second Parameter the Function takes
     59   */
     60#define DeclareSignal2(SignalName, param0, param1) \
     61  DeclareSignalBegin(SignalName) \
     62   void  SignalName (param0 val0, param1 val1) { \
     63     for (unsigned int i = 0; i < SignalName ## connected .size(); i++) \
     64       SignalName ## connected[i] (val0, val1); \
     65}\
     66    DeclareSignalEnd(SignalName)
     67
     68
     69
     70  /**
     71   * @brief declares a new Signal.
     72   * @param SignalName the Name of the Signal.
     73   * @param param0 the first Parameter the Function takes
     74   * @param param1 the second Parameter the Function takes
     75   * @param param2 the third Parameter the Function takes
     76   */
     77#define DeclareSignal3(SignalName, param0, param1, param2) \
     78  DeclareSignalBegin(SignalName) \
     79   void  SignalName (param0 val0, param1 val1, param2 val2) { \
     80     for (unsigned int i = 0; i < SignalName ## connected .size(); i++) \
     81       SignalName ## connected[i] (val0, val1, val2); \
     82}\
     83    DeclareSignalEnd(SignalName)
     84
     85  /**
     86   * @brief declares a new Signal.
     87   * @param SignalName the Name of the Signal.
     88   * @param param0 the first Parameter the Function takes
     89   * @param param1 the second Parameter the Function takes
     90   * @param param2 the third Parameter the Function takes
     91   * @param param3 the fourth Parameter the Function takes
     92   */
     93#define DeclareSignal4(SignalName, param0, param1, param2, param3) \
     94  DeclareSignalBegin(SignalName) \
     95   void  SignalName (param0 val0, param1 val1, param2 val2, param3 val3) { \
     96     for (unsigned int i = 0; i < SignalName ## connected .size(); i++) \
     97       SignalName ## connected[i] (val0, val1, val2, val3); \
     98}\
     99    DeclareSignalEnd(SignalName)
     100
     101
     102  /**
     103   * @brief declares a new Signal.
     104   * @param SignalName the Name of the Signal.
     105   * @param param0 the first Parameter the Function takes
     106   * @param param1 the second Parameter the Function takes
     107   * @param param2 the third Parameter the Function takes
     108   * @param param4 the fifth Parameter the Function takes
     109   */
     110#define DeclareSignal5(SignalName, param0, param1, param2, param3, param4) \
     111  DeclareSignalBegin(SignalName) \
     112   void  SignalName (param0 val0, param1 val1, param2 val2, param3 val3, param4 val4) { \
     113     for (unsigned int i = 0; i < SignalName ## connected .size(); i++) \
     114       SignalName ## connected[i] (val0, val1, val2, val3, val4); \
     115}\
     116    DeclareSignalEnd(SignalName)
     117
     118
     119  /**
     120   * @brief selects a Signal.
     121   * @param SignalName the Signal to be retrieved.
     122   */
     123#define SIGNAL(Object, SignalName) \
     124    Object->getSignalVector_##SignalName()
     125
     126  /**
     127   * @brief defines a Slot, the sink of a Signal.
     128   * @param Class the Class the Slot belongs to.
     129   * @param function the Function to Connect to.
     130   */
     131#define SLOT(Class, function) \
     132    createExecutor<Class>(&Class::function)
     133
     134  /**
     135   * @brief emits function
     136   */
     137#define emit(function) function
     138
     139  //! A class for Conncting Signals to Objects, inside of the Graphical user interface.
     140  /**
     141   * The SignalConnector binds an Object to a Functional (Executor)
     142   * The Usage is quite easy in the Widget for this:
     143   *
     144   * int the header (Class Definition) you can add a definition of a Signal with:
     145   * @verbatim DeclareSignal3(my_signal, int, int, float)
     146   * and a Signal with the the Parameters int,int and float will be created.
     147   *
     148   * now you can use the connect function of GLWidget to connect this Signal to a Slot.
     149   * @see GLGuiWidget::connect
     150   */
    27151  class SignalConnector
    28152  {
     
    34158
    35159    SignalConnector& operator=(const SignalConnector& signalConnector);
     160    bool operator==(const SignalConnector& signalConnector) const;
    36161
    37     void operator()(const std::string& parameters) const;
    38     void execute(const std::string& parameters) const { (*this)(parameters); };
     162    void operator()() const;
     163    void operator()(const MultiType& value0) const;
     164    void operator()(const MultiType& value0, const MultiType& value1) const;
     165    void operator()(const MultiType& value0, const MultiType& value1, const MultiType& value2) const;
     166    void operator()(const MultiType& value0, const MultiType& value1, const MultiType& value2, const MultiType& value3) const;
     167    void operator()(const MultiType& value0, const MultiType& value1, const MultiType& value2, const MultiType& value3, const MultiType& value4) const;
    39168
     169    /** checks wether the SignalConnector is valid @return true on valid. */
     170    bool isValid() const { return (this->object && this->exec); };
     171    /** @brief checks if the SignalConnector is clean, invalid @returns true if invalid */
    40172    bool isClean() const { return (this->object == NULL || this->exec == NULL); }
    41173
     
    45177    const Executor*      exec;           //!< The Executor, that will be called, on object.
    46178  };
     179
     180  //! TypeDefinition for SignalLists
     181  typedef std::vector<SignalConnector> Signal;
     182  //! TypeDefinition for a Slot.
     183  typedef Executor*                    Slot;
     184
    47185}
    48186#endif /* _SIGNAL_CONNECTOR_H */
Note: See TracChangeset for help on using the changeset viewer.