|
| constructor (hash< auto > h) |
| Creates the hash list iterator object. More...
|
|
| constructor () |
| Creates an empty hash list iterator object. More...
|
|
| copy () |
| Creates a copy of the HashListIterator object, iterating the same object as the original and in the same position. More...
|
|
bool | empty () |
| returns True if the result list is empty; False if not More...
|
|
bool | first () |
| returns True if on the first element of the list More...
|
|
auto | getKeyValue (string key) |
| Returns the current value for the column given as an argument. More...
|
|
hash< auto > | getRow () |
| returns the current row value as a hash or throws an INVALID-ITERATOR exception if the iterator is invalid More...
|
|
hash< auto > | getValue () |
| returns the current row value as a hash or throws an INVALID-ITERATOR exception if the iterator is invalid More...
|
|
int | index () |
| returns the current iterator position in the list or -1 if not pointing at a valid element More...
|
|
bool | last () |
| returns True if on the last element of the list More...
|
|
int | max () |
| returns the number of elements in the list More...
|
|
auto | memberGate (string key) |
| This method allows the iterator to be dereferenced directly as a hash for the current row being iterated, as memberGate methods are called implicitly when an unknown member is accessed from outside the class. More...
|
|
bool | next () |
| Moves the current position to the next element in the result list; returns False if there are no more elements; if the iterator is not pointing at a valid element before this call, the iterator will be positioned on the first element in the list if the list is not empty. More...
|
|
bool | prev () |
| Moves the current position to the previous element in the result list; returns False if there are no more elements; if the iterator is not pointing at a valid element before this call, the iterator will be positioned on the last element in the list if the list is not empty. More...
|
|
| reset () |
| Reset the iterator instance to its initial state. More...
|
|
bool | set (int pos) |
| sets the new position in the result list; if the position is invalid then the method returns False, meaning the iterator is not valid, otherwise it returns True More...
|
|
bool | valid () |
| returns True if the iterator is currently pointing at a valid element, False if not More...
|
|
This class an iterator class for hashes of lists as returned by Qore::SQL::Datasource::select() and Qore::SQL::DatasourcePool::select(), both of which return hashes with keys giving column names where the key values are lists of column values.
This class can be used as a more flexible alternative to the context statement.
Call HashListIterator::next() to iterate through the lists of column values assigned to each hash key; do not use the iterator if HashListIterator::next() returns False. A result list can be iterated in reverse order by calling HashListIterator::prev() instead of HashListIterator::next()
- Example: HashListIterator basic usge
hash<auto> data = {
"column1": (1, 2, 3,),
"column2": ("a", "b", "c",),
"column3": "constant",
};
HashListIterator it(data);
while (it.next()) {
printf(
"iter %d: getValue: %y; getKeyValue('column1'): %y\n",
it.index(), it.getValue(), it.getKeyValue('column1'));
}
iter 0: getValue: {column1: 1, column2: "a", column3: "constant"}; getKeyValue('column1'): 1
iter 1: getValue: {column1: 2, column2: "b", column3: "constant"}; getKeyValue('column1'): 2
iter 2: getValue: {column1: 3, column2: "c", column3: "constant"}; getKeyValue('column1'): 3
string printf(string fmt,...)
Outputs the string passed to standard output, using the first argument as a format string; does not e...
- Note
- A hash with all non-list values will be iterated as if each key value were a single element list
- A hash with mixed lists and single values will have the single values used as the repeating value for every element in the list (as in the above example), however all lists must be of the same size or a runtime exception will be raised
- A hash with empty lists and constants will not be iterated; in this case the constant values will be ignored; values with lists determine the number of times the data structure will be iterated
- In general, the HashListIterator class is not designed to be accessed from multiple threads; it was created without locking for fast and efficient use when used from a single thread. For methods that would be unsafe to use in another thread, any use of such methods in threads other than the thread where the constructor was called will cause an
ITERATOR-THREAD-ERROR
to be thrown.
- See also
- HashListReverseIterator
bool Qore::HashListIterator::next |
( |
| ) |
|
|
virtual |
Moves the current position to the next element in the result list; returns False if there are no more elements; if the iterator is not pointing at a valid element before this call, the iterator will be positioned on the first element in the list if the list is not empty.
This method will return True again after it returns False once if list is not empty, otherwise it will always return False. The iterator object should not be used after this method returns False
- Returns
- False if there are no more elements in the result list (in which case the iterator object is invalid and should not be used); True if successful (meaning that the iterator object is valid)
- Example:
while (i.next()) {
printf(
" + row %d: %y\n", i.index(), i.getValue());
}
- Exceptions
-
ITERATOR-THREAD-ERROR | this exception is thrown if this method is called from any thread other than the thread that created the object |
Implements Qore::AbstractIterator.
Reimplemented in Qore::HashListReverseIterator.
bool Qore::HashListIterator::prev |
( |
| ) |
|
|
virtual |
Moves the current position to the previous element in the result list; returns False if there are no more elements; if the iterator is not pointing at a valid element before this call, the iterator will be positioned on the last element in the list if the list is not empty.
This method will return True again after it returns False once if the list is not empty, otherwise it will always return False. The iterator object should not be used after this method returns False
- Returns
- False if there are no more elements in the result list (in which case the iterator object is invalid and should not be used); True if successful (meaning that the iterator object is valid)
- Example:
while (i.prev()) {
printf(
" + row %d: %y\n", i.index(), i.getValue());
}
- Exceptions
-
ITERATOR-THREAD-ERROR | this exception is thrown if this method is called from any thread other than the thread that created the object |
Implements Qore::AbstractBidirectionalIterator.
Reimplemented in Qore::HashListReverseIterator.