parameters: (self, spec)
docstring: Generate the C++ header to a stream.
docstring_summary: Generate the C++ header to a stream.
docstring_tokens: Generate the C ++ header to a stream .
function: def generate(self, spec):
          # type: (ast.IDLAST) -> None
          """Generate the C++ header to a stream."""
          # pylint: disable=too-many-branches,too-many-statements,too-many-locals,too-many-return-statements
          self.gen_file_header()
  
          self._writer.write_unindented_line('#pragma once')
          self.write_empty_line()
  
          # Generate system includes first
          header_list = [
              'algorithm',
              'boost/optional.hpp',
              'cstdint',
              'string',
              'tuple',
              'vector',
          ]
  
          header_list.sort()
  
          for include in header_list:
              self.gen_system_include(include)
  
          self.write_empty_line()
  
          # Generate user includes second
          header_list = [
              'mongo/base/string_data.h',
              'mongo/base/data_range.h',
              'mongo/bson/bsonobj.h',
              'mongo/bson/bsonobjbuilder.h',
              'mongo/bson/simple_bsonobj_comparator.h',
              'mongo/idl/idl_parser.h',
              'mongo/rpc/op_msg.h',
              'mongo/stdx/unordered_map.h',
          ] + spec.globals.cpp_includes
  
          if spec.configs:
              header_list.append('mongo/util/options_parser/option_description.h')
              config_init = spec.globals.configs and spec.globals.configs.initializer
              if config_init and (config_init.register or config_init.store):
                  header_list.append('mongo/util/options_parser/option_section.h')
                  header_list.append('mongo/util/options_parser/environment.h')
  
          if spec.server_parameters:
              if [param for param in spec.server_parameters if param.feature_flag]:
                  header_list.append('mongo/idl/feature_flag.h')
              header_list.append('mongo/idl/server_parameter.h')
              header_list.append('mongo/idl/server_parameter_with_storage.h')
  
          # Include this for TypedCommand only if a base class will be generated for a command in this
          # file.
          if any(command.api_version for command in spec.commands):
              header_list.append('mongo/db/commands.h')
  
          header_list.sort()
  
          for include in header_list:
              self.gen_include(include)
  
          self.write_empty_line()
  
          self._writer.write_line("namespace mongo { class AuthorizationContract; }")
          self.write_empty_line()
  
          # Generate namespace
          with self.gen_namespace_block(spec.globals.cpp_namespace):
              self.write_empty_line()
  
              for idl_enum in spec.enums:
                  self.gen_description_comment(idl_enum.description)
                  self.gen_enum_declaration(idl_enum)
                  self._writer.write_empty_line()
  
                  self.gen_enum_functions(idl_enum)
                  self._writer.write_empty_line()
  
              spec_and_structs = spec.structs
              spec_and_structs += spec.commands
  
              for struct in spec_and_structs:
                  self.gen_description_comment(struct.description)
                  with self.gen_class_declaration_block(struct.cpp_name):
                      self.write_unindented_line('public:')
  
                      if isinstance(struct, ast.Command):
                          if struct.reply_type:
                              # Alias the reply type as a named type for commands
                              self.gen_type_alias_declaration("Reply",
                                                              struct.reply_type.type.cpp_type)
                          else:
                              self._writer.write_line('using Reply = void;')
  
                      # Generate a sorted list of string constants
                      self.gen_string_constants_declarations(struct)
                      self.write_empty_line()
  
                      self.gen_authorization_contract_declaration(struct)
  
                      # Write constructor
                      self.gen_class_constructors(struct)
                      self.write_empty_line()
  
                      # Write serialization
                      self.gen_serializer_methods(struct)
  
                      if isinstance(struct, ast.Command):
                          self.gen_op_msg_request_methods(struct)
  
                      # Write getters & setters
                      for field in struct.fields:
                          if not field.ignore:
                              if field.description:
                                  self.gen_description_comment(field.description)
                              self.gen_getter(struct, field)
                              if not struct.immutable and not field.chained_struct_field:
                                  self.gen_setter(field)
                      self.write_unindented_line('protected:')
                      self.gen_protected_serializer_methods(struct)
  
                      # Write private validators
                      if [field for field in struct.fields if field.validator]:
                          self.write_unindented_line('private:')
                          for field in struct.fields:
                              if not field.ignore and not struct.immutable and field.validator:
                                  self.gen_validators(field)
  
                      self.write_unindented_line('private:')
  
                      if struct.generate_comparison_operators:
                          self.gen_comparison_operators_declarations(struct)
  
                      # Write command member variables
                      if isinstance(struct, ast.Command):
                          self.gen_known_fields_declaration()
                          self.write_empty_line()
  
                          self.gen_op_msg_request_member(struct)
  
                      # Write member variables
                      for field in struct.fields:
                          if not field.ignore and not field.chained_struct_field:
                              self.gen_member(field)
  
                      # Write serializer member variables
                      # Note: we write these out second to ensure the bit fields can be packed by
                      # the compiler.
                      for field in struct.fields:
                          if _is_required_serializer_field(field):
                              self.gen_serializer_member(field)
  
                  self.write_empty_line()
  
              field_lists_list: Iterable[Iterable[ast.FieldListBase]]
              field_lists_list = [spec.generic_argument_lists, spec.generic_reply_field_lists]
              for field_lists in field_lists_list:
                  for field_list in field_lists:
                      self.gen_description_comment(field_list.description)
                      with self.gen_class_declaration_block(field_list.cpp_name):
                          self.write_unindented_line('public:')
  
                          # Field lookup methods
                          self.gen_field_list_entry_lookup_methods(field_list)
                          self.write_empty_line()
  
                          # Member variables
                          self.write_unindented_line('private:')
                          self.gen_field_list_entries_declaration(field_list)
  
                      self.write_empty_line()
  
              for scp in spec.server_parameters:
                  if scp.cpp_class is None:
                      self._gen_exported_constexpr(scp.name, 'Default', scp.default, scp.condition)
                  self._gen_extern_declaration(scp.cpp_vartype, scp.cpp_varname, scp.condition)
                  self.gen_server_parameter_class(scp)
  
              if spec.configs:
                  for opt in spec.configs:
                      self._gen_exported_constexpr(opt.name, 'Default', opt.default, opt.condition)
                      self._gen_extern_declaration(opt.cpp_vartype, opt.cpp_varname, opt.condition)
                  self._gen_config_function_declaration(spec)
  
              # Write a base class for each command in API Version 1.
              for command in spec.commands:
                  if command.api_version:
                      self.generate_versioned_command_base_class(command)
function_tokens: def generate ( self , spec ) : # type: (ast.IDLAST) -> None # pylint: disable=too-many-branches,too-many-statements,too-many-locals,too-many-return-statements self . gen_file_header ( ) self . _writer . write_unindented_line ( '#pragma once' ) self . write_empty_line ( ) # Generate system includes first header_list = [ 'algorithm' , 'boost/optional.hpp' , 'cstdint' , 'string' , 'tuple' , 'vector' , ] header_list . sort ( ) for include in header_list : self . gen_system_include ( include ) self . write_empty_line ( ) # Generate user includes second header_list = [ 'mongo/base/string_data.h' , 'mongo/base/data_range.h' , 'mongo/bson/bsonobj.h' , 'mongo/bson/bsonobjbuilder.h' , 'mongo/bson/simple_bsonobj_comparator.h' , 'mongo/idl/idl_parser.h' , 'mongo/rpc/op_msg.h' , 'mongo/stdx/unordered_map.h' , ] + spec . globals . cpp_includes if spec . configs : header_list . append ( 'mongo/util/options_parser/option_description.h' ) config_init = spec . globals . configs and spec . globals . configs . initializer if config_init and ( config_init . register or config_init . store ) : header_list . append ( 'mongo/util/options_parser/option_section.h' ) header_list . append ( 'mongo/util/options_parser/environment.h' ) if spec . server_parameters : if [ param for param in spec . server_parameters if param . feature_flag ] : header_list . append ( 'mongo/idl/feature_flag.h' ) header_list . append ( 'mongo/idl/server_parameter.h' ) header_list . append ( 'mongo/idl/server_parameter_with_storage.h' ) # Include this for TypedCommand only if a base class will be generated for a command in this # file. if any ( command . api_version for command in spec . commands ) : header_list . append ( 'mongo/db/commands.h' ) header_list . sort ( ) for include in header_list : self . gen_include ( include ) self . write_empty_line ( ) self . _writer . write_line ( "namespace mongo { class AuthorizationContract; }" ) self . write_empty_line ( ) # Generate namespace with self . gen_namespace_block ( spec . globals . cpp_namespace ) : self . write_empty_line ( ) for idl_enum in spec . enums : self . gen_description_comment ( idl_enum . description ) self . gen_enum_declaration ( idl_enum ) self . _writer . write_empty_line ( ) self . gen_enum_functions ( idl_enum ) self . _writer . write_empty_line ( ) spec_and_structs = spec . structs spec_and_structs += spec . commands for struct in spec_and_structs : self . gen_description_comment ( struct . description ) with self . gen_class_declaration_block ( struct . cpp_name ) : self . write_unindented_line ( 'public:' ) if isinstance ( struct , ast . Command ) : if struct . reply_type : # Alias the reply type as a named type for commands self . gen_type_alias_declaration ( "Reply" , struct . reply_type . type . cpp_type ) else : self . _writer . write_line ( 'using Reply = void;' ) # Generate a sorted list of string constants self . gen_string_constants_declarations ( struct ) self . write_empty_line ( ) self . gen_authorization_contract_declaration ( struct ) # Write constructor self . gen_class_constructors ( struct ) self . write_empty_line ( ) # Write serialization self . gen_serializer_methods ( struct ) if isinstance ( struct , ast . Command ) : self . gen_op_msg_request_methods ( struct ) # Write getters & setters for field in struct . fields : if not field . ignore : if field . description : self . gen_description_comment ( field . description ) self . gen_getter ( struct , field ) if not struct . immutable and not field . chained_struct_field : self . gen_setter ( field ) self . write_unindented_line ( 'protected:' ) self . gen_protected_serializer_methods ( struct ) # Write private validators if [ field for field in struct . fields if field . validator ] : self . write_unindented_line ( 'private:' ) for field in struct . fields : if not field . ignore and not struct . immutable and field . validator : self . gen_validators ( field ) self . write_unindented_line ( 'private:' ) if struct . generate_comparison_operators : self . gen_comparison_operators_declarations ( struct ) # Write command member variables if isinstance ( struct , ast . Command ) : self . gen_known_fields_declaration ( ) self . write_empty_line ( ) self . gen_op_msg_request_member ( struct ) # Write member variables for field in struct . fields : if not field . ignore and not field . chained_struct_field : self . gen_member ( field ) # Write serializer member variables # Note: we write these out second to ensure the bit fields can be packed by # the compiler. for field in struct . fields : if _is_required_serializer_field ( field ) : self . gen_serializer_member ( field ) self . write_empty_line ( ) field_lists_list : Iterable [ Iterable [ ast . FieldListBase ] ] field_lists_list = [ spec . generic_argument_lists , spec . generic_reply_field_lists ] for field_lists in field_lists_list : for field_list in field_lists : self . gen_description_comment ( field_list . description ) with self . gen_class_declaration_block ( field_list . cpp_name ) : self . write_unindented_line ( 'public:' ) # Field lookup methods self . gen_field_list_entry_lookup_methods ( field_list ) self . write_empty_line ( ) # Member variables self . write_unindented_line ( 'private:' ) self . gen_field_list_entries_declaration ( field_list ) self . write_empty_line ( ) for scp in spec . server_parameters : if scp . cpp_class is None : self . _gen_exported_constexpr ( scp . name , 'Default' , scp . default , scp . condition ) self . _gen_extern_declaration ( scp . cpp_vartype , scp . cpp_varname , scp . condition ) self . gen_server_parameter_class ( scp ) if spec . configs : for opt in spec . configs : self . _gen_exported_constexpr ( opt . name , 'Default' , opt . default , opt . condition ) self . _gen_extern_declaration ( opt . cpp_vartype , opt . cpp_varname , opt . condition ) self . _gen_config_function_declaration ( spec ) # Write a base class for each command in API Version 1. for command in spec . commands : if command . api_version : self . generate_versioned_command_base_class ( command )