[C++-sig] Converting custom string pointer to python string

David Sveningsson ext at sidvind.com
Tue Feb 6 11:43:03 CET 2007


ext at sidvind.com skrev:
>>> Yes, I read that. That helped me to come as far as I have. But it only
>>> shows how to use copied instances and references, not pointers.
>>>       
>> In Python, strings are invariant (i.e. const). You can't modify a string
>> in place. Thus, what I believe you are aiming for isn't possible, on the
>> language level.
>>
>> Regards,
>> 		Stefan
>>
>>     
>
> First I should explain the CustomString class. It has no methods to modify
> the string, they are constructed once and then used as they are.
>
> CustomString is often passed around in my c++ code using pointers.
>
> What I want to do is to be able to use strings to/from python. If I call a
> function that takes a CustomString pointer I don't want to call a factory
> function to create the string first, I just want to use a python string.
>
> Like this:
>
> c++ prototype: void func(CustomString* str);
> current python code: func(factory('asdf'))
> wanted python code: func('asdf')
>
> I would also like to have a function returning a CustomString pointer to
> also be converted to a python string.
>
> c++ prototype: CustomString* foo()
>
> Right now the CustomString class is exposed and has the __str__ function
> overloaded to allow me to print it. But I would rather like to deal with
> it completely as a python string.
>
> I hope and think this is possible. As I said, I don't need to modify the
> strings.
>
> What about opaque pointer? Cant that be used to archive this?
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
>   
I still don't get this to work, using const doesn't help either. Should
I try to wrap the pointers with the raw python c api instead of boost?

-- 


//*David Sveningsson [eXt]*

Freelance coder | Game Development Student
http://sidvind.com

Thou shalt make thy program's purpose and structure clear to thy fellow man by using the One True Brace Style, even if thou likest it not, for thy creativity is better used in solving problems than in creating beautiful new impediments to understanding.




More information about the Cplusplus-sig mailing list