Using Boost Python, is it possible for a C++ function exposed to python to return either an integer or a string (or other type) depending on the value of the single argument passed in?
So in Python I want to do this:
from my_module import get_property_value
# get an integer property value
i = get_property_value("some_int_property")
# get a string
s = get_property_value("some_string_property")
C++ pseudo code (obviously won't it work like this, but you get the idea)
???? getPropertyValue(const char* propertyName)
{
Property *p = getProperty(propertyName);
switch(p->type)
{
case INTEGER: return p->as_int();
case STRING: return p->as_string();
...
}
}
BOOST_PYTHON_MODULE(my_module)
{
boost::python::def("get_property_value", &getPropertyValue);
}
If it makes any difference, I'm using Boost 1.48 with Python 3.2.