summaryrefslogtreecommitdiff
path: root/bson
diff options
context:
space:
mode:
authordwight <dwight@10gen.com>2010-11-25 12:17:07 -0500
committerdwight <dwight@10gen.com>2010-11-25 12:17:07 -0500
commit5e970e64bd21b01d9a77cb9c16f3c180d4054456 (patch)
tree40e5c380fbc0d1e5a64d7cb90d5dd7496dcaa0cd /bson
parent3e6f66004657fd76e890a6cc433a93f80ec6315f (diff)
downloadmongo-5e970e64bd21b01d9a77cb9c16f3c180d4054456.tar.gz
avoid using macro to save on header pollution
Diffstat (limited to 'bson')
-rw-r--r--bson/util/builder.h35
1 files changed, 18 insertions, 17 deletions
diff --git a/bson/util/builder.h b/bson/util/builder.h
index f1e89c47684..bbf5979388b 100644
--- a/bson/util/builder.h
+++ b/bson/util/builder.h
@@ -174,49 +174,41 @@ namespace mongo {
#pragma warning( disable : 4996 )
#endif
- /** Stringstream deals with locale so this is a lot faster for UTF8 */
+ /** StringBuilder deals with locale so this is a lot faster than std::stringstream for UTF8 */
class StringBuilder {
public:
StringBuilder( int initsize=256 )
: _buf( initsize ){
}
-#define SBNUM(val,maxSize,macro) \
- int prev = _buf.l; \
- int z = sprintf( _buf.grow(maxSize) , macro , (val) ); \
- assert( z >= 0 ); \
- _buf.l = prev + z; \
- return *this;
-
StringBuilder& operator<<( double x ){
- SBNUM( x , 25 , "%g" );
+ return SBNUM( x , 25 , "%g" );
}
StringBuilder& operator<<( int x ){
- SBNUM( x , 11 , "%d" );
+ return SBNUM( x , 11 , "%d" );
}
StringBuilder& operator<<( unsigned x ){
- SBNUM( x , 11 , "%u" );
+ return SBNUM( x , 11 , "%u" );
}
StringBuilder& operator<<( long x ){
- SBNUM( x , 22 , "%ld" );
+ return SBNUM( x , 22 , "%ld" );
}
StringBuilder& operator<<( unsigned long x ){
- SBNUM( x , 22 , "%lu" );
+ return SBNUM( x , 22 , "%lu" );
}
StringBuilder& operator<<( long long x ){
- SBNUM( x , 22 , "%lld" );
+ return SBNUM( x , 22 , "%lld" );
}
StringBuilder& operator<<( unsigned long long x ){
- SBNUM( x , 22 , "%llu" );
+ return SBNUM( x , 22 , "%llu" );
}
StringBuilder& operator<<( short x ){
- SBNUM( x , 8 , "%hd" );
+ return SBNUM( x , 8 , "%hd" );
}
StringBuilder& operator<<( char c ){
_buf.grow( 1 )[0] = c;
return *this;
}
-#undef SBNUM
void appendDoubleNice( double x ){
int prev = _buf.l;
@@ -248,6 +240,15 @@ namespace mongo {
// non-copyable, non-assignable
StringBuilder( const StringBuilder& );
StringBuilder& operator=( const StringBuilder& );
+
+ template <typename T>
+ StringBuilder& SBNUM(T val,int maxSize,const char *macro) {
+ int prev = _buf.l;
+ int z = sprintf( _buf.grow(maxSize) , macro , (val) );
+ assert( z >= 0 );
+ _buf.l = prev + z;
+ return *this;
+ }
};
#if defined(_WIN32)