class xr_definition_iterator¶
Iterator over the definitions ( xr_tuple ) of a token.
Initialize with sfile.token_definition_iterator().
Use as you would any other Python iterator. For example:
# set up sfile sf, then...
for e in sf.token_definition_iterator(36, "foo"):
print('xr_tuple: ', e)
xr_definition_iterator Members¶
| Constructors | none |
| Methods | __eq__(), __iter__(), __ne__(), __next__(), __repr__(), __str__(), at_end() |
xr_definition_iterator Details¶
-
class
cs.xr_definition_iterator¶ Iterator over the definitions (
xr_tuple) of a token.-
__eq__(other)¶ Iterator equality.
Parameters: other ( xr_definition_iterator) –Return type: bool Returns: Trueif and only ifselfandotherare at the same position. Behavior is undefined ifselfandotherare not iterating over the same collection.>>> sf = next(s for s in project.current().sfiles() ... if s.name().endswith('apitest.cpp')) >>> sfi = sf.arbitrary_instance() >>> iuse = next(i for i in range(1,sfi.line_count()+1) # find line containing 'i++' ... if 'i++' in sfi.read_line(i)) >>> defiter_A = sf.token_definition_iterator(iuse, 'i') >>> defiter_B = sf.token_definition_iterator(iuse, 'i') >>> defiter_A == defiter_B True >>> for tup in defiter_A: ... if tup.get_kind_role() == xr_kind_role.VAR_PARAMETER_DEFINITION: ... break ... >>> defiter_A == defiter_B False
-
__iter__()¶ Get the iterator object.
Return type: xr_definition_iteratorReturns: self.>>> sf = next(s for s in project.current().sfiles() ... if s.name().endswith('apitest.cpp')) >>> sfi = sf.arbitrary_instance() >>> iuse = next(i for i in range(1,sfi.line_count()+1) # find line containing 'i++' ... if 'i++' in sfi.read_line(i)) >>> defiter = sf.token_definition_iterator(iuse, 'i') >>> for tup in defiter: # iteration is managed by xr_definition_iterator.__iter__() and xr_definition_iterator.__next__() ... print(tup.get_file(), tup.get_line()) ... C:\alex\test\apitest.cpp 9
-
__ne__(other)¶ Iterator inequality.
Parameters: other ( xr_definition_iterator) – The iterator to compare against.Return type: bool Returns: Falseif and only ifselfandotherare at the same position. Behavior is undefined ifselfandotherare not iterating over the same collection.>>> sf = next(s for s in project.current().sfiles() ... if s.name().endswith('apitest.cpp')) >>> sfi = sf.arbitrary_instance() >>> iuse = next(i for i in range(1,sfi.line_count()+1) # find line containing 'i++' ... if 'i++' in sfi.read_line(i)) >>> defiter_A = sf.token_definition_iterator(iuse, 'i') >>> defiter_B = sf.token_definition_iterator(iuse, 'i') >>> defiter_A != defiter_B False >>> for tup in defiter_A: ... if tup.get_kind_role() == xr_kind_role.VAR_PARAMETER_DEFINITION: ... break ... >>> defiter_A != defiter_B True
-
__next__()¶ Iterator dereference operator.
Return type: xr_tupleReturns: The element at the current iterator position. Raises: StopIteration- Side effects: Modifies
self.
The typical use is implicit:
>>> for item in myiter: ... (do something to item)
>>> sf = next(s for s in project.current().sfiles() ... if s.name().endswith('apitest.cpp')) >>> sfi = sf.arbitrary_instance() >>> iuse = next(i for i in range(1,sfi.line_count()+1) # find line containing 'i++' ... if 'i++' in sfi.read_line(i)) >>> defiter = sf.token_definition_iterator(iuse, 'i') >>> for tup in defiter: # iteration is managed by xr_definition_iterator.__iter__() and xr_definition_iterator.__next__() ... print(tup.get_file(), tup.get_line()) ... C:\alex\test\apitest.cpp 9
- Side effects: Modifies
-
__repr__()¶ Get a representation of the iterator that includes information useful for debugging.
Return type: str Returns: The string representation. >>> sf = next(s for s in project.current().sfiles() ... if s.name().endswith('apitest.cpp')) >>> sfi = sf.arbitrary_instance() >>> iuse = next(i for i in range(1,sfi.line_count()+1) # find line containing 'i++' ... if 'i++' in sfi.read_line(i)) >>> defiter = sf.token_definition_iterator(iuse, 'i') >>> repr(defiter) '<cs.xr_definition_iterator begin>'
-
__str__()¶ Get a simple string representation of the iterator.
Return type: str Returns: The string representation. >>> sf = next(s for s in project.current().sfiles() ... if s.name().endswith('apitest.cpp')) >>> sfi = sf.arbitrary_instance() >>> iuse = next(i for i in range(1,sfi.line_count()+1) # find line containing 'i++' ... if 'i++' in sfi.read_line(i)) >>> defiter = sf.token_definition_iterator(iuse, 'i') >>> str(defiter) '<cs.xr_definition_iterator begin>'
-
at_end()¶ Check: is the iterator at the end of the structure?
Return type: bool Returns: Trueif the iterator is at the end of the structure (there are no more elements to iterate over),Falseotherwise.>>> sf = next(s for s in project.current().sfiles() ... if s.name().endswith('apitest.cpp')) >>> sfi = sf.arbitrary_instance() >>> iuse = next(i for i in range(1,sfi.line_count()+1) # find line containing 'i++' ... if 'i++' in sfi.read_line(i)) >>> defiter = sf.token_definition_iterator(iuse, 'i') >>> defiter.at_end() False
-