void append( BSONObjBuilder& b , string name , jsval val , BSONType oldType = EOO , int depth=0 ) { //cout << "name: " << name << "\t" << typeString( val ) << " oldType: " << oldType << endl; switch ( JS_TypeOfValue( _context , val ) ) { case JSTYPE_VOID: b.appendUndefined( name.c_str() ); break; case JSTYPE_NULL: b.appendNull( name.c_str() ); break; case JSTYPE_NUMBER: { double d = toNumber( val ); if ( oldType == NumberInt && ((int)d) == d ) b.append( name.c_str() , (int)d ); else b.append( name.c_str() , d ); break; } case JSTYPE_STRING: b.append( name.c_str() , toString( val ) ); break; case JSTYPE_BOOLEAN: b.appendBool( name.c_str() , toBoolean( val ) ); break; case JSTYPE_OBJECT: { JSObject * o = JSVAL_TO_OBJECT( val ); if ( ! o || o == JSVAL_NULL ) { b.appendNull( name.c_str() ); } else if ( ! appendSpecialDBObject( this , b , name , val , o ) ) { BSONObj sub = toObject( o , depth ); if ( JS_IsArrayObject( _context , o ) ) { b.appendArray( name.c_str() , sub ); } else { b.append( name.c_str() , sub ); } } break; } case JSTYPE_FUNCTION: { string s = toString(val); if ( s[0] == '/' ) { appendRegex( b , name , s ); } else { b.appendCode( name.c_str() , getFunctionCode( val ).c_str() ); } break; } default: uassert( 10217 , (string)"can't append field. name:" + name + " type: " + typeString( val ) , 0 ); } }
void BSONObjBuilder::appendMinForType( const StringData& fieldName , int t ) { switch ( t ) { // Shared canonical types case NumberInt: case NumberDouble: case NumberLong: append( fieldName , - std::numeric_limits<double>::max() ); return; case Symbol: case String: append( fieldName , "" ); return; case Date: // min varies with V0 and V1 indexes, so we go one type lower. appendBool(fieldName, true); //appendDate( fieldName , numeric_limits<long long>::min() ); return; case Timestamp: // TODO integrate with Date SERVER-3304 appendTimestamp( fieldName , 0 ); return; case Undefined: // shared with EOO appendUndefined( fieldName ); return; // Separate canonical types case MinKey: appendMinKey( fieldName ); return; case MaxKey: appendMaxKey( fieldName ); return; case jstOID: { OID o; appendOID( fieldName , &o); return; } case Bool: appendBool( fieldName , false); return; case jstNULL: appendNull( fieldName ); return; case Object: append( fieldName , BSONObj() ); return; case Array: appendArray( fieldName , BSONObj() ); return; case BinData: appendBinData( fieldName , 0 , BinDataGeneral , (const char *) 0 ); return; case RegEx: appendRegex( fieldName , "" ); return; case DBRef: { OID o; appendDBRef( fieldName , "" , o ); return; } case Code: appendCode( fieldName , "" ); return; case CodeWScope: appendCodeWScope( fieldName , "" , BSONObj() ); return; }; log() << "type not supported for appendMinElementForType: " << t; uassert( 10061 , "type not supported for appendMinElementForType" , false ); }
void BSONObjBuilder::appendMinForType( const string& field , int t ){ switch ( t ){ case MinKey: appendMinKey( field.c_str() ); return; case MaxKey: appendMinKey( field.c_str() ); return; case NumberInt: case NumberDouble: case NumberLong: append( field.c_str() , - numeric_limits<double>::max() ); return; case jstOID: { OID o; memset(&o, 0, sizeof(o)); appendOID( field.c_str() , &o); return; } case Bool: appendBool( field.c_str() , false); return; case Date: appendDate( field.c_str() , 0); return; case jstNULL: appendNull( field.c_str() ); return; case String: append( field.c_str() , "" ); return; case Object: append( field.c_str() , BSONObj() ); return; case Array: appendArray( field.c_str() , BSONObj() ); return; case BinData: appendBinData( field.c_str() , 0 , Function , 0 ); return; case Undefined: appendUndefined( field.c_str() ); return; case RegEx: appendRegex( field.c_str() , "" ); return; case DBRef: { OID o; memset(&o, 0, sizeof(o)); appendDBRef( field.c_str() , "" , o ); return; } case Code: appendCode( field.c_str() , "" ); return; case Symbol: appendSymbol( field.c_str() , "" ); return; case CodeWScope: appendCodeWScope( field.c_str() , "" , BSONObj() ); return; case Timestamp: appendTimestamp( field.c_str() , 0); return; }; log() << "type not support for appendMinElementForType: " << t << endl; uassert( "type not supported for appendMinElementForType" , false ); }