cpp-btree: Disable iostream/ostream includes and dump functionality

This commit is contained in:
Jonathan G Rennison 2024-09-01 22:47:27 +01:00
parent 2b5cae34ce
commit 2a3a41e2a6
4 changed files with 20 additions and 2 deletions

View File

@ -105,15 +105,18 @@
#include <sys/types.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <type_traits>
#include <new>
#include <ostream>
#include <string>
#include <utility>
#ifndef BTREE_NO_IOSTREAM
#include <iostream>
#include <ostream>
#endif
namespace btree {
// Inside a btree method, if we just call swap(), it will choose the
@ -1160,6 +1163,7 @@ class btree : public Params::key_compare {
return btree_compare_keys(key_comp(), x, y);
}
#ifndef BTREE_NO_IOSTREAM
// Dump the btree to the specified ostream. Requires that operator<< is
// defined for Key and Value.
void dump(std::ostream &os) const {
@ -1167,6 +1171,7 @@ class btree : public Params::key_compare {
internal_dump(os, root(), 0);
}
}
#endif
// Verifies the structure of the btree.
void verify() const;
@ -1398,8 +1403,10 @@ class btree : public Params::key_compare {
// Deletes a node and all of its children.
void internal_clear(node_type *node);
#ifndef BTREE_NO_IOSTREAM
// Dumps a node and all of its children to the specified ostream.
void internal_dump(std::ostream &os, const node_type *node, int level) const;
#endif
// Verifies the tree structure of node.
int internal_verify(const node_type *node,
@ -2400,6 +2407,7 @@ void btree<P>::internal_clear(node_type *node) {
}
}
#ifndef BTREE_NO_IOSTREAM
template <typename P>
void btree<P>::internal_dump(
std::ostream &os, const node_type *node, int level) const {
@ -2416,6 +2424,7 @@ void btree<P>::internal_dump(
internal_dump(os, node->child(node->count()), level + 1);
}
}
#endif
template <typename P>
int btree<P>::internal_verify(

View File

@ -99,9 +99,11 @@ class btree_container {
void swap(self_type &x) {
tree_.swap(x.tree_);
}
#ifndef BTREE_NO_IOSTREAM
void dump(std::ostream &os) const {
tree_.dump(os);
}
#endif
void verify() const {
tree_.verify();
}
@ -140,11 +142,13 @@ class btree_container {
Tree tree_;
};
#ifndef BTREE_NO_IOSTREAM
template <typename T>
inline std::ostream& operator<<(std::ostream &os, const btree_container<T> &b) {
b.dump(os);
return os;
}
#endif
// A common base class for btree_set and safe_btree_set.
template <typename Tree>

View File

@ -392,9 +392,11 @@ class safe_btree {
++x.generation_;
tree_.swap(x.tree_);
}
#ifndef BTREE_NO_IOSTREAM
void dump(std::ostream &os) const {
tree_.dump(os);
}
#endif
void verify() const {
tree_.verify();
}

View File

@ -393,6 +393,9 @@ typedef uint64_t unaligned_uint64;
/* JSON: Don't include IO stream headers/support */
#define JSON_NO_IO
/* cpp-btree: Don't include IO stream headers, dump support */
#define BTREE_NO_IOSTREAM
[[noreturn]] void CDECL usererror(const char *str, ...) WARN_FORMAT(1, 2);
[[noreturn]] void CDECL error(const char *str, ...) WARN_FORMAT(1, 2);
[[noreturn]] void CDECL assert_msg_error(int line, const char *file, const char *expr, const char *extra, const char *str, ...) WARN_FORMAT(5, 6);