diff --git a/src/clang_convert/cpp_code/code_info.py b/src/clang_convert/cpp_code/code_info.py index a83842779..808b39501 100755 --- a/src/clang_convert/cpp_code/code_info.py +++ b/src/clang_convert/cpp_code/code_info.py @@ -18,6 +18,9 @@ class CodeInfo: self._function_calls = [] # List all function calls made whilst converting (for post-processing) self._non_const_member_function_names = [] # default to const unless told otherwise! + # A place to add any specific data, usually as "identifier", data pairs + self._custom_data = {} + @property def file_name(self): return self._file_name @@ -86,3 +89,10 @@ class CodeInfo: def add_non_const_member_function_name(self, name): if name not in self._non_const_member_function_names: self._non_const_member_function_names.append(name) + + @property + def custom_data(self): + return self._custom_data + + def add_custom_data(self, identifier, data): + self._custom_data[identifier] = data diff --git a/src/clang_convert/cpp_code/cppcode.py b/src/clang_convert/cpp_code/cppcode.py index 3e2a24a3c..d7afbea32 100755 --- a/src/clang_convert/cpp_code/cppcode.py +++ b/src/clang_convert/cpp_code/cppcode.py @@ -27,6 +27,10 @@ class CppCode: def class_name(self): return self._code_info.class_name + @property + def class_name_camel_case(self): + return self.class_name[0].lower() + self.class_name[1:] + @property def super_class_name(self): return self._code_info.super_class_name @@ -51,6 +55,10 @@ class CppCode: def source_file_includes(self): return self._code_info.source_includes + @property + def custom_data(self): + return self._code_info.custom_data + # ============================== CodeInfo properties: end ============================== # ============================== CodeElements properties: start ============================== diff --git a/src/clang_convert/grib_accessor/grib_accessor_ccode_converter.py b/src/clang_convert/grib_accessor/grib_accessor_ccode_converter.py index c777c8119..3d4dbbc39 100755 --- a/src/clang_convert/grib_accessor/grib_accessor_ccode_converter.py +++ b/src/clang_convert/grib_accessor/grib_accessor_ccode_converter.py @@ -76,6 +76,10 @@ class GribAccessorCCodeConverter(default_ccode_converter.DefaultCCodeConverter): info.add_namespace("eccodes") info.add_namespace("accessor") + factory_name = self._ccode.class_name.replace(prefix, "") + info.add_custom_data("factory_name", factory_name) + debug.line("create_code_info", f"Set factory_name=[{factory_name}]") + return info def function_specific_conversion_pack_updates(self, cfunction_name, conv_pack): diff --git a/src/clang_convert/grib_accessor/j2/grib_accessor_source.cc.j2 b/src/clang_convert/grib_accessor/j2/grib_accessor_source.cc.j2 index 6a6852a1f..a16cb2beb 100644 --- a/src/clang_convert/grib_accessor/j2/grib_accessor_source.cc.j2 +++ b/src/clang_convert/grib_accessor/j2/grib_accessor_source.cc.j2 @@ -22,4 +22,8 @@ namespace {{ c.nested_namespaces }} { {{ func.as_string() }} {% endfor %} +namespace { +AccessorBuilder<{{ c.class_name }}> {{ c.class_name_camel_case }}Builder(AccessorType("{{ c.custom_data["factory_name"] }}")); +} + } // namespace {{ c.nested_namespaces }}