0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 00:56:44 +01:00

apbsonobjbuilder pend d list

This commit is contained in:
Dwight 2010-05-21 17:39:25 -04:00
parent 94792549ea
commit 13e25a7171
2 changed files with 27 additions and 14 deletions

View File

@ -23,6 +23,7 @@
#pragma once
#include <limits>
#include <list>
namespace mongo {
@ -438,21 +439,10 @@ namespace mongo {
/** Append an array of values. */
template < class T >
BSONObjBuilder& append( const char *fieldName, const vector< T >& vals ) {
BSONObjBuilder arrBuilder;
for ( unsigned int i = 0; i < vals.size(); ++i )
arrBuilder.append( numStr( i ).c_str(), vals[ i ] );
marshalArray( fieldName, arrBuilder.done() );
return *this;
}
BSONObjBuilder& append( const char *fieldName, const vector< T >& vals );
/* Append an array of ints
void appendArray( const char *fieldName, const vector< int >& vals ) {
BSONObjBuilder arrBuilder;
for ( unsigned i = 0; i < vals.size(); ++i )
arrBuilder.append( numStr( i ).c_str(), vals[ i ] );
marshalArray( fieldName, arrBuilder.done() );
}*/
template < class T >
BSONObjBuilder& append( const char *fieldName, const list< T >& vals );
/** The returned BSONObj will free the buffer when it is finished. */
BSONObj obj() {
@ -644,4 +634,24 @@ namespace mongo {
BSONObjBuilder _b;
};
template < class T >
inline BSONObjBuilder& BSONObjBuilder::append( const char *fieldName, const vector< T >& vals ) {
BSONObjBuilder arrBuilder;
for ( unsigned int i = 0; i < vals.size(); ++i )
arrBuilder.append( numStr( i ).c_str(), vals[ i ] );
marshalArray( fieldName, arrBuilder.done() );
return *this;
}
/** Append list of values as a BSON array. */
template < class T >
inline BSONObjBuilder& BSONObjBuilder::append( const char *fieldName, const list< T >& vals ) {
BSONObjBuilder arrBuilder;
int n = 0;
for( list<T>::const_iterator i = vals.begin(); i != vals.end(); i++ )
arrBuilder.append( numStr(n++).c_str(), *i );
marshalArray( fieldName, arrBuilder.done() );
return *this;
}
}

View File

@ -46,6 +46,9 @@ namespace mongo {
b.append("ismaster", 0);
b.append("ok", false);
b.append("msg", "not yet implemented");
//list<HostAndPort> L = memberHostnames();
//list<string> hosts;
//b.append("hosts", hosts);
}
/** @param cfgString <setname>/<seedhost1>,<seedhost2> */