Permalink
Browse files

temporarily Revert "git rid of "operator string""

This reverts commit 95fa51a.
  • Loading branch information...
1 parent e7cb7ec commit 13c6875815fdcb2d677c76905819d99a99a2d5d3 @RedBeard0531 RedBeard0531 committed Jul 7, 2010
View
@@ -86,6 +86,7 @@ class BSONElement {
bool ok() const { return !eoo(); }
string toString( bool includeFieldName = true ) const;
+ operator string() const { return toString(); }
string jsonString( JsonStringFormat format, bool includeFieldNames = true, int pretty = 0 ) const;
/** Returns the type of the element */
View
@@ -88,6 +88,7 @@ namespace mongo {
This is an abbreviated representation which might be used for logging.
*/
string toString( bool isArray = false ) const;
+ operator string() const { return toString(); }
/** Properly formatted JSON string.
@param pretty if true we try to add some lf's and indentation
View
@@ -55,8 +55,7 @@ namespace mongo {
BSONField( const string& name , const string& longName="" )
: _name(name), _longName(longName){}
const string& name() const { return _name; }
- string toString() const { return _name; }
- friend ostream& operator << (ostream& out, const BSONField& f) { return (out << f._name); }
+ operator string() const { return _name; }
BSONFieldValue<T> make( const T& t ) const {
return BSONFieldValue<T>( _name , t );
@@ -372,10 +371,6 @@ namespace mongo {
BSONObjBuilder& append(const char *fieldName, string str) {
return append(fieldName, str.c_str(), (int) str.size()+1);
}
- /** Append a string element */
- BSONObjBuilder& append(const char *fieldName, ThreadSafeString tss) {
- return append(fieldName, tss.toString());
- }
BSONObjBuilder& appendSymbol(const char *fieldName, const char *symbol) {
_b.append((char) Symbol);
_b.append(fieldName);
View
@@ -39,13 +39,12 @@ namespace mongo {
// for woCompare...
unsigned descending(unsigned mask) const { return bits & mask; }
- string toString() const {
+ operator string() const {
StringBuilder buf(32);
for ( unsigned i=0; i<nkeys; i++)
buf.append( get(i) > 0 ? "+" : "-" );
return buf.str();
}
- friend ostream& operator << (ostream& out, const Ordering& o) { return (out << o.toString()); }
static Ordering make(const BSONObj& obj) {
unsigned b = 0;
View
@@ -148,7 +148,7 @@ namespace mongo {
class StringBuilder {
public:
- explicit StringBuilder( int initsize=256 )
+ StringBuilder( int initsize=256 )
: _buf( initsize ){
}
@@ -188,18 +188,16 @@ namespace mongo {
}
#undef SBNUM
- void append( const char * str){
- append(str, strlen(str));
- }
- void append( const char * str, int len){
- memcpy( _buf.grow( len ) , str , len );
+ void append( const char * str ){
+ int x = (int) strlen( str );
+ memcpy( _buf.grow( x ) , str , x );
}
StringBuilder& operator<<( const char * str ){
- append( str, strlen(str) );
+ append( str );
return *this;
}
StringBuilder& operator<<( const std::string& s ){
- append( s.c_str(), s.size() );
+ append( s.c_str() );
return *this;
}
View
@@ -36,7 +36,7 @@ namespace mongo {
case MASTER: {
DBClientConnection * c = new DBClientConnection(true);
log(2) << "creating new connection to:" << _servers[0] << endl;
- if ( ! c->connect( _servers[0].toString() , errmsg ) ) {
+ if ( ! c->connect( _servers[0] , errmsg ) ) {
delete c;
return 0;
}
@@ -45,7 +45,7 @@ namespace mongo {
case SET: {
DBClientPaired *p = new DBClientPaired();
- if( !p->connect( _servers[0].toString() , _servers[1].toString() ) ){
+ if( !p->connect( _servers[0] , _servers[1] ) ){
delete p;
errmsg = "connect failed";
return 0;
View
@@ -129,7 +129,9 @@ namespace mongo {
return _string;
}
- friend ostream& operator << (ostream& out, const ConnectionString& cs) { return (out << cs.toString()); }
+ operator string() const {
+ return toString();
+ }
DBClientBase* connect( string& errmsg ) const;
@@ -267,7 +269,7 @@ namespace mongo {
bool isExplain() const;
string toString() const;
- friend ostream& operator << (ostream& out, const Query& q) { return (out << q.toString()); }
+ operator string() const { return toString(); }
private:
void makeComplex();
template< class T >
View
@@ -54,7 +54,9 @@ namespace mongo {
return ss.str();
}
- friend ostream& operator << (ostream& out, const ServerAndQuery& sq) { return (out << sq.toString()); }
+ operator string() const {
+ return toString();
+ }
string _server;
BSONObj _extra;
View
@@ -333,7 +333,7 @@ namespace mongo {
cmdSpec << "logSizeMb" << logSizeMb;
BSONObj info;
if ( !conn->runCommand( db, cmdSpec.done(), info ) ) {
- errmsg = "logCollection failed: " + info.toString();
+ errmsg = "logCollection failed: " + (string)info;
return false;
}
}
@@ -410,7 +410,7 @@ namespace mongo {
dbtemprelease t;
BSONObj info;
if ( !conn->runCommand( db, BSON( "logCollection" << ns << "validateComplete" << 1 ), info ) ) {
- errmsg = "logCollection failed: " + info.toString();
+ errmsg = "logCollection failed: " + (string)info;
return false;
}
}
@@ -642,7 +642,7 @@ namespace mongo {
if ( !authConn_->connect( fromhost, errmsg ) )
return false;
if( !authConn_->runCommand( "admin", BSON( "getnonce" << 1 ), ret ) ) {
- errmsg = "couldn't get nonce " + ret.toString();
+ errmsg = "couldn't get nonce " + string( ret );
return false;
}
}
@@ -692,7 +692,7 @@ namespace mongo {
{
dbtemprelease t;
if ( !authConn_->runCommand( fromdb, BSON( "authenticate" << 1 << "user" << username << "nonce" << nonce << "key" << key ), ret ) ) {
- errmsg = "unable to login " + ret.toString();
+ errmsg = "unable to login " + string( ret );
return false;
}
}
View
@@ -264,7 +264,7 @@ namespace mongo {
return _progressMeter;
}
- string getMessage() const { return _message.toString(); }
+ string getMessage() const { return _message; }
ProgressMeter& getProgressMeter() { return _progressMeter; }
friend class Client;
View
@@ -721,7 +721,7 @@ namespace mongo {
int idxId = d->findIndexByKeyPattern( f.embeddedObject() );
if ( idxId < 0 ){
errmsg = "can't find index with key:";
- errmsg += f.embeddedObject().toString();
+ errmsg += f.embeddedObject();
return false;
}
else {
@@ -1261,7 +1261,7 @@ namespace mongo {
if ( !client.runCommand( dbname ,
BSON( "cloneCollectionAsCapped" << from << "toCollection" << ( from + ".$temp_convertToCapped" ) << "size" << double( size ) ),
info ) ) {
- errmsg = "cloneCollectionAsCapped failed: " + info.toString();
+ errmsg = "cloneCollectionAsCapped failed: " + string(info);
return false;
}
@@ -1274,7 +1274,7 @@ namespace mongo {
BSON( "renameCollection" << ( dbname + "." + from + ".$temp_convertToCapped" )
<< "to" << ( dbname + "." + from ) ),
info ) ) {
- errmsg = "renameCollection failed: " + info.toString();
+ errmsg = "renameCollection failed: " + string(info);
return false;
}
View
@@ -86,7 +86,7 @@ namespace mongo {
ss << hex << fileNo << ':' << ofs;
return ss.str();
}
- friend ostream& operator << (ostream& out, const DiskLoc& dl) { return (out << dl.toString()); }
+ operator string() const { return toString(); }
BSONObj toBSONObj() const {
return BSON( "file" << fileNo << "offset" << ofs );
View
@@ -277,7 +277,9 @@ namespace mongo {
return buf.str();
}
- friend ostream& operator << (ostream& out, const Point& p) { return (out << p.toString()); }
+ operator string() const {
+ return toString();
+ }
bool between( double min , double max , double val , double fudge=0) const {
return val + fudge >= min && val <= max + fudge;
View
@@ -131,7 +131,9 @@ namespace mongo {
const IndexSpec& getSpec() const;
- friend ostream& operator << (ostream& out, const IndexDetails& id) { return (out << id.info.obj().toString()); }
+ operator string() const {
+ return info.obj().toString();
+ }
};
struct IndexChanges/*on an update*/ {
View
@@ -162,7 +162,7 @@ namespace mongo {
static void namespaceGetNamespacesCallback( const Namespace& k , NamespaceDetails& v , void * extra ) {
list<string> * l = (list<string>*)extra;
if ( ! k.hasDollarSign() )
- l->push_back( k.toString() );
+ l->push_back( (string)k );
}
void NamespaceIndex::getNamespaces( list<string>& tofill , bool onlyCollections ) const {
View
@@ -139,8 +139,8 @@ namespace mongo {
return old + "." + local;
}
- string toString() const {
- return buf;
+ operator string() const {
+ return (string)buf;
}
char buf[MaxNsLen];
View
@@ -234,7 +234,7 @@ namespace mongo {
bool operator==(const ReplSource&r) const {
return hostName == r.hostName && sourceName() == r.sourceName();
}
- string toString() const { return sourceName() + "@" + hostName; }
+ operator string() const { return sourceName() + "@" + hostName; }
bool haveMoreDbsToSync() const { return !addDbNextPass.empty(); }
int sleepAdvice() const {
View
@@ -632,7 +632,7 @@ namespace JSTests {
private:
void check( const BSONObj &one, const BSONObj &two ) {
if ( one.woCompare( two ) != 0 ) {
- static string fail = string( "Assertion failure expected " ) + one.toString() + ", got " + two.toString();
+ static string fail = string( "Assertion failure expected " ) + string( one ) + ", got " + string( two );
FAIL( fail.c_str() );
}
}
@@ -338,7 +338,7 @@ namespace QueryOptimizerTests {
public:
virtual ~DiffBase() {}
void run() {
- FieldRangeSet frs( "", fromjson( obj().toString() ) );
+ FieldRangeSet frs( "", fromjson( obj() ) );
FieldRange ret = frs.range( "a" );
ret -= frs.range( "b" );
check( ret );
View
@@ -794,7 +794,7 @@ namespace mongo {
for ( set<Shard>::iterator i=seen.begin(); i!=seen.end(); i++ ){
ScopedDbConnection conn( *i );
BSONObj res;
- if ( ! setShardVersion( conn.conn() , _ns , SCV(0) , true , res ) )
+ if ( ! setShardVersion( conn.conn() , _ns , 0 , true , res ) )
throw UserException( 8071 , (string)"OH KNOW, cleaning up after drop failed: " + res.toString() );
conn.done();
}
@@ -898,7 +898,7 @@ namespace mongo {
rwlock lk( _lock , false );
// TODO: cache or something?
- ShardChunkVersion max(0);
+ ShardChunkVersion max = 0;
for ( ChunkMap::const_iterator i=_chunkMap.begin(); i!=_chunkMap.end(); ++i ){
ChunkPtr c = i->second;
@@ -917,7 +917,7 @@ namespace mongo {
}
ShardChunkVersion ChunkManager::getVersion_inlock() const{
- ShardChunkVersion max(0);
+ ShardChunkVersion max = 0;
for ( ChunkMap::const_iterator i=_chunkMap.begin(); i!=_chunkMap.end(); ++i ){
ChunkPtr c = i->second;
View
@@ -49,11 +49,11 @@ namespace mongo {
unsigned long long _combined;
};
- explicit ShardChunkVersion( int major=0, int minor=0 )
+ ShardChunkVersion( int major=0, int minor=0 )
: _minor(minor),_major(major){
}
- explicit ShardChunkVersion( unsigned long long ll )
+ ShardChunkVersion( unsigned long long ll )
: _combined( ll ){
}
@@ -80,7 +80,7 @@ namespace mongo {
}
operator unsigned long long() const { return _combined; }
- friend ostream& operator << (ostream& out, const ShardChunkVersion& scv){ return (out << scv.toString()); }
+ operator string() const { return toString(); }
ShardChunkVersion& operator=( const BSONElement& elem ){
switch ( elem.type() ){
@@ -98,8 +98,6 @@ namespace mongo {
return *this;
}
};
-
- typedef ShardChunkVersion SCV; // shortcut for constructors
typedef shared_ptr<Chunk> ChunkPtr;
@@ -139,6 +137,7 @@ namespace mongo {
bool contains( const BSONObj& obj ) const;
string toString() const;
+ operator string() const { return toString(); }
friend ostream& operator << (ostream& out, const Chunk& c){ return (out << c.toString()); }
bool operator==(const Chunk& s) const;
@@ -182,7 +181,7 @@ namespace mongo {
bool moveAndCommit( const Shard& to , string& errmsg );
const char * getNS(){ return "config.chunks"; }
- void serialize(BSONObjBuilder& to, ShardChunkVersion myLastMod=SCV(0));
+ void serialize(BSONObjBuilder& to, ShardChunkVersion myLastMod=0);
void unserialize(const BSONObj& from);
string modelServer();
@@ -345,7 +344,7 @@ namespace mongo {
void save();
string toString() const;
- friend ostream& operator<<(ostream& out, const ChunkManager& cm) { return (out << cm.toString()); }
+ operator string() const { return toString(); }
ShardChunkVersion getVersion( const Shard& shard ) const;
ShardChunkVersion getVersion() const;
View
@@ -152,15 +152,15 @@ namespace mongo {
ShardStatus( const Shard& shard , const BSONObj& obj );
- string toString() const {
- stringstream ss;
- ss << *this;
- return ss.str();
+ friend ostream& operator << (ostream& out, const ShardStatus& s) {
+ out << (string)s;
+ return out;
}
- friend ostream& operator << (ostream& out, const ShardStatus& ss){
- out << "shard: " << ss._shard << " mapped: " << ss._mapped << " writeLock: " << ss._writeLock;
- return out;
+ operator string() const {
+ stringstream ss;
+ ss << "shard: " << _shard << " mapped: " << _mapped << " writeLock: " << _writeLock;
+ return ss.str();
}
bool operator<( const ShardStatus& other ) const{
Oops, something went wrong.

0 comments on commit 13c6875

Please sign in to comment.