ProgressTracker.h 675 B

123456789101112131415161718192021222324
  1. #pragma once
  2. #include "foundation/types.h"
  3. #include <map>
  4. #include "nu/AutoLock.h"
  5. /* Helper class for managing valid chunks in non-sequential scenarios
  6. e.g. progressive downloading */
  7. class ProgressTracker
  8. {
  9. public:
  10. static const uint64_t null_position;
  11. ProgressTracker();
  12. void Write(uint64_t bytes_written);
  13. bool Valid(uint64_t requested_position, uint64_t requested_end, uint64_t *available=0);
  14. bool Seek(uint64_t requested_position, uint64_t requested_end, uint64_t *new_start, uint64_t *new_end);
  15. void Dump();
  16. typedef std::map<uint64_t, uint64_t> ChunkList;
  17. ChunkList chunks;
  18. uint64_t current_chunk;
  19. uint64_t current_position;
  20. nu::LockGuard list_guard;
  21. };