The following conditional C++ methods apply the object's Boolean sequence to the input sequence(s). These methods are of the following types:
- Ternary operations iif() and cond(), which take two input sequence arguments then and else, and produce a result sequence of the same type by applying the
booleanelement in the object's condition sequence.- filter(), which returns a sequence of the same type as input with only the elements corresponding to
trueelements in the object's condition sequence.- filterPos(), which returns an integer sequence with the positions of the
trueelements in the object's condition sequence.The operation can be one of the following:
Sequence<R> iif(Sequence<R> const& then, Sequence<R> const& else) constChooses the element of the then sequence or the else sequence depending on the Boolean value of the element of the object's condition sequence. All three sequences are traversed at the same speed (if the element of the then sequence is used, then the element of the else sequence is skipped and vice versa). (Please see the Ternary Operations page for further details.)Sequence<R> cond(Sequence<R> const& then, Sequence<R> const& otherwise) constChooses the element of the then sequence or the else sequence depending on the Boolean value of the element of the object's condition sequence. Unlikeiif(), the position in the sequence not used is not changed. (Please see the Ternary Operations page for further details.)Sequence<T> filter(Sequence<mco_seq_bool> const& condition) constReturns a sequence of the same type with only the elements corresponding totrueelements in the object's condition sequence.Sequence<mco_seq_no_t> filterPos() constReturns an integer sequence with the positions of thetrueelements in the object's sequence.Example
Following is an example code snippet demonstrating a conditional method:
{ mco_trans_h trans; mco_cursor_t quote_cursor; Quote quote; mco_date last; MCO_RET rc; ... rc = mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &trans); if ( MCO_S_OK == 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); // Select the interval Sequence<uint4> day_iterator; quote.day_last(&last); quote.day_search(day_iterator, DMY(1, MONTH(last), YEAR(last)), MCO_SEQ_BOUNDARY_INCLUSIVE, last, MCO_SEQ_BOUNDARY_INCLUSIVE); // Display the days of last month when close > open print_sequence(quote, day_iterator.filter(quote.close_project(day_iterator) > quote.open_project(day_iterator))); } mco_trans_rollback(trans); } }