@private
| 1552 | |
| 1553 | /// @private |
| 1554 | class SubListGenerator : public Catch::Generators::IGenerator<int*> { |
| 1555 | int* list; |
| 1556 | int* sublist; |
| 1557 | int len; |
| 1558 | int sublen; |
| 1559 | vector<bool> featured; |
| 1560 | private: |
| 1561 | void createSublist() { |
| 1562 | |
| 1563 | // sublist to send to the user |
| 1564 | sublist = (int*) malloc(sublen * sizeof *sublist); |
| 1565 | |
| 1566 | // indicates which list members are currently in sublist |
| 1567 | featured = vector<bool>(len); |
| 1568 | fill(featured.end() - sublen, featured.end(), true); |
| 1569 | } |
| 1570 | |
| 1571 | void prepareSublist() { |
| 1572 | |
| 1573 | // choose the next combination |
| 1574 | int j=0; |
| 1575 | for (int i=0; i<len; i++) |
| 1576 | if (featured[i]) |
| 1577 | sublist[j++] = list[i]; |
| 1578 | |
| 1579 | // prepare for permuting |
| 1580 | std::sort(sublist, sublist+sublen); |
| 1581 | } |
| 1582 | public: |
| 1583 | SubListGenerator(int* elems, int numElems, int numSamps) { |
| 1584 | |
| 1585 | DEMAND( numSamps <= numElems ); |
| 1586 | |
| 1587 | // make a record of all elements |
| 1588 | len = numElems; |
| 1589 | list = (int*) malloc(len * sizeof *list); |
| 1590 | for (int i=0; i<len; i++) |
| 1591 | list[i] = elems[i]; |
| 1592 | |
| 1593 | // prepare sublist |
| 1594 | sublen = numSamps; |
| 1595 | createSublist(); |
| 1596 | prepareSublist(); |
| 1597 | } |
| 1598 | |
| 1599 | SubListGenerator( |
| 1600 | Catch::Generators::GeneratorWrapper<int>&& gen, |
| 1601 | int numSamps, const int* exclude, int numExclude |
| 1602 | ) { |
| 1603 | // extract all generator elems |
| 1604 | vector<int> elems = vector<int>(); |
| 1605 | do { elems.push_back(gen.get()); } while (gen.next()); |
| 1606 | |
| 1607 | // make (int*) of non-excluded elems |
| 1608 | len = 0; |
| 1609 | list = (int*) malloc(elems.size() * sizeof *list); |
| 1610 | for (size_t i=0; i<elems.size(); i++) { |
| 1611 | int elem = elems[i]; |
nothing calls this directly
no outgoing calls
no test coverage detected