The iterator C function
mco_seq_next_TYPE()
is used to iterate sequences of the specified type. The function signature is:MCO_RET mco_seq_next_TYPE(mco_seq_iterator_h iterator, mco_TYPE* val);where TYPE is one of the types listed in the Analytics Functions page. The function extracts the next element value into argument val and returns
MCO_S_CURSOR_END
when there are no more elements in the sequence. After iterating through a sequence, before that iterator can be used again a reset function must be called to "rewind" the iterator position to the beginning of the sequence. The function signature has the following form:MCO_RET mco_seq_reset_iterator(mco_seq_iterator_h iterator);Depending on the type of function that was used to create the iterator, one of the following reset functions must be used:
mco_seq_reset_iterator() Reset the iterator position to the first element in the sequence; this iterator is "root" and it does not depend on other sequences, e.g. the result of a search or a sequence field iteration mco_seq_reset_unary_iterator() Reset the position for a unary iterator to the first element in the sequence; this iterator has one operand and will try to reset the iterator on which it depends, e.g. functions like mco_seq_abs_TYPE()
,mco_seq_neg_TYPE()
.mco_seq_reset_binary_iterator() Reset the position for a binary iterator to the first element in the sequence; this iterator has two operands and will try to reset both iterators on which it depends, e.g. functions mco_seq_add_TYPE()
,mco_seq_sub_TYPE()
.
Example
Following is an example code snippet demonstrating different types of iteration:
{ mco_trans_h trans; mco_cursor_t quote_cursor; Quote quote; mco_seq_iterator_t high_iterator, day_iterator, day_str_iterator; mco_date day; float high; char buff[15]; char symbol[MAX_SYMBOL_LEN]; MCO_RET rc; ... for (rc = mco_cursor_first(trans, "e_cursor); rc != MCO_S_CURSOR_END; rc = mco_cursor_next(trans, "e_cursor)) { Quote_from_cursor(trans, "e_cursor, "e); Quote_high_iterator("e, &high_iterator); Quote_day_iterator("e, &day_iterator); Quote_day_str_iterator("e, &day_str_iterator)); ... while ((rc = mco_seq_next_uint4(&day_iterator, &day)) != MCO_S_CURSOR_END) { rc = mco_seq_next_float(&high_iterator, &high); rc = mco_seq_next_char(&day_str_iterator, buff); printf("%s[%u(%s)]: %f\n", symbol, day, buff, high); } ... } ... }