Package pyplusplus :: Package file_writers :: Module balanced_files

Source Code for Module pyplusplus.file_writers.balanced_files

 1  # Copyright 2004 Giovanni Beltrame 
 2  # Distributed under the Boost Software License, Version 1.0. (See 
 3  # accompanying file LICENSE_1_0.txt or copy at 
 4  # http://www.boost.org/LICENSE_1_0.txt) 
 5   
 6  """defines a class that writes L{code_creators.module_t} to multiple files""" 
 7   
 8  import os 
 9  import math 
10  import multiple_files 
11  from pyplusplus import messages 
12  from pyplusplus import _logging_ 
13  from pygccxml import declarations 
14  from pyplusplus import decl_wrappers 
15  from pyplusplus import code_creators 
16  from pyplusplus.utils import split_sequence 
17   
18  #TODO: to add namespace_alias_t classes 
19 -class balanced_files_t(multiple_files.multiple_files_t):
20 """ 21 This class implements classic strategy of deviding classes to files 22 one class in one header + source files. 23 """ 24 HEADER_EXT = '.pypp.hpp' 25 SOURCE_EXT = '.pypp.cpp' 26
27 - def __init__( self 28 , extmodule 29 , directory_path 30 , number_of_buckets 31 , write_main=True 32 , files_sum_repository=None 33 , encoding='ascii'):
34 """Constructor. 35 36 @param extmodule: The root of a code creator tree 37 @type extmodule: module_t 38 @param directory_path: The output directory where the source files are written 39 @type directory_path: str 40 41 @param write_main: if it is True, the class will write out a main file 42 that calls all the registration methods. 43 @type write_main: boolean 44 """ 45 multiple_files.multiple_files_t.__init__( self, extmodule, directory_path, write_main, files_sum_repository, encoding) 46 self.number_of_buckets = number_of_buckets
47
48 - def split_classes( self ):
49 class_creators = filter( lambda x: isinstance(x, ( code_creators.class_t, code_creators.class_declaration_t ) ) 50 , self.extmodule.body.creators ) 51 52 class_creators = filter( lambda cc: not cc.declaration.already_exposed 53 , class_creators ) 54 55 buckets = split_sequence(class_creators, len(class_creators)/self.number_of_buckets ) 56 if len(buckets) > self.number_of_buckets: 57 buckets[len(buckets)-2] += buckets[len(buckets)-1] 58 buckets = buckets[:len(buckets)-1] 59 60 for index, bucket in enumerate( buckets ): 61 self.split_creators( bucket 62 , '_classes_%d' % (index+1) 63 , 'register_classes_%d' % (index+1) 64 , -1 )
65