Revision: 251
Author: roman_yakovenko
Date: 2006-06-26 13:06:20 -0700 (Mon, 26 Jun 2006)
ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=251&view=rev
Log Message:
-----------
addinig initial support for indexing suite v2
Modified Paths:
--------------
pyplusplus_dev/pyplusplus/code_creators/__init__.py
pyplusplus_dev/pyplusplus/code_creators/indexing_suites.py
pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py
pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py
pyplusplus_dev/pyplusplus/decl_wrappers/indexing_suite.py
pyplusplus_dev/pyplusplus/module_creator/creator.py
pyplusplus_dev/pyplusplus/module_creator/types_database.py
Modified: pyplusplus_dev/pyplusplus/code_creators/__init__.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/__init__.py 2006-06-26 20:05:50 UTC (rev 250)
+++ pyplusplus_dev/pyplusplus/code_creators/__init__.py 2006-06-26 20:06:20 UTC (rev 251)
@@ -105,5 +105,4 @@
from array_1_registrator import array_1_registrator_t
-from indexing_suites import vector_indexing_suite_t
-from indexing_suites import map_indexing_suite_t
\ No newline at end of file
+from indexing_suites import indexing_suite_t
Modified: pyplusplus_dev/pyplusplus/code_creators/indexing_suites.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/indexing_suites.py 2006-06-26 20:05:50 UTC (rev 250)
+++ pyplusplus_dev/pyplusplus/code_creators/indexing_suites.py 2006-06-26 20:06:20 UTC (rev 251)
@@ -10,10 +10,9 @@
from pygccxml import declarations
class indexing_suite_t( code_creator.code_creator_t ):
- def __init__(self, suite_name, parent=None ):
+ def __init__(self, parent=None ):
code_creator.code_creator_t.__init__( self, parent=parent )
- self.__suite_name = suite_name
-
+
def _get_configuration( self ):
return self.parent.declaration.indexing_suite
configuration = property( _get_configuration )
@@ -22,8 +21,14 @@
return self.parent.declaration
container = property( _get_container )
+ def guess_suite_name( self ):
+ if self.container.name.startswith( 'vector' ):
+ return 'boost::python::vector_indexing_suite'
+ else:
+ return 'boost::python::map_indexing_suite'
+
def _create_suite_declaration( self ):
- suite_identifier = algorithm.create_identifier( self, self.__suite_name )
+ suite_identifier = algorithm.create_identifier( self, self.guess_suite_name() )
args = [ self.container.decl_string ]
if self.configuration.derived_policies:
if self.configuration.no_proxy:
@@ -38,27 +43,4 @@
def _create_impl(self):
return "def( %s() )" % self._create_suite_declaration()
-
-class vector_indexing_suite_t( indexing_suite_t ):
- """
- Creates boost.python code that needed to export a vector of some class
- """
- #class_< std::vector<X> >("XVec")
- # .def(vector_indexing_suite<std::vector<X> >())
- #;
-
- def __init__(self, parent=None ):
- indexing_suite_t.__init__( self, 'boost::python::vector_indexing_suite', parent=parent )
-
-class map_indexing_suite_t( indexing_suite_t ):
- """
- Creates boost.python code that needed to export a vector of some class
- """
- #class_< std::vector<X> >("XVec")
- # .def(vector_indexing_suite<std::vector<X> >())
- #;
-
- def __init__(self, parent=None ):
- indexing_suite_t.__init__( self, 'boost::python::map_indexing_suite', parent=parent )
-
-
\ No newline at end of file
+
\ No newline at end of file
Modified: pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py
===================================================================
--- pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py 2006-06-26 20:05:50 UTC (rev 250)
+++ pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py 2006-06-26 20:06:20 UTC (rev 251)
@@ -87,7 +87,6 @@
from user_text import class_user_text_t
from indexing_suite import indexing_suite_t
-from indexing_suite import vector_suite_t
class dwfactory_t( declarations.decl_factory_t ):
Modified: pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py
===================================================================
--- pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2006-06-26 20:05:50 UTC (rev 250)
+++ pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2006-06-26 20:06:20 UTC (rev 251)
@@ -9,15 +9,19 @@
from pygccxml import declarations
import indexing_suite as container_suites
-
-def guess_indexing_suite( class_ ):
- if declarations.vector_traits.is_my_case( class_ ) \
- or declarations.list_traits.is_my_case( class_ ):
- return container_suites.vector_suite_t( class_ )
- if declarations.map_traits.is_my_case( class_ ) \
- or declarations.hash_map_traits.is_my_case( class_ ):
- return container_suites.map_suite_t( class_ )
+def guess_container_traits( class_ ):
+ if declarations.vector_traits.is_my_case( class_ ):
+ return declarations.vector_traits
+ elif declarations.list_traits.is_my_case( class_ ):
+ return declarations.list_traits
+ elif declarations.map_traits.is_my_case( class_ ):
+ return declarations.map_traits
+ elif declarations.hash_map_traits.is_my_case( class_ ):
+ declarations.hash_map_traits
+ else:
+ return None
+
#this will only be exported if indexing suite is not None and only when needed
class class_declaration_t(decl_wrapper.decl_wrapper_t, declarations.class_declaration_t):
def __init__(self, *arguments, **keywords):
@@ -34,7 +38,9 @@
def _get_indexing_suite( self ):
if self._indexing_suite is None:
- self._indexing_suite = guess_indexing_suite( self )
+ container_traits = guess_container_traits( self )
+ if container_traits:
+ self._indexing_suite = container_suites.indexing_suite_t( self, container_traits )
return self._indexing_suite
indexing_suite = property( _get_indexing_suite )
@@ -110,7 +116,10 @@
def _get_indexing_suite( self ):
if self._indexing_suite is None:
- self._indexing_suite = guess_indexing_suite( self )
+ container_traits = guess_container_traits( self )
+ if container_traits:
+ self._indexing_suite \
+ = container_suites.indexing_suite_t( self, container_traits )
return self._indexing_suite
indexing_suite = property( _get_indexing_suite )
Modified: pyplusplus_dev/pyplusplus/decl_wrappers/indexing_suite.py
===================================================================
--- pyplusplus_dev/pyplusplus/decl_wrappers/indexing_suite.py 2006-06-26 20:05:50 UTC (rev 250)
+++ pyplusplus_dev/pyplusplus/decl_wrappers/indexing_suite.py 2006-06-26 20:06:20 UTC (rev 251)
@@ -17,18 +17,19 @@
# 5. shared_ptr
class indexing_suite_t( object ):
- def __init__( self, container_class, no_proxy=None, derived_policies=None ):
+ def __init__( self, container_class, container_traits, no_proxy=None, derived_policies=None ):
object.__init__( self )
self.__no_proxy = no_proxy
self.__derived_policies = None
self.__container_class = container_class
+ self.__container_traits = container_traits
def _get_container_class( self ):
return self.__container_class
container_class = property( _get_container_class )
def value_type(self):
- raise NotImplementedError()
+ return self.__container_traits.value_type( self.container_class )
def _get_no_proxy( self ):
if self.__no_proxy is None:
@@ -50,27 +51,7 @@
def _get_derived_policies( self ):
return self.__derived_policies
- def _set_derived_policied( self, derived_policies ):
+ def _set_derived_policies( self, derived_policies ):
self.__derived_policies = derived_policies
- derived_policies = property( _get_derived_policies, _set_derived_policied )
-
-
-class vector_suite_t( indexing_suite_t ):
- def __init__( self, cls ):
- indexing_suite_t.__init__( self, cls )
- self.__traits = declarations.vector_traits
- if declarations.list_traits.is_my_case( self.container_class ):
- self.__traits = declarations.list_traits
-
- def value_type( self ):
- return self.__traits.value_type( self.container_class )
-
-class map_suite_t( indexing_suite_t ):
- def __init__( self, cls ):
- indexing_suite_t.__init__( self, cls )
- self.__traits = declarations.map_traits
- if declarations.hash_map_traits.is_my_case( self.container_class ):
- self.__traits = declarations.hash_map_traits
-
- def value_type( self ):
- return self.__traits.value_type( self.container_class )
+ derived_policies = property( _get_derived_policies, _set_derived_policies )
+
\ No newline at end of file
Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py
===================================================================
--- pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-06-26 20:05:50 UTC (rev 250)
+++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-06-26 20:06:20 UTC (rev 251)
@@ -366,28 +366,32 @@
else:
return code_creators.class_declaration_t( class_inst=cls )
- if self.__types_db.used_vectors:
- header = "boost/python/suite/indexing/vector_indexing_suite.hpp"
- self.__extmodule.add_system_header( header )
- self.__extmodule.add_include( header=header )
- for cls in self.__types_db.used_vectors:
- cls_creator = create_cls_cc( cls )
- value_type = cls.indexing_suite.value_type()
- if declarations.is_class( value_type ) and not declarations.has_public_equal( value_type ):
- cls_creator.adopt_creator( create_explanation( cls ) )
- cls_creator.adopt_creator( code_creators.vector_indexing_suite_t() )
- self.__module_body.adopt_creator( cls_creator )
- if self.__types_db.used_maps:
- header = "boost/python/suite/indexing/map_indexing_suite.hpp"
- self.__extmodule.add_system_header( header )
- self.__extmodule.add_include( header=header )
- for cls in self.__types_db.used_maps:
- cls_creator = create_cls_cc( cls )
- value_type = cls.indexing_suite.value_type()
- if declarations.is_class( value_type ) and not declarations.has_public_equal( value_type ):
- cls_creator.adopt_creator( create_explanation( cls ) )
- cls_creator.adopt_creator( code_creators.map_indexing_suite_t() )
- self.__module_body.adopt_creator( cls_creator )
+ if not self.__types_db.used_containers:
+ return
+
+ map_header_was_used = False
+ vector_header_was_used = False
+
+ for cls in self.__types_db.used_containers:
+ if cls.name.startswith( 'vector' ):
+ if not vector_header_was_used:
+ vector_header_was_used = True
+ header = "boost/python/suite/indexing/vector_indexing_suite.hpp"
+ self.__extmodule.add_system_header( header )
+ self.__extmodule.add_include( header=header )
+ else:
+ if not map_header_was_used:
+ map_header_was_used = True
+ header = "boost/python/suite/indexing/map_indexing_suite.hpp"
+ self.__extmodule.add_system_header( header )
+ self.__extmodule.add_include( header=header )
+
+ cls_creator = create_cls_cc( cls )
+ value_type = cls.indexing_suite.value_type()
+ if declarations.is_class( value_type ) and not declarations.has_public_equal( value_type ):
+ cls_creator.adopt_creator( create_explanation( cls ) )
+ cls_creator.adopt_creator( code_creators.indexing_suite_t() )
+ self.__module_body.adopt_creator( cls_creator )
def create(self, decl_headers=None):
"""Create and return the module for the extension.
Modified: pyplusplus_dev/pyplusplus/module_creator/types_database.py
===================================================================
--- pyplusplus_dev/pyplusplus/module_creator/types_database.py 2006-06-26 20:05:50 UTC (rev 250)
+++ pyplusplus_dev/pyplusplus/module_creator/types_database.py 2006-06-26 20:06:20 UTC (rev 251)
@@ -18,8 +18,7 @@
self.__smart_ptrs = [ 'shared_ptr', 'auto_ptr' ]
self.__fundamental_strs = declarations.FUNDAMENTAL_TYPES.keys()
self.__normalize_data = [ ',', '<', '>', '*', '&', '(', ')', '::' ]
- self.__used_vectors = set()
- self.__used_maps = set()
+ self.__containers = set()
def update( self, decl ):
if isinstance( decl, declarations.calldef_t ):
@@ -55,29 +54,23 @@
type = declarations.remove_alias( type )
type = declarations.remove_pointer( type )
type = declarations.remove_reference( type )
- try:
- if declarations.vector_traits.is_my_case( type ):
- vector = declarations.vector_traits.class_declaration( type )
- declarations.vector_traits.value_type( vector )
- self.__used_vectors.add( vector )
- return True
- #the patch I submitted should be accepted, before pyplusplus will generate
- #the code
- #~ if declarations.list_traits.is_my_case( type ):
- #~ list_ = declarations.list_traits.class_declaration( type )
- #~ declarations.list_traits.value_type( list_ )
- #~ self.__used_vectors.add( list_ )
- #~ return True
- if declarations.map_traits.is_my_case( type ):
- map_ = declarations.map_traits.class_declaration( type )
- declarations.map_traits.value_type( map_ )
- self.__used_maps.add( map_ )
- return True
- if declarations.hash_map_traits.is_my_case( type ):
- map_ = declarations.hash_map_traits.class_declaration( type )
- declarations.hash_map_traits.value_type( map_ )
- self.__used_maps.add( map_ )
- return True
+
+ traits = None
+ if declarations.vector_traits.is_my_case( type ):
+ traits = declarations.vector_traits
+ elif declarations.map_traits.is_my_case( type ):
+ traits = declarations.map_traits
+ elif declarations.hash_map_traits.is_my_case( type ):
+ traits = declarations.hash_map_traits
+ else:
+ pass
+ if None is traits:
+ return False
+ try:
+ cls = traits.class_declaration( type )
+ traits.value_type( cls )
+ self.__containers.add( cls )
+ return True
except RuntimeError, error:
msg = 'WARNING: pyplusplus found std::vector instantiation declaration, '
msg = msg + 'but can not find out value type!'
@@ -180,10 +173,7 @@
for db in dbs:
self._print_single_db( db )
- def _get_used_vectors( self ):
- return self.__used_vectors
- used_vectors = property( _get_used_vectors )
-
- def _get_used_maps( self ):
- return self.__used_maps
- used_maps = property( _get_used_maps )
+ def _get_used_containers( self ):
+ return self.__containers
+ used_containers = property( _get_used_containers)
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|