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