Update of /cvsroot/pygccxml/source/pyplusplus/file_writers
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10214/file_writers
Modified Files:
writer.py multiple_files.py
Log Message:
Added some doc strings and comments
Index: writer.py
===================================================================
RCS file: /cvsroot/pygccxml/source/pyplusplus/file_writers/writer.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** writer.py 6 Apr 2006 06:16:08 -0000 1.14
--- writer.py 9 Apr 2006 15:12:21 -0000 1.15
***************
*** 23,27 ****
def _get_extmodule(self):
return self.__extmodule
! extmodule = property( _get_extmodule )
def write(self):
--- 23,29 ----
def _get_extmodule(self):
return self.__extmodule
! extmodule = property( _get_extmodule,
! doc="""The root of the code creator tree.
! @type: module_t""")
def write(self):
***************
*** 43,46 ****
--- 45,59 ----
def write_file( fpath, content ):
+ """Write a source file.
+
+ This method writes the string content into the specified file.
+ An additional fixed header is written at the top of the file before
+ content.
+
+ @param fpath: File name
+ @type fpath: str
+ @param content: The content of the file
+ @type content: str
+ """
_logging_.logger.debug( 'write code to file "%s" - started' % fpath )
start_time = time.clock()
Index: multiple_files.py
===================================================================
RCS file: /cvsroot/pygccxml/source/pyplusplus/file_writers/multiple_files.py,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** multiple_files.py 6 Apr 2006 06:16:08 -0000 1.16
--- multiple_files.py 9 Apr 2006 15:12:21 -0000 1.17
***************
*** 19,26 ****
def __init__(self, extmodule, directory_path):
writer.writer_t.__init__(self, extmodule)
self.__directory_path = directory_path
self._create_dir()
! self.__include_creators = []
self.split_header_names = [] # List of include file names for split files
self.split_method_names = [] # List of methods from the split files
--- 19,33 ----
def __init__(self, extmodule, directory_path):
+ """Constructor.
+
+ @param extmodule: The root of a code creator tree
+ @type extmodule: module_t
+ @param directory_path: The output directory where the source files are written
+ @type directory_path: str
+ """
writer.writer_t.__init__(self, extmodule)
self.__directory_path = directory_path
self._create_dir()
! self.__include_creators = [] # List of include_t creators that contain the generated headers
self.split_header_names = [] # List of include file names for split files
self.split_method_names = [] # List of methods from the split files
***************
*** 28,31 ****
--- 35,40 ----
def _create_dir( self ):
+ """Create the output directory if it doesn't already exist.
+ """
if os.path.exists( self.__directory_path ) and not os.path.isdir(self.__directory_path):
raise RuntimeError( 'directory_path should contain path to directory.' )
***************
*** 35,41 ****
def _get_directory_path(self):
return self.__directory_path
! directory_path = property( _get_directory_path )
def create_header( self, file_name, function_name ):
tmpl = os.linesep.join([
"#ifndef __%(file_name)s_hpp__pyplusplus_wrapper__"
--- 44,62 ----
def _get_directory_path(self):
return self.__directory_path
! directory_path = property( _get_directory_path,
! doc="""The name of the output directory.
! @type: str
! """ )
def create_header( self, file_name, function_name ):
+ """Return the content of a header file.
+
+ @param file_name: A string that uniquely identifies the file name
+ @type file_name: str
+ @param function_name: The name of the register_xyz() function
+ @type function_name: str
+ @returns: The content for a header file
+ @rtype: str
+ """
tmpl = os.linesep.join([
"#ifndef __%(file_name)s_hpp__pyplusplus_wrapper__"
***************
*** 54,57 ****
--- 75,90 ----
def create_source( self, file_name, function_name, creators ):
+ """Return the content of a cpp file.
+
+ @param file_name: The base name of the corresponding include file (without extension)
+ @type file_name: str
+ @param function_name: The name of the register_xyz() function
+ @type function_name: str
+ @param creators: The code creators that create the register_xyz() function
+ @type creators: list of code_creator_t
+ @returns: The content for a cpp file
+ @rtype: str
+ """
+
answer = []
if self.extmodule.license:
***************
*** 62,66 ****
answer.append( '#include "%s%s"' % ( file_name, self.HEADER_EXT ) )
!
include_creators = filter( lambda creator: isinstance( creator, code_creators.include_t )
and not isinstance( creator, code_creators.precompiled_header_t )
--- 95,100 ----
answer.append( '#include "%s%s"' % ( file_name, self.HEADER_EXT ) )
!
! # Include all 'global' include files...
include_creators = filter( lambda creator: isinstance( creator, code_creators.include_t )
and not isinstance( creator, code_creators.precompiled_header_t )
***************
*** 69,73 ****
, include_creators )
answer.append( os.linesep.join(includes) )
!
affect_creators = filter( lambda x: isinstance( x, code_creators.namespace_alias_t )
or isinstance( x, code_creators.namespace_using_t )
--- 103,108 ----
, include_creators )
answer.append( os.linesep.join(includes) )
!
! # Write all 'global' namespace_alias_t and namespace_using_t creators first...
affect_creators = filter( lambda x: isinstance( x, code_creators.namespace_alias_t )
or isinstance( x, code_creators.namespace_using_t )
***************
*** 82,91 ****
answer.append( '' )
answer.append( os.linesep.join(namespace_aliases) )
!
for creator in creators:
if isinstance( creator, code_creators.class_t ) and creator.wrapper:
answer.append( '' )
answer.append( creator.wrapper.create() )
!
answer.append( '' )
answer.append( 'void %s(){' % function_name )
--- 117,128 ----
answer.append( '' )
answer.append( os.linesep.join(namespace_aliases) )
!
! # Write wrapper classes...
for creator in creators:
if isinstance( creator, code_creators.class_t ) and creator.wrapper:
answer.append( '' )
answer.append( creator.wrapper.create() )
!
! # Write the register() function...
answer.append( '' )
answer.append( 'void %s(){' % function_name )
***************
*** 97,105 ****
--- 134,152 ----
def split_class( self, class_creator):
+ """Write the .h/.cpp file for one class.
+
+ Writes a .h/.cpp file for the given class. The files use the class name
+ as base file name.
+
+ @param class_creator: The class creator for one particular class
+ @type class_creator: class_t
+ """
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, function_name ) )
+ # Write the .cpp file...
self.write_file( file_path + self.SOURCE_EXT
, self.create_source( class_creator.alias
***************
*** 107,111 ****
--- 154,163 ----
, [class_creator] ))
if class_creator.wrapper:
+ # The wrapper has already been written above, so replace the create()
+ # method with a new 'method' that just returns an empty string because
+ # this method is later called again for the main source file.
class_creator.wrapper.create = lambda: ''
+ # 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 ) )
***************
*** 114,117 ****
--- 166,180 ----
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 code_creator_t
+ @param pattern: Name pattern that is used for constructing the final output file name
+ @type pattern: str
+ @param function_name: The name of the register_xyz() function
+ @type function_name: str
+ @param registrator_pos: The position of the code creator that creates the code to invoke the register_xyz() function.
+ @type registrator_pos: int
+ """
if not creators:
return
***************
*** 135,138 ****
--- 198,203 ----
def split_enums( self ):
+ """Write all enumerations into a separate .h/.cpp file.
+ """
enums_creators = filter( lambda x: isinstance(x, code_creators.enum_t )
, self.extmodule.body.creators )
***************
*** 141,144 ****
--- 206,211 ----
def split_global_variables( self ):
+ """Write all global variables into a separate .h/.cpp file.
+ """
creators = filter( lambda x: isinstance(x, code_creators.global_variable_t )
, self.extmodule.body.creators )
***************
*** 148,151 ****
--- 215,220 ----
def split_free_functions( self ):
+ """Write all free functions into a separate .h/.cpp file.
+ """
creators = filter( lambda x: isinstance(x, code_creators.function_t )
, self.extmodule.body.creators )
***************
*** 166,172 ****
self.extmodule.do_include_dirs_optimization()
!
class_creators = filter( lambda x: isinstance(x, code_creators.class_t )
, self.extmodule.body.creators )
map( self.split_class, class_creators )
--- 235,243 ----
self.extmodule.do_include_dirs_optimization()
!
! # Obtain a list of all class creators...
class_creators = filter( lambda x: isinstance(x, code_creators.class_t )
, self.extmodule.body.creators )
+ # ...and write a .h/.cpp file for each class
map( self.split_class, class_creators )
|