class xr_occurrence_iterator¶
Iterator over the occurrences ( xr_tuple ) of a token.
Initialize with sfile.token_occurrence_iterator().
Use as you would any other Python iterator. For example:
# set up sfile sf, then...
for e in sf.token_occurrence_iterator(36, "foo"):
print('xr_tuple: ', e)
xr_occurrence_iterator Members¶
| Constructors | none |
| Methods | __eq__(), __iter__(), __ne__(), __next__(), __repr__(), __str__(), at_end(), get_matched_count(), get_scanned_count(), get_unscanned_count() |
xr_occurrence_iterator Details¶
-
class
cs.xr_occurrence_iterator¶ Iterator over the occurrences (
xr_tuple) of a token.-
__eq__(other)¶ Iterator equality.
Parameters: other ( xr_occurrence_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() >>> mmdef = next(i for i in range(1,sfi.line_count()+1) ... if 'mymalloc(int i)' in sfi.read_line(i)) >>> occ_iterA = sf.token_occurrence_iterator(mmdef, 'mymalloc') >>> occ_iterB = sf.token_occurrence_iterator(mmdef, 'mymalloc') >>> occ_iterA == occ_iterB True >>> for tup in occ_iterA: ... print(tup.get_kind_role(), tup.get_file(), tup.get_line()) ... func_definition C:\alex\test\apitest.cpp 3 func_call C:\alex\test\apitest.cpp 15 func_call C:\alex\test\apitest.cpp 37 >>> occ_iterA == occ_iterB False
-
__iter__()¶ Get the iterator object.
Return type: xr_occurrence_iteratorReturns: self.>>> sf = next(s for s in project.current().sfiles() ... if s.name().endswith('apitest.cpp')) >>> sfi = sf.arbitrary_instance() >>> mmdef = next(i for i in range(1,sfi.line_count()+1) ... if 'mymalloc(int i)' in sfi.read_line(i)) >>> occ_iter = sf.token_occurrence_iterator(mmdef, 'mymalloc') >>> for tup in occ_iter: # iteration managed by xr_occurrence_iterator.__iter__() ... # and xr_occurrence_iterator.__next__() ... print(tup.get_kind_role(), tup.get_file(), tup.get_line()) ... func_definition C:\alex\test\apitest.cpp 3 func_call C:\alex\test\apitest.cpp 15 func_call C:\alex\test\apitest.cpp 37
-
__ne__(other)¶ Iterator inequality.
Parameters: other ( xr_occurrence_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() >>> mmdef = next(i for i in range(1,sfi.line_count()+1) ... if 'mymalloc(int i)' in sfi.read_line(i)) >>> occ_iterA = sf.token_occurrence_iterator(mmdef, 'mymalloc') >>> occ_iterB = sf.token_occurrence_iterator(mmdef, 'mymalloc') >>> occ_iterA != occ_iterB False >>> for tup in occ_iterA: ... print(tup.get_kind_role(), tup.get_file(), tup.get_line()) ... func_definition C:\alex\test\apitest.cpp 3 func_call C:\alex\test\apitest.cpp 15 func_call C:\alex\test\apitest.cpp 37 >>> occ_iterA != occ_iterB 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() >>> mmdef = next(i for i in range(1,sfi.line_count()+1) ... if 'mymalloc(int i)' in sfi.read_line(i)) >>> occ_iter = sf.token_occurrence_iterator(mmdef, 'mymalloc') >>> for tup in occ_iter: # iteration managed by xr_occurrence_iterator.__iter__() ... # and xr_occurrence_iterator.__next__() ... print(tup.get_kind_role(), tup.get_file(), tup.get_line()) ... func_definition C:\alex\test\apitest.cpp 3 func_call C:\alex\test\apitest.cpp 15 func_call C:\alex\test\apitest.cpp 37
- 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() >>> mmdef = next(i for i in range(1,sfi.line_count()+1) ... if 'mymalloc(int i)' in sfi.read_line(i)) >>> occ_iter = sf.token_occurrence_iterator(mmdef, 'mymalloc') >>> repr(occ_iter) '<cs.xr_occurrence_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() >>> mmdef = next(i for i in range(1,sfi.line_count()+1) ... if 'mymalloc(int i)' in sfi.read_line(i)) >>> occ_iter = sf.token_occurrence_iterator(mmdef, 'mymalloc') >>> str(occ_iter) '<cs.xr_occurrence_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() >>> mmdef = next(i for i in range(1,sfi.line_count()+1) ... if 'mymalloc(int i)' in sfi.read_line(i)) >>> occ_iter = sf.token_occurrence_iterator(mmdef, 'mymalloc') >>> occ_iter.at_end() False >>> for tup in occ_iter: ... print(tup.get_kind_role(), tup.get_file(), tup.get_line()) ... func_definition C:\alex\test\apitest.cpp 3 func_call C:\alex\test\apitest.cpp 15 func_call C:\alex\test\apitest.cpp 37 >>> occ_iter.at_end() True
-
get_matched_count()¶ Get the number of tuples (
xr_tuple) in the query result set forself.Return type: int Returns: The number of tuples in the query result set. Raises: result.ERROR_INVALID_ARGUMENTIfselfwas initialized with asfile.token_occurrence_iterator()call whoseflagsargument did not includexr_occ_iter_flags.POPULATE_COUNTERS, or ifselfwas not initialized withsfile.token_occurrence_iterator()at all.Note that the return value may grow as iteration progresses. For the final value, call after at_end() returns
True.>>> sf = next(s for s in project.current().sfiles() ... if s.name().endswith('apitest.cpp')) >>> sfi = sf.arbitrary_instance() >>> mmdef = next(i for i in range(1,sfi.line_count()+1) ... if 'mymalloc(int i)' in sfi.read_line(i)) >>> occ_iter = sf.token_occurrence_iterator(mmdef, 'mymalloc', 0, xr_occ_iter_flags.POPULATE_COUNTERS) >>> for tup in occ_iter: ... print(tup.get_kind_role(), tup.get_file(), tup.get_line()) ... func_definition C:\alex\test\apitest.cpp 3 func_call C:\alex\test\apitest.cpp 15 func_call C:\alex\test\apitest.cpp 37 >>> occ_iter.get_matched_count() 3
-
get_scanned_count()¶ Get the total number of tuples (
xr_tuple) examined while retrieving the set to be iterated over byself.Return type: int Returns: The total number of tuples examined: the tuples enumerated by xr_occurrence_iterator.get_matched_count(), plus all tuples examined but discarded as non-matching.Raises: result.ERROR_INVALID_ARGUMENTIfselfwas initialized with asfile.token_occurrence_iterator()call whoseflagsargument did not includexr_occ_iter_flags.POPULATE_COUNTERS, or ifselfwas not initialized withsfile.token_occurrence_iterator()at all.Note that the return value may grow as iteration progresses. For the final value, call after at_end() returns
True.>>> sf = next(s for s in project.current().sfiles() ... if s.name().endswith('apitest.cpp')) >>> sfi = sf.arbitrary_instance() >>> mmdef = next(i for i in range(1,sfi.line_count()+1) ... if 'mymalloc(int i)' in sfi.read_line(i)) >>> occ_iter = sf.token_occurrence_iterator(mmdef, 'mymalloc', 0, xr_occ_iter_flags.POPULATE_COUNTERS) >>> for tup in occ_iter: ... print(tup.get_kind_role(), tup.get_file(), tup.get_line()) ... func_definition C:\alex\test\apitest.cpp 3 func_call C:\alex\test\apitest.cpp 15 func_call C:\alex\test\apitest.cpp 37 >>> occ_iter.get_scanned_count() 5
-
get_unscanned_count()¶ Get the number of tuples (
xr_tuple) that were indexed for examination but ultimately not examined while retrieving the set to be iterated over byself.Return type: int Returns: The total number of tuples indexed for examination but ultimately not examined. Raises: result.ERROR_INVALID_ARGUMENTIfselfwas initialized with asfile.token_occurrence_iterator()call whoseflagsargument did not includexr_occ_iter_flags.POPULATE_COUNTERS, or ifselfwas not initialized withsfile.token_occurrence_iterator()at all.Note that the return value may grow as iteration progresses. For the final value, call after at_end() returns
True.>>> sf = next(s for s in project.current().sfiles() ... if s.name().endswith('apitest.cpp')) >>> sfi = sf.arbitrary_instance() >>> mmdef = next(i for i in range(1,sfi.line_count()+1) ... if 'mymalloc(int i)' in sfi.read_line(i)) >>> occ_iter = sf.token_occurrence_iterator(mmdef, 'mymalloc', 0, xr_occ_iter_flags.POPULATE_COUNTERS) >>> for tup in occ_iter: ... print(tup.get_kind_role(), tup.get_file(), tup.get_line()) ... func_definition C:\alex\test\apitest.cpp 3 func_call C:\alex\test\apitest.cpp 15 func_call C:\alex\test\apitest.cpp 37 >>> occ_iter.get_unscanned_count() 0
-