[C++-sig] Re: Argument handling, char** in constructor

David Abrahams dave at boost-consulting.com
Wed Aug 27 12:55:36 CEST 2003


Wolfgang Langner <wl at flexis.de> writes:

> David Abrahams wrote:
>> Wolfgang Langner <wl at flexis.de> writes:
>
>>>I use boost.python 1.30 with python 2.2.3 under Windows (VC6).
>>>
>>>My python module interfaces to a C++ class that has the following
>>>constructor:
>>>
>>>MyClass(int* argc = 0, char** argv = 0);
>>>
>>>In boost.python I exposed it with:
>>><some stuff> ...
>>>.def(init<optional<int*, char**> >())
>>>
>>>This works only if I have no arguments.
>>>The problem is, I have to pass arguments from the command line
>>>(called python programm) to the C++ class. (same as in main())
>>>
>>>First I tried to solve it with a small wrapper class that
>>>inherits from the C++ class and maps a python list of strings
>>>to that interface. But that don't work because the C++ class
>>>is a singleton.
>>>
>>>
>>>Are ther any suggestions to expose this class to python ?
>> Well, what do you expect to be able to pass to this class from
>> Python?
>> There are no built-in conversions from Python to char**.
>> I'm guessing you'd like to write:
>>    >>> MyClass(['arg1', 'arg2'])
>> ??
> Yes, that's right. So I have an easy to use interface for the python class.
>
>> I have an item on the TODO list which should address that need
>> (http://www.boost-consulting.com/boost/libs/python/todo.html#injected-constructors)
>> but I am not precisely sure that it will work for you because of the
>> "singleton" issue.  What does that mean in your case?  Can MyClass
>> instances be allocated on the heap?
>
> The item on the TODO list seems to bee usefull for me.
> I investigate it and read more about the thread.
>
> For the singelton issue, I need more time to look at it.
> It's also possible for me to change the C++ class, because I have
> the full code (but it's still closed source).
> The heap allocation is a good idea, I try it.

It wasn't a suggestion; I don't see how you'd take advantage of it.
I wanted to know because if someone implements the TODO item and you
want to use it, you'd need to be able to allocate your class on the
heap.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list