[pygccxml-commit] SF.net SVN: pygccxml: [233] pygccxml_dev/unittests
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-06-19 14:31:48
|
Revision: 233 Author: roman_yakovenko Date: 2006-06-19 07:31:22 -0700 (Mon, 19 Jun 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=233&view=rev Log Message: ----------- big refactoring to container traits to make it easy to add another container Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/container_traits.py pygccxml_dev/unittests/vector_traits_tester.py pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py pyplusplus_dev/pyplusplus/module_creator/types_database.py pyplusplus_dev/unittests/indexing_suites_tester.py Modified: pygccxml_dev/pygccxml/declarations/container_traits.py =================================================================== --- pygccxml_dev/pygccxml/declarations/container_traits.py 2006-06-19 13:24:30 UTC (rev 232) +++ pygccxml_dev/pygccxml/declarations/container_traits.py 2006-06-19 14:31:22 UTC (rev 233) @@ -12,10 +12,13 @@ import namespace import class_declaration import type_traits + +class container_traits_impl_t: + def __init__( self, container_name, value_type_index ): + self.name = container_name + self.value_type_index = value_type_index -class impl_details: - @staticmethod - def get_container_or_none( type, container_name ): + def get_container_or_none( self, type ): """returns reference to the class declaration or None""" type = type_traits.remove_alias( type ) type = type_traits.remove_cv( type ) @@ -30,40 +33,55 @@ else: return - if not cls.name.startswith( container_name + '<' ): + if not cls.name.startswith( self.name + '<' ): return if not type_traits.impl_details.is_defined_in_xxx( 'std', cls ): return return cls - -class vector_traits: - CONTAINER_NAME = 'vector' - - @staticmethod - def is_vector( type ): - """ - Returns True if type represents instantiation of std class vector, otherwise False.""" - return not( None is impl_details.get_container_or_none( type, vector_traits.CONTAINER_NAME ) ) - - @staticmethod - def class_declaration( type ): - """returns reference to the class declaration, """ - cls = impl_details.get_container_or_none( type, vector_traits.CONTAINER_NAME ) - if not cls: - raise TypeError( 'Type "%s" is not instantiation of std::vector' % type.decl_string ) - return cls - - @staticmethod - def value_type( type ): - """returns reference to value_type of the vector""" - cls = vector_traits.class_declaration( type ) - if isinstance( cls, class_declaration.class_t ): - return type_traits.remove_declarated( cls.typedef( "value_type", recursive=False ).type ) - else: - value_type_str = templates.args( cls.name )[0] + + def is_my_case( self, type ): + return bool( self.get_container_or_none( type ) ) + + def class_declaration( self, type ): + cls = self.get_container_or_none( type ) + if not cls: + raise TypeError( 'Type "%s" is not instantiation of std::%s' % ( type.decl_string, self.name ) ) + return cls + + def value_type( self, type ): + cls = self.class_declaration( type ) + if isinstance( cls, class_declaration.class_t ): + value_type = cls.typedef( "value_type", recursive=False ).type + return type_traits.remove_declarated( value_type ) + else: + value_type_str = templates.args( cls.name )[self.value_type_index] ref = type_traits.impl_details.find_value_type( cls.top_parent, value_type_str ) - if None is ref: - raise RuntimeError( "Unable to find out vector value type. vector class is: %s" % cls.decl_string ) - return ref + if None is ref: + raise RuntimeError( "Unable to find out %s '%s' value type." + % ( self.name, cls.decl_string ) ) + return ref +def create_traits_class( container_name, value_type_index ): + class xxx_traits: + impl = container_traits_impl_t( container_name, value_type_index ) + + @staticmethod + def is_my_case( type ): + return xxx_traits.impl.is_my_case( type ) + + @staticmethod + def class_declaration( type ): + return xxx_traits.impl.class_declaration( type ) + + @staticmethod + def value_type( type ): + return xxx_traits.impl.value_type( type ) + + return xxx_traits + +vector_traits = create_traits_class( 'vector', 0 ) +map_traits = create_traits_class( 'map', 1 ) +multimap_traits = create_traits_class( 'multimap', 1 ) +hash_map_traits = create_traits_class( 'hash_map', 1 ) +hash_multimap_traits = create_traits_class( 'hash_multimap', 1 ) \ No newline at end of file Modified: pygccxml_dev/unittests/vector_traits_tester.py =================================================================== --- pygccxml_dev/unittests/vector_traits_tester.py 2006-06-19 13:24:30 UTC (rev 232) +++ pygccxml_dev/unittests/vector_traits_tester.py 2006-06-19 14:31:22 UTC (rev 233) @@ -27,7 +27,7 @@ def validate_yes( self, value_type, container ): traits = declarations.vector_traits - self.failUnless( traits.is_vector( container ) ) + self.failUnless( traits.is_my_case( container ) ) self.failUnless( declarations.is_same( value_type, traits.value_type( container ) ) ) def test_global_ns( self ): @@ -53,7 +53,7 @@ continue if not struct.name.endswith( '_' ): continue - self.failUnless( not traits.is_vector( struct.typedef( 'container' ) ) ) + self.failUnless( not traits.is_my_case( struct.typedef( 'container' ) ) ) def create_suite(): suite = unittest.TestSuite() Modified: pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2006-06-19 13:24:30 UTC (rev 232) +++ pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2006-06-19 14:31:22 UTC (rev 233) @@ -11,7 +11,7 @@ def guess_indexing_suite( class_ ): - if declarations.vector_traits.is_vector( class_ ): + if declarations.vector_traits.is_my_case( class_ ): return container_suites.vector_suite_t( class_ ) #this will only be exported if indexing suite is not None and only when needed Modified: pyplusplus_dev/pyplusplus/module_creator/types_database.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/types_database.py 2006-06-19 13:24:30 UTC (rev 232) +++ pyplusplus_dev/pyplusplus/module_creator/types_database.py 2006-06-19 14:31:22 UTC (rev 233) @@ -54,7 +54,7 @@ type = declarations.remove_alias( type ) type = declarations.remove_pointer( type ) type = declarations.remove_reference( type ) - if declarations.vector_traits.is_vector( type ): + if declarations.vector_traits.is_my_case( type ): vector = declarations.vector_traits.class_declaration( type ) try: declarations.vector_traits.value_type( vector ) Modified: pyplusplus_dev/unittests/indexing_suites_tester.py =================================================================== --- pyplusplus_dev/unittests/indexing_suites_tester.py 2006-06-19 13:24:30 UTC (rev 232) +++ pyplusplus_dev/unittests/indexing_suites_tester.py 2006-06-19 14:31:22 UTC (rev 233) @@ -22,7 +22,7 @@ @staticmethod def matcher( item, decl ): - if not declarations.vector_traits.is_vector( decl ): + if not declarations.vector_traits.is_my_case( decl ): return False value_type = declarations.vector_traits.value_type(decl) if item is value_type: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |