1   
 2   
 3   
 4   
 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   
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   
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