class sfile_instance_iterator

Iterator over the instances ( sfileinst ) of a source file ( sfile ).

Initialize with sfile.instances().

Use as you would any other Python iterator. For example:

# set up sfile sf, then...
for e in sf.instances():
    print('sfileinst: ', e)

sfile_instance_iterator Details

class cs.sfile_instance_iterator

Iterator over the instances ( sfileinst ) of a source file ( sfile ).

__eq__(other)

Iterator equality.

Parameters:other (sfile_instance_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'))
>>> inst_iterA = sf.instances()
>>> inst_iterB = sf.instances()
>>> inst_iterA == inst_iterB
True
>>> next(inst_iterA)
<cs.sfileinst C:\alex\test\apitest.cpp>
>>> inst_iterA == inst_iterB
False
__iter__()

Get the iterator object.

Return type:sfile_instance_iterator
Returns:self.
>>> sf = next(s for s in project.current().sfiles()
...           if s.name().endswith('apitest.h'))
>>> for sfi in sf.instances():  # iteration managed by sfile_instance_iterator.__iter__()
...                             # and sfile_instance_iterator.__next__()
...    print('compunit=', sfi.get_compunit())
...    print('path=', ' | '.join([str(s) for s in sfi.include_tree_path()]))
...    print('---')
...
compunit= C:\alex\test\apitest.cpp
path= C:\alex\test\apitest.cpp | C:\alex\test\apitest.h
---
__ne__(other)

Iterator inequality.

Parameters:other (sfile_instance_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'))
>>> inst_iterA = sf.instances()
>>> inst_iterB = sf.instances()
>>> inst_iterA != inst_iterB
False
>>> next(inst_iterA)
<cs.sfileinst C:\alex\test\apitest.cpp>
>>> inst_iterA != inst_iterB
True
__next__()

Iterator dereference operator.

Return type:sfileinst
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)
>>> for sfi in sf.instances():  # iteration managed by sfile_instance_iterator.__iter__()
...                             # and sfile_instance_iterator.__next__()
...    print('compunit=', sfi.get_compunit())
...    print('path=', ' | '.join([str(s) for s in sfi.include_tree_path()]))
...    print('---')
...
compunit= C:\\alex\test\apitest.cpp
path= C:\\alex\test\apitest.cpp | C:\\alex\test\apitest.h
---
__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.h'))
>>> inst = sf.instances()
>>> repr(inst)
'<cs.sfile_instance_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.h'))
>>> inst = sf.instances()
>>> str(inst)
'<cs.sfile_instance_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.h'))
>>> inst = sf.instances()
>>> inst.at_end()
False
>>> next(inst)
<cs.sfileinst C:\alex\test\apitest.h>
>>> inst.at_end()
True