paul@65 | 1 | #include "pipe_paging.h" |
paul@65 | 2 | |
paul@66 | 3 | PipePaging::PipePaging(offset_t size) |
paul@66 | 4 | : _size(size) |
paul@65 | 5 | { |
paul@65 | 6 | } |
paul@65 | 7 | |
paul@65 | 8 | /* Add a region to the sequence. */ |
paul@65 | 9 | |
paul@65 | 10 | void PipePaging::add_region(PageMapper *mapper) |
paul@65 | 11 | { |
paul@65 | 12 | _regions.push_back(mapper); |
paul@65 | 13 | } |
paul@65 | 14 | |
paul@65 | 15 | /* Return the first region in the sequence. */ |
paul@65 | 16 | |
paul@65 | 17 | PageMapper *PipePaging::first_region() |
paul@65 | 18 | { |
paul@65 | 19 | return _regions.front(); |
paul@65 | 20 | } |
paul@65 | 21 | |
paul@65 | 22 | /* Return the next region for the reader. If only a single region remains, with |
paul@65 | 23 | the reader wishing to move to the next, return NULL. */ |
paul@65 | 24 | |
paul@65 | 25 | PageMapper *PipePaging::next_region() |
paul@65 | 26 | { |
paul@65 | 27 | if (_regions.size() > 1) |
paul@65 | 28 | { |
paul@66 | 29 | /* Discard the accessor from the current region. */ |
paul@66 | 30 | |
paul@66 | 31 | if (_accessors.size() > _regions.size()) |
paul@66 | 32 | _accessors.pop_front(); |
paul@66 | 33 | |
paul@65 | 34 | _regions.pop_front(); |
paul@65 | 35 | return _regions.front(); |
paul@65 | 36 | } |
paul@65 | 37 | else |
paul@65 | 38 | return NULL; |
paul@65 | 39 | } |
paul@65 | 40 | |
paul@66 | 41 | /* Initialise an accessor for a region. */ |
paul@66 | 42 | |
paul@66 | 43 | PipeAccessor *PipePaging::accessor() |
paul@66 | 44 | { |
paul@66 | 45 | PipeAccessor accessor; |
paul@66 | 46 | |
paul@66 | 47 | _accessors.push_back(accessor); |
paul@66 | 48 | return &_accessors.back(); |
paul@66 | 49 | } |
paul@66 | 50 | |
paul@65 | 51 | // vim: tabstop=4 expandtab shiftwidth=4 |