kick
|
00001 // 00002 // EventListener.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 00013 namespace kick { 00014 class AbstractEvent; 00015 00016 class AbstractEventListener{ 00017 public: 00018 AbstractEventListener(){}; 00019 AbstractEventListener(AbstractEvent *ae, int listenerId); 00020 AbstractEventListener(const AbstractEventListener&) = delete; 00021 AbstractEventListener& operator=( const AbstractEventListener& rhs ) = delete; 00022 00023 virtual ~AbstractEventListener(); 00024 friend class AbstractEvent; 00025 protected: 00026 void destroyListener(); 00027 int listenerId = -1; 00028 AbstractEvent *ae = nullptr; 00029 }; 00030 00031 template <typename E> 00032 class Event; 00033 00034 template <typename E> 00035 class EventListener : public AbstractEventListener { 00036 public: 00037 EventListener(); 00038 00039 EventListener(Event<E> *e, int listenerId); 00040 00041 EventListener(const EventListener&) = delete; 00042 EventListener& operator=( const EventListener& rhs ) = delete; 00043 00044 EventListener(EventListener&& other); 00045 EventListener& operator=( EventListener&& rhs ); 00046 friend class Event<E>; 00047 }; 00048 00049 template <typename E> 00050 class SyncValue : public AbstractEventListener { 00051 public: 00052 SyncValue(); 00053 00054 E& getValue(); 00055 00056 void setValue(const E& e); 00057 00058 SyncValue(const SyncValue&) = delete; 00059 SyncValue& operator=( const SyncValue& rhs ) = delete; 00060 00061 SyncValue(SyncValue&& other); 00062 00063 SyncValue& operator=( SyncValue&& rhs ); 00064 friend class Event<E>; 00065 private: 00066 E value; 00067 }; 00068 } 00069 00070 #include "event_listener.inl"