From 19a1596591736b75bd251ff5ba32249b4f3fc28c Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Wed, 9 Oct 2013 09:45:17 +0100 Subject: [PATCH] [caching/hint_array] add walk method --- caching/hint_array.cc | 42 +++++++++++++++++++++++++++++++----------- caching/hint_array.h | 7 +++++++ 2 files changed, 38 insertions(+), 11 deletions(-) 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: