def split_creators( self, creators, pattern, function_name, registrator_pos ): """Write non-class creators into a particular .h/.cpp file. :param creators: The code creators that should be written :type creators: list of :class:`code_creators.code_creator_t` :param pattern: Name pattern that is used for constructing the final output file name :type pattern: str :param function_name: "register" function name :type function_name: str :param registrator_pos: The position of the code creator that creates the code to invoke the "register" function. :type registrator_pos: int """ if not creators: return file_pattern = self.extmodule.body.name + pattern file_path = os.path.join( self.directory_path, file_pattern ) header_name = file_path + self.HEADER_EXT self.write_file( header_name , self.create_header( file_pattern, self.create_function_code( function_name ) ) ) self.write_file( file_path + self.SOURCE_EXT , self.create_source( file_pattern, function_name, creators )) for creator in creators: creator.create = lambda: '' self.extmodule.body.adopt_creator( code_creators.custom_text_t( function_name + '();' ) , registrator_pos) self.include_creators.append( code_creators.include_t( header_name ) ) self.split_header_names.append(header_name) self.split_method_names.append(function_name)
def split_class_impl( self, class_creator): if not class_creator.declaration in self.huge_classes: return super( class_multiple_files_t, self ).split_class_impl( class_creator ) class_creator.declaration.always_expose_using_scope = True function_name = 'register_%s_class' % class_creator.alias file_path = os.path.join( self.directory_path, class_creator.alias ) # Write the .h file... header_name = file_path + self.HEADER_EXT self.write_file( header_name , self.create_header( class_creator.alias , self.create_function_code( function_name ) ) ) self.write_wrapper( class_creator ) tail_headers = [] for splitter in self.internal_splitters: pattern = splitter( class_creator ) if not pattern: continue if isinstance( pattern, str ): tail_headers.append( self.create_base_fname( class_creator, pattern + self.HEADER_EXT ) ) else: assert( isinstance( pattern, list ) ) for p in pattern: tail_headers.append( self.create_base_fname( class_creator, p + self.HEADER_EXT ) ) #writting source file source_code = [] if self.extmodule.license: source_code.append( self.extmodule.license.create() ) source_code.append( self.create_include_code( [class_creator], tail_headers=tail_headers ) ) source_code.append( '' ) source_code.append( self.create_namespaces_code( [class_creator] ) ) for creator in class_creator.associated_decl_creators: source_code.append( '' ) source_code.append( creator.create() ) if not isinstance( creator, self.ref_count_creators ): creator.create = lambda: '' # Write the register() function... source_code.append( '' ) source_code.append( 'void %s(){' % function_name ) source_code.append( '' ) source_code.append( class_creator.create() ) source_code.append( '' ) source_code.append( '}' ) self.write_file( file_path + self.SOURCE_EXT, os.linesep.join( source_code ) ) # Replace the create() method so that only the register() method is called # (this is called later for the main source file). class_creator.create = lambda: function_name +'();' self.include_creators.append( code_creators.include_t( header_name ) ) self.split_header_names.append(header_name) self.split_method_names.append(function_name)
def split_class_impl( self, class_creator): function_name = 'register_%s_class' % class_creator.alias file_path = os.path.join( self.directory_path, class_creator.alias ) # Write the .h file... header_name = file_path + self.HEADER_EXT self.write_file( header_name , self.create_header( class_creator.alias , self.create_function_code( function_name ) ) ) # Write the .cpp file... cpp_code = self.create_source( class_creator.alias, function_name, [class_creator] ) self.write_file( file_path + self.SOURCE_EXT, cpp_code ) # Replace the create() method so that only the register() method is called # (this is called later for the main source file). class_creator.create = lambda: function_name +'();' self.include_creators.append( code_creators.include_t( header_name ) ) self.split_header_names.append(header_name) self.split_method_names.append(function_name)
def split_class_impl(self, class_creator): function_name = 'register_%s_class' % class_creator.alias file_path = os.path.join(self.directory_path, class_creator.alias) # Write the .h file... header_name = file_path + self.HEADER_EXT self.write_file( header_name, self.create_header(class_creator.alias, self.create_function_code(function_name))) # Write the .cpp file... cpp_code = self.create_source(class_creator.alias, function_name, [class_creator]) self.write_file(file_path + self.SOURCE_EXT, cpp_code) # Replace the create() method so that only the register() method is called # (this is called later for the main source file). class_creator.create = lambda: function_name + '();' self.include_creators.append(code_creators.include_t(header_name)) self.split_header_names.append(header_name) self.split_method_names.append(function_name)
def split_creators(self, creators, pattern, function_name, registrator_pos): """Write non-class creators into a particular .h/.cpp file. :param creators: The code creators that should be written :type creators: list of :class:`code_creators.code_creator_t` :param pattern: Name pattern that is used for constructing the final output file name :type pattern: str :param function_name: "register" function name :type function_name: str :param registrator_pos: The position of the code creator that creates the code to invoke the "register" function. :type registrator_pos: int """ if not creators: return file_pattern = self.extmodule.body.name + pattern file_path = os.path.join(self.directory_path, file_pattern) header_name = file_path + self.HEADER_EXT self.write_file( header_name, self.create_header(file_pattern, self.create_function_code(function_name))) self.write_file( file_path + self.SOURCE_EXT, self.create_source(file_pattern, function_name, creators)) for creator in creators: creator.create = lambda: '' self.extmodule.body.adopt_creator( code_creators.custom_text_t(function_name + '();'), registrator_pos) self.include_creators.append(code_creators.include_t(header_name)) self.split_header_names.append(header_name) self.split_method_names.append(function_name)