tools/json_to_struct/json_to_struct.py
def _GenerateH(basepath, fileroot, head, namespace, schema, description):
  """Generates the .h file containing the definition of the structure specified
  by the schema.

  Args:
    basepath: The base directory in which files are generated.
    fileroot: The filename and path, relative to basepath, of the file to
        create, without an extension.
    head: The string to output as the header of the .h file.
    namespace: A string corresponding to the C++ namespace to use.
    schema: A dict containing the schema. See comment at the top of this file.
    description: A dict containing the description. See comment at the top of
        this file.
  """

  h_filename = fileroot + u'.h'
  with io.open(os.path.join(basepath, h_filename), 'w', encoding='utf-8') as f:
    f.write(head)

    header_guard = _GenerateHeaderGuard(h_filename)
    f.write(u'#ifndef %s\n' % header_guard)
    f.write(u'#define %s\n' % header_guard)
    f.write(u'\n')

    f.write(u'#include <cstddef>\n')
    f.write(u'\n')

    for header in schema.get(u'headers', []):
      f.write(u'#include "%s"\n' % header)
    f.write(u'\n')

    if namespace:
      f.write(u'namespace %s {\n' % namespace)
      f.write(u'\n')

    f.write(struct_generator.GenerateStruct(
      schema['type_name'], schema['schema']))
    f.write(u'\n')

    for var_name, value in description.get('int_variables', {}).items():
      f.write(u'extern const int %s;\n' % var_name)
    f.write(u'\n')

    for element_name, element in description['elements'].items():
      f.write(u'extern const %s %s;\n' % (schema['type_name'], element_name))

    if 'generate_array' in description:
      f.write(u'\n')
      f.write(
          u'extern const %s* const %s[];\n' %
          (schema['type_name'], description['generate_array']['array_name']))
      f.write(u'extern const size_t %s;\n' %
              (description['generate_array']['array_name'] + u'Length'))

    if namespace:
      f.write(u'\n')
      f.write(u'}  // namespace %s\n' % namespace)

    f.write(u'\n')
    f.write(u'#endif  // %s\n' % header_guard)
Generates the .h file containing the definition of the structure specified
  by the schema.

  Args:
    basepath: The base directory in which files are generated.
    fileroot: The filename and path, relative to basepath, of the file to
        create, without an extension.
    head: The string to output as the header of the .h file.
    namespace: A string corresponding to the C++ namespace to use.
    schema: A dict containing the schema. See comment at the top of this file.
    description: A dict containing the description. See comment at the top of
        this file.
  
Generates the .h file containing the definition of the structure specified
by the schema.
Generates the . h file containing the definition of the structure specified by the schema .
def _GenerateH(basepath, fileroot, head, namespace, schema, description):
  h_filename = fileroot + u'.h'
  with io.open(os.path.join(basepath, h_filename), 'w', encoding='utf-8') as f:
    f.write(head)
    header_guard = _GenerateHeaderGuard(h_filename)
    f.write(u'#ifndef %s\n' % header_guard)
    f.write(u'#define %s\n' % header_guard)
    f.write(u'\n')
    f.write(u'#include <cstddef>\n')
    f.write(u'\n')
    for header in schema.get(u'headers', []):
      f.write(u'#include "%s"\n' % header)
    f.write(u'\n')
    if namespace:
      f.write(u'namespace %s {\n' % namespace)
      f.write(u'\n')
    f.write(struct_generator.GenerateStruct(
      schema['type_name'], schema['schema']))
    f.write(u'\n')
    for var_name, value in description.get('int_variables', {}).items():
      f.write(u'extern const int %s;\n' % var_name)
    f.write(u'\n')
    for element_name, element in description['elements'].items():
      f.write(u'extern const %s %s;\n' % (schema['type_name'], element_name))
    if 'generate_array' in description:
      f.write(u'\n')
      f.write(
          u'extern const %s* const %s[];\n' %
          (schema['type_name'], description['generate_array']['array_name']))
      f.write(u'extern const size_t %s;\n' %
              (description['generate_array']['array_name'] + u'Length'))
    if namespace:
      f.write(u'\n')
      f.write(u'}  // namespace %s\n' % namespace)
    f.write(u'\n')
    f.write(u'#endif  // %s\n' % header_guard)
def _GenerateH ( basepath , fileroot , head , namespace , schema , description ) : h_filename = fileroot + u'.h' with io . open ( os . path . join ( basepath , h_filename ) , 'w' , encoding = 'utf-8' ) as f : f . write ( head ) header_guard = _GenerateHeaderGuard ( h_filename ) f . write ( u'#ifndef %s\n' % header_guard ) f . write ( u'#define %s\n' % header_guard ) f . write ( u'\n' ) f . write ( u'#include <cstddef>\n' ) f . write ( u'\n' ) for header in schema . get ( u'headers' , [ ] ) : f . write ( u'#include "%s"\n' % header ) f . write ( u'\n' ) if namespace : f . write ( u'namespace %s {\n' % namespace ) f . write ( u'\n' ) f . write ( struct_generator . GenerateStruct ( schema [ 'type_name' ] , schema [ 'schema' ] ) ) f . write ( u'\n' ) for var_name , value in description . get ( 'int_variables' , { } ) . items ( ) : f . write ( u'extern const int %s;\n' % var_name ) f . write ( u'\n' ) for element_name , element in description [ 'elements' ] . items ( ) : f . write ( u'extern const %s %s;\n' % ( schema [ 'type_name' ] , element_name ) ) if 'generate_array' in description : f . write ( u'\n' ) f . write ( u'extern const %s* const %s[];\n' % ( schema [ 'type_name' ] , description [ 'generate_array' ] [ 'array_name' ] ) ) f . write ( u'extern const size_t %s;\n' % ( description [ 'generate_array' ] [ 'array_name' ] + u'Length' ) ) if namespace : f . write ( u'\n' ) f . write ( u'}  // namespace %s\n' % namespace ) f . write ( u'\n' ) f . write ( u'#endif  // %s\n' % header_guard )
Generates the .h file containing the definition of the structure specified
by the schema.
Generates the . h file containing the definition of the structure specified by the schema .
"""Generates the .h file containing the definition of the structure specified
  by the schema.

  Args:
    basepath: The base directory in which files are generated.
    fileroot: The filename and path, relative to basepath, of the file to
        create, without an extension.
    head: The string to output as the header of the .h file.
    namespace: A string corresponding to the C++ namespace to use.
    schema: A dict containing the schema. See comment at the top of this file.
    description: A dict containing the description. See comment at the top of
        this file.
  """
basepath
The base directory in which files are generated.
The base directory in which files are generated .
fileroot
The filename and path, relative to basepath, of the file to
create, without an extension.
The filename and path relative to basepath of the file to create without an extension .
head
The string to output as the header of the .h file.
The string to output as the header of the . h file .
namespace
A string corresponding to the C++ namespace to use.
A string corresponding to the C ++ namespace to use .
schema
A dict containing the schema. See comment at the top of this file.
A dict containing the schema . See comment at the top of this file .
description
A dict containing the description. See comment at the top of
this file.
A dict containing the description . See comment at the top of this file .