2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-21 17:12:22 +00:00

support for data members

[SVN r13309]
This commit is contained in:
Dave Abrahams
2002-03-30 01:23:28 +00:00
parent 4a81d366bb
commit 7ffc983edd
5 changed files with 98 additions and 13 deletions

View File

@@ -22,6 +22,7 @@
# include <boost/mpl/bool_t.hpp>
# include <boost/python/object/select_holder.hpp>
# include <boost/python/object/class_wrapper.hpp>
# include <boost/python/data_members.hpp>
# include <boost/utility.hpp>
namespace boost { namespace python {
@@ -65,7 +66,7 @@ template <
, class X2 // = detail::not_specified
, class X3 // = detail::not_specified
>
class class_ : private objects::class_base
class class_ : public objects::class_base
{
typedef class_<T,X1,X2,X3> self;
BOOST_STATIC_CONSTANT(bool, is_copyable = (!detail::has_noncopyable<X1,X2,X3>::value));
@@ -138,8 +139,28 @@ class class_ : private objects::class_base
return *this;
}
//
// Data member access
//
template <class D>
self& def_readonly(char const* name, D T::*pm)
{
ref fget(make_getter(pm));
this->add_property(name, fget);
return *this;
}
template <class D>
self& def_readwrite(char const* name, D T::*pm)
{
ref fget(make_getter(pm));
ref fset(make_setter(pm));
this->add_property(name, fget, fset);
return *this;
}
// return the underlying object
ref object() const;
// ref object() const;
private: // types
typedef objects::class_id class_id;
@@ -202,14 +223,6 @@ inline class_<T,X1,X2,X3>::class_(char const* name)
, this->object());
}
template <class T, class X1, class X2, class X3>
inline ref class_<T,X1,X2,X3>::object() const
{
typedef objects::class_base base;
return this->base::object();
}
namespace detail
{
// This is an mpl BinaryMetaFunction object with a runtime behavior,

View File

@@ -0,0 +1,41 @@
// Copyright David Abrahams 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 COPY_MUTABLE_REFERENCE_DWA2002131_HPP
# define COPY_MUTABLE_REFERENCE_DWA2002131_HPP
# include <boost/python/detail/indirect_traits.hpp>
# include <boost/mpl/select_type.hpp>
# include <boost/python/to_python_value.hpp>
namespace boost { namespace python {
namespace detail
{
template <class R>
struct copy_mutable_reference_expects_a_reference_to_non_const_return_type
# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__)
{}
# endif
;
}
template <class T> struct to_python_value;
struct copy_mutable_reference
{
template <class T>
struct apply
{
typedef typename mpl::select_type<
detail::is_reference_to_non_const<T>::value
, to_python_value<T>
, detail::copy_mutable_reference_expects_a_reference_to_non_const_return_type<T>
>::type type;
};
};
}} // namespace boost::python
#endif // COPY_MUTABLE_REFERENCE_DWA2002131_HPP