* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef __BASE__CHUNK_GENERATOR_HH__
-#define __BASE__CHUNK_GENERATOR_HH__
+#ifndef __BASE_CHUNK_GENERATOR_HH__
+#define __BASE_CHUNK_GENERATOR_HH__
/**
* @file
/** The starting address of the next chunk (after the current one). */
Addr nextAddr;
/** The size of the current chunk (in bytes). */
- unsigned curSize;
+ Addr curSize;
/** The number of bytes remaining in the region after the current chunk. */
- unsigned sizeLeft;
+ Addr sizeLeft;
/** The start address so we can calculate offset in writing block. */
const Addr startAddr;
/** The maximum chunk size, e.g., the cache block size or page size. */
- const unsigned chunkSize;
+ const Addr chunkSize;
public:
/**
*
* @ingroup api_chunk_generator
*/
- ChunkGenerator(Addr _startAddr, unsigned totalSize, unsigned _chunkSize)
- : startAddr(_startAddr), chunkSize(_chunkSize)
+ ChunkGenerator(Addr _startAddr, Addr totalSize, Addr _chunkSize) :
+ startAddr(_startAddr), chunkSize(_chunkSize)
{
// chunkSize must be a power of two
assert(chunkSize == 0 || isPowerOf2(chunkSize));
// set up initial chunk.
curAddr = startAddr;
- if (chunkSize == 0) //Special Case, if we see 0, assume no chuncking
- {
+ if (chunkSize == 0) { // Special Case, if we see 0, assume no chunking.
nextAddr = startAddr + totalSize;
- }
- else
- {
- // nextAddr should be *next* chunk start
+ } else {
+ // nextAddr should be *next* chunk start.
nextAddr = roundUp(startAddr, chunkSize);
if (curAddr == nextAddr) {
// ... even if startAddr is already chunk-aligned
}
}
- // how many bytes are left between curAddr and the end of this chunk?
- unsigned left_in_chunk = nextAddr - curAddr;
+ // How many bytes are left between curAddr and the end of this chunk?
+ Addr left_in_chunk = nextAddr - curAddr;
curSize = std::min(totalSize, left_in_chunk);
sizeLeft = totalSize - curSize;
}
*
* @ingroup api_chunk_generator
*/
- unsigned size() const { return curSize; }
+ Addr size() const { return curSize; }
/**
* Number of bytes we have already chunked up.
*
* @ingroup api_chunk_generator
*/
- unsigned complete() const { return curAddr - startAddr; }
+ Addr complete() const { return curAddr - startAddr; }
/**
* Are we done? That is, did the last call to next() advance
*
* @ingroup api_chunk_generator
*/
- bool done() const { return (curSize == 0); }
+ bool done() const { return curSize == 0; }
/**
* Is this the last chunk?
*
* @ingroup api_chunk_generator
*/
- bool last() const { return (sizeLeft == 0); }
+ bool last() const { return sizeLeft == 0; }
/**
* Advance generator to next chunk.
bool
next()
{
- if (sizeLeft == 0) {
+ if (last()) {
curSize = 0;
return false;
}
}
};
-#endif // __BASE__CHUNK_GENERATOR_HH__
+#endif // __BASE_CHUNK_GENERATOR_HH__