1#!/bin/bash
2# \author Hans J. Johnson
3#
4# Script to process a directory to remove unnecessary
5# backwards compatibility layers for C++11
6# options that are now required.
7#
8#  Step 1 for migration to ITKv5:  Continue building your toolkit with ITKv4, but use  -DITK_FUTURE_LEGACY_REMOVE:BOOL=ON
9
10
11function ReplaceCXXString()
12{
13  oldstring="$1"
14  newstring="$2"
15
16  git grep -l "${oldstring}" | \
17    fgrep -v itk_compiler_detection.h | fgrep -v itkMacro.h | fgrep -v CMakeLists.txt |fgrep -v .cmake | \
18    fgrep -v ITKv5Preparation | \
19    xargs sed -i '' -e "s/ ${oldstring}/ ${newstring}/g"
20
21  file_changed=$(expr $(git status --porcelain 2>/dev/null| grep "^ M" | wc -l))
22  if [[ file_changed -gt 0 ]];then
23
24    cat > /tmp/COMMIT_MSG << EOF
25COMP:  Use C++11 ${newstring} directly
26
27git grep -l \"${oldstring}\" | \
28  fgrep -v itk_compiler_detection.h | fgrep -v itkMacro.h | fgrep -v CMakeLists.txt |fgrep -v .cmake | \
29  xargs sed -i '' -e \"s/ ${oldstring}/ ${newstring}/g\"
30EOF
31    git add -A
32    git commit -F /tmp/COMMIT_MSG
33
34    if [[ $? -ne 0 ]]; then
35      echo "ERROR:  COMMIT DID NOT SUCCEED"
36      echo "        Fix, then use: git commit -F /tmp/COMMIT_MSG"
37      exit -1
38    fi
39  fi
40}
41
42ReplaceCXXString ITK_NOEXCEPT_OR_THROW ITK_NOEXCEPT
43ReplaceCXXString ITK_HAS_CXX11_STATIC_ASSERT ITK_COMPILER_CXX_STATIC_ASSERT
44ReplaceCXXString ITK_DELETE_FUNCTION ITK_DELETED_FUNCTION
45ReplaceCXXString ITK_HAS_CPP11_ALIGNAS ITK_COMPILER_CXX_ALIGNAS
46
47
48# cxx_nullptr
49#    define ITK_NULLPTR nullptr
50ReplaceCXXString ITK_NULLPTR nullptr
51
52# cxx_deleted_functions
53#    define ITK_DELETED_FUNCTION = delete
54ReplaceCXXString ITK_DELETED_FUNCTION "= delete"
55
56# cxx_constexpr
57#    define ITK_CONSTEXPR constexpr
58#COMP:  Use C++11 constexpr directly
59ReplaceCXXString ITK_CONSTEXPR_VAR constexpr
60ReplaceCXXString ITK_CONSTEXPR_FUNC constexpr
61
62
63# cxx_noexcept
64ReplaceCXXString ITK_NOEXCEPT noexcept
65
66### --- Other considerations for replacement
67# cxx_std_98
68# cxx_template_template_parameters
69# cxx_std_11
70# cxx_alias_templates
71# cxx_alignas
72# cxx_alignof
73# cxx_attributes
74# cxx_auto_type
75# cxx_decltype
76# cxx_decltype_incomplete_return_types
77# cxx_default_function_template_args
78# cxx_defaulted_functions
79# cxx_defaulted_move_initializers
80# cxx_delegating_constructors
81# cxx_enum_forward_declarations
82# cxx_explicit_conversions
83# cxx_extended_friend_declarations
84# cxx_extern_templates
85# cxx_final
86# cxx_func_identifier
87# cxx_generalized_initializers
88# cxx_inheriting_constructors
89# cxx_inline_namespaces
90# cxx_lambdas
91# cxx_local_type_template_args
92# cxx_long_long_type
93# cxx_nonstatic_member_init
94# cxx_override
95# cxx_range_for
96# cxx_raw_string_literals
97# cxx_reference_qualified_functions
98# cxx_right_angle_brackets
99# cxx_rvalue_references
100# cxx_sizeof_member
101# cxx_static_assert
102# cxx_strong_enums
103# cxx_thread_local
104# cxx_trailing_return_types
105# cxx_unicode_literals
106# cxx_uniform_initialization
107# cxx_unrestricted_unions
108# cxx_user_literals
109# cxx_variadic_macros
110# cxx_variadic_templates
111# cxx_std_14
112# cxx_aggregate_default_initializers
113# cxx_attribute_deprecated
114# cxx_binary_literals
115# cxx_contextual_conversions
116# cxx_decltype_auto
117# cxx_digit_separators
118# cxx_generic_lambdas
119# cxx_lambda_init_captures
120# cxx_relaxed_constexpr
121# cxx_return_type_deduction
122# cxx_variable_templates
123# cxx_std_17
124