parameters: (self,
                                        type_,
                                        src_var,
                                        dst_var,
                                        failure_value)
return_statement: return c
docstring: Returns Code that converts a string type in |src_var| to an enum with
      type |type_| in |dst_var|. In the generated code, if |src_var| is not
      a valid enum name then the function will return |failure_value|.
docstring_summary: Returns Code that converts a string type in |src_var| to an enum with
      type |type_| in |dst_var|. In the generated code, if |src_var| is not
      a valid enum name then the function will return |failure_value|.
docstring_tokens: Returns Code that converts a string type in |src_var| to an enum with type |type_| in |dst_var| . In the generated code if |src_var| is not a valid enum name then the function will return |failure_value| .
function: def _GenerateStringToEnumConversion(self,
                                        type_,
                                        src_var,
                                        dst_var,
                                        failure_value):
      """Returns Code that converts a string type in |src_var| to an enum with
      type |type_| in |dst_var|. In the generated code, if |src_var| is not
      a valid enum name then the function will return |failure_value|.
      """
      c = Code()
      enum_as_string = '%s_as_string' % type_.unix_name
      (c.Append('std::string %s;' % enum_as_string)
        .Sblock('if (!%s->GetAsString(&%s)) {' % (src_var, enum_as_string))
        .Concat(self._GenerateError(
          '"\'%%(key)s\': expected string, got " + ' +
          self._util_cc_helper.GetValueTypeString('%%(src_var)s', True)))
        .Append('return %s;' % failure_value)
        .Eblock('}')
        .Append('%s = Parse%s(%s);' % (dst_var,
                                       self._type_helper.GetCppType(type_),
                                       enum_as_string))
        .Sblock('if (%s == %s) {' % (dst_var,
                                   self._type_helper.GetEnumNoneValue(type_)))
        .Concat(self._GenerateError(
          '\"\'%%(key)s\': expected \\"' +
          '\\" or \\"'.join(
              enum_value.name
              for enum_value in self._type_helper.FollowRef(type_).enum_values) +
          '\\", got \\"" + %s + "\\""' % enum_as_string))
        .Append('return %s;' % failure_value)
        .Eblock('}')
        .Substitute({'src_var': src_var, 'key': type_.name})
      )
      return c
function_tokens: def _GenerateStringToEnumConversion ( self , type_ , src_var , dst_var , failure_value ) : c = Code ( ) enum_as_string = '%s_as_string' % type_ . unix_name ( c . Append ( 'std::string %s;' % enum_as_string ) . Sblock ( 'if (!%s->GetAsString(&%s)) {' % ( src_var , enum_as_string ) ) . Concat ( self . _GenerateError ( '"\'%%(key)s\': expected string, got " + ' + self . _util_cc_helper . GetValueTypeString ( '%%(src_var)s' , True ) ) ) . Append ( 'return %s;' % failure_value ) . Eblock ( '}' ) . Append ( '%s = Parse%s(%s);' % ( dst_var , self . _type_helper . GetCppType ( type_ ) , enum_as_string ) ) . Sblock ( 'if (%s == %s) {' % ( dst_var , self . _type_helper . GetEnumNoneValue ( type_ ) ) ) . Concat ( self . _GenerateError ( '\"\'%%(key)s\': expected \\"' + '\\" or \\"' . join ( enum_value . name for enum_value in self . _type_helper . FollowRef ( type_ ) . enum_values ) + '\\", got \\"" + %s + "\\""' % enum_as_string ) ) . Append ( 'return %s;' % failure_value ) . Eblock ( '}' ) . Substitute ( { 'src_var' : src_var , 'key' : type_ . name } ) ) return c