[pygccxml-commit] SF.net SVN: pygccxml: [1063] pygccxml_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2007-06-18 14:27:28
|
Revision: 1063 http://svn.sourceforge.net/pygccxml/?rev=1063&view=rev Author: roman_yakovenko Date: 2007-06-18 07:27:30 -0700 (Mon, 18 Jun 2007) Log Message: ----------- adding another set of containers to remove_defaults functionality Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/container_traits.py pygccxml_dev/unittests/data/remove_template_defaults.hpp pygccxml_dev/unittests/remove_template_defaults_tester.py Modified: pygccxml_dev/pygccxml/declarations/container_traits.py =================================================================== --- pygccxml_dev/pygccxml/declarations/container_traits.py 2007-06-18 07:17:19 UTC (rev 1062) +++ pygccxml_dev/pygccxml/declarations/container_traits.py 2007-06-18 14:27:30 UTC (rev 1063) @@ -37,7 +37,7 @@ class recursive_impl: @staticmethod - def decorated_call( cls_name, text, doit ): + def decorated_call_prefix( cls_name, text, doit ): has_text = cls_name.startswith( text ) if has_text: cls_name = cls_name[ len( text ): ] @@ -47,6 +47,16 @@ return answer @staticmethod + def decorated_call_suffix( cls_name, text, doit ): + has_text = cls_name.endswith( text ) + if has_text: + cls_name = cls_name[: len( text )] + answer = doit( cls_name ) + if has_text: + answer = answer + text + return answer + + @staticmethod def erase_call( cls_name ): global find_container_traits c_traits = find_container_traits( cls_name ) @@ -57,9 +67,11 @@ @staticmethod def erase_recursive( cls_name ): ri = defaults_eraser.recursive_impl - no_std = lambda cls_name: ri.decorated_call( cls_name, 'std::', ri.erase_call ) - no_const = lambda cls_name: ri.decorated_call( cls_name, 'const ', no_std ) - return no_const( cls_name ) + no_std = lambda cls_name: ri.decorated_call_prefix( cls_name, 'std::', ri.erase_call ) + no_stdext = lambda cls_name: ri.decorated_call_prefix( cls_name, 'stdext::', no_std ) + no_const = lambda cls_name: ri.decorated_call_prefix( cls_name, 'const ', no_stdext ) + no_end_const = lambda cls_name: ri.decorated_call_suffix( cls_name, ' const', no_const ) + return no_end_const( cls_name ) @staticmethod def erase_recursive( cls_name ): @@ -145,6 +157,53 @@ , [ defaults_eraser.erase_recursive( key_type ) , defaults_eraser.erase_recursive( mapped_type )] ) + + @staticmethod + def erase_hash_allocator( cls_name + , default_hash='stdext::hash_compare' + , default_compare='std::less' + , default_allocator='std::allocator' ): + cls_name = defaults_eraser.replace_basic_string( cls_name ) + c_name, c_args = templates.split( cls_name ) + if 3 != len( c_args ): + return + value_type = c_args[0] + tmpl = string.Template( "$container< $value_type, $hash<$value_type, $less<$value_type> >, $allocator<$value_type> >" ) + tmpl = tmpl.substitute( container=c_name + , value_type=value_type + , hash=default_hash + , less=default_compare + , allocator=default_allocator ) + if defaults_eraser.normalize( cls_name ) == defaults_eraser.normalize( tmpl ): + return templates.join( c_name, [defaults_eraser.erase_recursive( value_type )] ) + + + @staticmethod + def erase_hashmap_compare_allocator( cls_name + , default_hash='stdext::hash_compare' + , default_compare='std::less' + , default_allocator='std::allocator' ): + cls_name = defaults_eraser.replace_basic_string( cls_name ) + c_name, c_args = templates.split( cls_name ) + if 4 != len( c_args ): + return + key_type = c_args[0] + mapped_type = c_args[1] + tmpl = string.Template( "$container< $key_type, $mapped_type, $hash<$key_type, $less<$key_type> >, $allocator< std::pair< const $key_type, $mapped_type> > >" ) + if key_type.startswith( 'const ' ) or key_type.endswith( ' const' ): + tmpl = string.Template( "$container< $key_type, $mapped_type, $hash<$key_type, $less<$key_type> >, $allocator< std::pair< $key_type, $mapped_type> > >" ) + tmpl = tmpl.substitute( container=c_name + , key_type=key_type + , mapped_type=mapped_type + , hash=default_hash + , less=default_compare + , allocator=default_allocator ) + if defaults_eraser.normalize( cls_name ) == defaults_eraser.normalize( tmpl ): + return templates.join( c_name + , [ defaults_eraser.erase_recursive( key_type ) + , defaults_eraser.erase_recursive( mapped_type )] ) + + class container_traits_impl_t: """this class implements the functionality needed for convinient work with STD container classes. @@ -278,14 +337,14 @@ map_traits = create_traits_class( 'map', 1, 'mapped_type', defaults_eraser.erase_map_compare_allocator ) multimap_traits = create_traits_class( 'multimap', 1, 'mapped_type', defaults_eraser.erase_map_compare_allocator ) -hash_map_traits = create_traits_class( 'hash_map', 1, 'mapped_type' ) -hash_multimap_traits = create_traits_class( 'hash_multimap', 1, 'mapped_type' ) +hash_map_traits = create_traits_class( 'hash_map', 1, 'mapped_type', defaults_eraser.erase_hashmap_compare_allocator ) +hash_multimap_traits = create_traits_class( 'hash_multimap', 1, 'mapped_type', defaults_eraser.erase_hashmap_compare_allocator ) set_traits = create_traits_class( 'set', 0, 'value_type', defaults_eraser.erase_compare_allocator) multiset_traits = create_traits_class( 'multiset', 0, 'value_type', defaults_eraser.erase_compare_allocator ) -hash_set_traits = create_traits_class( 'hash_set', 0, 'value_type' ) -hash_multiset_traits = create_traits_class( 'hash_multiset', 0, 'value_type' ) +hash_set_traits = create_traits_class( 'hash_set', 0, 'value_type', defaults_eraser.erase_hash_allocator ) +hash_multiset_traits = create_traits_class( 'hash_multiset', 0, 'value_type', defaults_eraser.erase_hash_allocator ) container_traits = ( list_traits Modified: pygccxml_dev/unittests/data/remove_template_defaults.hpp =================================================================== --- pygccxml_dev/unittests/data/remove_template_defaults.hpp 2007-06-18 07:17:19 UTC (rev 1062) +++ pygccxml_dev/unittests/data/remove_template_defaults.hpp 2007-06-18 14:27:30 UTC (rev 1063) @@ -6,6 +6,8 @@ #ifndef __remove_template_defaults_hpp__ #define __remove_template_defaults_hpp__ +#include <hash_set> +#include <hash_map> #include <string> #include <vector> #include <deque> @@ -68,7 +70,28 @@ typedef std::multimap< std::vector< int > const, mm_wstr2d const > mm_v_i2mm_wstr2d; } +namespace hash_sets{ + typedef std::hash_set< std::vector< int > > hs_v_int; + typedef std::hash_set< std::string > hs_string; } +namespace hash_multisets{ + typedef std::hash_multiset< std::vector< int > > mhs_v_int; + typedef std::hash_multiset< std::string > mhs_string; +} + +namespace hash_maps{ + typedef std::hash_map< int, double > hm_i2d; + typedef std::hash_map< std::wstring, double > hm_wstr2d; +} + +namespace hash_multimaps{ + typedef std::hash_multimap< int, double > hmm_i2d; + typedef std::hash_multimap< std::wstring const, double > hmm_wstr2d; + typedef std::hash_multimap< std::vector< int > const, hmm_wstr2d const > hmm_v_i2mm_wstr2d; +} + +} + #endif//__remove_template_defaults_hpp__ Modified: pygccxml_dev/unittests/remove_template_defaults_tester.py =================================================================== --- pygccxml_dev/unittests/remove_template_defaults_tester.py 2007-06-18 07:17:19 UTC (rev 1062) +++ pygccxml_dev/unittests/remove_template_defaults_tester.py 2007-06-18 14:27:30 UTC (rev 1063) @@ -104,6 +104,42 @@ self.failUnless( 'multimap< const std::vector< int >, const std::multimap< const std::wstring, double > >' == declarations.multimap_traits.remove_defaults( mm_v_i2mm_wstr2d ) ) + def test_hash_set( self ): + hs_v_int = self.global_ns.typedef( 'hs_v_int' ) + self.failUnless( 'hash_set< std::vector< int > >' + == declarations.hash_set_traits.remove_defaults( hs_v_int ) ) + hs_string = self.global_ns.typedef( 'hs_string' ) + self.failUnless( 'hash_set< std::string >' + == declarations.hash_set_traits.remove_defaults( hs_string ) ) + + def test_hash_multiset( self ): + mhs_v_int = self.global_ns.typedef( 'mhs_v_int' ) + self.failUnless( 'hash_multiset< std::vector< int > >' + == declarations.hash_multiset_traits.remove_defaults( mhs_v_int ) ) + mhs_string = self.global_ns.typedef( 'mhs_string' ) + self.failUnless( 'hash_multiset< std::string >' + == declarations.hash_multiset_traits.remove_defaults( mhs_string ) ) + + def test_hash_map( self ): + hm_i2d = self.global_ns.typedef( 'hm_i2d' ) + self.failUnless( 'hash_map< int, double >' + == declarations.hash_map_traits.remove_defaults( hm_i2d ) ) + hm_wstr2d = self.global_ns.typedef( 'hm_wstr2d' ) + self.failUnless( 'hash_map< std::wstring, double >' + == declarations.hash_map_traits.remove_defaults( hm_wstr2d ) ) + + def test_hash_multimap( self ): + hmm_i2d = self.global_ns.typedef( 'hmm_i2d' ) + self.failUnless( 'hash_multimap< int, double >' + == declarations.hash_multimap_traits.remove_defaults( hmm_i2d ) ) + hmm_wstr2d = self.global_ns.typedef( 'hmm_wstr2d' ) + self.failUnless( 'hash_multimap< const std::wstring, double >' + == declarations.hash_multimap_traits.remove_defaults( hmm_wstr2d ) ) + hmm_v_i2mm_wstr2d = self.global_ns.typedef( 'hmm_v_i2mm_wstr2d' ) + self.failUnless( 'hash_multimap< const std::vector< int >, const std::hash_multimap< const std::wstring, double > >' + == declarations.hash_multimap_traits.remove_defaults( hmm_v_i2mm_wstr2d ) ) + + def create_suite(): suite = unittest.TestSuite() suite.addTest( unittest.makeSuite(tester_t)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |