[C++-sig] RE: ÆC++-sigÅ How to turn output parameters to return values?

Kirsebom Nikolai nikolai.kirsebom at siemens.no
Fri Feb 20 11:35:59 CET 2004


Hi

See example - hope it helps:

//// C++

class CDbHandler
{
public:

	boost::python::tuple GetCurUserInfo();
};

tuple CDbHandler::GetCurUserInfo()
{
	int userId;
	CString userName;

	m_Dbh->GetCurUserInfo(userId, userName);

	char buf[200];
	strcpy(buf, userName.GetBuffer(1000));
	tuple x = make_tuple(userId, buf);
	return x;
}

BOOST_PYTHON_MODULE(CDbHandler)
{
	class_<CDbHandler>(..some init stmt..)
		.def("GetCurUserInfo", &CDbHandler::GetCurUserInfo)
	;
}

//// PYTHON:

import CDbHandler
.....

usi = dbh.GetCurUserInfo()

# usi[0] contains userId
# usi[1] contains userName

Nikolai


> -----Original Message-----
> From: Matthias Baas [mailto:baas at ira.uka.de]
> Sent: 20. februar 2004 10:47
> To: c++-sig at python.org
> Subject: ÆC++-sigÅ How to turn output parameters to return values?
> 
> 
> Hi,
> 
> suppose I have a function or method that takes references as 
> arguments 
> in order to return values like this:
> 
> void getImageSize(int& width, int& height);
> 
> How do I wrap that function? Ideally, I want the corresponding Python 
> function/method to take no input parameter and return a tuple (width, 
> height).
> I've experimented with the return_arg call policy but didn't 
> get far. I 
> was only able to return one single value but only if it was *not* a 
> reference (in which case it's useless for my purpose). So is there an 
> example somewhere how to wrap a function like the above?
> 
> Cheers,
> 
> - Matthias -
> 
> 
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
> 




More information about the Cplusplus-sig mailing list