[caching/hint_array] add walk method
This commit is contained in:
parent
d02b3b6399
commit
19a1596591
@ -162,9 +162,22 @@ namespace {
|
||||
|
||||
//--------------------------------
|
||||
|
||||
template <typename ValueType>
|
||||
struct no_op_visitor {
|
||||
virtual void visit(uint32_t index, ValueType const &v) {
|
||||
class value_adapter {
|
||||
public:
|
||||
value_adapter(hint_visitor &v)
|
||||
: v_(v) {
|
||||
}
|
||||
|
||||
virtual void visit(uint32_t index, std::vector<unsigned char> const &v) {
|
||||
v_.visit(static_cast<block_address>(index), v);
|
||||
}
|
||||
|
||||
private:
|
||||
hint_visitor &v_;
|
||||
};
|
||||
|
||||
struct no_op_visitor : public hint_visitor {
|
||||
virtual void visit(block_address cblock, std::vector<unsigned char> const &v) {
|
||||
}
|
||||
};
|
||||
|
||||
@ -183,20 +196,20 @@ namespace {
|
||||
};
|
||||
|
||||
template <uint32_t WIDTH>
|
||||
void check_hints(shared_ptr<array_base> base, damage_visitor &visitor) {
|
||||
void walk_hints(shared_ptr<array_base> base, hint_visitor &hv, damage_visitor &dv) {
|
||||
typedef hint_traits<WIDTH> traits;
|
||||
typedef array<traits> ha;
|
||||
|
||||
shared_ptr<ha> a = downcast_array<ha>(base);
|
||||
no_op_visitor<typename traits::value_type> nv;
|
||||
ll_damage_visitor ll(visitor);
|
||||
a->visit_values(nv, ll);
|
||||
value_adapter vv(hv);
|
||||
ll_damage_visitor ll(dv);
|
||||
a->visit_values(vv, ll);
|
||||
}
|
||||
|
||||
void check_hints_(uint32_t width, shared_ptr<array_base> base,
|
||||
damage_visitor &visitor) {
|
||||
void walk_hints_(uint32_t width, shared_ptr<array_base> base,
|
||||
hint_visitor &hv, damage_visitor &dv) {
|
||||
switch (width) {
|
||||
#define xx(n) case n: check_hints<n>(base, visitor); break
|
||||
#define xx(n) case n: walk_hints<n>(base, hv, dv); break
|
||||
all_widths
|
||||
#undef xx
|
||||
}
|
||||
@ -256,10 +269,17 @@ hint_array::grow(unsigned new_nr_entries, vector<unsigned char> const &value)
|
||||
grow_(width_, impl_, new_nr_entries, value);
|
||||
}
|
||||
|
||||
void
|
||||
hint_array::walk(hint_visitor &hv, hint_array_damage::damage_visitor &dv)
|
||||
{
|
||||
walk_hints_(width_, impl_, hv, dv);
|
||||
}
|
||||
|
||||
void
|
||||
hint_array::check(hint_array_damage::damage_visitor &visitor)
|
||||
{
|
||||
check_hints_(width_, impl_, visitor);
|
||||
no_op_visitor vv;
|
||||
walk(vv, visitor);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -47,6 +47,12 @@ namespace caching {
|
||||
};
|
||||
}
|
||||
|
||||
class hint_visitor {
|
||||
public:
|
||||
virtual ~hint_visitor() {}
|
||||
virtual void visit(block_address cblock, std::vector<unsigned char> const &data) = 0;
|
||||
};
|
||||
|
||||
class hint_array {
|
||||
public:
|
||||
typedef boost::shared_ptr<hint_array> ptr;
|
||||
@ -65,6 +71,7 @@ namespace caching {
|
||||
void set_hint(unsigned index, vector<unsigned char> const &data);
|
||||
|
||||
void grow(unsigned new_nr_entries, vector<unsigned char> const &value);
|
||||
void walk(hint_visitor &hv, hint_array_damage::damage_visitor &dv);
|
||||
void check(hint_array_damage::damage_visitor &visitor);
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user