Beispiel #1
0
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 open(os.path.join(basepath, fileroot + '.cc'), 'w') as f:
    f.write(head)

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

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

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

    if namespace:
      f.write('\n')
      f.write('}  // namespace %s\n' % namespace)
Beispiel #2
0
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)