基本は無限ループ
つまり同期型の処理ということになる。
以下は,標準入力から入力があると実行される。
string buf;
while( cin >> buf && buf != "quit" ){
cout << buf << endl;
}
イベントハンドラ
// 無限ループでイベントを検出し,
while( (e = getevent()) != QUIT_SIGNAL )
// それをイベントハンドラに渡して,
obj.handle_event( e );
// ハンドラは該当するイベントを呼び出す。
void Obj::handle_event( int e )
{
switch( e ) ...
}
関数ポインタ配列によるイベントハンドラ(C)
#define msg_func1 0
#define msg_func2 1
...
void (*func[])( Type hoge ) = {func1, func2, ...}
...
int msg = msg_func2;
func[msg]( hoge );
典型的なGUIの構成
// 窓口
class Console {
public:
Console();
~Console();
void start(); // main()で実際に呼び出すのはこいつ。
protected:
各オブジェクトへのポインタ
};
// 実際に画面を叩くのはここ
class Screen {
public:
void draw(){ std::cout << obj->to_s(); }
protected:
表示するオブジェクトへのポインタ
};
// データはインタフェースから分離する。
class Data {
public:
表示メソッド
protected:
生データ
};
最終更新:2010年01月07日 12:12