Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/python/object_attributes.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Copyright David Abrahams 2002.
0002 // Distributed under the Boost Software License, Version 1.0. (See
0003 // accompanying file LICENSE_1_0.txt or copy at
0004 // http://www.boost.org/LICENSE_1_0.txt)
0005 #ifndef OBJECT_ATTRIBUTES_DWA2002615_HPP
0006 # define OBJECT_ATTRIBUTES_DWA2002615_HPP
0007 
0008 # include <boost/python/detail/prefix.hpp>
0009 
0010 # include <boost/python/proxy.hpp>
0011 # include <boost/python/object_core.hpp>
0012 # include <boost/python/object_protocol.hpp>
0013 
0014 namespace boost { namespace python { namespace api {
0015 
0016 struct const_attribute_policies
0017 {
0018     typedef char const* key_type;
0019     static object get(object const& target, char const* key);
0020     static object get(object const& target, object const& key);
0021 };
0022   
0023 struct attribute_policies : const_attribute_policies
0024 {
0025     static object const& set(object const& target, char const* key, object const& value);
0026     static void del(object const&target, char const* key);
0027 };
0028 
0029 struct const_objattribute_policies
0030 {
0031     typedef object const key_type;
0032     static object get(object const& target, object const& key);
0033 };
0034   
0035 struct objattribute_policies : const_objattribute_policies
0036 {
0037     static object const& set(object const& target, object const& key, object const& value);
0038     static void del(object const&target, object const& key);
0039 };
0040 
0041 //
0042 // implementation
0043 //
0044 template <class U>
0045 inline object_attribute object_operators<U>::attr(char const* name)
0046 {
0047     object_cref2 x = *static_cast<U*>(this);
0048     return object_attribute(x, name);
0049 }
0050 
0051 template <class U>
0052 inline const_object_attribute object_operators<U>::attr(char const* name) const
0053 {
0054     object_cref2 x = *static_cast<U const*>(this);
0055     return const_object_attribute(x, name);
0056 }
0057 
0058 template <class U>
0059 inline object_objattribute object_operators<U>::attr(object const& name)
0060 {
0061     object_cref2 x = *static_cast<U*>(this);
0062     return object_objattribute(x, name);
0063 }
0064 
0065 template <class U>
0066 inline const_object_objattribute object_operators<U>::attr(object const& name) const
0067 {
0068     object_cref2 x = *static_cast<U const*>(this);
0069     return const_object_objattribute(x, name);
0070 }
0071 
0072 inline object const_attribute_policies::get(object const& target, char const* key)
0073 {
0074     return python::getattr(target, key);
0075 }
0076 
0077 inline object const_objattribute_policies::get(object const& target, object const& key)
0078 {
0079     return python::getattr(target, key);
0080 }
0081 
0082 inline object const& attribute_policies::set(
0083     object const& target
0084     , char const* key
0085     , object const& value)
0086 {
0087     python::setattr(target, key, value);
0088     return value;
0089 }
0090 
0091 inline object const& objattribute_policies::set(
0092     object const& target
0093     , object const& key
0094     , object const& value)
0095 {
0096     python::setattr(target, key, value);
0097     return value;
0098 }
0099 
0100 inline void attribute_policies::del(
0101     object const& target
0102     , char const* key)
0103 {
0104     python::delattr(target, key);
0105 }
0106 
0107 inline void objattribute_policies::del(
0108     object const& target
0109     , object const& key)
0110 {
0111     python::delattr(target, key);
0112 }
0113 
0114 }}} // namespace boost::python::api
0115 
0116 #endif // OBJECT_ATTRIBUTES_DWA2002615_HPP