Posted on 2008-05-21 16:47
RichardHe 閱讀(188)
評論(0) 編輯 收藏 引用
事件訂閱,subscribeEvent(事件名,Event::subcribe(回調函數);
方法subcribe通過一個Map Container;
typedef std::multimap<Group, Connection> SlotContainer,添加到容器中,
d_slots.insert(std::pair<Group,Connection>(group,c));而在事件觸發時,
Event操作()遍歷每個訂閱事件的函數,代碼如下:
for (; iter != end_iter; ++iter)
args.handled |= (*iter->second->d_subscriber)(args);
這樣訂閱事件的函數都會遍歷回調到!
遇見一個CEGUI的設計問題
有的是函數指針,而有的是類型的別名?比如:
typedef bool (*SortCallback)(const ItemEntry* a, const ItemEntry* b);
typedef bool (SlotFunction)(const EventArgs&);//為什么不聲明為函數指針呢?
typedef bool(T::*MemberFunctionType)(const EventArgs&);
typedef bool PropertyCallback(Window* window, String& propname, String& propvalue, void* userdata);