Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Adding extern C block for C++ use
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianSipos committed Sep 26, 2023
1 parent 30707d2 commit dab31bf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/camp/generators/create_gen_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def write(self, outfile: TextIO):

self.write_defines(outfile)
self.write_includes(outfile)
outfile.write(campch.make_cplusplus_open())
self.write_adm_template_documentation(outfile)

self.write_agent_nickname_definitions(outfile)
Expand All @@ -62,6 +63,7 @@ def write(self, outfile: TextIO):

self.write_initialization_functions(outfile)

outfile.write(campch.make_cplusplus_close())
self.write_endifs(outfile)

#
Expand Down Expand Up @@ -90,8 +92,9 @@ def write_endifs(self, outfile):
name_upper = self.adm.norm_name.upper()
ns_upper = self.adm.norm_namespace.replace("/", "_").upper()
endifs_str = """\
#endif /* _HAVE_{1}_ADM_ */
#endif // ADM_{0}_H_
#endif /* ADM_{0}_H_ */
"""
outfile.write(endifs_str.format(name_upper, ns_upper))

Expand Down Expand Up @@ -491,7 +494,7 @@ def write_initialization_functions(self, outfile):
name = self.adm.norm_namespace
body = (
"/* Initialization functions. */\n"
"void {0}_init();\n\n"
"void {0}_init();\n"
).format(name)

outfile.write(body.format(name))
4 changes: 3 additions & 1 deletion src/camp/generators/create_impl_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def write(self, outfile: TextIO):

self._scraper.write_custom_includes(outfile)
self.write_includes(outfile)
outfile.write(campch.make_cplusplus_open())

self._scraper.write_custom_type_enums(outfile)

Expand All @@ -75,6 +76,7 @@ def write(self, outfile: TextIO):
self.write_operator_functions(outfile)
self.write_table_functions(outfile)

outfile.write(campch.make_cplusplus_close())
self.write_endifs(outfile)

#
Expand All @@ -95,7 +97,7 @@ def write_endifs(self, outfile):
name_upper = self.adm.norm_name.upper()
endifs_str = """\
#endif // ADM_{0}_IMPL_H_
#endif /* ADM_{0}_IMPL_H_ */
"""
outfile.write(endifs_str.format(name_upper))

Expand Down
18 changes: 18 additions & 0 deletions src/camp/generators/lib/campch.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,3 +691,21 @@ def write_init_function(c_file, adm: ace.models.AdmFile, g_var_idx: str, mgr: bo

c_file.write(init_decls + "\n")
write_formatted_init_function(c_file, adm.norm_namespace, None, body)

def make_cplusplus_open():
''' Open an "extern C" block for C++ inclusion. '''
return """\
#ifdef __cplusplus
extern "C" {
#endif
"""

def make_cplusplus_close():
''' Close an "extern C" block for C++ inclusion. '''
return """\
#ifdef __cplusplus
}
#endif
"""

0 comments on commit dab31bf

Please sign in to comment.