Re: [pygccxml-development] Parameter default value, no type?
Brought to you by:
mbaas,
roman_yakovenko
From: Roman Y. <rom...@gm...> - 2008-07-13 19:00:21
|
On Sun, Jul 13, 2008 at 6:09 PM, Gustavo Carneiro <gjc...@gm...> wrote: > Hi, > > I am trying to wrap methods like this: > > > void SetMac (std::string type, > std::string n0 = "", const AttributeValue &v0 = > EmptyAttributeValue (), > std::string n1 = "", const AttributeValue &v1 = > EmptyAttributeValue (), > std::string n2 = "", const AttributeValue &v2 = > EmptyAttributeValue (), > std::string n3 = "", const AttributeValue &v3 = > EmptyAttributeValue (), > std::string n4 = "", const AttributeValue &v4 = > EmptyAttributeValue (), > std::string n5 = "", const AttributeValue &v5 = > EmptyAttributeValue (), > std::string n6 = "", const AttributeValue &v6 = > EmptyAttributeValue (), > std::string n7 = "", const AttributeValue &v7 = > EmptyAttributeValue ()); > > The problem I am having is that class AttributeValue is abstract and cannot > be instantiated. Normally in pybindgen I handle default values like this: > > PyParameter *pyParam = NULL; > PyArg_ParseTupleAndKeywords("...|O!", ..., &PyParameter_Type, &pyParam); > [...] > CallMyMethod ((pyParam? pyParam->obj : <Param Default Value>)); > > For instance,, if <Param Default> is ns3::EmptyAttributeValue(), I get a > compilation error: > > debug/bindings/python/ns3_module_helper.cc:83: error: cannot allocate an > object of abstract type 'ns3::AttributeValue' > debug/ns3/attribute.h:52: note: since type 'ns3::AttributeValue' has pure > virtual functions > > One solution to this problem would be the following: > > PyParameter *pyParam = NULL; > <Param Default Type> paramDefault = <Param Default Value>; > PyArg_ParseTupleAndKeywords("...|O!", ..., &PyParameter_Type, &pyParam); > [...] > CallMyMethod ((pyParam? pyParam->obj : paramDefault)); > > The above code would compile; I tested. The problem is that pygccxml does > not give me the type of the default parameter value, and of course the type > of the parameter itself is useless in these cases (it is abstract). > > Any suggestion would be welcome. There is a problem with default arguments and gccxml: http://language-binding.net/pygccxml/upgrade_issues.html#free-and-member-function-default-arguments I am not sure what can you do, I will give you few links to other possible solutions: 1. http://www.boost.org/doc/libs/1_35_0/libs/python/doc/v2/overloads.html 2. Second you can ask your users to update default values - pygccxml supports this functionality. May be you will even find some use case, that pygccxml could treat automaticaly: http://language-binding.net/pygccxml/apidocs/pygccxml.parser.patcher-pysrc.html HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |