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


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

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


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

示例1: parseLegacyPoint

 void GeoParser::parseLegacyPoint(const BSONObj &obj, Point *out) {
     BSONObjIterator it(obj);
     BSONElement x = it.next();
     BSONElement y = it.next();
     out->x = x.number();
     out->y = y.number();
 }
开发者ID:QiuYe,项目名称:mongo,代码行数:7,代码来源:geoparser.cpp

示例2: parseCap

    bool GeoParser::parseCap(const BSONObj& obj, CapWithCRS *out) {
        if (isLegacyCenter(obj)) {
            BSONObjIterator typeIt(obj);
            BSONElement type = typeIt.next();
            BSONObjIterator objIt(type.embeddedObject());
            BSONElement center = objIt.next();
            if (!parseLegacyPoint(center.Obj(), &out->circle.center)) { return false; }
            BSONElement radius = objIt.next();
            out->circle.radius = radius.number();
            out->crs = FLAT;
        } else {
            verify(isLegacyCenterSphere(obj));
            BSONObjIterator typeIt(obj);
            BSONElement type = typeIt.next();
            BSONObjIterator objIt(type.embeddedObject());
            BSONObj centerObj = objIt.next().Obj();

            S2Point centerPoint;
            BSONObjIterator it(centerObj);
            BSONElement x = it.next();
            BSONElement y = it.next();
            centerPoint = coordToPoint(x.Number(), y.Number());
            BSONElement radiusElt = objIt.next();
            double radius = radiusElt.number();
            out->cap = S2Cap::FromAxisAngle(centerPoint, S1Angle::Radians(radius));
            out->circle.radius = radius;
            out->circle.center = Point(x.Number(), y.Number());
            out->crs = SPHERE;
        }
        return true;
    }
开发者ID:ashleybrener,项目名称:mongo,代码行数:31,代码来源:geoparser.cpp

示例3: diff

 double StatUtil::diff( const string& name , const BSONObj& a , const BSONObj& b ) {
     BSONElement x = a.getFieldDotted( name.c_str() );
     BSONElement y = b.getFieldDotted( name.c_str() );
     if ( ! x.isNumber() || ! y.isNumber() )
         return -1;
     return ( y.number() - x.number() ) / _seconds;
 }
开发者ID:Desartstudio,项目名称:mongo-nonx86,代码行数:7,代码来源:stat_util.cpp

示例4: parsePointWithMaxDistance

    bool GeoParser::parsePointWithMaxDistance(const BSONObj& obj, PointWithCRS* out, double* maxOut) {
        BSONObjIterator it(obj);
        if (!it.more()) { return false; }

        BSONElement lng = it.next();
        if (!lng.isNumber()) { return false; }
        if (!it.more()) { return false; }

        BSONElement lat = it.next();
        if (!lat.isNumber()) { return false; }
        if (!it.more()) { return false; }

        BSONElement dist = it.next();
        if (!dist.isNumber()) { return false; }
        if (it.more()) { return false; }

        out->crs = FLAT;
        out->oldPoint.x = lng.number();
        out->oldPoint.y = lat.number();
        *maxOut = dist.number();
        if (isValidLngLat(lng.Number(), lat.Number())) {
            out->flatUpgradedToSphere = true;
            out->point = coordToPoint(lng.Number(), lat.Number());
            out->cell = S2Cell(out->point);
        }
        return true;
    }
开发者ID:ashleybrener,项目名称:mongo,代码行数:27,代码来源:geoparser.cpp

示例5: parseLegacyPoint

 static bool parseLegacyPoint(const BSONObj &obj, Point *out) {
     BSONObjIterator it(obj);
     BSONElement x = it.next();
     BSONElement y = it.next();
     out->x = x.number();
     out->y = y.number();
     return true;
 }
开发者ID:ashleybrener,项目名称:mongo,代码行数:8,代码来源:geoparser.cpp

示例6: parsePoint

 bool GeoParser::parsePoint(const BSONObj &obj, S2Point *out) {
     if (isGeoJSONPoint(obj)) {
         parseGeoJSONPoint(obj, out);
         return true;
     } else if (isLegacyPoint(obj)) {
         BSONObjIterator it(obj);
         BSONElement x = it.next();
         BSONElement y = it.next();
         *out = coordToPoint(x.number(), y.number());
         return true;
     }
     return false;
 }
开发者ID:QiuYe,项目名称:mongo,代码行数:13,代码来源:geoparser.cpp

示例7: woCompare

    /* well ordered compare */
    int BSONObj::woCompare(const BSONObj &r, const BSONObj &idxKey,
                           bool considerFieldName) const {
        if ( isEmpty() )
            return r.isEmpty() ? 0 : -1;
        if ( r.isEmpty() )
            return 1;

        bool ordered = !idxKey.isEmpty();

        BSONObjIterator i(*this);
        BSONObjIterator j(r);
        BSONObjIterator k(idxKey);
        while ( 1 ) {
            // so far, equal...

            BSONElement l = i.next();
            BSONElement r = j.next();
            BSONElement o;
            if ( ordered )
                o = k.next();
            if ( l.eoo() )
                return r.eoo() ? 0 : -1;
            if ( r.eoo() )
                return 1;

            int x = l.woCompare( r, considerFieldName );
            if ( ordered && o.number() < 0 )
                x = -x;
            if ( x != 0 )
                return x;
        }
        return -1;
    }
开发者ID:agiamas,项目名称:mongo,代码行数:34,代码来源:jsobj.cpp

示例8: woSortOrder

    /* well ordered compare */
    int BSONObj::woSortOrder(const BSONObj& other, const BSONObj& sortKey ) const{
        if ( isEmpty() )
            return other.isEmpty() ? 0 : -1;
        if ( other.isEmpty() )
            return 1;

        uassert( "woSortOrder needs a non-empty sortKey" , ! sortKey.isEmpty() );
        
        BSONObjIterator i(sortKey);
        while ( 1 ){
            BSONElement f = i.next();
            if ( f.eoo() )
                return 0;
            
            BSONElement l = getField( f.fieldName() );
            if ( l.eoo() )
                l = staticNull.firstElement();
            BSONElement r = other.getField( f.fieldName() );
            if ( r.eoo() )
                r = staticNull.firstElement();
            
            int x = l.woCompare( r, false );
            if ( f.number() < 0 )
                x = -x;
            if ( x != 0 )
                return x;
        }
        return -1;
    }
开发者ID:agiamas,项目名称:mongo,代码行数:30,代码来源:jsobj.cpp

示例9: isValidFor

bool IndexBounds::isValidFor(const BSONObj& keyPattern, int direction) {
    if (isSimpleRange) {
        return direction == sgn(endKey.woCompare(startKey, keyPattern, false));
    }

    BSONObjIterator it(keyPattern);

    for (size_t i = 0; i < fields.size(); ++i) {
        // We expect a bound for each field in the index.
        if (!it.more()) {
            return false;
        }
        BSONElement elt = it.next();

        const OrderedIntervalList& field = fields[i];

        // Make sure the names match up.
        if (field.name != elt.fieldName()) {
            return false;
        }

        // Special indices are all inserted increasing.  elt.number() will return 0 if it's
        // not a number.  Special indices are strings, not numbers.
        int expectedOrientation = direction * ((elt.number() >= 0) ? 1 : -1);

        if (!field.isValidFor(expectedOrientation)) {
            return false;
        }
    }

    return !it.more();
}
开发者ID:AlexOreshkevich,项目名称:mongo,代码行数:32,代码来源:index_bounds.cpp

示例10: findAll

    /* get a table scan cursor, but can be forward or reverse direction.
       order.$natural - if set, > 0 means forward (asc), < 0 backward (desc).
    */
    shared_ptr<Cursor> findTableScan(const char *ns, const BSONObj& order, const DiskLoc &startLoc) {
        BSONElement el = order.getField("$natural"); // e.g., { $natural : -1 }

        if ( el.number() >= 0 )
            return DataFileMgr::findAll(ns, startLoc);

        // "reverse natural order"
        NamespaceDetails *d = nsdetails(ns);

        if ( !d )
            return shared_ptr<Cursor>(new BasicCursor(DiskLoc()));

        if ( !d->isCapped() ) {
            if ( !startLoc.isNull() )
                return shared_ptr<Cursor>(new ReverseCursor( startLoc ));
            Extent *e = d->lastExtent().ext();
            while ( e->lastRecord.isNull() && !e->xprev.isNull() ) {
                OCCASIONALLY out() << "  findTableScan: extent empty, skipping ahead" << endl;
                e = e->getPrevExtent();
            }
            return shared_ptr<Cursor>(new ReverseCursor( e->lastRecord ));
        }
        else {
            return shared_ptr<Cursor>( new ReverseCappedCursor( d, startLoc ) );
        }
    }
开发者ID:ChrisKozak,项目名称:mongo,代码行数:29,代码来源:pdfile.cpp

示例11: parseLegacyCenter

 void GeoParser::parseLegacyCenter(const BSONObj &obj, Point *centerOut, double *radiusOut) {
     BSONObjIterator objIt(obj);
     BSONElement center = objIt.next();
     parseLegacyPoint(center.Obj(), centerOut);
     BSONElement radius = objIt.next();
     *radiusOut = radius.number();
 }
开发者ID:sebdah,项目名称:mongo,代码行数:7,代码来源:geoparser.cpp

示例12: filterAndScore

    void TextStage::filterAndScore(BSONObj key, DiskLoc loc) {
        // Locate score within possibly compound key: {prefix,term,score,suffix}.
        BSONObjIterator keyIt(key);
        for (unsigned i = 0; i < _params.spec.numExtraBefore(); i++) {
            keyIt.next();
        }

        keyIt.next(); // Skip past 'term'.

        BSONElement scoreElement = keyIt.next();
        double documentTermScore = scoreElement.number();
        double& documentAggregateScore = _scores[loc];
        
        // Handle filtering.
        if (documentAggregateScore < 0) {
            // We have already rejected this document.
            return;
        }
        if (documentAggregateScore == 0 && _filter) {
            // We have not seen this document before and need to apply a filter.
            Record* rec_p = loc.rec();
            BSONObj doc = BSONObj::make(rec_p);

            // TODO: Covered index matching logic here.
            if (!_filter->matchesBSON(doc)) {
                documentAggregateScore = -1;
                return;
            }
        }

        // Aggregate relevance score, term keys.
        documentAggregateScore += documentTermScore;
    }
开发者ID:Convey-Compliance,项目名称:mongo,代码行数:33,代码来源:text.cpp

示例13: compareObjectsAccordingToSort

int compareObjectsAccordingToSort(const BSONObj& firstObj,
                                  const BSONObj& secondObj,
                                  const BSONObj& sortKey,
                                  bool assumeDottedPaths) {
    if (firstObj.isEmpty())
        return secondObj.isEmpty() ? 0 : -1;
    if (secondObj.isEmpty())
        return 1;

    uassert(10060, "compareObjectsAccordingToSort() needs a non-empty sortKey", !sortKey.isEmpty());

    BSONObjIterator i(sortKey);
    while (1) {
        BSONElement f = i.next();
        if (f.eoo())
            return 0;

        BSONElement l = assumeDottedPaths ? extractElementAtPath(firstObj, f.fieldName())
                                          : firstObj.getField(f.fieldName());
        if (l.eoo())
            l = kNullElt;
        BSONElement r = assumeDottedPaths ? extractElementAtPath(secondObj, f.fieldName())
                                          : secondObj.getField(f.fieldName());
        if (r.eoo())
            r = kNullElt;

        int x = l.woCompare(r, false);
        if (f.number() < 0)
            x = -x;
        if (x != 0)
            return x;
    }
    return -1;
}
开发者ID:AshishSanju,项目名称:mongo,代码行数:34,代码来源:dotted_path_support.cpp

示例14: it

// Is lhs less than rhs?  Note that priority_queue is a max heap by default so we invert
// the return from the expected value.
bool MergeSortStage::StageWithValueComparison::operator()(const MergingRef& lhs,
                                                          const MergingRef& rhs) {
    WorkingSetMember* lhsMember = _ws->get(lhs->id);
    WorkingSetMember* rhsMember = _ws->get(rhs->id);

    BSONObjIterator it(_pattern);
    while (it.more()) {
        BSONElement patternElt = it.next();
        string fn = patternElt.fieldName();

        BSONElement lhsElt;
        verify(lhsMember->getFieldDotted(fn, &lhsElt));

        BSONElement rhsElt;
        verify(rhsMember->getFieldDotted(fn, &rhsElt));

        // false means don't compare field name.
        int x = lhsElt.woCompare(rhsElt, false);
        if (-1 == patternElt.number()) {
            x = -x;
        }
        if (x != 0) {
            return x > 0;
        }
    }

    // A comparator for use with sort is required to model a strict weak ordering, so
    // to satisfy irreflexivity we must return 'false' for elements that we consider
    // equivalent under the pattern.
    return false;
}
开发者ID:To4e,项目名称:mongo,代码行数:33,代码来源:merge_sort.cpp

示例15: printData

        static void printData( const BSONObj& o , const BSONObj& headers ) {

            BSONObjIterator i(headers);
            while ( i.more() ) {
                BSONElement e = i.next();
                BSONObj h = e.Obj();
                int w = h["width"].numberInt();

                BSONElement data;
                {
                    BSONElement temp = o[e.fieldName()];
                    if ( temp.isABSONObj() )
                        data = temp.Obj()["data"];
                }

                if ( data.type() == String )
                    cout << setw(w) << data.String();
                else if ( data.type() == NumberDouble )
                    cout << setw(w) << setprecision(3) << data.number();
                else if ( data.type() == NumberInt )
                    cout << setw(w) << data.numberInt();
                else if ( data.eoo() )
                    cout << setw(w) << "";
                else
                    cout << setw(w) << "???";

                cout << ' ';
            }
            cout << endl;
        }
开发者ID:nosqldb,项目名称:mongo,代码行数:30,代码来源:stat.cpp


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