Re: [Boost-users] Serialization of functors and MPL

Hello, Thanks for the response. Actually, I need to create dynamically functor, because I call a lot of different methods coming from several classes. see below: MyObject myObject("before"); SetCommand<std::string,MyObject> cmd(myObject,&MyObject::setName,&MyObject::getName,"after"); Thus, I'm wondering if it is not possible to use the MPL library to register the link between a class and it functor. Example: template<class Object,class Type> class SetCommand { typedef mpl::pair<MyObject,Function>::type �container; template<class Functor> SetCommand() { typedef mpl::insert<container,mpl::pair<Object,Functor>::type myType; } }; serialize() { boost::function<Type ()> getter=mpl::at< container,MyObject>::type; } MyObject myObject("before"); SetCommand<std::string,MyObject> cmd(myObject,&MyObject::setName,&MyObject::getName,"after"); The mechanism should be like the registration of serializable class with boost. The problem here is the registration of the functor, we don't register the address of the functor, but only its type(function signature). Thus it is difficult to allocate this functor ! If someone can give me a solution to this problem, it would be great :) Remark: I don't want to implement the operator () inside each object used, because it is not appropriate in my code (too much classes).� Thanks in advance. Regards.
----- Original message ----- From: "Robert Ramey" <ramey@rrsd.com> To: boost-users@lists.boost.org Subject: Re: [Boost-users] Serialization of functors and MPL Date: Thu, 16 Sep 2010 14:20:06 -0800
Anonymous user wrote:
Hello everybody,
I'm currently trying to serialize functors. ... Thanks in advance.
Without going through your specific situation, I can say that this is an easy problem. Here are a couple of ways to do it.
a) use boost::variant
Make your functors: f, g, h make a variant boost::variant<f, g, h> v;
v = f or g or h ...
#include boost/serialization/variant.hpp serialize v
b) make your functors f, g, h all derived from a base class - functors make the base class polymorphic by making at least one member virtual EXPORT f, g, and h
functor *fx; fx = &f, or &g, or &h
serialize fx
c) There might be a way to do it with boost::any also.
Robert Ramey
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-------------------------------------------------------------- Ovi Mail: Making email access easy http://mail.ovi.com
participants (1)
-
Anonymous user