[btree_node_checker] tidy up the code
1. Add const qualifiers 2. Add virtual destructor
This commit is contained in:
		@@ -6,11 +6,11 @@ using persistent_data::btree_detail::btree_node_checker;
 | 
			
		||||
 | 
			
		||||
//----------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
btree_node_checker::error_type btree_node_checker::get_last_error() {
 | 
			
		||||
btree_node_checker::error_type btree_node_checker::get_last_error() const {
 | 
			
		||||
	return last_error_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string btree_node_checker::get_last_error_string() {
 | 
			
		||||
std::string btree_node_checker::get_last_error_string() const {
 | 
			
		||||
	switch (last_error_) {
 | 
			
		||||
	case BLOCK_NR_MISMATCH:
 | 
			
		||||
		return block_nr_mismatch_string();
 | 
			
		||||
@@ -39,7 +39,7 @@ void btree_node_checker::reset() {
 | 
			
		||||
	last_error_ = NO_ERROR;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string btree_node_checker::block_nr_mismatch_string() {
 | 
			
		||||
std::string btree_node_checker::block_nr_mismatch_string() const {
 | 
			
		||||
	std::ostringstream out;
 | 
			
		||||
	out << "block number mismatch: actually "
 | 
			
		||||
	    << error_location_
 | 
			
		||||
@@ -48,7 +48,7 @@ std::string btree_node_checker::block_nr_mismatch_string() {
 | 
			
		||||
	return out.str();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string btree_node_checker::value_sizes_mismatch_string() {
 | 
			
		||||
std::string btree_node_checker::value_sizes_mismatch_string() const {
 | 
			
		||||
	std::ostringstream out;
 | 
			
		||||
	out << "value size mismatch: expected " << error_value_sizes_[1]
 | 
			
		||||
	    << ", but got " << error_value_sizes_[0]
 | 
			
		||||
@@ -58,7 +58,7 @@ std::string btree_node_checker::value_sizes_mismatch_string() {
 | 
			
		||||
	return out.str();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string btree_node_checker::max_entries_too_large_string() {
 | 
			
		||||
std::string btree_node_checker::max_entries_too_large_string() const {
 | 
			
		||||
	std::ostringstream out;
 | 
			
		||||
	out << "max entries too large: " << error_max_entries_
 | 
			
		||||
	    << " (block " << error_location_ << ")";
 | 
			
		||||
@@ -66,7 +66,7 @@ std::string btree_node_checker::max_entries_too_large_string() {
 | 
			
		||||
	return out.str();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string btree_node_checker::max_entries_not_divisible_string() {
 | 
			
		||||
std::string btree_node_checker::max_entries_not_divisible_string() const {
 | 
			
		||||
	std::ostringstream out;
 | 
			
		||||
	out << "max entries is not divisible by 3: " << error_max_entries_
 | 
			
		||||
	    << " (block " << error_location_ << ")";
 | 
			
		||||
@@ -74,7 +74,7 @@ std::string btree_node_checker::max_entries_not_divisible_string() {
 | 
			
		||||
	return out.str();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string btree_node_checker::nr_entries_too_large_string() {
 | 
			
		||||
std::string btree_node_checker::nr_entries_too_large_string() const {
 | 
			
		||||
	std::ostringstream out;
 | 
			
		||||
	out << "bad nr_entries: "
 | 
			
		||||
	    << error_nr_entries_ << " < "
 | 
			
		||||
@@ -84,7 +84,7 @@ std::string btree_node_checker::nr_entries_too_large_string() {
 | 
			
		||||
	return out.str();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string btree_node_checker::nr_entries_too_small_string() {
 | 
			
		||||
std::string btree_node_checker::nr_entries_too_small_string() const {
 | 
			
		||||
	std::ostringstream out;
 | 
			
		||||
	out << "too few entries in btree_node: "
 | 
			
		||||
	    << error_nr_entries_
 | 
			
		||||
@@ -96,7 +96,7 @@ std::string btree_node_checker::nr_entries_too_small_string() {
 | 
			
		||||
	return out.str();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string btree_node_checker::keys_out_of_order_string() {
 | 
			
		||||
std::string btree_node_checker::keys_out_of_order_string() const {
 | 
			
		||||
	std::ostringstream out;
 | 
			
		||||
	out << "keys are out of order, "
 | 
			
		||||
	    << error_keys_[0] << " <= " << error_keys_[1]
 | 
			
		||||
@@ -105,7 +105,7 @@ std::string btree_node_checker::keys_out_of_order_string() {
 | 
			
		||||
	return out.str();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string btree_node_checker::parent_key_mismatch_string() {
 | 
			
		||||
std::string btree_node_checker::parent_key_mismatch_string() const {
 | 
			
		||||
	std::ostringstream out;
 | 
			
		||||
	out << "parent key mismatch: parent was " << error_keys_[1]
 | 
			
		||||
	    << ", but lowest in node was " << error_keys_[0]
 | 
			
		||||
@@ -114,7 +114,7 @@ std::string btree_node_checker::parent_key_mismatch_string() {
 | 
			
		||||
	return out.str();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string btree_node_checker::leaf_key_overlapped_string() {
 | 
			
		||||
std::string btree_node_checker::leaf_key_overlapped_string() const {
 | 
			
		||||
	std::ostringstream out;
 | 
			
		||||
	out << "the last key of the previous leaf was " << error_keys_[1]
 | 
			
		||||
	    << " and the first key of this leaf is " << error_keys_[0]
 | 
			
		||||
 
 | 
			
		||||
@@ -41,6 +41,8 @@ namespace persistent_data {
 | 
			
		||||
				error_keys_{0, 0} {
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			virtual ~btree_node_checker() {}
 | 
			
		||||
 | 
			
		||||
			template <typename ValueTraits>
 | 
			
		||||
			bool check_block_nr(btree_detail::node_ref<ValueTraits> const &n) {
 | 
			
		||||
				if (n.get_location() != n.get_block_nr()) {
 | 
			
		||||
@@ -175,20 +177,20 @@ namespace persistent_data {
 | 
			
		||||
				return true;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			error_type get_last_error();
 | 
			
		||||
			std::string get_last_error_string();
 | 
			
		||||
			error_type get_last_error() const;
 | 
			
		||||
			std::string get_last_error_string() const;
 | 
			
		||||
			void reset();
 | 
			
		||||
 | 
			
		||||
		private:
 | 
			
		||||
			std::string block_nr_mismatch_string();
 | 
			
		||||
			std::string value_sizes_mismatch_string();
 | 
			
		||||
			std::string max_entries_too_large_string();
 | 
			
		||||
			std::string max_entries_not_divisible_string();
 | 
			
		||||
			std::string nr_entries_too_large_string();
 | 
			
		||||
			std::string nr_entries_too_small_string();
 | 
			
		||||
			std::string keys_out_of_order_string();
 | 
			
		||||
			std::string parent_key_mismatch_string();
 | 
			
		||||
			std::string leaf_key_overlapped_string();
 | 
			
		||||
			std::string block_nr_mismatch_string() const;
 | 
			
		||||
			std::string value_sizes_mismatch_string() const;
 | 
			
		||||
			std::string max_entries_too_large_string() const;
 | 
			
		||||
			std::string max_entries_not_divisible_string() const;
 | 
			
		||||
			std::string nr_entries_too_large_string() const;
 | 
			
		||||
			std::string nr_entries_too_small_string() const;
 | 
			
		||||
			std::string keys_out_of_order_string() const;
 | 
			
		||||
			std::string parent_key_mismatch_string() const;
 | 
			
		||||
			std::string leaf_key_overlapped_string() const;
 | 
			
		||||
 | 
			
		||||
			error_type last_error_;
 | 
			
		||||
			block_address error_location_;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user