Created
November 9, 2008 11:56
-
-
Save cypok/23258 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "../console/console.h" | |
#include <stdlib.h> | |
#include <stdio.h> | |
namespace MDS | |
{ | |
#pragma pack(push, 1) | |
class Data | |
{ | |
protected: | |
union | |
{ | |
int integer; | |
void *pointer; | |
} value; | |
public: | |
Data(int i = 0); | |
Data(void *p); | |
int integer(); | |
void * pointer(); | |
}; | |
class MessageLoop; | |
class Object | |
{ | |
private: | |
MessageLoop *loop; | |
public: | |
virtual bool processMessage(int message, Data &extra_data) = 0; | |
MessageLoop *getLoop(); | |
void setLoop(MessageLoop *loop); | |
Object(); | |
virtual ~Object(); | |
}; | |
class QueueItem; | |
class MessageLoop | |
{ | |
private: | |
// internals | |
static MessageLoop *running; // pointer to currently running MessageLoop (NULL if none) | |
QueueItem *queue; | |
void afterRun(); | |
protected: | |
// FOR ALL: if true leave run() | |
virtual bool processMessage(int message, Data &extra_data) = 0; | |
virtual bool processKey(int ch) = 0; | |
virtual bool processIdle() = 0; | |
// you can place some code in this function | |
// which will be executed before every run | |
virtual void beforeRun(); | |
public: | |
MessageLoop(); | |
~MessageLoop(); | |
Data sendMessage (Object *obj, int message, Data &extra_data); | |
void postMessage (Object *obj, int message, Data &extra_data, unsigned delay = 0); | |
void run(); | |
}; | |
#pragma pack(pop) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment