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 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:True if and only if self and other are at the same position. Behavior is undefined if self and other are 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_iterator
Returns: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:False if and only if self and other are at the same position. Behavior is undefined if self and other are 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_tuple
Returns: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
__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:True if the iterator is at the end of the structure (there are no more elements to iterate over), False otherwise.
>>> 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