diff --git a/caching/mapping_array.cc b/caching/mapping_array.cc index c26460e..93e2d09 100644 --- a/caching/mapping_array.cc +++ b/caching/mapping_array.cc @@ -26,3 +26,49 @@ mapping_traits::pack(value_type const &value, disk_type &disk) } //---------------------------------------------------------------- + +missing_mappings::missing_mappings(run const &keys, + std::string const &desc) + : keys_(keys), + desc_(desc) +{ + +} + +void +missing_mappings::visit(damage_visitor &v) const +{ + v.visit(*this); +} + +namespace { + struct no_op_visitor { + virtual void visit(uint32_t index, + mapping_traits::value_type const &v) { + } + }; + + class ll_damage_visitor { + public: + ll_damage_visitor(damage_visitor &v) + : v_(v) { + } + + virtual void visit(array_detail::damage const &d) { + v_.visit(missing_mappings(d.lost_keys_, d.desc_)); + } + + private: + damage_visitor &v_; + }; +} + +void +caching::check_mapping_array(mapping_array const &array, damage_visitor &visitor) +{ + no_op_visitor vv; + ll_damage_visitor ll(visitor); + array.visit_values(vv, ll); +} + +//---------------------------------------------------------------- diff --git a/caching/mapping_array.h b/caching/mapping_array.h index 030ec4f..9d22b26 100644 --- a/caching/mapping_array.h +++ b/caching/mapping_array.h @@ -26,10 +26,37 @@ namespace caching { static void pack(value_type const &value, disk_type &disk); }; - // FIXME: damage visitor stuff + class damage_visitor; + + struct damage { + virtual ~damage() {} + virtual void visit(damage_visitor &v) const = 0; + }; + + struct missing_mappings : public damage { + missing_mappings(run const &keys, std::string const &desc); + virtual void visit(damage_visitor &v) const; + + run keys_; + std::string desc_; + }; + + class damage_visitor { + public: + virtual ~damage_visitor() {} + + virtual void visit(mapping_array_detail::damage const &d) { + d.visit(*this); + } + + virtual void visit(missing_mappings const &d) = 0; + }; } typedef persistent_data::array mapping_array; + + void check_mapping_array(mapping_array const &array, + mapping_array_detail::damage_visitor &visitor); } //----------------------------------------------------------------