diff options
author | Adam Chelminski <adam.chelminski@mongodb.com> | 2016-08-15 10:48:29 -0400 |
---|---|---|
committer | Adam Chelminski <adam.chelminski@mongodb.com> | 2016-08-15 10:49:01 -0400 |
commit | 9175ab505d970a6e97733a28e16496426d10f3ee (patch) | |
tree | 898fc0191b977c0e69b7a2c731f9986ad4b1ef5d /src/mongo/bson | |
parent | d19d5cdb3a2dd6905361545239c7c37d07cf5aba (diff) | |
download | mongo-9175ab505d970a6e97733a28e16496426d10f3ee.tar.gz |
SERVER-13367 Specialize operator<< for BSONType for std::ostream, LogstreamBuilder, and StringBuilder
Diffstat (limited to 'src/mongo/bson')
-rw-r--r-- | src/mongo/bson/bsontypes.cpp | 4 | ||||
-rw-r--r-- | src/mongo/bson/bsontypes.h | 7 | ||||
-rw-r--r-- | src/mongo/bson/util/builder.h | 5 |
3 files changed, 16 insertions, 0 deletions
diff --git a/src/mongo/bson/bsontypes.cpp b/src/mongo/bson/bsontypes.cpp index ee806e0e8a7..8ff370ec12f 100644 --- a/src/mongo/bson/bsontypes.cpp +++ b/src/mongo/bson/bsontypes.cpp @@ -95,6 +95,10 @@ const char* typeName(BSONType type) { } } +std::ostream& operator<<(std::ostream& stream, BSONType type) { + return stream << typeName(type); +} + bool isValidBSONType(int type) { switch (type) { case MinKey: diff --git a/src/mongo/bson/bsontypes.h b/src/mongo/bson/bsontypes.h index 622547ca098..e3fde085ad9 100644 --- a/src/mongo/bson/bsontypes.h +++ b/src/mongo/bson/bsontypes.h @@ -29,6 +29,8 @@ #pragma once +#include <iosfwd> + #include "mongo/config.h" #include "mongo/platform/decimal128.h" #include "mongo/util/assert_util.h" @@ -118,6 +120,11 @@ enum BSONType { const char* typeName(BSONType type); /** + * Prints the name of the argument's type to the given stream. + */ +std::ostream& operator<<(std::ostream& stream, BSONType type); + +/** * Returns whether or not 'type' can be converted to a valid BSONType. */ bool isValidBSONType(int type); diff --git a/src/mongo/bson/util/builder.h b/src/mongo/bson/util/builder.h index 2cce0d93ad5..e6d29ceb175 100644 --- a/src/mongo/bson/util/builder.h +++ b/src/mongo/bson/util/builder.h @@ -41,6 +41,7 @@ #include "mongo/base/data_view.h" #include "mongo/base/disallow_copying.h" #include "mongo/base/string_data.h" +#include "mongo/bson/bsontypes.h" #include "mongo/bson/inline_decls.h" #include "mongo/platform/decimal128.h" #include "mongo/stdx/type_traits.h" @@ -411,6 +412,10 @@ public: append(str); return *this; } + StringBuilderImpl& operator<<(BSONType type) { + append(typeName(type)); + return *this; + } void appendDoubleNice(double x) { const int prev = _buf.l; |