[C++-sig] Re: [Boost-python-cvs] CVS: boost/boost/python/object pickle_support.hpp,NONE,1.1
David Abrahams
david.abrahams at rcn.com
Sun Jul 21 13:42:09 CEST 2002
- Previous message: [C++-sig] Re: [Boost-python-cvs] CVS: boost/libs/python/test pickle1.cpp,NONE,1.1 pickle1.py,NONE,1.1 pickle2.cpp,NONE,1.1 pickle2.py,NONE,1.1 pickle3.cpp,NONE,1.1 pickle3.py,NONE,1.1
- Next message: [C++-sig] VC6 extract.cpp warning
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More questions...
1. I don't see how your error message thing is going to cause a message to
appear under any circumstance (?)
2. Are users expected to call this "register_" function?
It would be nice to avoid that.
3. How about a "curiously recursive template" formulation,
roughly:
template <class Derived>
struct pickle_support
{
typedef char undefined;
undefined getintitargs;
undefined getstate;
undefined setstate;
undefined getstate_manages_dict;
// I'm not attached to using the constructor here.
template <class Class_>
pickle_support(Class_ c)
{
// Guarantees derivation of Derived.
Derived* self = static_cast<Derived*>(this);
register_(c,
&Derived::getinitargs, &Derived::getstate,
&Derived::setstate, &Derived::getstate_manages_dict);
}
private:
// Definitions of appropriate register_ functions left as an exercise
};
Used as:
struct pickle_world : pickle_support<pickle_world>
{
...
};
???
----- Original Message -----
From: "Ralf W. Grosse-Kunstleve" <rwgk at users.sourceforge.net>
To: <boost-python-cvs at lists.sourceforge.net>
Sent: Sunday, July 21, 2002 3:49 AM
Subject: [Boost-python-cvs] CVS: boost/boost/python/object
pickle_support.hpp,NONE,1.1
> Update of /cvsroot/boost/boost/boost/python/object
> In directory usw-pr-cvs1:/tmp/cvs-serv31721/object
>
> Added Files:
> pickle_support.hpp
> Log Message:
> additional files for pickle support; no modification of any existing
files
>
> --- NEW FILE: pickle_support.hpp ---
> // (C) Copyright R.W. Grosse-Kunstleve 2002.
> // Permission to copy, use, modify, sell and distribute this software
> // is granted provided this copyright notice appears in all copies. This
> // software is provided "as is" without express or implied warranty, and
> // with no claim as to its suitability for any purpose.
> #ifndef BOOST_PYTHON_OBJECT_PICKLE_SUPPORT_RWGK20020603_HPP
> #define BOOST_PYTHON_OBJECT_PICKLE_SUPPORT_RWGK20020603_HPP
>
> #include <boost/python/object/class.hpp>
> #include <boost/python/tuple.hpp>
>
> namespace boost { namespace python {
>
> handle<> make_instance_reduce_function();
>
> namespace error_messages {
>
> template <class T>
> struct missing_pickle_support_function_or_incorrect_signature {};
>
> }
>
> class pickle_support_base
> {
> private:
> struct dummy_return_type_ {};
>
> public:
> template <class Class_, class Tgetinitargs>
> static
> void
> register_(
> Class_& cl,
> tuple (*getinitargs_fn)(Tgetinitargs),
> dummy_return_type_* (*getstate_fn)(),
> dummy_return_type_* (*setstate_fn)(),
> bool)
> {
> cl.enable_pickle_support(false);
> cl.def("__getinitargs__", getinitargs_fn);
> }
>
> template <class Class_, class Tgetstate, class Tsetstate>
> static
> void
> register_(
> Class_& cl,
> dummy_return_type_* (*getinitargs_fn)(),
> tuple (*getstate_fn)(Tgetstate),
> void (*setstate_fn)(Tsetstate, object),
> bool getstate_manages_dict)
> {
> cl.enable_pickle_support(getstate_manages_dict);
> cl.def("__getstate__", getstate_fn);
> cl.def("__setstate__", setstate_fn);
> }
>
> template <class Class_,
> class Tgetinitargs, class Tgetstate, class Tsetstate>
> static
> void
> register_(
> Class_& cl,
> tuple (*getinitargs_fn)(Tgetinitargs),
> tuple (*getstate_fn)(Tgetstate),
> void (*setstate_fn)(Tsetstate, object),
> bool getstate_manages_dict)
> {
> cl.enable_pickle_support(getstate_manages_dict);
> cl.def("__getinitargs__", getinitargs_fn);
> cl.def("__getstate__", getstate_fn);
> cl.def("__setstate__", setstate_fn);
> }
>
> template <class Class_>
> static
> void
> register_(
> Class_&,
> ...)
> {
> typedef typename
>
error_messages::missing_pickle_support_function_or_incorrect_signature<
> Class_>::error_type error_type;
> }
>
> static dummy_return_type_* getinitargs() { return 0; }
> static dummy_return_type_* getstate() { return 0; }
> static dummy_return_type_* setstate() { return 0; }
>
> static bool getstate_manages_dict() { return false; }
> };
>
> }} // namespace boost::python
>
> #endif // BOOST_PYTHON_OBJECT_PICKLE_SUPPORT_RWGK20020603_HPP
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Boost-python-cvs mailing list
> Boost-python-cvs at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/boost-python-cvs
- Previous message: [C++-sig] Re: [Boost-python-cvs] CVS: boost/libs/python/test pickle1.cpp,NONE,1.1 pickle1.py,NONE,1.1 pickle2.cpp,NONE,1.1 pickle2.py,NONE,1.1 pickle3.cpp,NONE,1.1 pickle3.py,NONE,1.1
- Next message: [C++-sig] VC6 extract.cpp warning
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Cplusplus-sig
mailing list