Boost logo

Boost :

From: Kevin Wan (wanjunfeng_at_[hidden])
Date: 2006-02-11 08:22:53


sorry, i forgot to delete the quotes.

and btw, i'd like to give a simple example of my delegate implementation.

example.cc
#include <stdio.h>
#include "delegate.h"

const char* bar = "##########################################";

void native_func(int value)
{
    printf("%s\n", bar);
    printf("native function, value = %d\n", value);
}

class Object
{
public:
    static void static_member_func(int value)
    {
        printf("%s\n", bar);
        printf("static member function, value = %d\n", value);
    }
    void non_const_member_func(int value)
    {
        printf("%s\n", bar);
        printf("non-const member function, value = %d\n", value);
    }
    void const_member_func(int value) const
    {
        printf("%s\n", bar);
        printf("const member function, value = %d\n", value);
    }
};

class Functor
{
public:
    void operator()(int value)
    {
        printf("%s\n", bar);
        printf("non-const functor, value = %d\n", value);
    }
};

class ConstFunctor
{
public:
    void operator()(int value) const
    {
        printf("%s\n", bar);
        printf("const functor, value = %d\n", value);
    }
};

int main()
{
    typedef wan::delegate<void(int)> MyDelegate;

    Object obj;
    Functor functor;
    ConstFunctor constFunctor;
    MyDelegate dele;
    dele.add(&native_func);
    dele.add(&Object::static_member_func);
    dele.add(&obj, &Object::non_const_member_func);
    dele.add(&obj, &Object::const_member_func);
    dele.add(&functor);
    dele.add(&constFunctor);
    dele(111);

    printf("%s\n", bar);
    printf("\n\nafter remove operations\n\n");

    dele.remove(&native_func);
    dele.remove(&obj, &Object::non_const_member_func);
    dele(222);

    printf("%s\n", bar);
    printf("\n\nadd delegate object to delegate object\n\n");

    MyDelegate temp;
    temp.add(&native_func);
    temp.add(&obj, &Object::non_const_member_func);
    dele.add(&temp);
    dele(333);

    printf("%s\n", bar);
}

$ g++ example.cc -o test
$ ./test
##########################################
native function, value = 111
##########################################
static member function, value = 111
##########################################
non-const member function, value = 111
##########################################
const member function, value = 111
##########################################
non-const functor, value = 111
##########################################
const functor, value = 111
##########################################

after remove operations

##########################################
static member function, value = 222
##########################################
const member function, value = 222
##########################################
non-const functor, value = 222
##########################################
const functor, value = 222
##########################################

add delegate object to delegate object

##########################################
static member function, value = 333
##########################################
const member function, value = 333
##########################################
non-const functor, value = 333
##########################################
const functor, value = 333
##########################################
native function, value = 333
##########################################
non-const member function, value = 333
##########################################
$

thanks,
Kevin

On 2/11/06, Martin Wille <mw8329_at_[hidden]> wrote:
>
> Kevin Wan wrote:
>
> [lots of quoted text]
>
>
> Please don't overquote and don't put quotes at the bottom of your
> message. See http://boost.org/more/discussion_policy.htm#effective
>
>
> Regards,
> m
> Send instant messages to your online friends http://au.messenger.yahoo.com
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>

--
Things don't just happen, you have to make them happen.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk