[thin_show_duplicates] start factoring out a chunk_stream abstraction

This commit is contained in:
Joe Thornber committed 2015-08-24 11:18:31 +01:00
1 parent d954f230fa
commit c8d3ce6af5
2 files changed
+144 -13

No files matched your search

+39
View File
@@ -12,6 +12,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <vector>
#include <iostream>
//----------------------------------------------------------------
@@ -112,6 +113,44 @@ namespace bcache {
validator::ptr v_;
};
class auto_block {
public:
auto_block()
: b_(0) {
}
auto_block(block &b)
: b_(&b) {
}
~auto_block() {
put();
}
auto_block &operator =(block &b) {
put();
b_ = &b;
return *this;
}
void *get_data() const {
if (b_)
return b_->get_data();
throw std::runtime_error("auto_block not set");
}
private:
void put() {
if (b_) {
b_->put();
b_ = 0;
}
}
block *b_;
};
//--------------------------------
block_cache(int fd, sector_t block_size,