parameters: (self, struct, constructor, default_init)
docstring: Generate the C++ constructor definition.
docstring_summary: Generate the C++ constructor definition.
docstring_tokens: Generate the C ++ constructor definition .
function: def _gen_constructor(self, struct, constructor, default_init):
          # type: (ast.Struct, struct_types.MethodInfo, bool) -> None
          """Generate the C++ constructor definition."""
          # pylint: disable=too-many-branches
  
          initializers = ['_%s(std::move(%s))' % (arg.name, arg.name) for arg in constructor.args]
  
          # Serialize non-has fields first
          # Initialize int and other primitive fields to -1 to prevent Coverity warnings.
          if default_init:
              for field in struct.fields:
                  needs_init = (field.type and field.type.cpp_type and not field.type.is_array
                                and _is_required_serializer_field(field)
                                and field.cpp_name != 'dbName')
                  if needs_init:
                      initializers.append(
                          '%s(mongo::idl::preparsedValue<decltype(%s)>())' %
                          (_get_field_member_name(field), _get_field_member_name(field)))
  
          # Serialize the _dbName field second
          initializes_db_name = False
          if [arg for arg in constructor.args if arg.name == 'nss']:
              if [field for field in struct.fields if field.serialize_op_msg_request_only]:
                  initializers.append('_dbName(nss.db().toString())')
                  initializes_db_name = True
          elif [arg for arg in constructor.args if arg.name == 'nssOrUUID']:
              if [field for field in struct.fields if field.serialize_op_msg_request_only]:
                  initializers.append(
                      '_dbName(nssOrUUID.uuid() ? nssOrUUID.dbname() : nssOrUUID.nss().get().db().toString())'
                  )
                  initializes_db_name = True
  
          # Serialize has fields third
          # Add _has{FIELD} bool members to ensure fields are set before serialization.
          for field in struct.fields:
              if _is_required_serializer_field(field) and not (field.name == "$db"
                                                               and initializes_db_name):
                  if default_init:
                      initializers.append('%s(false)' % _get_has_field_member_name(field))
                  else:
                      initializers.append('%s(true)' % _get_has_field_member_name(field))
  
          if initializes_db_name:
              initializers.append('_hasDbName(true)')
  
          initializers_str = ''
          if initializers:
              initializers_str = ': ' + ', '.join(initializers)
  
          with self._block('%s %s {' % (constructor.get_definition(), initializers_str), '}'):
              self._writer.write_line('// Used for initialization only')
function_tokens: def _gen_constructor ( self , struct , constructor , default_init ) : # type: (ast.Struct, struct_types.MethodInfo, bool) -> None # pylint: disable=too-many-branches initializers = [ '_%s(std::move(%s))' % ( arg . name , arg . name ) for arg in constructor . args ] # Serialize non-has fields first # Initialize int and other primitive fields to -1 to prevent Coverity warnings. if default_init : for field in struct . fields : needs_init = ( field . type and field . type . cpp_type and not field . type . is_array and _is_required_serializer_field ( field ) and field . cpp_name != 'dbName' ) if needs_init : initializers . append ( '%s(mongo::idl::preparsedValue<decltype(%s)>())' % ( _get_field_member_name ( field ) , _get_field_member_name ( field ) ) ) # Serialize the _dbName field second initializes_db_name = False if [ arg for arg in constructor . args if arg . name == 'nss' ] : if [ field for field in struct . fields if field . serialize_op_msg_request_only ] : initializers . append ( '_dbName(nss.db().toString())' ) initializes_db_name = True elif [ arg for arg in constructor . args if arg . name == 'nssOrUUID' ] : if [ field for field in struct . fields if field . serialize_op_msg_request_only ] : initializers . append ( '_dbName(nssOrUUID.uuid() ? nssOrUUID.dbname() : nssOrUUID.nss().get().db().toString())' ) initializes_db_name = True # Serialize has fields third # Add _has{FIELD} bool members to ensure fields are set before serialization. for field in struct . fields : if _is_required_serializer_field ( field ) and not ( field . name == "$db" and initializes_db_name ) : if default_init : initializers . append ( '%s(false)' % _get_has_field_member_name ( field ) ) else : initializers . append ( '%s(true)' % _get_has_field_member_name ( field ) ) if initializes_db_name : initializers . append ( '_hasDbName(true)' ) initializers_str = '' if initializers : initializers_str = ': ' + ', ' . join ( initializers ) with self . _block ( '%s %s {' % ( constructor . get_definition ( ) , initializers_str ) , '}' ) : self . _writer . write_line ( '// Used for initialization only' )