当前位置: 首页>>代码示例>>C++>>正文


C++ BSONElement::date方法代码示例

本文整理汇总了C++中BSONElement::date方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONElement::date方法的具体用法?C++ BSONElement::date怎么用?C++ BSONElement::date使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BSONElement的用法示例。


在下文中一共展示了BSONElement::date方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: run

 virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
     BSONObj fromToken = cmdObj.getObjectField("finishCloneCollection");
     if ( fromToken.isEmpty() ) {
         errmsg = "missing finishCloneCollection finishToken spec";
         return false;
     }
     string fromhost = fromToken.getStringField( "fromhost" );
     if ( fromhost.empty() ) {
         errmsg = "missing fromhost spec";
         return false;
     }
     string collection = fromToken.getStringField("collection");
     if ( collection.empty() ) {
         errmsg = "missing collection spec";
         return false;
     }
     BSONObj query = fromToken.getObjectField("query");
     if ( query.isEmpty() ) {
         query = BSONObj();
     }
     long long cursorId = 0;
     BSONElement cursorIdToken = fromToken.getField( "cursorId" );
     if ( cursorIdToken.type() == Date ) {
         cursorId = cursorIdToken.date();
     }
     
     setClient( collection.c_str() );
     
     log() << "finishCloneCollection.  db:" << ns << " collection:" << collection << " from: " << fromhost << " query: " << query << endl;
     
     Cloner c;
     return c.finishCloneCollection( fromhost.c_str(), collection.c_str(), query, cursorId, errmsg );
 }
开发者ID:catap,项目名称:mongo,代码行数:33,代码来源:cloner.cpp

示例2: report

 void report() const {
     const OpTime &maxOpTimeSynced = _player->maxOpTimeSynced();
     LOG(0) << "synced up to " << fmtOpTime(maxOpTimeSynced);
     if (!_rconn) {
         LOG(0) << endl;
         return;
     }
     Query lastQuery;
     lastQuery.sort("$natural", -1);
     BSONObj lastFields = BSON("ts" << 1);
     BSONObj lastObj = _rconn->conn().findOne(_oplogns, lastQuery, &lastFields);
     BSONElement tsElt = lastObj["ts"];
     if (!tsElt.ok()) {
         warning() << "couldn't find last oplog entry on remote host" << endl;
         LOG(0) << endl;
         return;
     }
     OpTime lastOpTime = OpTime(tsElt.date());
     LOG(0) << ", source has up to " << fmtOpTime(lastOpTime);
     if (maxOpTimeSynced == lastOpTime) {
         LOG(0) << ", fully synced." << endl;
     }
     else {
         int diff = lastOpTime.getSecs() - maxOpTimeSynced.getSecs();
         if (diff > 0) {
             LOG(0) << ", " << (lastOpTime.getSecs() - maxOpTimeSynced.getSecs())
                    << " seconds behind source." << endl;
         }
         else {
             LOG(0) << ", less than 1 second behind source." << endl;
         }
     }
     _reportingTimer.reset();
 }
开发者ID:7segments,项目名称:mongo,代码行数:34,代码来源:2toku.cpp

示例3: responseObj

StatusWith<DistLockCatalog::ServerInfo> DistLockCatalogImpl::getServerInfo(OperationContext* txn) {
    auto resultStatus = _client->getConfigShard()->runCommand(txn,
                                                              kReadPref,
                                                              "admin",
                                                              BSON("serverStatus" << 1),
                                                              Shard::kDefaultConfigCommandTimeout,
                                                              Shard::RetryPolicy::kIdempotent);

    if (!resultStatus.isOK()) {
        return resultStatus.getStatus();
    }
    if (!resultStatus.getValue().commandStatus.isOK()) {
        return resultStatus.getValue().commandStatus;
    }

    BSONObj responseObj(std::move(resultStatus.getValue().response));

    BSONElement localTimeElem;
    auto localTimeStatus =
        bsonExtractTypedField(responseObj, kLocalTimeField, Date, &localTimeElem);

    if (!localTimeStatus.isOK()) {
        return {ErrorCodes::UnsupportedFormat, localTimeStatus.reason()};
    }

    auto electionIdStatus = extractElectionId(responseObj);

    if (!electionIdStatus.isOK()) {
        return {ErrorCodes::UnsupportedFormat, electionIdStatus.getStatus().reason()};
    }

    return DistLockCatalog::ServerInfo(localTimeElem.date(), electionIdStatus.getValue());
}
开发者ID:ChineseDr,项目名称:mongo,代码行数:33,代码来源:dist_lock_catalog_impl.cpp

示例4: bsonExtractStringField

StatusWith<MongosType> MongosType::fromBSON(const BSONObj& source) {
    MongosType mt;

    {
        std::string mtName;
        Status status = bsonExtractStringField(source, name.name(), &mtName);
        if (!status.isOK())
            return status;
        mt._name = mtName;
    }

    {
        BSONElement mtPingElem;
        Status status = bsonExtractTypedField(source, ping.name(), BSONType::Date, &mtPingElem);
        if (!status.isOK())
            return status;
        mt._ping = mtPingElem.date();
    }

    {
        long long mtUptime;
        Status status = bsonExtractIntegerField(source, uptime.name(), &mtUptime);
        if (!status.isOK())
            return status;
        mt._uptime = mtUptime;
    }

    {
        bool mtWaiting;
        Status status = bsonExtractBooleanField(source, waiting.name(), &mtWaiting);
        if (!status.isOK())
            return status;
        mt._waiting = mtWaiting;
    }

    if (source.hasField(mongoVersion.name())) {
        std::string mtMongoVersion;
        Status status = bsonExtractStringField(source, mongoVersion.name(), &mtMongoVersion);
        if (!status.isOK())
            return status;
        mt._mongoVersion = mtMongoVersion;
    }

    if (source.hasField(configVersion.name())) {
        long long mtConfigVersion;
        Status status = bsonExtractIntegerField(source, configVersion.name(), &mtConfigVersion);
        if (!status.isOK())
            return status;
        mt._configVersion = mtConfigVersion;
    }

    return mt;
}
开发者ID:i80and,项目名称:mongo,代码行数:53,代码来源:type_mongos.cpp

示例5: syncToTailOfRemoteLog

 void ReplSource::syncToTailOfRemoteLog() {
     string _ns = ns();
     BSONObjBuilder b;
     if ( !only.empty() ) {
         b.appendRegex("ns", string("^") + only);
     }
     BSONObj last = oplogReader.findOne( _ns.c_str(), Query( b.done() ).sort( BSON( "$natural" << -1 ) ) );
     if ( !last.isEmpty() ) {
         BSONElement ts = last.getField( "ts" );
         massert( 10386 ,  "non Date ts found: " + last.toString(), ts.type() == Date || ts.type() == Timestamp );
         syncedTo = OpTime( ts.date() );
     }
 }
开发者ID:CoolCloud,项目名称:mongo,代码行数:13,代码来源:repl.cpp

示例6: attemptQuery

    bool attemptQuery(int queryOptions) {
        BSONObj res;
        auto_ptr<DBClientCursor> cursor(_rconn->conn().query(
            _oplogns, QUERY("ts" << GTE << _player->maxOpTimeSynced()),
            0, 0, &res, queryOptions));

        if (!cursor->more()) {
            log() << "oplog query returned no results, sleeping 10 seconds..." << endl;
            sleepsecs(10);
            log() << "retrying" << endl;
            return true;
        }

        BSONObj firstObj = cursor->next();
        {
            BSONElement tsElt = firstObj["ts"];
            if (!tsElt.ok()) {
                log() << "oplog format error: " << firstObj << " missing 'ts' field." << endl;
                logPosition();
                return false;
            }
            OpTime firstTime(tsElt.date());
            if (firstTime != _player->maxOpTimeSynced()) {
                throw CantFindTimestamp(firstTime);
            }
        }

        report();

        while (running && cursor->more()) {
            while (running && cursor->moreInCurrentBatch()) {
                BSONObj obj = cursor->next();
                LOG(2) << obj << endl;

                bool ok = _player->processObj(obj);
                if (!ok) {
                    logPosition();
                    return false;
                }
            }
            _player->flushInserts();

            if (_reportingTimer.seconds() >= _reportingPeriod) {
                report();
            }
        }

        return true;
    }
开发者ID:7segments,项目名称:mongo,代码行数:49,代码来源:2toku.cpp

示例7: Status

StatusWith<ShardingMetadata> ShardingMetadata::readFromMetadata(const BSONObj& metadataObj) {
    BSONElement smElem;
    auto smExtractStatus =
        bsonExtractTypedField(metadataObj, kGLEStatsFieldName, mongol::Object, &smElem);
    if (!smExtractStatus.isOK()) {
        return smExtractStatus;
    }

    if (smElem.embeddedObject().nFields() != 2) {
        return Status(ErrorCodes::InvalidOptions,
                      str::stream() << "The $gleStats object can only have 2 fields, but got "
                                    << smElem.embeddedObject().toString());
    }

    repl::OpTime opTime;
    const BSONElement opTimeElement = smElem.embeddedObject()[kGLEStatsLastOpTimeFieldName];
    if (opTimeElement.eoo()) {
        return Status(ErrorCodes::NoSuchKey, "lastOpTime field missing");
    } else if (opTimeElement.type() == bsonTimestamp) {
        opTime = repl::OpTime(opTimeElement.timestamp(), repl::OpTime::kUninitializedTerm);
    } else if (opTimeElement.type() == Date) {
        opTime = repl::OpTime(Timestamp(opTimeElement.date()), repl::OpTime::kUninitializedTerm);
    } else if (opTimeElement.type() == Object) {
        Status status =
            bsonExtractOpTimeField(smElem.embeddedObject(), kGLEStatsLastOpTimeFieldName, &opTime);
        if (!status.isOK()) {
            return status;
        }
    } else {
        return Status(ErrorCodes::TypeMismatch,
                      str::stream() << "Expected \"" << kGLEStatsLastOpTimeFieldName
                                    << "\" field in response to replSetHeartbeat "
                                       "command to have type Date or Timestamp, but found type "
                                    << typeName(opTimeElement.type()));
    }

    BSONElement lastElectionIdElem;
    auto lastElectionIdExtractStatus = bsonExtractTypedField(
        smElem.embeddedObject(), kGLEStatsElectionIdFieldName, mongol::jstOID, &lastElectionIdElem);
    if (!lastElectionIdExtractStatus.isOK()) {
        return lastElectionIdExtractStatus;
    }

    return ShardingMetadata(opTime, lastElectionIdElem.OID());
}
开发者ID:stevelyall,项目名称:mongol-db,代码行数:45,代码来源:sharding_metadata.cpp

示例8: responseObj

    StatusWith<DistLockCatalog::ServerInfo> DistLockCatalogImpl::getServerInfo() {
        auto targetStatus = _targeter->findHost(kReadPref);

        if (!targetStatus.isOK()) {
            return targetStatus.getStatus();
        }

        auto resultStatus = _cmdRunner->runCommand(RemoteCommandRequest(
                targetStatus.getValue(),
                "admin",
                BSON("serverStatus" << 1)));

        if (!resultStatus.isOK()) {
            return resultStatus.getStatus();
        }

        const RemoteCommandResponse& response = resultStatus.getValue();
        BSONObj responseObj(response.data);

        auto cmdStatus = getStatusFromCommandResult(responseObj);

        if (!cmdStatus.isOK()) {
            return cmdStatus;
        }

        BSONElement localTimeElem;
        auto localTimeStatus = bsonExtractTypedField(responseObj,
                                                     kLocalTimeField,
                                                     Date,
                                                     &localTimeElem);

        if (!localTimeStatus.isOK()) {
            return {ErrorCodes::UnsupportedFormat, localTimeStatus.reason()};
        }

        auto electionIdStatus = extractElectionId(responseObj);

        if (!electionIdStatus.isOK()) {
            return {ErrorCodes::UnsupportedFormat, electionIdStatus.getStatus().reason()};
        }

        return DistLockCatalog::ServerInfo(localTimeElem.date(), electionIdStatus.getValue());
    }
开发者ID:EliNok,项目名称:mongo,代码行数:43,代码来源:dist_lock_catalog_impl.cpp

示例9: getVersion

    unsigned long long getVersion( BSONElement e , string& errmsg ){
        if ( e.eoo() ){
            errmsg = "no version";
            return 0;
        }
        
        if ( e.isNumberLong() )
            return (unsigned long long)e.number64();
        
        if ( e.isNumber() )
            return (unsigned long long)e.number();
        
        if ( e.type() == Date || e.type() == Timestamp )
            return e.date();

        
        errmsg = "version is not a numberic type";
        return 0;
    }
开发者ID:fes,项目名称:mongo,代码行数:19,代码来源:d_logic.cpp

示例10: extract

FieldParser::FieldState FieldParser::extract(BSONElement elem,
                                             const BSONField<Date_t>& field,
                                             Date_t* out,
                                             string* errMsg) {
    if (elem.eoo()) {
        if (field.hasDefault()) {
            *out = field.getDefault();
            return FIELD_DEFAULT;
        } else {
            return FIELD_NONE;
        }
    }

    if (elem.type() == Date) {
        *out = elem.date();
        return FIELD_SET;
    }

    _genFieldErrMsg(elem, field, "date", errMsg);
    return FIELD_INVALID;
}
开发者ID:stevelyall,项目名称:mongol-db,代码行数:21,代码来源:field_parser.cpp

示例11: toval

    jsval toval( const BSONElement& e ) {

        switch( e.type() ) {
        case EOO:
        case jstNULL:
        case Undefined:
            return JSVAL_NULL;
        case NumberDouble:
        case NumberInt:
            return toval( e.number() );
        case Symbol: // TODO: should we make a special class for this
        case String:
            return toval( e.valuestr() );
        case Bool:
            return e.boolean() ? JSVAL_TRUE : JSVAL_FALSE;
        case Object: {
            BSONObj embed = e.embeddedObject().getOwned();
            return toval( &embed );
        }
        case Array: {

            BSONObj embed = e.embeddedObject().getOwned();

            if ( embed.isEmpty() ) {
                return OBJECT_TO_JSVAL( JS_NewArrayObject( _context , 0 , 0 ) );
            }

            int n = embed.nFields();

            JSObject * array = JS_NewArrayObject( _context , n , 0 );
            assert( array );

            jsval myarray = OBJECT_TO_JSVAL( array );

            for ( int i=0; i<n; i++ ) {
                jsval v = toval( embed[i] );
                assert( JS_SetElement( _context , array , i , &v ) );
            }

            return myarray;
        }
        case jstOID: {
            OID oid = e.__oid();
            JSObject * o = JS_NewObject( _context , &object_id_class , 0 , 0 );
            setProperty( o , "str" , toval( oid.str().c_str() ) );
            return OBJECT_TO_JSVAL( o );
        }
        case RegEx: {
            const char * flags = e.regexFlags();
            uintN flagNumber = 0;
            while ( *flags ) {
                switch ( *flags ) {
                case 'g':
                    flagNumber |= JSREG_GLOB;
                    break;
                case 'i':
                    flagNumber |= JSREG_FOLD;
                    break;
                case 'm':
                    flagNumber |= JSREG_MULTILINE;
                    break;
                //case 'y': flagNumber |= JSREG_STICKY; break;

                default:
                    log() << "warning: unknown regex flag:" << *flags << endl;
                }
                flags++;
            }

            JSObject * r = JS_NewRegExpObject( _context , (char*)e.regex() , strlen( e.regex() ) , flagNumber );
            assert( r );
            return OBJECT_TO_JSVAL( r );
        }
        case Code: {
            JSFunction * func = compileFunction( e.valuestr() );
            return OBJECT_TO_JSVAL( JS_GetFunctionObject( func ) );
        }
        case CodeWScope: {
            JSFunction * func = compileFunction( e.codeWScopeCode() );

            BSONObj extraScope = e.codeWScopeObject();
            if ( ! extraScope.isEmpty() ) {
                log() << "warning: CodeWScope doesn't transfer to db.eval" << endl;
            }

            return OBJECT_TO_JSVAL( JS_GetFunctionObject( func ) );
        }
        case Date:
            return OBJECT_TO_JSVAL( js_NewDateObjectMsec( _context , (jsdouble) e.date().millis ) );

        case MinKey:
            return OBJECT_TO_JSVAL( JS_NewObject( _context , &minkey_class , 0 , 0 ) );

        case MaxKey:
            return OBJECT_TO_JSVAL( JS_NewObject( _context , &maxkey_class , 0 , 0 ) );

        case Timestamp: {
            JSObject * o = JS_NewObject( _context , &timestamp_class , 0 , 0 );
            setProperty( o , "t" , toval( (double)(e.timestampTime()) ) );
            setProperty( o , "i" , toval( (double)(e.timestampInc()) ) );
//.........这里部分代码省略.........
开发者ID:xrogaan,项目名称:mongo,代码行数:101,代码来源:engine_spidermonkey.cpp

示例12: compareElementValues

 /* must be same type! */
 int compareElementValues(const BSONElement& l, const BSONElement& r) {
     int f;
     double x;
     switch ( l.type() ) {
     case EOO:
     case Undefined:
     case jstNULL:
     case MaxKey:
     case MinKey:
         f = l.type() - r.type();
         if ( f<0 ) return -1;
         return f==0 ? 0 : 1;
     case Bool:
         return *l.value() - *r.value();
     case Timestamp:
     case Date:
         if ( l.date() < r.date() )
             return -1;
         return l.date() == r.date() ? 0 : 1;
     case NumberInt:
     case NumberDouble: {
         double left = l.number();
         double right = r.number();
         bool lNan = !( left <= numeric_limits< double >::max() &&
                      left >= -numeric_limits< double >::max() );
         bool rNan = !( right <= numeric_limits< double >::max() &&
                      right >= -numeric_limits< double >::max() );
         if ( lNan ) {
             if ( rNan ) {
                 return 0;
             } else {
                 return -1;
             }
         } else if ( rNan ) {
             return 1;
         }
         x = left - right;
         if ( x < 0 ) return -1;
         return x == 0 ? 0 : 1;
         }
     case jstOID:
         return memcmp(l.value(), r.value(), 12);
     case Code:
     case Symbol:
     case String:
         /* todo: utf version */
         return strcmp(l.valuestr(), r.valuestr());
     case Object:
     case Array:
         return l.embeddedObject().woCompare( r.embeddedObject() );
     case DBRef:
     case BinData: {
         int lsz = l.valuesize();
         int rsz = r.valuesize();
         if ( lsz - rsz != 0 ) return lsz - rsz;
         return memcmp(l.value(), r.value(), lsz);
     }
     case RegEx:
     {
         int c = strcmp(l.regex(), r.regex());
         if ( c )
             return c;
         return strcmp(l.regexFlags(), r.regexFlags());
     }
     default:
         out() << "compareElementValues: bad type " << (int) l.type() << endl;
         assert(false);
     }
     return -1;
 }
开发者ID:agiamas,项目名称:mongo,代码行数:71,代码来源:jsobj.cpp

示例13: switch

Local<v8::Object> mongoToV8( BSONObj & m , bool array ){
    Local<v8::Object> o;
    if ( array )
        o = v8::Array::New();
    else 
        o = v8::Object::New();
    
    mongo::BSONObj sub;
    
    for ( BSONObjIterator i(m); i.more(); ) {
        BSONElement f = i.next();
        if ( f.eoo() )
            break;
        
        Local<Value> v;
        
        switch ( f.type() ){

        case mongo::Code:
            cout << "warning, code saved in database just turned into string right now" << endl;
        case mongo::String: 
            o->Set( v8::String::New( f.fieldName() ) , v8::String::New( f.valuestr() ) );
            break;
            
        case mongo::jstOID: {
            v8::Function * idCons = getObjectIdCons();
            v8::Handle<v8::Value> argv[1];
            argv[0] = v8::String::New( f.__oid().str().c_str() );
            o->Set( v8::String::New( f.fieldName() ) , 
                    idCons->NewInstance( 1 , argv ) );
            break;
        }
            
        case mongo::NumberDouble:
        case mongo::NumberInt:
            o->Set( v8::String::New( f.fieldName() ) , v8::Number::New( f.number() ) );
            break;
            
        case mongo::Array:
        case mongo::Object:
            sub = f.embeddedObject();
            o->Set( v8::String::New( f.fieldName() ) , mongoToV8( sub , f.type() == mongo::Array ) );
            break;
            
        case mongo::Date:
            o->Set( v8::String::New( f.fieldName() ) , v8::Date::New( f.date() ) );
            break;

        case mongo::Bool:
            o->Set( v8::String::New( f.fieldName() ) , v8::Boolean::New( f.boolean() ) );
            break;
            
        case mongo::jstNULL:
            o->Set( v8::String::New( f.fieldName() ) , v8::Null() );
            break;
            
        case mongo::RegEx: {
            v8::Function * regex = getNamedCons( "RegExp" );
            
            v8::Handle<v8::Value> argv[2];
            argv[0] = v8::String::New( f.regex() );
            argv[1] = v8::String::New( f.regexFlags() );
            
            o->Set( v8::String::New( f.fieldName() ) , regex->NewInstance( 2 , argv ) );
            break;
        }
            
        case mongo::BinData: {
            Local<v8::Object> b = v8::Object::New();

            int len;
            f.binData( len );
            
            b->Set( v8::String::New( "subtype" ) , v8::Number::New( f.binDataType() ) );
            b->Set( v8::String::New( "length" ) , v8::Number::New( len ) );
            
            o->Set( v8::String::New( f.fieldName() ) , b );
            break;
        };
            
        case mongo::Timestamp: {
            Local<v8::Object> sub = v8::Object::New();            

            sub->Set( v8::String::New( "time" ) , v8::Date::New( f.timestampTime() ) );
            sub->Set( v8::String::New( "i" ) , v8::Number::New( f.timestampInc() ) );
            
            o->Set( v8::String::New( f.fieldName() ) , sub );
            break;
        }

        default:
            cout << "can't handle type: ";
			cout  << f.type() << " ";
			cout  << f.toString();
			cout  << endl;
            break;
        }
        
    }

//.........这里部分代码省略.........
开发者ID:tanfulai,项目名称:mongo,代码行数:101,代码来源:MongoJS.cpp

示例14: dcmlNorm

void BSONComparatorInterfaceBase<T>::hashCombineBSONElement(
    size_t& hash,
    BSONElement elemToHash,
    bool considerFieldName,
    const StringData::ComparatorInterface* stringComparator) {
    boost::hash_combine(hash, elemToHash.canonicalType());

    const StringData fieldName = elemToHash.fieldNameStringData();
    if (considerFieldName && !fieldName.empty()) {
        SimpleStringDataComparator::kInstance.hash_combine(hash, fieldName);
    }

    switch (elemToHash.type()) {
        // Order of types is the same as in compareElementValues().

        case mongo::EOO:
        case mongo::Undefined:
        case mongo::jstNULL:
        case mongo::MaxKey:
        case mongo::MinKey:
            // These are valueless types
            break;

        case mongo::Bool:
            boost::hash_combine(hash, elemToHash.boolean());
            break;

        case mongo::bsonTimestamp:
            boost::hash_combine(hash, elemToHash.timestamp().asULL());
            break;

        case mongo::Date:
            boost::hash_combine(hash, elemToHash.date().asInt64());
            break;

        case mongo::NumberDecimal: {
            const Decimal128 dcml = elemToHash.numberDecimal();
            if (dcml.toAbs().isGreater(Decimal128(std::numeric_limits<double>::max(),
                                                  Decimal128::kRoundTo34Digits,
                                                  Decimal128::kRoundTowardZero)) &&
                !dcml.isInfinite() && !dcml.isNaN()) {
                // Normalize our decimal to force equivalent decimals
                // in the same cohort to hash to the same value
                Decimal128 dcmlNorm(dcml.normalize());
                boost::hash_combine(hash, dcmlNorm.getValue().low64);
                boost::hash_combine(hash, dcmlNorm.getValue().high64);
                break;
            }
            // Else, fall through and convert the decimal to a double and hash.
            // At this point the decimal fits into the range of doubles, is infinity, or is NaN,
            // which doubles have a cheaper representation for.
        }
        case mongo::NumberDouble:
        case mongo::NumberLong:
        case mongo::NumberInt: {
            // This converts all numbers to doubles, which ignores the low-order bits of
            // NumberLongs > 2**53 and precise decimal numbers without double representations,
            // but that is ok since the hash will still be the same for equal numbers and is
            // still likely to be different for different numbers. (Note: this issue only
            // applies for decimals when they are outside of the valid double range. See
            // the above case.)
            // SERVER-16851
            const double dbl = elemToHash.numberDouble();
            if (std::isnan(dbl)) {
                boost::hash_combine(hash, std::numeric_limits<double>::quiet_NaN());
            } else {
                boost::hash_combine(hash, dbl);
            }
            break;
        }

        case mongo::jstOID:
            elemToHash.__oid().hash_combine(hash);
            break;

        case mongo::String: {
            if (stringComparator) {
                stringComparator->hash_combine(hash, elemToHash.valueStringData());
            } else {
                SimpleStringDataComparator::kInstance.hash_combine(hash,
                                                                   elemToHash.valueStringData());
            }
            break;
        }

        case mongo::Code:
        case mongo::Symbol:
            SimpleStringDataComparator::kInstance.hash_combine(hash, elemToHash.valueStringData());
            break;

        case mongo::Object:
        case mongo::Array:
            hashCombineBSONObj(hash,
                               elemToHash.embeddedObject(),
                               true,  // considerFieldName
                               stringComparator);
            break;

        case mongo::DBRef:
        case mongo::BinData:
//.........这里部分代码省略.........
开发者ID:DINKIN,项目名称:mongo,代码行数:101,代码来源:bson_comparator_interface_base.cpp

示例15: i

// fromBSON to Key format
KeyV1Owned::KeyV1Owned(const BSONObj& obj) {
    BSONObj::iterator i(obj);
    assert( i.more() );
    unsigned char bits = 0;
    while( 1 ) {
        BSONElement e = i.next();
        if( i.more() )
            bits |= cHASMORE;
        switch( e.type() ) {
        case MinKey:
            b.appendUChar(cminkey|bits);
            break;
        case jstNULL:
            b.appendUChar(cnull|bits);
            break;
        case MaxKey:
            b.appendUChar(cmaxkey|bits);
            break;
        case Bool:
            b.appendUChar( (e.boolean()?ctrue:cfalse) | bits );
            break;
        case jstOID:
            b.appendUChar(coid|bits);
            b.appendBuf(&e.__oid(), sizeof(OID));
            break;
        case BinData:
        {
            int t = e.binDataType();
            // 0-7 and 0x80 to 0x87 are supported by Key
            if( (t & 0x78) == 0 && t != ByteArrayDeprecated ) {
                int len;
                const char * d = e.binData(len);
                int code = BinDataLengthToCode[len];
                if( code >= 0 ) {
                    if( t >= 128 )
                        t = (t-128) | 0x08;
                    dassert( (code&t) == 0 );
                    b.appendUChar( cbindata|bits );
                    b.appendUChar( code | t );
                    b.appendBuf(d, len);
                    break;
                }
            }
            traditional(obj);
            return;
        }
        case Date:
            b.appendUChar(cdate|bits);
            b.appendStruct(e.date());
            break;
        case String:
        {
            b.appendUChar(cstring|bits);
            // note we do not store the terminating null, to save space.
            unsigned x = (unsigned) e.valuestrsize() - 1;
            if( x > 255 ) {
                traditional(obj);
                return;
            }
            b.appendUChar(x);
            b.appendBuf(e.valuestr(), x);
            break;
        }
        case NumberInt:
            b.appendUChar(cint|bits);
            b.appendNum((double) e._numberInt());
            break;
        case NumberLong:
        {
            long long n = e._numberLong();
            double d = (double) n;
            if( d != n ) {
                traditional(obj);
                return;
            }
            b.appendUChar(clong|bits);
            b.appendNum(d);
            break;
        }
        case NumberDouble:
        {
            double d = e._numberDouble();
            bool nan = !( d <= numeric_limits< double >::max() &&
                          d >= -numeric_limits< double >::max() );
            if( !nan ) {
                b.appendUChar(cdouble|bits);
                b.appendNum(d);
                break;
            }
            // else fall through and return a traditional BSON obj so our compressed keys need not check for nan
        }
        default:
            // if other types involved, store as traditional BSON
            traditional(obj);
            return;
        }
        if( !i.more() )
            break;
        bits = 0;
//.........这里部分代码省略.........
开发者ID:kzys,项目名称:mongo,代码行数:101,代码来源:key.cpp


注:本文中的BSONElement::date方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。