diff options
| author | John Zulauf <jzulauf@lunarg.com> | 2018-01-23 11:20:50 -0700 |
|---|---|---|
| committer | jzulauf-lunarg <32470354+jzulauf-lunarg@users.noreply.github.com> | 2018-01-26 13:00:21 -0700 |
| commit | 5e9d78552ad49b0a3f1aad4520a09d64afd57f19 (patch) | |
| tree | b203bfb6648767a88fb3cd4f3aff6997357c1c38 /scripts | |
| parent | af03d81f286342fb826545dcef6498f23e5addea (diff) | |
| download | usermoji-5e9d78552ad49b0a3f1aad4520a09d64afd57f19.tar.xz | |
layer: Add utility template for sType init
Add utility function to auto populate sType field based on typename
given to autogen of typemap helper. Return value optimization (copy
elision) should make this perfomance neutral vs. inline init.
Change-Id: I231cf92d5063c19f9ad5b14189dd162fdac76a43
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/helper_file_generator.py | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/scripts/helper_file_generator.py b/scripts/helper_file_generator.py index 114f47f8..f47857a8 100644 --- a/scripts/helper_file_generator.py +++ b/scripts/helper_file_generator.py @@ -1103,6 +1103,7 @@ class HelperFileOutputGenerator(OutputGenerator): typename_func = fprefix + 'typename' idname_func = fprefix + 'stype_name' find_func = fprefix + 'find_in_chain' + init_func = fprefix + 'init_struct' explanatory_comment = '\n'.join(( '// These empty generic templates are specialized for each type with sType', @@ -1142,22 +1143,35 @@ class HelperFileOutputGenerator(OutputGenerator): ' }}', ' return found;', '}}', + '', + '// Init the header of an sType struct with pNext', + 'template <typename T> T {init_func}(void *p_next) {{', + ' T out = {{}};', + ' out.sType = {type_map}<T>::kSType;', + ' out.pNext = p_next;', + ' return out;', + '}}', + '', + '// Init the header of an sType struct', + 'template <typename T> T {init_func}() {{', + ' T out = {{}};', + ' out.sType = {type_map}<T>::kSType;', + ' return out;', + '}}', + '')) code = [] + + # Generate header code.append('\n'.join(( '#pragma once', '#include <vulkan/vulkan.h>\n', explanatory_comment, '', empty_idmap, - empty_typemap, '', - utilities_format.format(id_member=id_member, id_map=idmap, type_map=typemap, - type_member=type_member, header=generic_header, typename_func=typename_func, idname_func=idname_func, - find_func=find_func), '' - ))) + empty_typemap, ''))) # Generate the specializations for each type and stype - for item in self.structMembers: typename = item.name info = self.structTypes.get(typename) @@ -1175,6 +1189,13 @@ class HelperFileOutputGenerator(OutputGenerator): if item.ifdef_protect != None: code.append('#endif // %s' % item.ifdef_protect) + # Generate utilities for all types + code.append('\n'.join(( + utilities_format.format(id_member=id_member, id_map=idmap, type_map=typemap, + type_member=type_member, header=generic_header, typename_func=typename_func, idname_func=idname_func, + find_func=find_func, init_func=init_func), '' + ))) + return "\n".join(code) # |
