@@ -1719,33 +1719,7 @@ template <>
1719
1719
1720
1720
for (const auto & inputField : inputType.fields )
1721
1721
{
1722
- std::string fieldName (inputField.name );
1723
-
1724
- fieldName[0 ] = std::toupper (fieldName[0 ]);
1725
- if (inputField.defaultValue .type () == response::Type::Null)
1726
- {
1727
- sourceFile << R"cpp( auto value)cpp" << fieldName
1728
- << R"cpp( = )cpp" << getArgumentAccessType (inputField)
1729
- << R"cpp( ::require)cpp" << getTypeModifiers (inputField.modifiers )
1730
- << R"cpp( (")cpp" << inputField.name
1731
- << R"cpp( ", value);
1732
- )cpp" ;
1733
- }
1734
- else
1735
- {
1736
- sourceFile << R"cpp( auto pair)cpp" << fieldName
1737
- << R"cpp( = )cpp" << getArgumentAccessType (inputField)
1738
- << R"cpp( ::find)cpp" << getTypeModifiers (inputField.modifiers )
1739
- << R"cpp( (")cpp" << inputField.name
1740
- << R"cpp( ", value);
1741
- auto value)cpp" << fieldName << R"cpp( = (pair)cpp" << fieldName << R"cpp( .second
1742
- ? std::move(pair)cpp" << fieldName << R"cpp( .first)
1743
- : )cpp" << getArgumentAccessType (inputField)
1744
- << R"cpp( ::require)cpp" << getTypeModifiers (inputField.modifiers )
1745
- << R"cpp( (")cpp" << inputField.name
1746
- << R"cpp( ", defaultValue));
1747
- )cpp" ;
1748
- }
1722
+ sourceFile << getArgumentDeclaration (inputField, " value" , " value" , " defaultValue" );
1749
1723
}
1750
1724
1751
1725
if (!inputType.fields .empty ())
@@ -1942,33 +1916,7 @@ std::future<response::Value> )cpp" << objectType.type
1942
1916
1943
1917
for (const auto & argument : outputField.arguments )
1944
1918
{
1945
- std::string argumentName (argument.name );
1946
-
1947
- argumentName[0 ] = std::toupper (argumentName[0 ]);
1948
- if (argument.defaultValue .type () == response::Type::Null)
1949
- {
1950
- sourceFile << R"cpp( auto arg)cpp" << argumentName
1951
- << R"cpp( = )cpp" << getArgumentAccessType (argument)
1952
- << R"cpp( ::require)cpp" << getTypeModifiers (argument.modifiers )
1953
- << R"cpp( (")cpp" << argument.name
1954
- << R"cpp( ", params.arguments);
1955
- )cpp" ;
1956
- }
1957
- else
1958
- {
1959
- sourceFile << R"cpp( auto pair)cpp" << argumentName
1960
- << R"cpp( = )cpp" << getArgumentAccessType (argument)
1961
- << R"cpp( ::find)cpp" << getTypeModifiers (argument.modifiers )
1962
- << R"cpp( (")cpp" << argument.name
1963
- << R"cpp( ", params.arguments);
1964
- auto arg)cpp" << argumentName << R"cpp( = (pair)cpp" << argumentName << R"cpp( .second
1965
- ? std::move(pair)cpp" << argumentName << R"cpp( .first)
1966
- : )cpp" << getArgumentAccessType (argument)
1967
- << R"cpp( ::require)cpp" << getTypeModifiers (argument.modifiers )
1968
- << R"cpp( (")cpp" << argument.name
1969
- << R"cpp( ", defaultArguments));
1970
- )cpp" ;
1971
- }
1919
+ sourceFile << getArgumentDeclaration (argument, " arg" , " params.arguments" , " defaultArguments" );
1972
1920
}
1973
1921
}
1974
1922
@@ -2733,6 +2681,43 @@ std::string Generator::getArgumentDefaultValue(size_t level, const response::Val
2733
2681
return argumentDefaultValue.str ();
2734
2682
}
2735
2683
2684
+ std::string Generator::getArgumentDeclaration (const InputField& argument, const char * prefixToken, const char * argumentsToken, const char * defaultToken) const noexcept
2685
+ {
2686
+ std::ostringstream argumentDeclaration;
2687
+ std::string argumentName (argument.name );
2688
+
2689
+ argumentName[0 ] = std::toupper (argumentName[0 ]);
2690
+ if (argument.defaultValue .type () == response::Type::Null)
2691
+ {
2692
+ argumentDeclaration << R"cpp( auto )cpp" << prefixToken << argumentName
2693
+ << R"cpp( = )cpp" << getArgumentAccessType (argument)
2694
+ << R"cpp( ::require)cpp" << getTypeModifiers (argument.modifiers )
2695
+ << R"cpp( (")cpp" << argument.name
2696
+ << R"cpp( ", )cpp" << argumentsToken
2697
+ << R"cpp( );
2698
+ )cpp" ;
2699
+ }
2700
+ else
2701
+ {
2702
+ argumentDeclaration << R"cpp( auto pair)cpp" << argumentName
2703
+ << R"cpp( = )cpp" << getArgumentAccessType (argument)
2704
+ << R"cpp( ::find)cpp" << getTypeModifiers (argument.modifiers )
2705
+ << R"cpp( (")cpp" << argument.name
2706
+ << R"cpp( ", )cpp" << argumentsToken
2707
+ << R"cpp( );
2708
+ auto )cpp" << prefixToken << argumentName << R"cpp( = (pair)cpp" << argumentName << R"cpp( .second
2709
+ ? std::move(pair)cpp" << argumentName << R"cpp( .first)
2710
+ : )cpp" << getArgumentAccessType (argument)
2711
+ << R"cpp( ::require)cpp" << getTypeModifiers (argument.modifiers )
2712
+ << R"cpp( (")cpp" << argument.name
2713
+ << R"cpp( ", )cpp" << defaultToken
2714
+ << R"cpp( ));
2715
+ )cpp" ;
2716
+ }
2717
+
2718
+ return argumentDeclaration.str ();
2719
+ }
2720
+
2736
2721
std::string Generator::getArgumentAccessType (const InputField& argument) const noexcept
2737
2722
{
2738
2723
std::ostringstream argumentType;
0 commit comments