The iterator C++ Sequence methods and operator are used to iterate or return the count of the object's sequence elements.
The iterator operation can be one of the following:
bool next(T& val) also T operator++() Extract the next sequence value (may return &McoSql::Null
value if it encounters a null in the sequence)void reset() Reset the iterator position to the first element in the sequence; this iterator must be a "root", i.e. it does not depend on other sequences such as the result of a search or a sequence field iteration uint8 count() const Return the count of elements in the object's materialized sequence. Example
Following is an example code snippet demonstrating different types of sequence iteration, note the use of
next()
and operator++
:{ mco_trans_h trans; mco_date day; mco_cursor_t quote_cursor; Quote quote; MCO_RET rc; rc = mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &trans); if ( MCO_S_OK == rc ) { /* Iterate through all Quote objects */ Quote::by_sym::cursor(trans, "e_cursor); for (rc = mco_cursor_first(trans, "e_cursor); rc != MCO_S_CURSOR_END; rc = mco_cursor_next(trans, "e_cursor)) { /* Get current object */ quote.from_cursor(trans, "e_cursor); /* Initialize iterators */ Sequence<uint4> day_iterator = quote.day_iterator(); Sequence<float> high_iterator = quote.high_iterator(); Sequence< Char<15> > day_str_iterator = quote.day_str_iterator(); /* Iterate sequence fields */ while (day_iterator.next(day)) { Char<MAX_SYMBOL_LEN> symbol = quote.symbol; Char<15> day_str = ++day_str_iterator; printf("%s[%u(%s)]: %f\n", (char*)symbol, day, (char*)day_str, ++high_iterator); } } mco_trans_commit(trans); } }