source: NonGTP/Boost/boost/python/object_attributes.hpp @ 857

Revision 857, 1.8 KB checked in by igarcia, 19 years ago (diff)
RevLine 
[857]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
7
8# include <boost/python/detail/prefix.hpp>
9
10# include <boost/python/proxy.hpp>
11# include <boost/python/object_core.hpp>
12# include <boost/python/object_protocol.hpp>
13
14namespace boost { namespace python { namespace api {
15
16struct const_attribute_policies
17{
18    typedef char const* key_type;
19    static object get(object const& target, char const* key);
20};
21 
22struct attribute_policies : const_attribute_policies
23{
24    static object const& set(object const& target, char const* key, object const& value);
25    static void del(object const&target, char const* key);
26};
27
28//
29// implementation
30//
31template <class U>
32inline object_attribute object_operators<U>::attr(char const* name)
33{
34    object_cref2 x = *static_cast<U*>(this);
35    return object_attribute(x, name);
36}
37
38template <class U>
39inline const_object_attribute object_operators<U>::attr(char const* name) const
40{
41    object_cref2 x = *static_cast<U const*>(this);
42    return const_object_attribute(x, name);
43}
44
45inline object const_attribute_policies::get(object const& target, char const* key)
46{
47    return python::getattr(target, key);
48}
49
50inline object const& attribute_policies::set(
51    object const& target
52    , char const* key
53    , object const& value)
54{
55    python::setattr(target, key, value);
56    return value;
57}
58
59inline void attribute_policies::del(
60    object const& target
61    , char const* key)
62{
63    python::delattr(target, key);
64}
65
66}}} // namespace boost::python::api
67
68#endif // OBJECT_ATTRIBUTES_DWA2002615_HPP
Note: See TracBrowser for help on using the repository browser.