kick
/Users/morten/Programmering/cpp/kick/src/kick/core/event.h
00001 //
00002 //  Event.h
00003 //  TmpProject
00004 //
00005 //  Created by morten on 8/18/13.
00006 //  Copyright (c) 2013 morten. All rights reserved.
00007 //
00008 
00009 #pragma once
00010 
00011 #include <iostream>
00012 #include <functional>
00013 #include "event_listener.h"
00014 #include <vector>
00015 #include <utility>
00016 
00017 #define GET_LISTENER_FN(x) std::get<0>(x)
00018 #define GET_LISTENER_ID(x) std::get<1>(x)
00019 #define GET_LISTENER_SORTKEY(x) std::get<2>(x)
00020 
00021 namespace kick {
00022     class AbstractEvent{
00023     public:
00024         virtual bool removeListener(int id) = 0;
00025     };
00026     
00027     template <typename E>
00028     class Event : public AbstractEvent{
00029     public:
00030         EventListener<E> createListener(std::function<void (E)> listener, int sortPriority = 0);
00031         
00032         void registerSyncValue(SyncValue<E>& syncValue);
00033         
00034         void notifyListeners(E e);
00035         
00036         bool removeListener(int id);
00037     protected:
00038         std::vector<std::tuple<std::function< void (E)>, int, int>> listeners;
00039         friend class EventListener<E>;
00040         int eventListenerId = 0;
00041     };
00042 }
00043 
00044 #include "event.inl"
 All Classes Functions Variables