diff --git a/caching/hint_array.cc b/caching/hint_array.cc index effbd08..cb7b2bf 100644 --- a/caching/hint_array.cc +++ b/caching/hint_array.cc @@ -162,9 +162,22 @@ namespace { //-------------------------------- - template - 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 const &v) { + v_.visit(static_cast(index), v); + } + + private: + hint_visitor &v_; + }; + + struct no_op_visitor : public hint_visitor { + virtual void visit(block_address cblock, std::vector const &v) { } }; @@ -183,20 +196,20 @@ namespace { }; template - void check_hints(shared_ptr base, damage_visitor &visitor) { + void walk_hints(shared_ptr base, hint_visitor &hv, damage_visitor &dv) { typedef hint_traits traits; typedef array ha; shared_ptr a = downcast_array(base); - no_op_visitor 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 base, - damage_visitor &visitor) { + void walk_hints_(uint32_t width, shared_ptr base, + hint_visitor &hv, damage_visitor &dv) { switch (width) { -#define xx(n) case n: check_hints(base, visitor); break +#define xx(n) case n: walk_hints(base, hv, dv); break all_widths #undef xx } @@ -256,10 +269,17 @@ hint_array::grow(unsigned new_nr_entries, vector 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); } //---------------------------------------------------------------- diff --git a/caching/hint_array.h b/caching/hint_array.h index 2818b80..fccf7b3 100644 --- a/caching/hint_array.h +++ b/caching/hint_array.h @@ -47,6 +47,12 @@ namespace caching { }; } + class hint_visitor { + public: + virtual ~hint_visitor() {} + virtual void visit(block_address cblock, std::vector const &data) = 0; + }; + class hint_array { public: typedef boost::shared_ptr ptr; @@ -65,6 +71,7 @@ namespace caching { void set_hint(unsigned index, vector const &data); void grow(unsigned new_nr_entries, vector const &value); + void walk(hint_visitor &hv, hint_array_damage::damage_visitor &dv); void check(hint_array_damage::damage_visitor &visitor); private: