|
Boost Users : |
From: Anders Dalvander (anders_at_[hidden])
Date: 2008-06-02 16:12:46
>
> Your approach is exactly what we don't want, since it makes it an object-based
> based solution rather than instance-based.
> We are using a functor (therefor the oprerator()) so that the solution remains
> instance-based.
>
Is your application threaded? If so couldn't you use thread_specific_ptr
for emulating a instance-based functor?
class A;
class B;
class C
{
public:
C()
{
instance().push_back(this);
}
~C()
{
instance().pop_back();
}
int operator()(A* a, B* b)
{
// Do your stuff.
}
static int wrapper(A* a, B* b)
{
return instance().back()->operator()(a, b);
}
private:
C(const C& rhs);
C& operator=(const C& rhs);
static this_vector& instance()
{
this_vector* t = ptr.get();
if (!t)
{
t = new this_vector();
ptr.reset(t);
}
return *t;
}
typedef std::vector<C*> this_vector;
static boost::thread_specific_ptr<this_vector> ptr;
};
typedef int (*foobar)(A*,B*);
void do_something(foobar cb);
C obj;
do_something(C::wrapper);
Regards,
Anders
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net