thin-provisioning-tools/caching/hint_array.h
Joe Thornber bb898eeaad [cache_restore/dump] hint_width work.
dump/restore cycle works again.
2013-09-26 11:36:01 +01:00

61 lines
1.6 KiB
C++

#ifndef CACHE_HINT_ARRAY_H
#define CACHE_HINT_ARRAY_H
#include "persistent-data/data-structures/array.h"
#include <string>
//----------------------------------------------------------------
namespace caching {
namespace hint_array_detail {
template <uint32_t WIDTH>
struct hint_traits {
typedef unsigned char byte;
typedef byte disk_type[WIDTH];
typedef vector<byte> value_type;
typedef no_op_ref_counter<value_type> ref_counter;
// FIXME: slow copying for now
static void unpack(disk_type const &disk, value_type &value) {
for (unsigned byte = 0; byte < WIDTH; byte++)
value.at(byte) = disk[byte];
}
static void pack(value_type const &value, disk_type &disk) {
for (unsigned byte = 0; byte < WIDTH; byte++)
disk[byte] = value.at(byte);
}
};
// FIXME: data visitor stuff
}
class hint_array {
public:
typedef boost::shared_ptr<hint_array> ptr;
typedef typename persistent_data::transaction_manager::ptr tm_ptr;
hint_array(tm_ptr tm, unsigned width);
hint_array(tm_ptr tm, unsigned width, block_address root, unsigned nr_entries);
unsigned get_nr_entries() const;
void grow(unsigned new_nr_entries, void const *v);
block_address get_root() const;
void get_hint(unsigned index, vector<unsigned char> &data) const;
void set_hint(unsigned index, vector<unsigned char> const &data);
void grow(unsigned new_nr_entries, vector<unsigned char> const &value);
private:
unsigned width_;
boost::shared_ptr<persistent_data::array_base> impl_;
};
}
//----------------------------------------------------------------
#endif