mirror of
https://github.com/boostorg/python.git
synced 2026-01-24 06:02:14 +00:00
beginning of object support
[SVN r14157]
This commit is contained in:
35
src/object_protocol.cpp
Executable file
35
src/object_protocol.cpp
Executable file
@@ -0,0 +1,35 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
|
||||
#include <boost/python/object_protocol.hpp>
|
||||
#include <boost/python/errors.hpp>
|
||||
#include <boost/python/object.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
object getattr(object const& target, object const& key)
|
||||
{
|
||||
return object((object::new_pyobject_reference*)PyObject_GetAttr(&*target, &*key));
|
||||
}
|
||||
|
||||
void setattr(object const& target, object const& key, object const& value)
|
||||
{
|
||||
if (PyObject_SetAttr(&*target, &*key, &*value) == -1)
|
||||
throw_error_already_set();
|
||||
}
|
||||
|
||||
object getitem(object const& target, object const& key)
|
||||
{
|
||||
return object((object::new_pyobject_reference*)PyObject_GetItem(&*target, &*key));
|
||||
}
|
||||
|
||||
void setitem(object const& target, object const& key, object const& value)
|
||||
{
|
||||
if (PyObject_SetItem(&*target, &*key, &*value) == -1)
|
||||
throw_error_already_set();
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
Reference in New Issue
Block a user