diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2014-08-22 10:13:25 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2014-08-25 15:08:22 -0400 |
commit | d1767c999d4371fc1aa1eb85f5f8b58c0b5f4848 (patch) | |
tree | f90e13f38c9a30dcd9376f9332ef8147510e7281 /src/mongo/bson/util/builder.h | |
parent | 8e0a7c273bf6ef02425fd406e6ac182bb716cc79 (diff) | |
download | mongo-d1767c999d4371fc1aa1eb85f5f8b58c0b5f4848.tar.gz |
SERVER-14668 Add function to StringBuilder for formatting addresses
Diffstat (limited to 'src/mongo/bson/util/builder.h')
-rw-r--r-- | src/mongo/bson/util/builder.h | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/mongo/bson/util/builder.h b/src/mongo/bson/util/builder.h index 38e24b59d5f..c784283afa5 100644 --- a/src/mongo/bson/util/builder.h +++ b/src/mongo/bson/util/builder.h @@ -30,6 +30,7 @@ #pragma once #include <cfloat> +#include <inttypes.h> #include <iostream> #include <sstream> #include <stdio.h> @@ -269,12 +270,14 @@ namespace mongo { template <typename Allocator> class StringBuilderImpl { public: - static const size_t MONGO_DBL_SIZE = 3 + DBL_MANT_DIG - DBL_MIN_EXP; + // Sizes are determined based on the number of characters in 64-bit + the trailing '\0' + static const size_t MONGO_DBL_SIZE = 3 + DBL_MANT_DIG - DBL_MIN_EXP + 1; static const size_t MONGO_S32_SIZE = 12; static const size_t MONGO_U32_SIZE = 11; static const size_t MONGO_S64_SIZE = 23; static const size_t MONGO_U64_SIZE = 22; static const size_t MONGO_S16_SIZE = 7; + static const size_t MONGO_PTR_SIZE = 17; // FFFFFFFFFFFFFFFF has 16 characters StringBuilderImpl() { } @@ -302,10 +305,20 @@ namespace mongo { StringBuilderImpl& operator<<( short x ) { return SBNUM( x , MONGO_S16_SIZE , "%hd" ); } + StringBuilderImpl& operator<<(const void* x) { + return SBNUM(x, MONGO_PTR_SIZE, "0x%"PRIXPTR""); + } StringBuilderImpl& operator<<( char c ) { _buf.grow( 1 )[0] = c; return *this; } + StringBuilderImpl& operator<<(const char* str) { + return *this << StringData(str); + } + StringBuilderImpl& operator<<(const StringData& str) { + append(str); + return *this; + } void appendDoubleNice( double x ) { const int prev = _buf.l; @@ -324,11 +337,6 @@ namespace mongo { void append( const StringData& str ) { str.copyTo( _buf.grow( str.size() ), false ); } - StringBuilderImpl& operator<<( const StringData& str ) { - append( str ); - return *this; - } - void reset( int maxSize = 0 ) { _buf.reset( maxSize ); } std::string str() const { return std::string(_buf.data, _buf.l); } |