加文

希望是美好的……
随笔 - 0, 文章 - 209, 评论 - 0, 引用 - 0
数据加载中……

EventSet 介绍

class CEGUIEXPORT EventSet
{
public:
    /*!
    \brief
        Constructor for EventSet objects
    
*/
    EventSet();


    /*!
    \brief
        Destructor for EventSet objects
    
*/
    virtual ~EventSet(void);


    /*!
    \brief
        Add a new Event to the EventSet with the given name.

    \param name
        String object containing the name to give the new Event.  The name must be unique for the EventSet.

    \return
        Nothing

    \exception AlreadyExistsException    Thrown if an Event already exists named \a name.
    
*/
    void    addEvent(const String& name);


    /*!
    \brief
        Removes the Event with the given name.  All connections to the event are disconnected.

    \param name
        String object containing the name of the Event to remove.  If no such Event exists, nothing happens.

    \return
        Nothing.
    
*/
    void    removeEvent(const String& name);


    /*!
    \brief
        Remove all Event objects from the EventSet

    \return
        Nothing
    
*/
    void    removeAllEvents(void);


    /*!
    \brief
        Checks to see if an Event with the given name is present in the EventSet.

    \return
        true if an Event named \a name was found, or false if the Event was not found
    
*/
    bool    isEventPresent(const String& name);


    /*!
    \brief
        Subscribes a handler to the named Event.  If the named Event is not yet
        present in the EventSet, it is created and added.

    \param name
        String object containing the name of the Event to subscribe to.

    \param subscriber
        Function or object that is to be subscribed to the Event.

    \return
        Connection object that can be used to check the status of the Event
        connection and to disconnect (unsubscribe) from the Event.
    
*/
    virtual Event::Connection subscribeEvent(const String& name, Event::Subscriber subscriber);


    /*!
    \brief
        Subscribes a handler to the specified group of the named Event.  If the
        named Event is not yet present in the EventSet, it is created and added.

    \param name
        String object containing the name of the Event to subscribe to.

    \param group
        Group which is to be subscribed to.  Subscription groups are called in
        ascending order.

    \param subscriber
        Function or object that is to be subscribed to the Event.

    \return
        Connection object that can be used to check the status of the Event
        connection and to disconnect (unsubscribe) from the Event.
    
*/
    virtual Event::Connection subscribeEvent(const String& name, Event::Group group, Event::Subscriber subscriber);


    /*!
    \brief
        Subscribes the named Event to a scripted funtion

    \param name
        String object containing the name of the Event to subscribe to.

    \param subscriber_name
        String object containing the name of the script funtion that is to be
        subscribed to the Event.

    \return
        Connection object that can be used to check the status of the Event
        connection and to disconnect (unsubscribe) from the Event.
    
*/
    virtual Event::Connection subscribeScriptedEvent(const String& name, const String& subscriber_name);


    /*!
    \brief
        Subscribes the specified group of the named Event to a scripted funtion.

    \param name
        String object containing the name of the Event to subscribe to.

    \param group
        Group which is to be subscribed to.  Subscription groups are called in
        ascending order.

    \param subscriber_name
        String object containing the name of the script funtion that is to be
        subscribed to the Event.

    \return
        Connection object that can be used to check the status of the Event
        connection and to disconnect (unsubscribe) from the Event.
    
*/
    virtual Event::Connection subscribeScriptedEvent(const String& name, Event::Group group, const String& subscriber_name);


    /*!
    \brief
        Fires the named event passing the given EventArgs object.

    \param name
        String object holding the name of the Event that is to be fired
        (triggered)

    \param args
        The EventArgs (or derived) object that is to be bassed to each
        subscriber of the Event.  Once all subscribers
        have been called the 'handled' field of the event is updated
        appropriately.

    \param eventNamespace
        String object describing the global event namespace prefix for this
        event.

    \return
        Nothing.
    
*/
    virtual void fireEvent(const String& name, EventArgs& args, const String& eventNamespace = "");


    /*!
    \brief
        Return whether the EventSet is muted or not.

    \return
        - true if the EventSet is muted.  All requests to fire events will be ignored.
        - false if the EventSet is not muted.  All requests to fire events are processed as normal.
    
*/
    bool    isMuted(voidconst;


    /*!
    \brief
        Set the mute state for this EventSet.

    \param setting
        - true if the EventSet is to be muted (no further event firing requests will be honoured until EventSet is unmuted).
        - false if the EventSet is not to be muted and all events should fired as requested.

    \return
        Nothing.
    
*/
    void    setMutedState(bool setting);


protected:
    /*!
    \brief
        Return a pointer to the Event object with the given name, optionally
        adding such an Event object to the EventSet if it does not already
        exist.

    \param name
        String object holding the name of the Event to return.

    \param autoAdd
        - true if an Event object named \a name should be added to the set
          if such an Event does not currently exist.
        - false if no object should automatically be added to the set.  In this
          case, if the Event does not already exist 0 will be returned.

    \return
        Pointer to the Event object in this EventSet with the specifed name.
        Or 0 if such an Event does not exist and \a autoAdd was false.
    
*/
    Event* getEventObject(const String& name, bool autoAdd = false);

    /*!
    \brief
        Implementation event firing member
    
*/
    void fireEvent_impl(const String& name, EventArgs& args);


    // Do not allow copying, assignment, or any other usage than simple creation.
    EventSet(EventSet&) {}
    EventSet& operator=(EventSet&) {return *this;}

    typedef std::map<String, Event*, String::FastLessCompare>    EventMap;
    EventMap    d_events;

    bool    d_muted;    //!< true if events for this EventSet have been muted.

public:
    /*************************************************************************
        Iterator stuff
    ************************************************************************
*/
    typedef    ConstBaseIterator<EventMap> Iterator;

    /*!
    \brief
        Return a EventSet::Iterator object to iterate over the events currently
        added to the EventSet.
    
*/
    Iterator getIterator(voidconst;
};

}
EventSet包含以下处理功能:1,添加事件;2,删除事件;3,激发一个事件;4,添加事件处理函数;5,查找事件。
这五种功能对应的函数分别为:
添加事件:addEvent
删除事件:removeEvent,removeAllEvent;
激发事件:fireEvent,fireEvent_impl
注册函数:subcirberEvent,subscribeScriptEvent;
查找事件:getEventObject,isEventPresent;
成员变量定义如下:
EventSet(EventSet&) {}
EventSet& operator=(EventSet&) {return *this;}
typedef std::map<String, Event*, String::FastLessCompare> EventMap;
EventMap d_events;
bool d_mute;
d_mute 决定这个事件集合是否相应,如果为false ,则这组事件不响应。
第一组从事件的添加,删除,查找
void EventSet::addEvent(const String& name);
void EventSet::removeEvent(cosnt String& name);
void EventSet::removeAllEvent(void);
bool EventSet::isEventPresent(const String& name);
Event* EvetnSet::getEventObject(const String& name,bool auatoAdd);
第二组事件处理函数的注册:
Event::Connection EventSet::subscriberScriptedEvent(const String& name,const String& sbuscriber_name); Event::Connection EventSet::subscribeScriptedEvent(const String& name,Event::Group group,const String& subscriber_name); Event::Connection EventSet::subScriberEvent(const String& name,Event::Subscriber subscriber); Event::Connection EventSet::subscribeEvent(const String& name,Event::Group group,Event::Subscriber subscriber);
第三组事件的激发,对应处理函数的调用
void EventSet::fireEvent(const String& name,EventArgs& args,const String& eventNamespace);
void  EventSet::fireEvent_impl(const String& name,EventArgs& args);

posted on 2012-04-13 12:40 加文 阅读(281) 评论(0)  编辑 收藏 引用 所属分类: C++


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理