1
2
3
4
5
6 """
7 defines class L{mdecl_wrapper_t} that allows to work on set of declarations,
8 as it was one declaration.
9
10 The L{class<mdecl_wrapper_t>} allows user to not write "for" loops within the code.
11 """
12
13 import os
14
16 """Internal class used to call some function of objects"""
18 """creates call_redirector_t instance.
19
20 @param name: name of method, to be called on every object in C{decls} list
21 @param decls: list of objects
22 """
23 object.__init__( self )
24 self.name = name
25 self.decls = decls
26
27 - def __call__( self, *arguments, **keywords ):
28 """calls method C{self.name} on every object within C{self.decls} list"""
29 for d in self.decls:
30 callable_ = getattr(d, self.name)
31 callable_( *arguments, **keywords )
32
34 """Multiple declarations wrapper.
35
36 The main purpose of this class is to allow an user to work on many
37 declarations, as they were only one single declaration.
38
39 Example:
40 mb = module_builder_t( ... )
41 #lets say we want to exclude all member functions, that returns reference to int:
42 mb.member_functions( return_type='int &' ).exclude()
43
44 "exclude" function will be called on every function that match the criteria.
45 """
46
48 """@param decls: list of declarations to operate on.
49 @type decls: list of L{declaration wrappers<decl_wrapper_t>}
50 """
51 object.__init__( self )
52 self.__dict__['declarations'] = decls
53
56
58 """returns the number of declarations"""
59 return len( self.declarations )
60
62 """provides access to declaration"""
63 return self.declarations[index]
64
67
69 invalid_decls = filter( lambda d: not hasattr( d, name ), self.declarations )
70 sep = os.linesep + ' '
71 if invalid_decls:
72 raise RuntimeError( "Next declarations don't have '%s' attribute: %s"
73 % ( name, sep.join( map( str, invalid_decls ) ) ) )
74
76 """Updates the value of attribute on all declarations.
77 @param name: name of attribute
78 @param value: new value of attribute
79 """
80 self.__ensure_attribute( name )
81 for d in self.declarations:
82 setattr( d, name, value )
83
88
91
93 l = []
94 for d in self.declarations:
95 l.append( d )
96 return l
97