[caching/mapping_array] add damage visitor

This commit is contained in:
Joe Thornber 2013-10-02 10:50:13 +01:00
parent 326134a7aa
commit b1f5807513
2 changed files with 74 additions and 1 deletions

View File

@ -26,3 +26,49 @@ mapping_traits::pack(value_type const &value, disk_type &disk)
} }
//---------------------------------------------------------------- //----------------------------------------------------------------
missing_mappings::missing_mappings(run<uint32_t> 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);
}
//----------------------------------------------------------------

View File

@ -26,10 +26,37 @@ namespace caching {
static void pack(value_type const &value, disk_type &disk); 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<uint32_t> const &keys, std::string const &desc);
virtual void visit(damage_visitor &v) const;
run<uint32_t> 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_detail::mapping_traits> mapping_array; typedef persistent_data::array<mapping_array_detail::mapping_traits> mapping_array;
void check_mapping_array(mapping_array const &array,
mapping_array_detail::damage_visitor &visitor);
} }
//---------------------------------------------------------------- //----------------------------------------------------------------