sl@0
|
1 |
// Copyright David Abrahams 2002.
|
sl@0
|
2 |
// Distributed under the Boost Software License, Version 1.0. (See
|
sl@0
|
3 |
// accompanying file LICENSE_1_0.txt or copy at
|
sl@0
|
4 |
// http://www.boost.org/LICENSE_1_0.txt)
|
sl@0
|
5 |
#ifndef OBJECT_ATTRIBUTES_DWA2002615_HPP
|
sl@0
|
6 |
# define OBJECT_ATTRIBUTES_DWA2002615_HPP
|
sl@0
|
7 |
|
sl@0
|
8 |
# include <boost/python/detail/prefix.hpp>
|
sl@0
|
9 |
|
sl@0
|
10 |
# include <boost/python/proxy.hpp>
|
sl@0
|
11 |
# include <boost/python/object_core.hpp>
|
sl@0
|
12 |
# include <boost/python/object_protocol.hpp>
|
sl@0
|
13 |
|
sl@0
|
14 |
namespace boost { namespace python { namespace api {
|
sl@0
|
15 |
|
sl@0
|
16 |
struct const_attribute_policies
|
sl@0
|
17 |
{
|
sl@0
|
18 |
typedef char const* key_type;
|
sl@0
|
19 |
static object get(object const& target, char const* key);
|
sl@0
|
20 |
};
|
sl@0
|
21 |
|
sl@0
|
22 |
struct attribute_policies : const_attribute_policies
|
sl@0
|
23 |
{
|
sl@0
|
24 |
static object const& set(object const& target, char const* key, object const& value);
|
sl@0
|
25 |
static void del(object const&target, char const* key);
|
sl@0
|
26 |
};
|
sl@0
|
27 |
|
sl@0
|
28 |
//
|
sl@0
|
29 |
// implementation
|
sl@0
|
30 |
//
|
sl@0
|
31 |
template <class U>
|
sl@0
|
32 |
inline object_attribute object_operators<U>::attr(char const* name)
|
sl@0
|
33 |
{
|
sl@0
|
34 |
object_cref2 x = *static_cast<U*>(this);
|
sl@0
|
35 |
return object_attribute(x, name);
|
sl@0
|
36 |
}
|
sl@0
|
37 |
|
sl@0
|
38 |
template <class U>
|
sl@0
|
39 |
inline const_object_attribute object_operators<U>::attr(char const* name) const
|
sl@0
|
40 |
{
|
sl@0
|
41 |
object_cref2 x = *static_cast<U const*>(this);
|
sl@0
|
42 |
return const_object_attribute(x, name);
|
sl@0
|
43 |
}
|
sl@0
|
44 |
|
sl@0
|
45 |
inline object const_attribute_policies::get(object const& target, char const* key)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
return python::getattr(target, key);
|
sl@0
|
48 |
}
|
sl@0
|
49 |
|
sl@0
|
50 |
inline object const& attribute_policies::set(
|
sl@0
|
51 |
object const& target
|
sl@0
|
52 |
, char const* key
|
sl@0
|
53 |
, object const& value)
|
sl@0
|
54 |
{
|
sl@0
|
55 |
python::setattr(target, key, value);
|
sl@0
|
56 |
return value;
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
inline void attribute_policies::del(
|
sl@0
|
60 |
object const& target
|
sl@0
|
61 |
, char const* key)
|
sl@0
|
62 |
{
|
sl@0
|
63 |
python::delattr(target, key);
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
}}} // namespace boost::python::api
|
sl@0
|
67 |
|
sl@0
|
68 |
#endif // OBJECT_ATTRIBUTES_DWA2002615_HPP
|