(name: str,
ctype: str,
cpptype: str,
destroy: Optional[str] = None,
ref=False,
skip_def=False)
| 894 | |
| 895 | |
| 896 | def add_handle(name: str, |
| 897 | ctype: str, |
| 898 | cpptype: str, |
| 899 | destroy: Optional[str] = None, |
| 900 | ref=False, |
| 901 | skip_def=False) -> None: |
| 902 | opaque_type = ctype + '_t' |
| 903 | const_opaque_type = 'const_' + opaque_type |
| 904 | |
| 905 | def handle_wrap(p: Parameter): |
| 906 | t = Type(opaque_type) |
| 907 | if p.type.is_const(): |
| 908 | t = Type('const_' + opaque_type) |
| 909 | # p.read = 'object_cast<${ctype}>(&(${name}))' |
| 910 | if p.virtual: |
| 911 | p.add_param(t) |
| 912 | elif p.returns: |
| 913 | p.add_param(t.add_pointer()) |
| 914 | else: |
| 915 | p.add_param(t) |
| 916 | p.bad_param('${name} == nullptr', 'Null pointer') |
| 917 | if p.type.is_reference(): |
| 918 | p.virtual_read = ['object_cast<${ctype}>(&(${name}))'] |
| 919 | p.cpp_write = '${cpptype}(${name}, false)' |
| 920 | p.write = ['*${name} = object_cast<${ctype}>(&(${result}))'] |
| 921 | elif p.type.is_pointer(): |
| 922 | p.virtual_read = ['object_cast<${ctype}>(${result})'] |
| 923 | p.cpp_write = '${cpptype}(${name}, false)' |
| 924 | p.write = ['*${name} = object_cast<${ctype}>(${result})'] |
| 925 | else: |
| 926 | p.virtual_read = ['object_cast<${ctype}>(&(${name}))'] |
| 927 | p.cpp_write = '${cpptype}(${name})' |
| 928 | p.write = ['*${name} = allocate<${ctype}>(${result})'] |
| 929 | if skip_def: |
| 930 | p.read = '*${name}' |
| 931 | else: |
| 932 | p.read = '${name}->object' |
| 933 | p.cpp_read = '${name}.get_handle_ptr()' |
| 934 | |
| 935 | type_map[cpptype] = handle_wrap |
| 936 | if not ref: |
| 937 | add_function(destroy or ctype + '_' + 'destroy', |
| 938 | params({name: opaque_type}), |
| 939 | fname='destroy') |
| 940 | add_function(ctype + '_' + 'assign_to', |
| 941 | params(output=opaque_type, input=const_opaque_type), |
| 942 | invoke='*output = *input') |
| 943 | add_handle_preamble() |
| 944 | c_header_preamble.append(handle_typedef.substitute(locals())) |
| 945 | if not skip_def: |
| 946 | c_api_body_preamble.append(handle_definition.substitute(locals())) |
| 947 | |
| 948 | |
| 949 | @cwrap('std::vector') |
no test coverage detected