summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/python/test/properties.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/boost/libs/python/test/properties.cpp
parentInitial commit. (diff)
downloadceph-upstream/16.2.11+ds.tar.xz
ceph-upstream/16.2.11+ds.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/python/test/properties.cpp')
-rw-r--r--src/boost/libs/python/test/properties.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/boost/libs/python/test/properties.cpp b/src/boost/libs/python/test/properties.cpp
new file mode 100644
index 000000000..d338beb91
--- /dev/null
+++ b/src/boost/libs/python/test/properties.cpp
@@ -0,0 +1,100 @@
+// Copyright David Abrahams 2004. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#include <boost/python.hpp>
+
+using namespace boost::python;
+
+namespace test {
+
+// Hmm. return_internal_reference<>() wants to wrap a real class.
+class ret_type
+{
+ public:
+ ret_type() : i(42.5) {}
+ double i;
+};
+
+class crash_me
+{
+ private:
+ ret_type i;
+ public:
+ ret_type& get_i() { return i; }
+};
+
+}
+
+struct X
+{
+ X( int value ) : m_value( value )
+ { ++s_count; }
+
+ X( const X &other ) : m_value( other.m_value )
+ { ++s_count; }
+
+ ~X()
+ { --s_count; }
+
+ int get_value() const
+ { return m_value; }
+
+ void set_value(int new_value)
+ { m_value = new_value; }
+
+ static int get_instance_count()
+ { return s_count; }
+
+ int m_value;
+
+ static int s_count;
+};
+
+int X::s_count = 0;
+
+int get_X_instance_count()
+{ return X::get_instance_count(); }
+
+
+
+BOOST_PYTHON_MODULE(properties_ext)
+{
+ typedef return_value_policy<return_by_value> return_by_value_t;
+ typedef return_internal_reference<> return_by_internal_reference_t;
+ class_<X>("X", init<int>() )
+ //defining read only property
+ .add_property( "value_r", &X::get_value )
+ .add_property( "value_r_ds", &X::get_value, "value_r_ds is read-only")
+ //defining read \ write property
+ .add_property( "value_rw", &X::get_value, &X::set_value )
+ .add_property( "value_rw_ds", &X::get_value, &X::set_value,
+ "value_rw_ds is read-write")
+ //defining read \ write property using make_getter and make_setter
+ .add_property( "value_direct",
+ make_getter( &X::m_value, return_by_value_t() ),
+ make_setter( &X::m_value, return_by_internal_reference_t() ) )
+ //defining read only property for static member
+ .add_static_property( "instance_count", &X::get_instance_count )
+ //defining read \ write property for static member using make_getter and make_setter
+ .add_static_property( "instance_count_direct",
+ make_getter( &X::s_count, return_by_value_t() ),
+ make_setter( &X::s_count, return_by_internal_reference_t() ) )
+ //defining class property using a global function
+ .add_static_property( "instance_count_injected", &get_X_instance_count );
+
+
+ class_< test::ret_type>( "ret_type")
+ .add_property( "i", &test::ret_type::i, &test::ret_type::i)
+ ;
+
+ class_< test::crash_me> crash_me_wrapper( "crash_me");
+
+ crash_me_wrapper
+ .def( "get_i", &test::crash_me::get_i , return_internal_reference<>())
+ ;
+
+ crash_me_wrapper.add_property( "i", crash_me_wrapper.attr("get_i"));
+
+}
+
+#include "module_tail.cpp"