Skip to content

Commit

Permalink
STYLE: Inlined single call macro.
Browse files Browse the repository at this point in the history
Macro itk_wrap_template_all_generators was only called once.
Its contents were moved inlince to improve readability.

The macro itk_wrap_named_class_all_generators was only called in one place.
Its body was moved inline to improve readability.

Macro itk_wrap_simple_type_all_generators was only called once.
Its mody was moved inline to the itk_wrap_simple_type macro to improve readability.

The macro itk_wrap_simple_type_python contained little code and
was only called once. Its contents were moved inline in the itk_wrap_simple_type macro.

macro itk_wrap_named_class_python was only called once. Its body
was moved inlint to the itk_wrap_named_class macro.

These macros were only called once all by the same macro itk_wrap_one_type_all_generators.
The bodies of itk_wrap_one_type_castxml, itk_wrap_one_type_DOC, and itk_wrap_one_type_python
were inlined in the calling macro.
  • Loading branch information
kian-weimer authored and hjmjohnson committed Mar 10, 2022
1 parent 1a3b189 commit 5f21dc0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 67 deletions.
40 changes: 11 additions & 29 deletions Wrapping/Generators/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,50 +1,32 @@
###############################################################################
# the macros in charge of dispatching to the language specific macros

macro(itk_wrap_named_class_all_generators class swig_name)
if(${module_prefix}_WRAP_PYTHON AND WRAPPER_LIBRARY_PYTHON)
itk_wrap_named_class_python("${class}" "${swig_name}")
endif()
if(${module_prefix}_WRAP_DOC)
itk_wrap_named_class_DOC("${class}" "${swig_name}")
endif()
endmacro()


macro(itk_wrap_template_all_generators name types)
if(${module_prefix}_WRAP_PYTHON AND WRAPPER_LIBRARY_PYTHON)
itk_wrap_template_python("${name}" "${types}")
endif()
endmacro()


macro(itk_wrap_one_type_all_generators wrap_method wrap_class swig_name template_params)
if(${module_prefix}_WRAP_CASTXML)
itk_wrap_one_type_castxml("${wrap_method}" "${wrap_class}" "${swig_name}" "${template_params}")
# insert a blank line to separate the classes
set(CASTXML_TYPEDEFS "${CASTXML_TYPEDEFS}\n")
# add a piece of code for type instantiation
set(CASTXML_FORCE_INSTANTIATE "${CASTXML_FORCE_INSTANTIATE}\n")
endif()
if(${module_prefix}_WRAP_SWIGINTERFACE)
itk_wrap_one_type_swig_interface("${wrap_method}" "${wrap_class}" "${swig_name}" "${template_params}")
endif()
if(${module_prefix}_WRAP_DOC)
itk_wrap_one_type_DOC("${wrap_method}" "${wrap_class}" "${swig_name}" "${template_params}")
if(ITK_WRAP_DOC_GENERATE_DOXY2SWIG_INPUT)
set(ITK_WRAP_DOC_DOXY2SWIG_INPUT "${ITK_WRAP_DOC_DOXY2SWIG_INPUT}\t${swig_name}")
endif()
endif()
if(${module_prefix}_WRAP_PYTHON AND WRAPPER_LIBRARY_PYTHON)
itk_wrap_one_type_python("${wrap_method}" "${wrap_class}" "${swig_name}" "${template_params}")
endif()
endmacro()

string(REGEX REPLACE "(.*::)" "" base_name "${wrap_class}")

macro(itk_wrap_simple_type_all_generators wrap_class swig_name)
if(${module_prefix}_WRAP_CASTXML)
itk_wrap_simple_type_castxml("${wrap_class}" "${swig_name}")
endif()
if(${module_prefix}_WRAP_PYTHON AND WRAPPER_LIBRARY_PYTHON)
itk_wrap_simple_type_python("${wrap_class}" "${swig_name}")
if(NOT "${wrap_class}" STREQUAL "MetaEvent" AND NOT "${wrap_method}" MATCHES "ENUM")
ADD_PYTHON_CONFIG_TEMPLATE("${base_name}" "${wrap_class}" "${swig_name}" "${template_params}")
endif()
endif()
endmacro()



###############################################################################
# ccache management. This option is shared by most of generators, so put it here.
option(ITK_USE_CCACHE "Use ccache to cache swig/castxml/... output and speedup the rebuild." OFF)
Expand Down
13 changes: 0 additions & 13 deletions Wrapping/Generators/CastXML/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,6 @@ mark_as_advanced(CASTXML_EXECUTABLE)
set(ITK_WRAP_CASTXML_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "castxml source dir")


macro(itk_wrap_simple_type_castxml wrap_class swig_name)
set(CASTXML_TYPEDEFS "${CASTXML_TYPEDEFS} typedef ${wrap_class} ${swig_name};\n")
set(CASTXML_FORCE_INSTANTIATE "${CASTXML_FORCE_INSTANTIATE} (void)sizeof(${swig_name});\n")
endmacro()


macro(itk_end_wrap_submodule_castxml module)
# write the wrap_*.cxx file
#
Expand Down Expand Up @@ -277,13 +271,6 @@ macro(itk_end_wrap_submodule_castxml module)
endmacro()


macro(itk_wrap_one_type_castxml wrap_method wrap_class swig_name template_params)
# insert a blank line to separate the classes
set(CASTXML_TYPEDEFS "${CASTXML_TYPEDEFS}\n")
# add a piece of code for type instantiation
set(CASTXML_FORCE_INSTANTIATE "${CASTXML_FORCE_INSTANTIATE}\n")
endmacro()

macro(itk_wrap_module_castxml library_name)
# create the files used to pass the file to include to castxml
set(castxml_inc_file "${WRAPPER_LIBRARY_OUTPUT_DIR}/${library_name}.castxml.inc")
Expand Down
5 changes: 0 additions & 5 deletions Wrapping/Generators/Doc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ macro(itk_wrap_named_class_DOC class swig_name)

endmacro()

macro(itk_wrap_one_type_DOC wrap_method wrap_class swig_name template_params)
if(ITK_WRAP_DOC_GENERATE_DOXY2SWIG_INPUT)
set(ITK_WRAP_DOC_DOXY2SWIG_INPUT "${ITK_WRAP_DOC_DOXY2SWIG_INPUT}\t${swig_name}")
endif()
endmacro()

###############################################################################
macro(itk_end_wrap_module_DOC)
Expand Down
17 changes: 0 additions & 17 deletions Wrapping/Generators/Python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -388,16 +388,6 @@ macro(itk_end_wrap_submodule_python group_name)
endmacro()



macro(itk_wrap_one_type_python wrap_method wrap_class swig_name template_params)
string(REGEX REPLACE "(.*::)" "" base_name "${wrap_class}")

if(NOT "${wrap_class}" STREQUAL "MetaEvent" AND NOT "${wrap_method}" MATCHES "ENUM")
ADD_PYTHON_CONFIG_TEMPLATE("${base_name}" "${wrap_class}" "${swig_name}" "${template_params}")
endif()
endmacro()


macro(ADD_PYTHON_CONFIG_TEMPLATE base_name wrap_class swig_name template_params)
# Find if a header file corresponding to 'base_name' can be found in the current include directory
set(_include ${${WRAPPER_LIBRARY_NAME}_SOURCE_DIR}/include/itk${base_name}.h)
Expand Down Expand Up @@ -428,13 +418,6 @@ macro(itk_wrap_submodule_python submodule module)
endmacro()


macro(itk_wrap_named_class_python class swig_name)
# store the current class wrapped, so we can generate the typemaps for itk::ImageSource
set(ITK_WRAP_PYTHON_CURRENT_CLASS "${class}")
set(ITK_WRAP_PYTHON_CURRENT_SWIG_NAME "${swig_name}")
endmacro()


macro(itk_wrap_template_python name types)
if("${ITK_WRAP_PYTHON_CURRENT_CLASS}" STREQUAL "itk::ImageSource")
# generate the typemap which let pass an ImageSource instead of an Image
Expand Down
21 changes: 18 additions & 3 deletions Wrapping/TypedefMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,14 @@ macro(itk_wrap_named_class class swig_name)
# TODO: It shouldn't be used with the new architecture!!
set(WRAPPER_TEMPLATES)

itk_wrap_named_class_all_generators("${class}" "${swig_name}")
if(${module_prefix}_WRAP_PYTHON AND WRAPPER_LIBRARY_PYTHON)
# store the current class wrapped, so we can generate the typemaps for itk::ImageSource
set(ITK_WRAP_PYTHON_CURRENT_CLASS "${class}")
set(ITK_WRAP_PYTHON_CURRENT_SWIG_NAME "${swig_name}")
endif()
if(${module_prefix}_WRAP_DOC)
itk_wrap_named_class_DOC("${class}" "${swig_name}")
endif()
endmacro()

macro(itk_wrap_simple_class class)
Expand Down Expand Up @@ -952,7 +959,13 @@ endmacro()

macro(itk_wrap_simple_type wrap_class swig_name)
# Add a typedef, without support for any option
itk_wrap_simple_type_all_generators("${wrap_class}" "${swig_name}")
if(${module_prefix}_WRAP_CASTXML)
set(CASTXML_TYPEDEFS "${CASTXML_TYPEDEFS} typedef ${wrap_class} ${swig_name};\n")
set(CASTXML_FORCE_INSTANTIATE "${CASTXML_FORCE_INSTANTIATE} (void)sizeof(${swig_name});\n")
endif()
if(${module_prefix}_WRAP_PYTHON AND WRAPPER_LIBRARY_PYTHON)
itk_wrap_simple_type_python("${wrap_class}" "${swig_name}")
endif()
endmacro()


Expand Down Expand Up @@ -1043,7 +1056,9 @@ macro(itk_wrap_template name types)
# list(APPEND WRAPPER_TEMPLATES "${name} # ${types}")
set(WRAPPER_WARN_ABOUT_NO_TEMPLATE OFF)
itk_wrap_one_type("${WRAPPER_WRAP_METHOD}" "${WRAPPER_CLASS}" "${WRAPPER_SWIG_NAME}${name}" "${types}")
itk_wrap_template_all_generators("${name}" "${types}")
if(${module_prefix}_WRAP_PYTHON AND WRAPPER_LIBRARY_PYTHON)
itk_wrap_template_python("${name}" "${types}")
endif()
endmacro()

###################################
Expand Down

0 comments on commit 5f21dc0

Please sign in to comment.