[thin_show_duplicates] start factoring out a chunk_stream abstraction
This commit is contained in:
@ -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,
|
||||
|
Reference in New Issue
Block a user