tools/json_to_struct/json_to_struct.py
def _GenerateCC(basepath, fileroot, head, namespace, schema, description):
  """Generates the .cc file containing the static initializers for the
  of the elements specified in the description.

  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 .cc 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.
  """

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

    f.write(u'#include "%s"\n' % (fileroot + u'.h'))
    f.write(u'\n')

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

    f.write(element_generator.GenerateElements(schema['type_name'],
        schema['schema'], description))

    if 'generate_array' in description:
      f.write(u'\n')
      f.write(
          u'const %s* const %s[] = {\n' %
          (schema['type_name'], description['generate_array']['array_name']))
      for element_name, _ in description['elements'].items():
        f.write(u'\t&%s,\n' % element_name)
      f.write(u'};\n')
      f.write(u'const size_t %s = %d;\n' %
              (description['generate_array']['array_name'] + u'Length',
               len(description['elements'])))

    if namespace:
      f.write(u'\n')
      f.write(u'}  // namespace %s\n' % namespace)
Generates the .cc file containing the static initializers for the
  of the elements specified in the description.

  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 .cc 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 .cc file containing the static initializers for the
of the elements specified in the description.
Generates the . cc file containing the static initializers for the of the elements specified in the description .
def _GenerateCC(basepath, fileroot, head, namespace, schema, description):
  with io.open(os.path.join(basepath, fileroot + '.cc'), 'w',
               encoding='utf-8') as f:
    f.write(head)
    f.write(u'#include "%s"\n' % (fileroot + u'.h'))
    f.write(u'\n')
    if namespace:
      f.write(u'namespace %s {\n' % namespace)
      f.write(u'\n')
    f.write(element_generator.GenerateElements(schema['type_name'],
        schema['schema'], description))
    if 'generate_array' in description:
      f.write(u'\n')
      f.write(
          u'const %s* const %s[] = {\n' %
          (schema['type_name'], description['generate_array']['array_name']))
      for element_name, _ in description['elements'].items():
        f.write(u'\t&%s,\n' % element_name)
      f.write(u'};\n')
      f.write(u'const size_t %s = %d;\n' %
              (description['generate_array']['array_name'] + u'Length',
               len(description['elements'])))
    if namespace:
      f.write(u'\n')
      f.write(u'}  // namespace %s\n' % namespace)
def _GenerateCC ( basepath , fileroot , head , namespace , schema , description ) : with io . open ( os . path . join ( basepath , fileroot + '.cc' ) , 'w' , encoding = 'utf-8' ) as f : f . write ( head ) f . write ( u'#include "%s"\n' % ( fileroot + u'.h' ) ) f . write ( u'\n' ) if namespace : f . write ( u'namespace %s {\n' % namespace ) f . write ( u'\n' ) f . write ( element_generator . GenerateElements ( schema [ 'type_name' ] , schema [ 'schema' ] , description ) ) if 'generate_array' in description : f . write ( u'\n' ) f . write ( u'const %s* const %s[] = {\n' % ( schema [ 'type_name' ] , description [ 'generate_array' ] [ 'array_name' ] ) ) for element_name , _ in description [ 'elements' ] . items ( ) : f . write ( u'\t&%s,\n' % element_name ) f . write ( u'};\n' ) f . write ( u'const size_t %s = %d;\n' % ( description [ 'generate_array' ] [ 'array_name' ] + u'Length' , len ( description [ 'elements' ] ) ) ) if namespace : f . write ( u'\n' ) f . write ( u'}  // namespace %s\n' % namespace )
Generates the .cc file containing the static initializers for the
of the elements specified in the description.
Generates the . cc file containing the static initializers for the of the elements specified in the description .
"""Generates the .cc file containing the static initializers for the
  of the elements specified in the description.

  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 .cc 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 .cc file.
The string to output as the header of the . cc 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 .