[pygccxml-commit] SF.net SVN: pygccxml:[1407] pygccxml_dev
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2008-08-26 08:55:48
|
Revision: 1407
http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1407&view=rev
Author: roman_yakovenko
Date: 2008-08-26 08:55:58 +0000 (Tue, 26 Aug 2008)
Log Message:
-----------
simplify container_traits functionality
Modified Paths:
--------------
pygccxml_dev/pygccxml/declarations/container_traits.py
pygccxml_dev/unittests/find_container_traits_tester.py
Modified: pygccxml_dev/pygccxml/declarations/container_traits.py
===================================================================
--- pygccxml_dev/pygccxml/declarations/container_traits.py 2008-08-26 05:14:49 UTC (rev 1406)
+++ pygccxml_dev/pygccxml/declarations/container_traits.py 2008-08-26 08:55:58 UTC (rev 1407)
@@ -254,17 +254,31 @@
declaration( and not definition ) it parsers the class name in order to
extract all the information.
"""
- def __init__( self, container_name, element_type_index, element_type_typedef ):
+ def __init__( self
+ , container_name
+ , element_type_index
+ , element_type_typedef
+ , defaults_remover
+ , key_type_index=None
+ , key_type_typedef=None ):
"""
container_name - std container name
element_type_index - position of value\\mapped type within template
arguments list
element_type_typedef - class typedef to the value\\mapped type
+ key_type_index - position of key type within template arguments list
+ key_type_typedef - class typedef to the key type
"""
- self.name = container_name
+ self._name = container_name
+ self.remove_defaults_impl = defaults_remover
self.element_type_index = element_type_index
self.element_type_typedef = element_type_typedef
+ self.key_type_index = key_type_index
+ self.key_type_typedef = key_type_typedef
+ def name(self):
+ return self._name
+
def get_container_or_none( self, type ):
"""returns reference to the class declaration or None"""
type = type_traits.remove_alias( type )
@@ -280,7 +294,7 @@
else:
return
- if not cls.name.startswith( self.name + '<' ):
+ if not cls.name.startswith( self.name() + '<' ):
return
for ns in std_namespaces:
@@ -295,7 +309,7 @@
"""returns reference to the class declaration"""
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 ) )
+ raise TypeError( 'Type "%s" is not instantiation of std::%s' % ( type.decl_string, self.name() ) )
return cls
def element_type( self, type ):
@@ -309,86 +323,45 @@
ref = type_traits.impl_details.find_value_type( cls.top_parent, value_type_str )
if None is ref:
raise RuntimeError( "Unable to find out %s '%s' value type."
- % ( self.name, cls.decl_string ) )
+ % ( self.name(), cls.decl_string ) )
return ref
+ def remove_defaults( self, type_or_string ):
+ name = type_or_string
+ if not isinstance( type_or_string, types.StringTypes ):
+ name = self.class_declaration( type_or_string ).name
+ if not self.remove_defaults_impl:
+ return name
+ no_defaults = self.remove_defaults_impl( name )
+ if not no_defaults:
+ return name
+ else:
+ return no_defaults
+list_traits = container_traits_impl_t( 'list', 0, 'value_type', defaults_eraser.erase_allocator )
-def create_traits_class( container_name
- , element_type_index
- , element_type_typedef
- , remove_defaults_=None ):
- """ creates concrete container traits class """
+deque_traits = container_traits_impl_t( 'deque', 0, 'value_type', defaults_eraser.erase_allocator )
- impl_tmp = container_traits_impl_t( container_name, element_type_index, element_type_typedef )
+queue_traits = container_traits_impl_t( 'queue', 0, 'value_type', defaults_eraser.erase_container )
- class xxx_traits:
- """extract information from the container"""
+priority_queue_traits = container_traits_impl_t( 'priority_queue', 0, 'value_type', defaults_eraser.erase_container_compare )
- impl = None
+vector_traits = container_traits_impl_t( 'vector', 0, 'value_type', defaults_eraser.erase_allocator )
- @staticmethod
- def name():
- return xxx_traits.impl.name
+stack_traits = container_traits_impl_t( 'stack', 0, 'value_type', defaults_eraser.erase_container )
- @staticmethod
- def is_my_case( type ):
- """returns True if type is the container class, otherwise False"""
- return xxx_traits.impl.is_my_case( type )
+map_traits = container_traits_impl_t( 'map', 1, 'mapped_type', defaults_eraser.erase_map_compare_allocator )
+multimap_traits = container_traits_impl_t( 'multimap', 1, 'mapped_type', defaults_eraser.erase_map_compare_allocator )
- @staticmethod
- def class_declaration( type ):
- """returns reference to the container class"""
- return xxx_traits.impl.class_declaration( type )
+hash_map_traits = container_traits_impl_t( 'hash_map', 1, 'mapped_type', defaults_eraser.erase_hashmap_compare_allocator )
+hash_multimap_traits = container_traits_impl_t( 'hash_multimap', 1, 'mapped_type', defaults_eraser.erase_hashmap_compare_allocator )
- @staticmethod
- def element_type( type ):
- """returns reference to container name value\\mapped type class"""
- return xxx_traits.impl.element_type( type )
+set_traits = container_traits_impl_t( 'set', 0, 'value_type', defaults_eraser.erase_compare_allocator)
+multiset_traits = container_traits_impl_t( 'multiset', 0, 'value_type', defaults_eraser.erase_compare_allocator )
- @staticmethod
- def remove_defaults( type_or_string ):
- name = None
- if not isinstance( type_or_string, types.StringTypes ):
- name = xxx_traits.class_declaration( type_or_string ).name
- else:
- name = type_or_string
- if not remove_defaults_:
- return name
- no_defaults = remove_defaults_( name )
- if not no_defaults:
- return name
- else:
- return no_defaults
-
- xxx_traits.impl = impl_tmp
-
- return xxx_traits
+hash_set_traits = container_traits_impl_t( 'hash_set', 0, 'value_type', defaults_eraser.erase_hash_allocator )
+hash_multiset_traits = container_traits_impl_t( 'hash_multiset', 0, 'value_type', defaults_eraser.erase_hash_allocator )
-list_traits = create_traits_class( 'list', 0, 'value_type', defaults_eraser.erase_allocator )
-
-deque_traits = create_traits_class( 'deque', 0, 'value_type', defaults_eraser.erase_allocator )
-
-queue_traits = create_traits_class( 'queue', 0, 'value_type', defaults_eraser.erase_container )
-
-priority_queue_traits = create_traits_class( 'priority_queue', 0, 'value_type', defaults_eraser.erase_container_compare )
-
-vector_traits = create_traits_class( 'vector', 0, 'value_type', defaults_eraser.erase_allocator )
-
-stack_traits = create_traits_class( 'stack', 0, 'value_type', defaults_eraser.erase_container )
-
-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', 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', 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
, deque_traits
Modified: pygccxml_dev/unittests/find_container_traits_tester.py
===================================================================
--- pygccxml_dev/unittests/find_container_traits_tester.py 2008-08-26 05:14:49 UTC (rev 1406)
+++ pygccxml_dev/unittests/find_container_traits_tester.py 2008-08-26 08:55:58 UTC (rev 1407)
@@ -23,14 +23,14 @@
tester_t.global_ns = declarations.get_global_namespace( decls )
tester_t.global_ns.init_optimizer()
- def __cmp_traits( self, typedef, expected, partial_name ):
+ def __cmp_traits( self, typedef, expected, partial_name):
if isinstance( typedef, str ):
typedef = self.global_ns.typedef( typedef )
traits = declarations.find_container_traits( typedef )
self.failUnless( traits, 'container traits for "%s" not found' % str( typedef ) )
self.failUnless( traits is expected
- , 'container "%s", expected %s, got %s'
- % ( str(typedef), expected.__name__, traits.__name__ ) )
+ , 'container "%s", expected %s_traits, got %s_traits'
+ % ( str(typedef), expected.name(), traits.name() ) )
cls = declarations.remove_declarated( typedef )
self.failUnless( cls.container_traits is expected )
self.failUnless( cls.partial_name == partial_name )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|