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 Members¶
| Constructors | none |
| Methods | __eq__(), __iter__(), __ne__(), __next__(), __repr__(), __str__(), at_end() |
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: 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')) >>> 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_iteratorReturns: 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: 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')) >>> 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: sfileinstReturns: 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 ---
- 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.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: 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.h')) >>> inst = sf.instances() >>> inst.at_end() False >>> next(inst) <cs.sfileinst C:\alex\test\apitest.h> >>> inst.at_end() True
-