parameters: (
        self, prop, value_var, dst, failure_value, check_type=True)
return_statement: return c
docstring: Generates code to populate a model.Property given a Value*. The
      existence of data inside the Value* is assumed so checks for existence
      should be performed before the code this generates.
  
      prop: the property the code is populating.
      value_var: a Value* that should represent |prop|.
      dst: the object with |prop| as a member.
      failure_value: the value to return if |prop| cannot be extracted from
      |value_var|
      check_type: if true, will check if |value_var| is the correct Value::Type
docstring_summary: Generates code to populate a model.Property given a Value*. The
      existence of data inside the Value* is assumed so checks for existence
      should be performed before the code this generates.
docstring_tokens: Generates code to populate a model . Property given a Value * . The existence of data inside the Value * is assumed so checks for existence should be performed before the code this generates .
function: def _GeneratePopulatePropertyFromValue(
        self, prop, value_var, dst, failure_value, check_type=True):
      """Generates code to populate a model.Property given a Value*. The
      existence of data inside the Value* is assumed so checks for existence
      should be performed before the code this generates.
  
      prop: the property the code is populating.
      value_var: a Value* that should represent |prop|.
      dst: the object with |prop| as a member.
      failure_value: the value to return if |prop| cannot be extracted from
      |value_var|
      check_type: if true, will check if |value_var| is the correct Value::Type
      """
      c = Code()
      c.Sblock('{')
  
      if check_type and prop.type_ not in (
          PropertyType.CHOICES, PropertyType.ANY):
        (c.Append('if (!%(value_var)s->IsType(%(value_type)s))')
          .Append('  return %(failure_value)s;')
        )
  
      if self._IsFundamentalOrFundamentalRef(prop):
        if prop.optional:
          (c.Append('%(ctype)s temp;')
            .Append('if (%s)' %
                cpp_util.GetAsFundamentalValue(
                    self._cpp_type_generator.GetReferencedProperty(prop),
                    value_var,
                    '&temp'))
            .Append('  %(dst)s->%(name)s.reset(new %(ctype)s(temp));')
          )
        else:
          (c.Append('if (!%s)' %
              cpp_util.GetAsFundamentalValue(
                  self._cpp_type_generator.GetReferencedProperty(prop),
                  value_var,
                  '&%s->%s' % (dst, prop.unix_name)))
            .Append('return %(failure_value)s;')
          )
      elif self._IsObjectOrObjectRef(prop):
        if prop.optional:
          (c.Append('DictionaryValue* dictionary = NULL;')
            .Append('if (!%(value_var)s->GetAsDictionary(&dictionary))')
            .Append('  return %(failure_value)s;')
            .Append('scoped_ptr<%(ctype)s> temp(new %(ctype)s());')
            .Append('if (!%(ctype)s::Populate(*dictionary, temp.get()))')
            .Append('  return %(failure_value)s;')
            .Append('%(dst)s->%(name)s = temp.Pass();')
          )
        else:
          (c.Append('DictionaryValue* dictionary = NULL;')
            .Append('if (!%(value_var)s->GetAsDictionary(&dictionary))')
            .Append('  return %(failure_value)s;')
            .Append(
                'if (!%(ctype)s::Populate(*dictionary, &%(dst)s->%(name)s))')
            .Append('  return %(failure_value)s;')
          )
      elif prop.type_ == PropertyType.ANY:
        if prop.optional:
          c.Append('%(dst)s->%(name)s.reset(new Any());')
        c.Append(self._any_helper.Init(prop, value_var, dst) + ';')
      elif self._IsArrayOrArrayRef(prop):
        # util_cc_helper deals with optional and required arrays
        (c.Append('ListValue* list = NULL;')
          .Append('if (!%(value_var)s->GetAsList(&list))')
          .Append('  return %(failure_value)s;')
          .Append('if (!%s)' % self._util_cc_helper.PopulateArrayFromList(
              self._cpp_type_generator.GetReferencedProperty(prop), 'list',
              dst + '->' + prop.unix_name, prop.optional))
          .Append('  return %(failure_value)s;')
        )
      elif prop.type_ == PropertyType.CHOICES:
        type_var = '%(dst)s->%(name)s_type'
        c.Sblock('switch (%(value_var)s->GetType()) {')
        for choice in self._cpp_type_generator.GetExpandedChoicesInParams([prop]):
          (c.Sblock('case %s: {' % cpp_util.GetValueType(
              self._cpp_type_generator.GetReferencedProperty(choice).type_))
              .Concat(self._GeneratePopulatePropertyFromValue(
                  choice, value_var, dst, failure_value, check_type=False))
              .Append('%s = %s;' %
                  (type_var,
                   self._cpp_type_generator.GetEnumValue(
                       prop, choice.type_.name)))
              .Append('break;')
            .Eblock('}')
          )
        (c.Append('default:')
          .Append('  return %(failure_value)s;')
        )
        c.Eblock('}')
      elif prop.type_ == PropertyType.ENUM:
        (c.Append('std::string enum_temp;')
          .Append('if (!%(value_var)s->GetAsString(&enum_temp))')
          .Append('  return %(failure_value)s;')
        )
        for i, enum_value in enumerate(prop.enum_values):
          (c.Append(
              ('if' if i == 0 else 'else if') +
              '(enum_temp == "%s")' % enum_value)
            .Append('  %s->%s = %s;' % (
              dst,
              prop.unix_name,
              self._cpp_type_generator.GetEnumValue(prop, enum_value)))
          )
        (c.Append('else')
          .Append('  return %(failure_value)s;')
        )
      elif prop.type_ == PropertyType.BINARY:
        # This is the same if the property is optional or not. We need a pointer
        # to the BinaryValue to be able to populate it, so a scoped_ptr is used
        # whether it is optional or required.
        (c.Append('%(dst)s->%(name)s.reset(')
          .Append('    static_cast<BinaryValue*>(%(value_var)s)->DeepCopy());')
        )
      else:
        raise NotImplementedError(prop.type_)
      c.Eblock('}')
      sub = {
          'value_var': value_var,
          'name': prop.unix_name,
          'dst': dst,
          'failure_value': failure_value,
      }
      if prop.type_ not in (PropertyType.CHOICES, PropertyType.ANY):
        sub['ctype'] = self._cpp_type_generator.GetType(prop)
        sub['value_type'] = cpp_util.GetValueType(self._cpp_type_generator
            .GetReferencedProperty(prop).type_)
      c.Substitute(sub)
      return c
function_tokens: def _GeneratePopulatePropertyFromValue ( self , prop , value_var , dst , failure_value , check_type = True ) : c = Code ( ) c . Sblock ( '{' ) if check_type and prop . type_ not in ( PropertyType . CHOICES , PropertyType . ANY ) : ( c . Append ( 'if (!%(value_var)s->IsType(%(value_type)s))' ) . Append ( '  return %(failure_value)s;' ) ) if self . _IsFundamentalOrFundamentalRef ( prop ) : if prop . optional : ( c . Append ( '%(ctype)s temp;' ) . Append ( 'if (%s)' % cpp_util . GetAsFundamentalValue ( self . _cpp_type_generator . GetReferencedProperty ( prop ) , value_var , '&temp' ) ) . Append ( '  %(dst)s->%(name)s.reset(new %(ctype)s(temp));' ) ) else : ( c . Append ( 'if (!%s)' % cpp_util . GetAsFundamentalValue ( self . _cpp_type_generator . GetReferencedProperty ( prop ) , value_var , '&%s->%s' % ( dst , prop . unix_name ) ) ) . Append ( 'return %(failure_value)s;' ) ) elif self . _IsObjectOrObjectRef ( prop ) : if prop . optional : ( c . Append ( 'DictionaryValue* dictionary = NULL;' ) . Append ( 'if (!%(value_var)s->GetAsDictionary(&dictionary))' ) . Append ( '  return %(failure_value)s;' ) . Append ( 'scoped_ptr<%(ctype)s> temp(new %(ctype)s());' ) . Append ( 'if (!%(ctype)s::Populate(*dictionary, temp.get()))' ) . Append ( '  return %(failure_value)s;' ) . Append ( '%(dst)s->%(name)s = temp.Pass();' ) ) else : ( c . Append ( 'DictionaryValue* dictionary = NULL;' ) . Append ( 'if (!%(value_var)s->GetAsDictionary(&dictionary))' ) . Append ( '  return %(failure_value)s;' ) . Append ( 'if (!%(ctype)s::Populate(*dictionary, &%(dst)s->%(name)s))' ) . Append ( '  return %(failure_value)s;' ) ) elif prop . type_ == PropertyType . ANY : if prop . optional : c . Append ( '%(dst)s->%(name)s.reset(new Any());' ) c . Append ( self . _any_helper . Init ( prop , value_var , dst ) + ';' ) elif self . _IsArrayOrArrayRef ( prop ) : # util_cc_helper deals with optional and required arrays ( c . Append ( 'ListValue* list = NULL;' ) . Append ( 'if (!%(value_var)s->GetAsList(&list))' ) . Append ( '  return %(failure_value)s;' ) . Append ( 'if (!%s)' % self . _util_cc_helper . PopulateArrayFromList ( self . _cpp_type_generator . GetReferencedProperty ( prop ) , 'list' , dst + '->' + prop . unix_name , prop . optional ) ) . Append ( '  return %(failure_value)s;' ) ) elif prop . type_ == PropertyType . CHOICES : type_var = '%(dst)s->%(name)s_type' c . Sblock ( 'switch (%(value_var)s->GetType()) {' ) for choice in self . _cpp_type_generator . GetExpandedChoicesInParams ( [ prop ] ) : ( c . Sblock ( 'case %s: {' % cpp_util . GetValueType ( self . _cpp_type_generator . GetReferencedProperty ( choice ) . type_ ) ) . Concat ( self . _GeneratePopulatePropertyFromValue ( choice , value_var , dst , failure_value , check_type = False ) ) . Append ( '%s = %s;' % ( type_var , self . _cpp_type_generator . GetEnumValue ( prop , choice . type_ . name ) ) ) . Append ( 'break;' ) . Eblock ( '}' ) ) ( c . Append ( 'default:' ) . Append ( '  return %(failure_value)s;' ) ) c . Eblock ( '}' ) elif prop . type_ == PropertyType . ENUM : ( c . Append ( 'std::string enum_temp;' ) . Append ( 'if (!%(value_var)s->GetAsString(&enum_temp))' ) . Append ( '  return %(failure_value)s;' ) ) for i , enum_value in enumerate ( prop . enum_values ) : ( c . Append ( ( 'if' if i == 0 else 'else if' ) + '(enum_temp == "%s")' % enum_value ) . Append ( '  %s->%s = %s;' % ( dst , prop . unix_name , self . _cpp_type_generator . GetEnumValue ( prop , enum_value ) ) ) ) ( c . Append ( 'else' ) . Append ( '  return %(failure_value)s;' ) ) elif prop . type_ == PropertyType . BINARY : # This is the same if the property is optional or not. We need a pointer # to the BinaryValue to be able to populate it, so a scoped_ptr is used # whether it is optional or required. ( c . Append ( '%(dst)s->%(name)s.reset(' ) . Append ( '    static_cast<BinaryValue*>(%(value_var)s)->DeepCopy());' ) ) else : raise NotImplementedError ( prop . type_ ) c . Eblock ( '}' ) sub = { 'value_var' : value_var , 'name' : prop . unix_name , 'dst' : dst , 'failure_value' : failure_value , } if prop . type_ not in ( PropertyType . CHOICES , PropertyType . ANY ) : sub [ 'ctype' ] = self . _cpp_type_generator . GetType ( prop ) sub [ 'value_type' ] = cpp_util . GetValueType ( self . _cpp_type_generator . GetReferencedProperty ( prop ) . type_ ) c . Substitute ( sub ) return c