writeDataClass method

  1. @override
void writeDataClass(
  1. CppOptions generatorOptions,
  2. Root root,
  3. Indent indent,
  4. Class klass, {
  5. required String dartPackageName,
})
override

Writes a single data class to indent.

Implementation

@override
void writeDataClass(
  CppOptions generatorOptions,
  Root root,
  Indent indent,
  Class klass, {
  required String dartPackageName,
}) {
  final Set<String> customClassNames =
      root.classes.map((Class x) => x.name).toSet();
  final Set<String> customEnumNames =
      root.enums.map((Enum x) => x.name).toSet();

  indent.writeln('$_commentPrefix ${klass.name}');
  indent.newln();

  final Iterable<NamedType> orderedFields =
      getFieldsInSerializationOrder(klass);
  final Iterable<NamedType> requiredFields =
      orderedFields.where((NamedType type) => !type.type.isNullable);
  // Minimal constructor, if needed.
  if (requiredFields.length != orderedFields.length) {
    _writeClassConstructor(root, indent, klass, requiredFields);
  }
  // All-field constructor.
  _writeClassConstructor(root, indent, klass, orderedFields);

  // Getters and setters.
  for (final NamedType field in orderedFields) {
    _writeCppSourceClassField(generatorOptions, root, indent, klass, field);
  }

  // Serialization.
  writeClassEncode(
    generatorOptions,
    root,
    indent,
    klass,
    customClassNames,
    customEnumNames,
    dartPackageName: dartPackageName,
  );

  // Deserialization.
  writeClassDecode(
    generatorOptions,
    root,
    indent,
    klass,
    customClassNames,
    customEnumNames,
    dartPackageName: dartPackageName,
  );
}