Skip to content

Instantly share code, notes, and snippets.

@cypok
Created November 9, 2008 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cypok/23258 to your computer and use it in GitHub Desktop.
Save cypok/23258 to your computer and use it in GitHub Desktop.
#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