fix doc example typo
[boost.git] / boost / python / object_attributes.hpp
blob26d599113f11a2dfb19d338bb4ed6b6819b7b79f
1 // Copyright David Abrahams 2002.
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 #ifndef OBJECT_ATTRIBUTES_DWA2002615_HPP
6 # define OBJECT_ATTRIBUTES_DWA2002615_HPP
8 # include <boost/python/detail/prefix.hpp>
10 # include <boost/python/proxy.hpp>
11 # include <boost/python/object_core.hpp>
12 # include <boost/python/object_protocol.hpp>
14 namespace boost { namespace python { namespace api {
16 struct const_attribute_policies
18 typedef char const* key_type;
19 static object get(object const& target, char const* key);
20 static object get(object const& target, object const& key);
23 struct attribute_policies : const_attribute_policies
25 static object const& set(object const& target, char const* key, object const& value);
26 static void del(object const&target, char const* key);
29 struct const_objattribute_policies
31 typedef object const key_type;
32 static object get(object const& target, object const& key);
35 struct objattribute_policies : const_objattribute_policies
37 static object const& set(object const& target, object const& key, object const& value);
38 static void del(object const&target, object const& key);
42 // implementation
44 template <class U>
45 inline object_attribute object_operators<U>::attr(char const* name)
47 object_cref2 x = *static_cast<U*>(this);
48 return object_attribute(x, name);
51 template <class U>
52 inline const_object_attribute object_operators<U>::attr(char const* name) const
54 object_cref2 x = *static_cast<U const*>(this);
55 return const_object_attribute(x, name);
58 template <class U>
59 inline object_objattribute object_operators<U>::attr(object const& name)
61 object_cref2 x = *static_cast<U*>(this);
62 return object_objattribute(x, name);
65 template <class U>
66 inline const_object_objattribute object_operators<U>::attr(object const& name) const
68 object_cref2 x = *static_cast<U const*>(this);
69 return const_object_objattribute(x, name);
72 inline object const_attribute_policies::get(object const& target, char const* key)
74 return python::getattr(target, key);
77 inline object const_objattribute_policies::get(object const& target, object const& key)
79 return python::getattr(target, key);
82 inline object const& attribute_policies::set(
83 object const& target
84 , char const* key
85 , object const& value)
87 python::setattr(target, key, value);
88 return value;
91 inline object const& objattribute_policies::set(
92 object const& target
93 , object const& key
94 , object const& value)
96 python::setattr(target, key, value);
97 return value;
100 inline void attribute_policies::del(
101 object const& target
102 , char const* key)
104 python::delattr(target, key);
107 inline void objattribute_policies::del(
108 object const& target
109 , object const& key)
111 python::delattr(target, key);
114 }}} // namespace boost::python::api
116 #endif // OBJECT_ATTRIBUTES_DWA2002615_HPP