Skip to content

CXX-3102 Remove use of BSONCXX_ENUM in public headers #1207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ QT_AUTOBRIEF = NO
# not recognized any more.
# The default value is: NO.

MULTILINE_CPP_IS_BRIEF = NO
MULTILINE_CPP_IS_BRIEF = YES

# By default Python docstrings are displayed as preformatted text and doxygen's
# special commands cannot be used. By setting PYTHON_DOCSTRING to NO the
Expand Down Expand Up @@ -1726,7 +1726,7 @@ FULL_SIDEBAR = NO
# Minimum value: 0, maximum value: 20, default value: 4.
# This tag requires that the tag GENERATE_HTML is set to YES.

ENUM_VALUES_PER_LINE = 4
ENUM_VALUES_PER_LINE = 0

# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used
# to set the initial width (in pixels) of the frame in which the tree is shown.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,30 @@ enum class error_code : std::int32_t {
/// A document operation was performed while building an array.
k_cannot_perform_document_operation_on_array,

// @cond DOXYGEN_DISABLE
#define BSONCXX_ENUM(name, value) k_need_element_type_k_##name,
#include <bsoncxx/enums/type.hpp>
#undef BSONCXX_ENUM
// @endcond DOXYGEN_DISABLE
/// The underlying value does not have the requested type.
/// @{
k_need_element_type_k_double,
k_need_element_type_k_string,
k_need_element_type_k_document,
k_need_element_type_k_array,
k_need_element_type_k_binary,
k_need_element_type_k_undefined,
k_need_element_type_k_oid,
k_need_element_type_k_bool,
k_need_element_type_k_date,
k_need_element_type_k_null,
k_need_element_type_k_regex,
k_need_element_type_k_dbpointer,
k_need_element_type_k_code,
k_need_element_type_k_symbol,
k_need_element_type_k_codewscope,
k_need_element_type_k_int32,
k_need_element_type_k_timestamp,
k_need_element_type_k_int64,
k_need_element_type_k_decimal128,
k_need_element_type_k_maxkey,
k_need_element_type_k_minkey,
/// @}

/// No key was provided when one was needed.
k_need_key,
Expand Down Expand Up @@ -97,13 +116,32 @@ enum class error_code : std::int32_t {
/// Invalid type.
k_invalid_bson_type_id,

// @cond DOXYGEN_DISABLE
#define BSONCXX_ENUM(name, value) k_cannot_append_##name,
#include <bsoncxx/enums/type.hpp>
#undef BSONCXX_ENUM
// @endcond DOXYGEN_DISABLE

/// A value failed to append.
/// Failed to append a value of the given type.
/// @{
k_cannot_append_double,
k_cannot_append_string,
k_cannot_append_document,
k_cannot_append_array,
k_cannot_append_binary,
k_cannot_append_undefined,
k_cannot_append_oid,
k_cannot_append_bool,
k_cannot_append_date,
k_cannot_append_null,
k_cannot_append_regex,
k_cannot_append_dbpointer,
k_cannot_append_code,
k_cannot_append_symbol,
k_cannot_append_codewscope,
k_cannot_append_int32,
k_cannot_append_timestamp,
k_cannot_append_int64,
k_cannot_append_decimal128,
k_cannot_append_maxkey,
k_cannot_append_minkey,
/// @}

/// Failed to append a value of the given type.
k_cannot_append_utf8 = k_cannot_append_string,

/// @deprecated Use `k_need_element_type_k_string` instead.
Expand Down
54 changes: 42 additions & 12 deletions src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/types-fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,27 @@ namespace bsoncxx {
namespace v_noabi {
namespace types {

#pragma push_macro("BSONCXX_ENUM")
#undef BSONCXX_ENUM
#define BSONCXX_ENUM(name, val) struct b_##name;
#include <bsoncxx/enums/type.hpp>
#undef BSONCXX_ENUM
#pragma pop_macro("BSONCXX_ENUM")
struct b_double;
struct b_string;
struct b_document;
struct b_array;
struct b_binary;
struct b_undefined;
struct b_oid;
struct b_bool;
struct b_date;
struct b_null;
struct b_regex;
struct b_dbpointer;
struct b_code;
struct b_symbol;
struct b_codewscope;
struct b_int32;
struct b_timestamp;
struct b_int64;
struct b_decimal128;
struct b_maxkey;
struct b_minkey;

} // namespace types
} // namespace v_noabi
Expand All @@ -52,12 +67,27 @@ using ::bsoncxx::v_noabi::type;
namespace bsoncxx {
namespace types {

#pragma push_macro("BSONCXX_ENUM")
#undef BSONCXX_ENUM
#define BSONCXX_ENUM(name, val) using ::bsoncxx::v_noabi::types::b_##name;
#include <bsoncxx/enums/type.hpp>
#undef BSONCXX_ENUM
#pragma pop_macro("BSONCXX_ENUM")
using ::bsoncxx::v_noabi::types::b_array;
using ::bsoncxx::v_noabi::types::b_binary;
using ::bsoncxx::v_noabi::types::b_bool;
using ::bsoncxx::v_noabi::types::b_code;
using ::bsoncxx::v_noabi::types::b_codewscope;
using ::bsoncxx::v_noabi::types::b_date;
using ::bsoncxx::v_noabi::types::b_dbpointer;
using ::bsoncxx::v_noabi::types::b_decimal128;
using ::bsoncxx::v_noabi::types::b_document;
using ::bsoncxx::v_noabi::types::b_double;
using ::bsoncxx::v_noabi::types::b_int32;
using ::bsoncxx::v_noabi::types::b_int64;
using ::bsoncxx::v_noabi::types::b_maxkey;
using ::bsoncxx::v_noabi::types::b_minkey;
using ::bsoncxx::v_noabi::types::b_null;
using ::bsoncxx::v_noabi::types::b_oid;
using ::bsoncxx::v_noabi::types::b_regex;
using ::bsoncxx::v_noabi::types::b_string;
using ::bsoncxx::v_noabi::types::b_symbol;
using ::bsoncxx::v_noabi::types::b_timestamp;
using ::bsoncxx::v_noabi::types::b_undefined;

} // namespace types
} // namespace bsoncxx
Expand Down
66 changes: 36 additions & 30 deletions src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@

#include <bsoncxx/config/prelude.hpp>

#pragma push_macro("BSONCXX_ENUM")
#undef BSONCXX_ENUM

BSONCXX_PUSH_WARNINGS();
BSONCXX_DISABLE_WARNING(GNU("-Wfloat-equal"));

Expand All @@ -40,36 +37,50 @@ namespace v_noabi {

///
/// An enumeration of each BSON type.
/// These x-macros will expand to be of the form:
/// k_double = 0x01,
/// k_string = 0x02,
/// k_document = 0x03,
/// k_array = 0x04 ...
///
/// @showenumvalues
///
enum class type : std::uint8_t {
#define BSONCXX_ENUM(name, val) k_##name = val,
#include <bsoncxx/enums/type.hpp>
#undef BSONCXX_ENUM
k_utf8 = 0x02,
k_double = 0x01, ///< 64-bit binary floating point.
k_string = 0x02, ///< UTF-8 string.
k_utf8 = 0x02, ///< Equivalent to @ref k_string. @deprecated
k_document = 0x03, ///< Embedded document.
k_array = 0x04, ///< Array.
k_binary = 0x05, ///< Binary data.
k_undefined = 0x06, ///< Undefined value. @deprecated
k_oid = 0x07, ///< ObjectId.
k_bool = 0x08, ///< Boolean.
k_date = 0x09, ///< UTC datetime.
k_null = 0x0A, ///< Null value.
k_regex = 0x0B, ///< Regular expression.
k_dbpointer = 0x0C, ///< DBPointer. @deprecated
k_code = 0x0D, ///< JavaScript code.
k_symbol = 0x0E, ///< Symbol. @deprecated
k_codewscope = 0x0F, ///< JavaScript code with scope.
k_int32 = 0x10, ///< 32-bit integer.
k_timestamp = 0x11, ///< Timestamp.
k_int64 = 0x12, ///< 64-bit integer.
k_decimal128 = 0x13, ///< 128-bit decimal floating point.
k_maxkey = 0x7F, ///< Min key.
k_minkey = 0xFF, ///< Max key.
};

///
/// An enumeration of each BSON binary sub type.
/// These x-macros will expand to be of the form:
/// k_binary = 0x00,
/// k_function = 0x01,
/// k_binary_deprecated = 0x02,
/// k_uuid_deprecated = 0x03,
/// k_uuid = 0x04,
/// k_md5 = 0x05,
/// k_encrypted = 0x06,
/// k_column = 0x07,
/// k_user = 0x80
///
/// @showenumvalues
///
enum class binary_sub_type : std::uint8_t {
#define BSONCXX_ENUM(name, val) k_##name = val,
#include <bsoncxx/enums/binary_sub_type.hpp>
#undef BSONCXX_ENUM
k_binary = 0x00, ///< Generic binary subtype.
k_function = 0x01, ///< Function.
k_binary_deprecated = 0x02, ///< Binary (Old). @deprecated
k_uuid_deprecated = 0x03, ///< UUID (Old). @deprecated
k_uuid = 0x04, ///< UUID.
k_md5 = 0x05, ///< MD5.
k_encrypted = 0x06, ///< Encrypted BSON value.
k_column = 0x07, ///< Compressed BSON column.
k_sensitive = 0x08, ///< Sensitive.
k_user = 0x80, ///< User defined.
};

///
Expand Down Expand Up @@ -871,11 +882,6 @@ using ::bsoncxx::v_noabi::types::operator!=;
} // namespace types
} // namespace bsoncxx

#ifdef BSONCXX_ENUM
static_assert(false, "BSONCXX_ENUM must be undef'ed");
#endif
#pragma pop_macro("BSONCXX_ENUM")

#include <bsoncxx/config/postlude.hpp>

///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,37 @@ namespace bson_value {
/// For accessors into this type and to extract the various BSON types out,
/// please use bson_value::view.
///
/// @see bsoncxx::v_noabi::bson_value::view
/// @see @ref bsoncxx::v_noabi::types::bson_value::view
///
class value {
public:
///
/// Constructor for each BSON type.
///
/// These x-macros will expand to:
/// value(b_double v);
/// value(b_string v);
/// value(b_document v);
/// value(b_array v); ...
///
#define BSONCXX_ENUM(name, val) BSONCXX_ABI_EXPORT_CDECL() value(b_##name v);
#include <bsoncxx/enums/type.hpp>
#undef BSONCXX_ENUM
///
/// Construct a bson_value::value from the provided BSON type.
///
/// @{
BSONCXX_ABI_EXPORT_CDECL() value(b_double v);
BSONCXX_ABI_EXPORT_CDECL() value(b_string v);
BSONCXX_ABI_EXPORT_CDECL() value(b_document v);
BSONCXX_ABI_EXPORT_CDECL() value(b_array v);
BSONCXX_ABI_EXPORT_CDECL() value(b_binary v);
BSONCXX_ABI_EXPORT_CDECL() value(b_undefined v);
BSONCXX_ABI_EXPORT_CDECL() value(b_oid v);
BSONCXX_ABI_EXPORT_CDECL() value(b_bool v);
BSONCXX_ABI_EXPORT_CDECL() value(b_date v);
BSONCXX_ABI_EXPORT_CDECL() value(b_null);
BSONCXX_ABI_EXPORT_CDECL() value(b_regex v);
BSONCXX_ABI_EXPORT_CDECL() value(b_dbpointer v);
BSONCXX_ABI_EXPORT_CDECL() value(b_code v);
BSONCXX_ABI_EXPORT_CDECL() value(b_symbol v);
BSONCXX_ABI_EXPORT_CDECL() value(b_codewscope v);
BSONCXX_ABI_EXPORT_CDECL() value(b_int32 v);
BSONCXX_ABI_EXPORT_CDECL() value(b_timestamp v);
BSONCXX_ABI_EXPORT_CDECL() value(b_int64 v);
BSONCXX_ABI_EXPORT_CDECL() value(b_decimal128 v);
BSONCXX_ABI_EXPORT_CDECL() value(b_maxkey v);
BSONCXX_ABI_EXPORT_CDECL() value(b_minkey v);
/// @}
///

///
/// Constructs a BSON UTF-8 string value.
Expand Down
Loading