C++ wrapper: public structure support improvement

This commit is contained in:
François Grisez 2017-03-28 16:41:52 +02:00
parent 64584409ae
commit d410536b2d
3 changed files with 22 additions and 1 deletions

View file

@ -726,6 +726,7 @@ class CParser(object):
elif cType.ctype in self.classesIndex or cType.ctype in self.interfacesIndex:
absType = ClassType(cType.ctype)
absType.isconst = cType.completeType.startswith('const ')
absType.isref = cType.completeType.endswith('*')
elif cType.ctype == self.cListType:
absType = ListType(cType.containedType)
else:

View file

@ -334,7 +334,13 @@ class CppTranslator(object):
else:
return 'Object::cPtrToSharedPtr<{0}>({1})'.format(cppReturnType, cExpr)
else:
return '{0}({1})'.format(exprtype.desc.name.to_camel_case(), cExpr);
if exprtype.isref:
return '{0}({1})'.format(exprtype.desc.name.to_camel_case(), cExpr)
else:
return '{0}(StructWrapper<::{1}>({2}).ptr())'.format(
exprtype.desc.name.to_camel_case(),
exprtype.desc.name.to_c(),
cExpr)
elif type(exprtype) is AbsApi.ListType:
if type(exprtype.containedTypeDesc) is AbsApi.BaseType and exprtype.containedTypeDesc.name == 'string':
return 'StringBctbxListWrapper::bctbxListToCppList({0})'.format(cExpr)

View file

@ -119,6 +119,20 @@ namespace linphone {
static std::list<std::string> cStringArrayToCppList(const char **cArray);
};
template <class T>
class StructWrapper {
public:
StructWrapper(const T &s) {
mStruct = s;
}
const void *ptr() const {
return &mStruct;
}
private:
T mStruct;
};
};
#endif // _TOOLS_HH