Source code
/*
* Callback.h
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
//2015/08/03
#pragma once
#include <viz++/Object.h>
namespace OZ {
template <class CLASS, //A pointer to a C++ class
typename METHOD, //A pointer to a method of CLASS
typename PARAM> //A parameter to a callback
class Callback1 :public Object {
private:
CLASS object; //A pointer to an instance of CLASS
METHOD method; //A pointer to a a method of CLASS
public:
Callback1()
:object(NULL),
method(NULL)
{
}
public:
void set(CLASS object, METHOD method)
{
if (object && method) {
this -> object = object;
this -> method = method;
} else {
throw IException("Invalid argument");
}
}
//Call method of object with one parameter.
void call(PARAM param)
{
if (object && method) {
(object->*method)(param);
}
}
};
template <class CLASS, //A pointer to a C++ class
typename METHOD, //A pointer to a method of CLASS
typename PARAM1,
typename PARAM2> //A parameter to a callback
class Callback2 :public Object {
private:
CLASS object; //A pointer to an instance of CLASS
METHOD method; //A pointer to a a method of CLASS
public:
Callback2()
:object(NULL),
method(NULL)
{
}
public:
void set(CLASS object, METHOD method)
{
if (object && method) {
this -> object = object;
this -> method = method;
} else {
throw IException("Invalid argument");
}
}
//Call method of object two parameters.
void call(PARAM1 param1, PARAM2 param2)
{
if (object && method) {
(object->*method)(param1, param2);
}
}
};
template <class CLASS, //A pointer to a C++ class
typename METHOD, //A pointer to a method of CLASS
typename PARAM1,
typename PARAM2,
typename PARAM3> //A parameter to a callback
class Callback3 :public Object {
private:
CLASS object; //A pointer to an instance of CLASS
METHOD method; //A pointer to a a method of CLASS
public:
Callback3()
:object(NULL),
method(NULL)
{
}
public:
void set(CLASS object, METHOD method)
{
if (object && method) {
this -> object = object;
this -> method = method;
} else {
throw IException("Invalid argument");
}
}
//Call method of object with three parameters.
void call(PARAM1 param, PARAM2 param2, PARAM3 param3)
{
if (object && method) {
(object->*method)(param1, param2, param3);
}
}
};
}
Last modified: 10 Feb 2017
Copyright (c) 2009-2017 Antillia.com ALL RIGHTS RESERVED.