Added by-value conversions to Python for bool. This allowed me to
expose all of the amount_t members now.
This commit is contained in:
parent
c211335760
commit
426a01b3f4
3 changed files with 38 additions and 4 deletions
|
|
@ -55,7 +55,6 @@ void export_amount()
|
|||
make_getter(&amount_t::current_pool,
|
||||
return_value_policy<reference_existing_object>()))
|
||||
|
||||
#if 0
|
||||
.add_static_property("keep_base", &amount_t::keep_base)
|
||||
|
||||
.add_static_property("keep_price", &amount_t::keep_price)
|
||||
|
|
@ -63,7 +62,6 @@ void export_amount()
|
|||
.add_static_property("keep_tag", &amount_t::keep_tag)
|
||||
|
||||
.add_static_property("stream_fullstrings", &amount_t::stream_fullstrings)
|
||||
#endif
|
||||
|
||||
.def(init<double>())
|
||||
.def(init<long>())
|
||||
|
|
|
|||
|
|
@ -9,6 +9,40 @@ namespace ledger {
|
|||
|
||||
using namespace boost::python;
|
||||
|
||||
struct bool_to_python
|
||||
{
|
||||
static PyObject * convert(const bool truth)
|
||||
{
|
||||
if (truth)
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
};
|
||||
|
||||
struct bool_from_python
|
||||
{
|
||||
static void* convertible(PyObject* obj_ptr)
|
||||
{
|
||||
if (!PyBool_Check(obj_ptr)) return 0;
|
||||
return obj_ptr;
|
||||
}
|
||||
|
||||
static void construct(PyObject* obj_ptr,
|
||||
converter::rvalue_from_python_stage1_data* data)
|
||||
{
|
||||
void* storage = ((converter::rvalue_from_python_storage<bool>*) data)->storage.bytes;
|
||||
if (obj_ptr == Py_True)
|
||||
new (storage) bool(true);
|
||||
else
|
||||
new (storage) bool(false);
|
||||
data->convertible = storage;
|
||||
}
|
||||
};
|
||||
|
||||
typedef register_python_conversion<bool, bool_to_python, bool_from_python>
|
||||
bool_python_conversion;
|
||||
|
||||
struct string_to_python
|
||||
{
|
||||
static PyObject* convert(const string& str)
|
||||
|
|
@ -40,6 +74,7 @@ typedef register_python_conversion<string, string_to_python, string_from_python>
|
|||
|
||||
void export_utils()
|
||||
{
|
||||
bool_python_conversion();
|
||||
string_python_conversion();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,8 +27,9 @@ struct register_optional_to_python : public boost::noncopyable
|
|||
{
|
||||
static PyObject * convert(const boost::optional<T>& value)
|
||||
{
|
||||
return (value ? boost::python::to_python_value<T>()(*value) :
|
||||
boost::python::detail::none());
|
||||
return boost::python::incref
|
||||
(value ? boost::python::to_python_value<T>()(*value) :
|
||||
boost::python::detail::none());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue