@@ -741,10 +741,8 @@ using namespace )cpp"
741
741
742
742
pendingSeparator.add ();
743
743
744
- std::unordered_set<std::string_view> outputEnumNames;
745
744
std::unordered_set<std::string_view> outputModifiedVariableEnum;
746
745
std::unordered_set<std::string_view> outputModifiedVariableInput;
747
- std::unordered_set<std::string_view> outputEnumValues;
748
746
std::unordered_set<std::string_view> outputModifiedResponseEnum;
749
747
750
748
for (const auto & operation : operations)
@@ -762,48 +760,39 @@ using namespace )cpp"
762
760
continue ;
763
761
}
764
762
765
- if (outputEnumNames.insert (cppType).second )
766
- {
767
- pendingSeparator.reset ();
763
+ pendingSeparator.reset ();
768
764
769
- const auto & enumValues = enumType->enumValues ();
765
+ const auto & enumValues = enumType->enumValues ();
770
766
771
- sourceFile << R"cpp( static const std::array<std::string_view, )cpp"
772
- << enumValues.size () << R"cpp( > s_names)cpp" << cppType
773
- << R"cpp( = {)cpp" ;
767
+ sourceFile << R"cpp( template <>
768
+ response::Value Variable<)cpp"
769
+ << cppType << R"cpp( >::serialize()cpp" << cppType << R"cpp( && value)
770
+ {
771
+ static const std::array<std::string_view, )cpp"
772
+ << enumValues.size () << R"cpp( > s_names = {)cpp" ;
774
773
775
- bool firstValue = true ;
774
+ bool firstValue = true ;
776
775
777
- for (const auto & enumValue : enumValues)
776
+ for (const auto & enumValue : enumValues)
777
+ {
778
+ if (!firstValue)
778
779
{
779
- if (!firstValue)
780
- {
781
- sourceFile << R"cpp( ,)cpp" ;
782
- }
783
-
784
- firstValue = false ;
785
- sourceFile << R"cpp(
786
- R"gql()cpp" << enumValue->name ()
787
- << R"cpp( )gql"sv)cpp" ;
788
- pendingSeparator.add ();
780
+ sourceFile << R"cpp( ,)cpp" ;
789
781
}
790
782
791
- pendingSeparator.reset ();
792
- sourceFile << R"cpp( };
793
-
794
- )cpp" ;
783
+ firstValue = false ;
784
+ sourceFile << R"cpp(
785
+ R"gql()cpp" << enumValue->name ()
786
+ << R"cpp( )gql"sv)cpp" ;
787
+ pendingSeparator.add ();
795
788
}
796
789
797
790
pendingSeparator.reset ();
791
+ sourceFile << R"cpp( };
798
792
799
- sourceFile << R"cpp( template <>
800
- response::Value Variable<)cpp"
801
- << cppType << R"cpp( >::serialize()cpp" << cppType << R"cpp( && value)
802
- {
803
793
response::Value result { response::Type::EnumValue };
804
794
805
- result.set<std::string>(std::string { s_names)cpp"
806
- << cppType << R"cpp( [static_cast<size_t>(value)] });
795
+ result.set<std::string>(std::string { s_names[static_cast<size_t>(value)] });
807
796
808
797
return result;
809
798
}
@@ -862,58 +851,10 @@ response::Value Variable<)cpp"
862
851
continue ;
863
852
}
864
853
865
- if (outputEnumValues.insert (cppType).second )
866
- {
867
- pendingSeparator.reset ();
868
-
869
- const auto & enumValues = enumType->enumValues ();
870
-
871
- sourceFile << R"cpp( static const std::array<std::pair<std::string_view, )cpp"
872
- << cppType << R"cpp( >, )cpp" << enumValues.size ()
873
- << R"cpp( > s_values)cpp" << cppType << R"cpp( = {)cpp" ;
874
-
875
- std::vector<std::pair<std::string_view, std::string_view>> sortedValues (
876
- enumValues.size ());
877
-
878
- std::transform (enumValues.cbegin (),
879
- enumValues.cend (),
880
- sortedValues.begin (),
881
- [](const auto & value) noexcept {
882
- return std::make_pair (value->name (),
883
- SchemaLoader::getSafeCppName (value->name ()));
884
- });
885
- std::sort (sortedValues.begin (),
886
- sortedValues.end (),
887
- [](const auto & lhs, const auto & rhs) noexcept {
888
- return internal::shorter_or_less {}(lhs.first , rhs.first );
889
- });
890
-
891
- bool firstValue = true ;
892
-
893
- for (const auto & enumValue : sortedValues)
894
- {
895
- if (!firstValue)
896
- {
897
- sourceFile << R"cpp( ,)cpp" ;
898
- }
899
-
900
- firstValue = false ;
901
- sourceFile << R"cpp(
902
- std::make_pair(R"gql()cpp" << enumValue.first
903
- << R"cpp( )gql"sv, )cpp" << cppType << R"cpp( ::)cpp"
904
- << enumValue.second << R"cpp( ))cpp" ;
905
- pendingSeparator.add ();
906
- }
907
-
908
- pendingSeparator.reset ();
909
- sourceFile << R"cpp( };
910
- )cpp" ;
911
-
912
- pendingSeparator.add ();
913
- }
914
-
915
854
pendingSeparator.reset ();
916
855
856
+ const auto & enumValues = enumType->enumValues ();
857
+
917
858
sourceFile << R"cpp( template <>
918
859
)cpp" << cppType << R"cpp( Response<)cpp"
919
860
<< cppType << R"cpp( >::parse(response::Value&& value)
@@ -924,9 +865,48 @@ response::Value Variable<)cpp"
924
865
<< enumType->name () << R"cpp( value)ex" };
925
866
}
926
867
868
+ static const std::array<std::pair<std::string_view, )cpp"
869
+ << cppType << R"cpp( >, )cpp" << enumValues.size ()
870
+ << R"cpp( > s_values = {)cpp" ;
871
+
872
+ std::vector<std::pair<std::string_view, std::string_view>> sortedValues (
873
+ enumValues.size ());
874
+
875
+ std::transform (enumValues.cbegin (),
876
+ enumValues.cend (),
877
+ sortedValues.begin (),
878
+ [](const auto & value) noexcept {
879
+ return std::make_pair (value->name (),
880
+ SchemaLoader::getSafeCppName (value->name ()));
881
+ });
882
+ std::sort (sortedValues.begin (),
883
+ sortedValues.end (),
884
+ [](const auto & lhs, const auto & rhs) noexcept {
885
+ return internal::shorter_or_less {}(lhs.first , rhs.first );
886
+ });
887
+
888
+ bool firstValue = true ;
889
+
890
+ for (const auto & enumValue : sortedValues)
891
+ {
892
+ if (!firstValue)
893
+ {
894
+ sourceFile << R"cpp( ,)cpp" ;
895
+ }
896
+
897
+ firstValue = false ;
898
+ sourceFile << R"cpp(
899
+ std::make_pair(R"gql()cpp"
900
+ << enumValue.first << R"cpp( )gql"sv, )cpp" << cppType << R"cpp( ::)cpp"
901
+ << enumValue.second << R"cpp( ))cpp" ;
902
+ pendingSeparator.add ();
903
+ }
904
+
905
+ pendingSeparator.reset ();
906
+ sourceFile << R"cpp( };
907
+
927
908
const auto result = internal::sorted_map_lookup<internal::shorter_or_less>(
928
- s_values)cpp" << cppType
929
- << R"cpp( ,
909
+ s_values,
930
910
std::string_view { value.get<std::string>() });
931
911
932
912
if (!result)
0 commit comments