[C++-sig] Converting CString to/from std::string

Kirsebom Nikolai nikolai.kirsebom at siemens.no
Tue May 27 14:09:04 CEST 2003


-----Original Message-----
From: Ralf W. Grosse-Kunstleve [mailto:rwgk at yahoo.com]
Sent: 27. mai 2003 08:46
To: c++-sig at python.org
Subject: Re: ÆC++-sigÅ Converting CString to/from std::string


--- Nikolai Kirsebom <nikolai at micon.no> wrote:
> I have a rather large set of C++ classes I want to make accessible
> (initially only parts of some of the classes) from Python.  I cannot
> change the classes as they are defined and used throughout a large
> application.  Some of the methods take CString as parameters and others
> return CString values.
> 
> Does anyone have suggestion on how I can convert these parameters so
> that I can use Boost.Python to generate the wrapper code.

What do you want your CStrings to be in Python? Regular Python strings?
If you think "yes" remind yourself that Python strings are immutable.
I.e. if you have function signatures involving non-const references or
pointers to CString as arguments or return values the mapping from C++
CStrings to Python strings will not work very well.
More depending on your response.
Ralf


Some time ago I made a 'socket based' system (using BISON/FLEX for parsing)
where I expose C++ objects to python.  In this system CStrings are regular
Python strings.  So as an example I can write:
---------------------------------------------
C++:

class IF {
	CString MenuText;
	CString GetHelpText();
	int SetHelpText(CString s);
};

In Python:

o = IF()		# Behind the 'curtains' create a 'link' to a C++
object
print o.MenuText
s = o.GetHelpText(o.MenuText + "some text")
----------------------------------------------

So I would like something similar.

I'm very new to the Boost system and do not really have experience in C++
Template development so I find the Reference Manual somewhat difficult to
understand.  This may explain if I request 'dead easy' or 'impossible'
things.

Thanks for any help
Nikolai










More information about the Cplusplus-sig mailing list