tools/json_to_struct/element_generator.py
def GenerateElement(type_name, schema, element_name, element, field_name_count):
  """Generate the static structure initializer for one element.
  """
  lines = [];
  lines.append('const %s %s = {' % (type_name, element_name));
  for field_info in schema:
    content = element.get(field_info['field'], None)
    if (content == None and not field_info.get('optional', False)):
      raise RuntimeError('Mandatory field "%s" omitted in element "%s".' %
                         (field_info['field'], element_name))
    GenerateFieldContent(element_name, field_info, content, lines, '  ',
                         field_name_count)
  lines.append('};')
  return '\n'.join(lines)
Generate the static structure initializer for one element.
  
Generate the static structure initializer for one element.
Generate the static structure initializer for one element .
def GenerateElement(type_name, schema, element_name, element, field_name_count):
  lines = [];
  lines.append('const %s %s = {' % (type_name, element_name));
  for field_info in schema:
    content = element.get(field_info['field'], None)
    if (content == None and not field_info.get('optional', False)):
      raise RuntimeError('Mandatory field "%s" omitted in element "%s".' %
                         (field_info['field'], element_name))
    GenerateFieldContent(element_name, field_info, content, lines, '  ',
                         field_name_count)
  lines.append('};')
  return '\n'.join(lines)
def GenerateElement ( type_name , schema , element_name , element , field_name_count ) : lines = [ ] ; lines . append ( 'const %s %s = {' % ( type_name , element_name ) ) ; for field_info in schema : content = element . get ( field_info [ 'field' ] , None ) if ( content == None and not field_info . get ( 'optional' , False ) ) : raise RuntimeError ( 'Mandatory field "%s" omitted in element "%s".' % ( field_info [ 'field' ] , element_name ) ) GenerateFieldContent ( element_name , field_info , content , lines , '  ' , field_name_count ) lines . append ( '};' ) return '\n' . join ( lines )
Generate the static structure initializer for one element.
Generate the static structure initializer for one element .
"""Generate the static structure initializer for one element.
  """
type_name
schema
element_name
element
field_name_count