1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
{# useful macros -#}
{%- macro cls_name(cls) -%}
{{ cls.name|replace('<', '_')|replace(' ', '_')|replace('>', '') }}
{%- endmacro -%}
{%- macro pointer(cls) -%}
{%- if "Standard_Transient" in cls.rootclass or cls.name == "Standard_Transient" -%} ,opencascade::handle<{{cls.name}}>
{%- elif cls.nonpublic_destructors|length>0 -%} , shared_ptr_nodelete<{{cls.name}}>
{%- elif parent_has_nonpublic_destructor(cls) -%} , shared_ptr<{{cls.name}}>
{%- else -%} , shared_ptr<{{cls.name}}>
{%- endif -%}
{%- endmacro -%}
{%- macro super(cls,classes,typedefs) -%}
{% for super in cls.superclass if super in classes or super in typedefs %}, {{super}} {% endfor %}
{%- endmacro -%}
{%- macro prototype(f) -%}
{{f.return_type}} {{f.name}}({% for n,t,d in f.args %}{{ t }} {{ n }}{{ "," if not loop.last }}{% endfor %}){% if f.const %} const {%endif%}
{%- endmacro -%}
{%- macro pybind_overload(c,m) -%}
using return_type = {{m.return_type}};
PYBIND11_OVERLOAD_PURE(return_type,{{c.name}},{{m.name}},{% for n,t,d in m.args %}{{ n }}{{ "," if not loop.last }}{% endfor %})
{%- endmacro -%}
{%- macro argtypes(f) -%}
{% for _,t,_ in f.args %}{{ t }}{{ "," if not loop.last }}{% endfor %}
{%- endmacro -%}
{%- macro argtypes_names(f) -%}
{% for arg,t,_ in f.args %}{{ t }} {{ arg }}{{ "," if not loop.last }}{% endfor %}
{%- endmacro -%}
{%- macro argtypes_names_not_byref(f) -%}
{% for arg,t,_ in f.args if not is_byref(t) %}{{ type_from_byref_smart_ptr(t)+'&' if is_byref_smart_ptr(t) else t }} {{ arg }}{{ "," if not loop.last }}{% endfor %}
{%- endmacro -%}
{%- macro init_outputs_byref(f) -%}
{% for arg,t,_ in f.args if is_byref(t) %}{{ t[:-1] }} {{ arg }};
{% endfor %}
{% for arg,t,_ in f.args if is_byref_smart_ptr(t) -%}
{{ t[:-1] }} {{ arg }}_ptr; {{ arg }}_ptr = &{{arg}};
{% endfor %}
{%- endmacro -%}
{%- macro argnames_wo_type(f) -%}
{% for arg,t,_ in f.args %}{% if is_byref_smart_ptr(t) %}{{ arg }}_ptr{% else %}{{ arg }}{% endif %}{{ "," if not loop.last }}{% endfor %}
{%- endmacro -%}
{%- macro argnames_byref(f) -%}
{% for arg,t,_ in f.args if is_byref(t) %}{{ arg }}{{ "," if not loop.last }}{% endfor %}
{%- endmacro -%}
{%- macro argnames(f) -%}
{% for arg,t,d in f.args %} {{ "," if loop.first }} py::arg("{{arg if arg!='' else 'arg'}}"){% if d %}=static_cast<{{t}}>({{d}}){% endif %}{{ "," if not loop.last }}{% endfor %}
{%- endmacro -%}
{%- macro argnames_template(template, f) -%}
{%- for arg,t,d in f.args -%} {{ "," if loop.first }}
{%- set ns = namespace(t=t) -%}
{%- if t.startswith(template.name) -%}
{% set ns.t = template.name + '<' + template.type_params|map('get',1)|join(', ') + '>' + t.split(template.name)[-1] %}
{%- endif -%}
py::arg("{{arg if arg!='' else 'arg'}}"){% if d %}=static_cast<{{arg_type_with_template_params(template, t)}}>({{d}}){% endif %}{{ ", " if not loop.last }}
{%- endfor -%}
{%- endmacro -%}
{%- macro arg_type_with_template_params(template, t) -%}
{%- set ns = namespace(t=t) -%}
{%- if t.startswith(template.name+'::') -%}
{% set ns.t = 'typename ' + template.name + '<' + template.type_params|map('get',1)|join(', ') + '>' + t.split(template.name)[-1] %}
{%- endif -%}
{{ ns.t }}
{%- endmacro -%}
{%- macro argnames_not_byref(f) -%}
{% for arg,t,d in f.args if not is_byref(t) %} {{ "," if loop.first }} py::arg("{{arg if arg!='' else 'arg'}}"){% if d %}=static_cast<{{t}}>({{d}}){% endif %}{{ "," if not loop.last }}{% endfor %}
{%- endmacro -%}
{%- macro handle_results_ptr_byref(f) -%}
{% for arg,t,_ in f.args if is_byref_smart_ptr(t) -%}
if ( {{ arg }}_ptr.get() != &{{arg}} ) copy_if_copy_constructible({{arg}}, *{{ arg }}_ptr);
{% endfor -%}
{%- endmacro -%}
{%- macro method_pointer(cls,f) -%}
({{f.return_type}} ({{cls.name}}::*)({% for _,t,d in f.args %} {{t}} {{ "," if not loop.last }} {% endfor %}) {{ "const" if f.const }}) static_cast<{{f.return_type}} ({{cls.name}}::*)({% for _,t,_ in f.args %} {{t}} {{ "," if not loop.last }} {% endfor %}) {{ "const" if f.const }}>(&{{cls.name}}::{{f.name}})
{%- endmacro -%}
{%- macro static_method_pointer(cls,f) -%}
({{f.return_type}} (*)({% for _,t,d in f.args %} {{t}} {{ "," if not loop.last }} {% endfor %}) {{ "const" if f.const }}) static_cast<{{f.return_type}} (*)({% for _,t,_ in f.args %} {{t}} {{ "," if not loop.last }} {% endfor %}) {{ "const" if f.const }}>(&{{cls.name}}::{{f.name}})
{%- endmacro -%}
{%- macro function_pointer(f) -%}
({{f.return_type}} (*)({% for _,t,d in f.args %} {{t}} {{ "," if not loop.last }} {% endfor %})) static_cast<{{f.return_type}} (*)({% for _,t,_ in f.args %} {{t}} {{ "," if not loop.last }} {% endfor %})>(&{% if f.namespace %}{{f.namespace}}::{% endif %}{{f.name}})
{%- endmacro -%}
{%- macro template_args_typename(t) -%}
<{% for type,name,default in t.type_params %}{% if type %}{{ type }}{% else %}typename{% endif %} {{name}}{% if default %}={{default}}{% endif %}{{ "," if not loop.last }}{% endfor %}>
{%- endmacro -%}
{%- macro template_args(t) -%}
<{% for type,name,default in t.type_params %}{{name}}{{ "," if not loop.last }}{% endfor %}>
{%- endmacro -%}
{%- macro template_return_type(cls,f) -%}
{% if f.return_type.startswith(cls.name+'::') %}typename {{cls.name}}{{ template_args(cls) }}::{{ f.return_type.split('::')[1]}}{% else %}{{f.return_type}}{% endif %}
{%- endmacro -%}
{%- macro template_method_pointer(cls,f) -%}
({{template_return_type(cls,f)}} ({{cls.name}}{{template_args(cls)}}::*)({% for _,t,d in f.args %} {{arg_type_with_template_params(cls, t)}} {{ "," if not loop.last }} {% endfor %}) {{ "const" if f.const }}) &{{cls.name}}{{template_args(cls)}}::{{f.name}}
{%- endmacro -%}
{%- macro template_static_method_pointer(cls,f) -%}
({{template_return_type(cls,f)}} (*)({% for _,t,d in f.args %} {{arg_type_with_template_params(cls, t)}} {{ "," if not loop.last }} {% endfor %}) {{ "const" if f.const }}) &{{cls.name}}{{template_args(cls)}}::{{f.name}}
{%- endmacro -%}
{%- macro template_pointer(cls) -%}
{%- if "Standard_Transient" in cls.rootclass or cls.name == "Standard_Transient" -%} , opencascade::handle<{{cls.name}}{{template_args(cls)}}>
{%- elif cls.nonpublic_destructors|length>0 -%} , shared_ptr_nodelete<{{cls.name}}{{template_args(cls)}}>
{%- else -%} , shared_ptr<{{cls.name}}{{template_args(cls)}}>
{%- endif -%}
{%- endmacro -%}
{%- macro trampoline_class(c) -%}
class Py_{{c.name}} : public {{c.name}}{
public:
using {{c.name}}::{{c.name}};
{% set methods = [] %}
// public pure virtual
{% for m in c.methods+c.methods_byref %}{% if m.pure_virtual %}
{{ prototype(m) }} override { {{pybind_overload(c,m)}} };
{% do methods.append(m.full_name) %}
{% endif %}{% endfor %}
{% for super in c.superclasses %}
{% set p = all_classes.get(super,None) %}{% if p %}
{% for m in p.methods %}{% if m.pure_virtual and m.name not in c.methods_dict and not m.full_name in methods %}
{{ prototype(m) }} override { {{pybind_overload(p,m)}} };
{% do methods.append(m.full_name) %}
{% endif %}{% endfor %}
{% endif %}
{% endfor %}
// protected pure virtual
{% for m in c.protected_virtual_methods %}
{{ prototype(m) }} override { {{pybind_overload(c,m)}} };
{% do methods.append(m.full_name) %}
{% endfor %}
{% for super in c.superclasses %}
{% set p = all_classes.get(super,None) %}{% if p %}
{% for m in p.protected_virtual_methods %}{% if m.name not in c.protected_virtual_methods_dict and not m.full_name in methods %}
{{ prototype(m) }} override { {{pybind_overload(p,m)}} };
{% do methods.append(m.full_name) %}
{% endif %}{% endfor %}
{% endif %}
{% endfor %}
// private pure virtual
{% for m in c.private_virtual_methods %}
{{ prototype(m) }} override { {{pybind_overload(c,m)}} };
{% endfor %}
{% for super in c.superclasses %}
{% set p = all_classes.get(super,None) %}{% if p %}
{% for m in p.private_virtual_methods %}{% if m.name not in c.private_virtual_methods_dict and not m.full_name in methods %}
{{ prototype(m) }} override { {{pybind_overload(p,m)}} };
{% do methods.append(m.full_name) %}
{% endif %}{% endfor %}
{% endif %}
{% endfor %}
};
{%- endmacro -%}
{# end of macros macros -#}
|