Commit 91720d2b authored by François Grisez's avatar François Grisez

abstractapi.py: introduce a new list type for list containing freshly allocated object.

parent 21203d48
......@@ -229,6 +229,7 @@ TAB_SIZE = 8
# newlines.
ALIASES = bctbx_list{1}="A list of \ref \1 objects. \xmlonly <bctbxlist>\1</bctbxlist> \endxmlonly"
ALIASES += onTheFlyList="The objects inside the list are freshly allocated with a reference counter equal to one, so they need to be freed on list destruction with bctbx_list_free_with_data() for instance. \xmlonly <onTheFlyList/> \endxmlonly"
ALIASES += donotwrap="\xmlonly <donotwrap /> \endxmlonly"
# This tag can be used to specify a number of word-keyword mappings (TCL only).
......
......@@ -182,7 +182,7 @@ LINPHONE_PUBLIC bctbx_list_t *linphone_chat_room_get_history (LinphoneChatRoom *
* @param[in] cr The #LinphoneChatRoom object corresponding to the conversation for which messages should be retrieved
* @param[in] begin The first message of the range to be retrieved. History most recent message has index 0.
* @param[in] end The last message of the range to be retrieved. History oldest message has index of history size - 1 (use #linphone_chat_room_get_history_size to retrieve history size)
* @return \bctbx_list{LinphoneChatMessage}
* @return \bctbx_list{LinphoneChatMessage} \onTheFlyList
*/
LINPHONE_PUBLIC bctbx_list_t *linphone_chat_room_get_history_range(LinphoneChatRoom *cr, int begin, int end);
......
......@@ -179,6 +179,14 @@ class ListType(Type):
return translator.translate_list_type(self, **params)
class BasicListType(ListType):
pass
class OnTheFlyListType(ListType):
pass
class DocumentableObject(Object):
def __init__(self, name):
Object.__init__(self, name)
......@@ -868,7 +876,10 @@ class CParser(object):
absType.isconst = cType.completeType.startswith('const ')
absType.isref = cType.completeType.endswith('*')
elif cType.ctype == self.cListType:
absType = ListType(cType.containedType)
if cType.onTheFlyList:
absType = OnTheFlyListType(cType.containedType)
else:
absType = BasicListType(cType.containedType)
absType.isconst = cType.completeType.startswith('const ')
elif cType.ctype.endswith('Mask'):
absType = BaseType('integer', isUnsigned=True)
......
......@@ -88,6 +88,7 @@ class CArgument(CObject):
CObject.__init__(self, name)
self.description = None
self.containedType = None
self.onTheFlyList = False
keywords = [ 'const', 'struct', 'enum', 'signed', 'unsigned', 'short', 'long', '*' ]
fullySplittedType = []
splittedType = t.strip().split(' ')
......@@ -563,6 +564,7 @@ class Project:
n = returndesc.find('.//bctbxlist')
if n is not None:
returnarg.containedType = n.text
returnarg.onTheFlyList = True if returndesc.find('.//onTheFlyList') is not None else False
returnarg.description = self.__cleanDescription(returndesc)
elif returnarg.completeType != 'void':
missingDocWarning += "\tReturn value is not documented\n"
......
......@@ -246,14 +246,14 @@ class CppTranslator(object):
return ', '.join(args)
def _wrap_cpp_expression_to_c(self, cppExpr, exprtype, usedNamespace=None):
if type(exprtype) is AbsApi.BaseType:
if isinstance(exprtype, AbsApi.BaseType):
if exprtype.name == 'string':
cExpr = 'StringUtilities::cppStringToC({0})'.format(cppExpr);
else:
cExpr = cppExpr
elif type(exprtype) is AbsApi.EnumType:
elif isinstance(exprtype, AbsApi.EnumType):
cExpr = '(::{0}){1}'.format(exprtype.desc.name.to_c(), cppExpr)
elif type(exprtype) is AbsApi.ClassType:
elif isinstance(exprtype, AbsApi.ClassType):
cPtrType = exprtype.desc.name.to_c()
if exprtype.desc.refcountable:
ptrType = exprtype.translate(self.langTranslator, namespace=usedNamespace)
......@@ -270,10 +270,10 @@ class CppTranslator(object):
cExpr = '(const ::{_type} *)({expr}).c_struct()'.format(_type=cPtrType, expr=cppExpr)
else:
cExpr = '*(const ::{_type} *)({expr}).c_struct()'.format(_type=cPtrType, expr=cppExpr)
elif type(exprtype) is AbsApi.ListType:
if type(exprtype.containedTypeDesc) is AbsApi.BaseType and exprtype.containedTypeDesc.name == 'string':
elif isinstance(exprtype, AbsApi.ListType):
if isinstance(exprtype.containedTypeDesc, AbsApi.BaseType) and exprtype.containedTypeDesc.name == 'string':
cExpr = 'StringBctbxListWrapper({0}).c_list()'.format(cppExpr)
elif type(exprtype.containedTypeDesc) is AbsApi.ClassType:
elif isinstance(exprtype.containedTypeDesc, AbsApi.ClassType):
ptrType = exprtype.containedTypeDesc.translate(self.langTranslator, namespace=usedNamespace)
if exprtype.containedTypeDesc.desc.refcountable:
ptrType = CppTranslator.sharedPtrTypeExtractor.match(ptrType).group(2)
......@@ -290,7 +290,7 @@ class CppTranslator(object):
return cExpr
def _wrap_c_expression_to_cpp(self, cExpr, exprtype, usedNamespace=None):
if type(exprtype) is AbsApi.BaseType:
if isinstance(exprtype, AbsApi.BaseType):
if exprtype.name == 'string':
return 'StringUtilities::cStringToCpp({0})'.format(cExpr)
elif exprtype.name == 'string_array':
......@@ -299,15 +299,15 @@ class CppTranslator(object):
return '({0} != FALSE)'.format(cExpr)
else:
return cExpr
elif type(exprtype) is AbsApi.EnumType:
elif isinstance(exprtype, AbsApi.EnumType):
cppEnumName = exprtype.translate(self.langTranslator, namespace=usedNamespace)
return '({0}){1}'.format(cppEnumName, cExpr)
elif type(exprtype) is AbsApi.ClassType:
elif isinstance(exprtype, AbsApi.ClassType):
cppReturnType = exprtype.translate(self.langTranslator, namespace=usedNamespace)
if exprtype.desc.refcountable:
cppReturnType = CppTranslator.sharedPtrTypeExtractor.match(cppReturnType).group(2)
if type(exprtype.parent) is AbsApi.Method and len(exprtype.parent.name.words) >=1 and (exprtype.parent.name.words == ['new'] or exprtype.parent.name.words[0] == 'create'):
if isinstance(exprtype.parent, AbsApi.Method) and len(exprtype.parent.name.words) >=1 and (exprtype.parent.name.words == ['new'] or exprtype.parent.name.words[0] == 'create'):
return 'Object::cPtrToSharedPtr<{0}>({1}, false)'.format(cppReturnType, cExpr)
else:
return 'Object::cPtrToSharedPtr<{0}>({1})'.format(cppReturnType, cExpr)
......@@ -319,17 +319,18 @@ class CppTranslator(object):
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':
elif isinstance(exprtype, AbsApi.ListType):
if isinstance(exprtype.containedTypeDesc, AbsApi.BaseType) and exprtype.containedTypeDesc.name == 'string':
return 'StringBctbxListWrapper::bctbxListToCppList({0})'.format(cExpr)
elif type(exprtype.containedTypeDesc) is AbsApi.ClassType:
elif isinstance(exprtype.containedTypeDesc, AbsApi.ClassType):
cppReturnType = exprtype.containedTypeDesc.translate(self.langTranslator, namespace=usedNamespace)
takeRef = 'false' if isinstance(exprtype, AbsApi.OnTheFlyListType) else 'true'
if exprtype.containedTypeDesc.desc.refcountable:
cppReturnType = CppTranslator.sharedPtrTypeExtractor.match(cppReturnType).group(2)
return 'ObjectBctbxListWrapper<{0}>::bctbxListToCppList({1})'.format(cppReturnType, cExpr)
return 'ObjectBctbxListWrapper<{0}>::bctbxListToCppList({1}, {2})'.format(cppReturnType, cExpr, takeRef)
else:
cType = exprtype.containedTypeDesc.desc.name.to_c()
return 'StructBctbxListWrapper<{0},{1}>::bctbxListToCppList({2})'.format(cppReturnType, cType, cExpr)
return 'StructBctbxListWrapper<{0},{1}>::bctbxListToCppList({2}, {3})'.format(cppReturnType, cType, cExpr, takeRef)
else:
raise AbsApi.Error('translation of bctbx_list_t of enums or basic C types is not supported')
else:
......
......@@ -50,16 +50,16 @@ namespace linphone {
bctbx_list_free_with_data(mCList, unrefData);
}
}
static std::list<std::shared_ptr<T> > bctbxListToCppList(const ::bctbx_list_t *bctbxList) {
static std::list<std::shared_ptr<T> > bctbxListToCppList(const ::bctbx_list_t *bctbxList, bool takeRef=true) {
std::list<std::shared_ptr<T> > cppList;
for(const ::bctbx_list_t *it=bctbxList; it!=NULL; it=it->next) {
std::shared_ptr<T> newObj = Object::cPtrToSharedPtr<T>(it->data);
std::shared_ptr<T> newObj = Object::cPtrToSharedPtr<T>(it->data, takeRef);
cppList.push_back(newObj);
}
return cppList;
}
static std::list<std::shared_ptr<T>> bctbxListToCppList(::bctbx_list_t *bctbxList) {
std::list<std::shared_ptr<T>> cppList = bctbxListToCppList((const ::bctbx_list_t *)bctbxList);
static std::list<std::shared_ptr<T>> bctbxListToCppList(::bctbx_list_t *bctbxList, bool takeRef=true) {
std::list<std::shared_ptr<T>> cppList = bctbxListToCppList(const_cast<const ::bctbx_list_t *>(bctbxList), takeRef);
bctbx_list_free(bctbxList);
return cppList;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment