// Retrieve up to "N" items where N is list.size(). // Items must match filter and lie adjacent to Cursor. // Returns false on IO error. bool HistoryFlat::get(const Filter &filter, Cursor &cursor, std::vector<Item> &list) { // number of items found. size_t i = 0; // record index to start scan. size_t index = cursor.indices[cursor.forward]; // update opposing scan index. cursor.indices[!cursor.forward] = index; // is our list full? while ( i < list.size() ) { // no: read a record. if ( !read(index) ) // IO error. return false; // match filter criteria? if ( filter.eval(_item) ) { // yes: add it. list[i++] = _item; } // advance cursor; stop if reach limit. if ( !cursor.index(index) ) break; } // resize to number records found. list.resize(i); // update cursor index. cursor.indices[cursor.forward] = index; return true; }
bike.props.set("type", "bike"); bike.props.set("series", "CB"); bike.props.set("check", "available"); bike.props.set("serial", 4398046511105); // 2^42 + 1 ctx.setKeyword("$geometry", Value(1)); ctx.setKeyword("$zoom", Value("false")); } //1. basic predicate TEST_CASE( "yaml-filter-tests: basic predicate test", "[filters][core][yaml]") { init(); Filter filter = load("filter: { series: !!str 3}"); REQUIRE(!filter.eval(civic, ctx)); REQUIRE(filter.eval(bmw1, ctx)); REQUIRE(!filter.eval(bike, ctx)); } //2. predicate with valueList TEST_CASE( "yaml-filter-tests: predicate with valueList", "[filters][core][yaml]") { init(); Filter filter = load("filter: { name : [civic, bmw320i] }"); REQUIRE(filter.eval(civic, ctx)); REQUIRE(filter.eval(bmw1, ctx)); REQUIRE(!filter.eval(bike, ctx)); }