@@ -254,16 +254,30 @@ class container_traits_impl_t:
254
254
declaration( and not definition ) it parsers the class name in order to
255
255
extract all the information.
256
256
"""
257
- def __init__ ( self , container_name , element_type_index , element_type_typedef ):
257
+ def __init__ ( self
258
+ , container_name
259
+ , element_type_index
260
+ , element_type_typedef
261
+ , defaults_remover
262
+ , key_type_index = None
263
+ , key_type_typedef = None ):
258
264
"""
259
265
container_name - std container name
260
266
element_type_index - position of value\\ mapped type within template
261
267
arguments list
262
268
element_type_typedef - class typedef to the value\\ mapped type
269
+ key_type_index - position of key type within template arguments list
270
+ key_type_typedef - class typedef to the key type
263
271
"""
264
- self .name = container_name
272
+ self ._name = container_name
273
+ self .remove_defaults_impl = defaults_remover
265
274
self .element_type_index = element_type_index
266
275
self .element_type_typedef = element_type_typedef
276
+ self .key_type_index = key_type_index
277
+ self .key_type_typedef = key_type_typedef
278
+
279
+ def name (self ):
280
+ return self ._name
267
281
268
282
def get_container_or_none ( self , type ):
269
283
"""returns reference to the class declaration or None"""
@@ -280,7 +294,7 @@ def get_container_or_none( self, type ):
280
294
else :
281
295
return
282
296
283
- if not cls .name .startswith ( self .name + '<' ):
297
+ if not cls .name .startswith ( self .name () + '<' ):
284
298
return
285
299
286
300
for ns in std_namespaces :
@@ -295,7 +309,7 @@ def class_declaration( self, type ):
295
309
"""returns reference to the class declaration"""
296
310
cls = self .get_container_or_none ( type )
297
311
if not cls :
298
- raise TypeError ( 'Type "%s" is not instantiation of std::%s' % ( type .decl_string , self .name ) )
312
+ raise TypeError ( 'Type "%s" is not instantiation of std::%s' % ( type .decl_string , self .name () ) )
299
313
return cls
300
314
301
315
def element_type ( self , type ):
@@ -309,85 +323,44 @@ def element_type( self, type ):
309
323
ref = type_traits .impl_details .find_value_type ( cls .top_parent , value_type_str )
310
324
if None is ref :
311
325
raise RuntimeError ( "Unable to find out %s '%s' value type."
312
- % ( self .name , cls .decl_string ) )
326
+ % ( self .name () , cls .decl_string ) )
313
327
return ref
314
328
329
+ def remove_defaults ( self , type_or_string ):
330
+ name = type_or_string
331
+ if not isinstance ( type_or_string , types .StringTypes ):
332
+ name = self .class_declaration ( type_or_string ).name
333
+ if not self .remove_defaults_impl :
334
+ return name
335
+ no_defaults = self .remove_defaults_impl ( name )
336
+ if not no_defaults :
337
+ return name
338
+ else :
339
+ return no_defaults
315
340
341
+ list_traits = container_traits_impl_t ( 'list' , 0 , 'value_type' , defaults_eraser .erase_allocator )
316
342
317
- def create_traits_class ( container_name
318
- , element_type_index
319
- , element_type_typedef
320
- , remove_defaults_ = None ):
321
- """ creates concrete container traits class """
322
-
323
- impl_tmp = container_traits_impl_t ( container_name , element_type_index , element_type_typedef )
324
-
325
- class xxx_traits :
326
- """extract information from the container"""
327
-
328
- impl = None
329
-
330
- @staticmethod
331
- def name ():
332
- return xxx_traits .impl .name
333
-
334
- @staticmethod
335
- def is_my_case ( type ):
336
- """returns True if type is the container class, otherwise False"""
337
- return xxx_traits .impl .is_my_case ( type )
338
-
339
- @staticmethod
340
- def class_declaration ( type ):
341
- """returns reference to the container class"""
342
- return xxx_traits .impl .class_declaration ( type )
343
-
344
- @staticmethod
345
- def element_type ( type ):
346
- """returns reference to container name value\\ mapped type class"""
347
- return xxx_traits .impl .element_type ( type )
348
-
349
- @staticmethod
350
- def remove_defaults ( type_or_string ):
351
- name = None
352
- if not isinstance ( type_or_string , types .StringTypes ):
353
- name = xxx_traits .class_declaration ( type_or_string ).name
354
- else :
355
- name = type_or_string
356
- if not remove_defaults_ :
357
- return name
358
- no_defaults = remove_defaults_ ( name )
359
- if not no_defaults :
360
- return name
361
- else :
362
- return no_defaults
363
-
364
- xxx_traits .impl = impl_tmp
365
-
366
- return xxx_traits
367
-
368
- list_traits = create_traits_class ( 'list' , 0 , 'value_type' , defaults_eraser .erase_allocator )
369
-
370
- deque_traits = create_traits_class ( 'deque' , 0 , 'value_type' , defaults_eraser .erase_allocator )
343
+ deque_traits = container_traits_impl_t ( 'deque' , 0 , 'value_type' , defaults_eraser .erase_allocator )
371
344
372
- queue_traits = create_traits_class ( 'queue' , 0 , 'value_type' , defaults_eraser .erase_container )
345
+ queue_traits = container_traits_impl_t ( 'queue' , 0 , 'value_type' , defaults_eraser .erase_container )
373
346
374
- priority_queue_traits = create_traits_class ( 'priority_queue' , 0 , 'value_type' , defaults_eraser .erase_container_compare )
347
+ priority_queue_traits = container_traits_impl_t ( 'priority_queue' , 0 , 'value_type' , defaults_eraser .erase_container_compare )
375
348
376
- vector_traits = create_traits_class ( 'vector' , 0 , 'value_type' , defaults_eraser .erase_allocator )
349
+ vector_traits = container_traits_impl_t ( 'vector' , 0 , 'value_type' , defaults_eraser .erase_allocator )
377
350
378
- stack_traits = create_traits_class ( 'stack' , 0 , 'value_type' , defaults_eraser .erase_container )
351
+ stack_traits = container_traits_impl_t ( 'stack' , 0 , 'value_type' , defaults_eraser .erase_container )
379
352
380
- map_traits = create_traits_class ( 'map' , 1 , 'mapped_type' , defaults_eraser .erase_map_compare_allocator )
381
- multimap_traits = create_traits_class ( 'multimap' , 1 , 'mapped_type' , defaults_eraser .erase_map_compare_allocator )
353
+ map_traits = container_traits_impl_t ( 'map' , 1 , 'mapped_type' , defaults_eraser .erase_map_compare_allocator )
354
+ multimap_traits = container_traits_impl_t ( 'multimap' , 1 , 'mapped_type' , defaults_eraser .erase_map_compare_allocator )
382
355
383
- hash_map_traits = create_traits_class ( 'hash_map' , 1 , 'mapped_type' , defaults_eraser .erase_hashmap_compare_allocator )
384
- hash_multimap_traits = create_traits_class ( 'hash_multimap' , 1 , 'mapped_type' , defaults_eraser .erase_hashmap_compare_allocator )
356
+ hash_map_traits = container_traits_impl_t ( 'hash_map' , 1 , 'mapped_type' , defaults_eraser .erase_hashmap_compare_allocator )
357
+ hash_multimap_traits = container_traits_impl_t ( 'hash_multimap' , 1 , 'mapped_type' , defaults_eraser .erase_hashmap_compare_allocator )
385
358
386
- set_traits = create_traits_class ( 'set' , 0 , 'value_type' , defaults_eraser .erase_compare_allocator )
387
- multiset_traits = create_traits_class ( 'multiset' , 0 , 'value_type' , defaults_eraser .erase_compare_allocator )
359
+ set_traits = container_traits_impl_t ( 'set' , 0 , 'value_type' , defaults_eraser .erase_compare_allocator )
360
+ multiset_traits = container_traits_impl_t ( 'multiset' , 0 , 'value_type' , defaults_eraser .erase_compare_allocator )
388
361
389
- hash_set_traits = create_traits_class ( 'hash_set' , 0 , 'value_type' , defaults_eraser .erase_hash_allocator )
390
- hash_multiset_traits = create_traits_class ( 'hash_multiset' , 0 , 'value_type' , defaults_eraser .erase_hash_allocator )
362
+ hash_set_traits = container_traits_impl_t ( 'hash_set' , 0 , 'value_type' , defaults_eraser .erase_hash_allocator )
363
+ hash_multiset_traits = container_traits_impl_t ( 'hash_multiset' , 0 , 'value_type' , defaults_eraser .erase_hash_allocator )
391
364
392
365
container_traits = (
393
366
list_traits
0 commit comments