@@ -581,6 +581,8 @@ bool Generator::outputSource() const noexcept
581581#include ")cpp" << _schemaLoader.getFilenamePrefix ()
582582 << R"cpp( Client.h"
583583
584+ #include "graphqlservice/internal/SortedMap.h"
585+
584586#include <algorithm>
585587#include <array>
586588#include <sstream>
@@ -618,16 +620,49 @@ using namespace std::literals;
618620 const auto & enumValues = enumType->enumValues ();
619621
620622 sourceFile << R"cpp( static const std::array<std::string_view, )cpp" << enumValues.size ()
621- << R"cpp( > s_names)cpp" << cppType << R"cpp( = {
622- )cpp" ;
623+ << R"cpp( > s_names)cpp" << cppType << R"cpp( = {)cpp" ;
624+
625+ bool firstValue = true ;
623626
624627 for (const auto & enumValue : enumValues)
625628 {
626- sourceFile << R"cpp( ")cpp" << SchemaLoader::getSafeCppName (enumValue->name ())
627- << R"cpp( "sv,
628- )cpp" ;
629+ if (!firstValue)
630+ {
631+ sourceFile << R"cpp( ,)cpp" ;
632+ }
633+
634+ firstValue = false ;
635+ sourceFile << R"cpp(
636+ R"gql()cpp" << enumValue->name ()
637+ << R"cpp( )gql"sv)cpp" ;
638+ pendingSeparator.add ();
639+ }
640+
641+ pendingSeparator.reset ();
642+ sourceFile << R"cpp( };
643+
644+ static const std::array<std::pair<std::string_view, )cpp"
645+ << cppType << R"cpp( >, )cpp" << enumValues.size () << R"cpp( > s_values)cpp"
646+ << cppType << R"cpp( = {)cpp" ;
647+
648+ firstValue = true ;
649+
650+ for (const auto & enumValue : enumValues)
651+ {
652+ if (!firstValue)
653+ {
654+ sourceFile << R"cpp( ,)cpp" ;
655+ }
656+
657+ firstValue = false ;
658+ sourceFile << R"cpp(
659+ std::make_pair(R"gql()cpp"
660+ << enumValue->name () << R"cpp( )gql"sv, )cpp" << cppType << R"cpp( ::)cpp"
661+ << SchemaLoader::getSafeCppName (enumValue->name ()) << R"cpp( ))cpp" ;
662+ pendingSeparator.add ();
629663 }
630664
665+ pendingSeparator.reset ();
631666 sourceFile << R"cpp( };
632667)cpp" ;
633668
@@ -873,23 +908,22 @@ response::Value ModifiedVariable<)cpp"
873908{
874909 if (!value.maybe_enum())
875910 {
876- throw std::logic_error { " not a valid )cpp"
877- << cppType << R"cpp( value" };
911+ throw std::logic_error { R"ex( not a valid )cpp"
912+ << enumType-> name () << R"cpp( value)ex " };
878913 }
879914
880- const auto itr = std::find(s_names)cpp"
881- << cppType << R"cpp( .cbegin(), s_names)cpp" << cppType
882- << R"cpp( .cend(), value.release<std::string>());
915+ const auto result = internal::sorted_map_lookup<internal::shorter_or_less>(
916+ s_values)cpp" << cppType
917+ << R"cpp( ,
918+ std::string_view { value.get<std::string>() });
883919
884- if (itr == s_names)cpp"
885- << cppType << R"cpp( .cend())
920+ if (!result)
886921 {
887- throw std::logic_error { " not a valid )cpp"
888- << cppType << R"cpp( value" };
922+ throw std::logic_error { { R"ex( not a valid )cpp"
923+ << enumType-> name () << R"cpp( value)ex" } };
889924 }
890925
891- return static_cast<)cpp"
892- << cppType << R"cpp( >(itr - s_names)cpp" << cppType << R"cpp( .cbegin());
926+ return *result;
893927}
894928)cpp" ;
895929
0 commit comments