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


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

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


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

示例1: _getSvcNameFromArg

   const CHAR* _omAgentNodeMgr::_getSvcNameFromArg( const CHAR * arg )
   {
      const CHAR *pSvcName = NULL ;

      try
      {
         BSONObj objArg1( arg ) ;
         BSONElement e = objArg1.getField( PMD_OPTION_SVCNAME ) ;
         if ( e.type() != String )
         {
            PD_LOG( PDERROR, "Param[%s] type[%s] error: %s",
                    PMD_OPTION_SVCNAME, e.type(), e.toString().c_str() ) ;
            goto error ;
         }
         pSvcName = e.valuestrsafe() ;
      }
      catch( std::exception &e )
      {
         PD_LOG( PDERROR, "Ocuur exception: %s", e.what() ) ;
         goto error ;
      }

   done:
      return pSvcName ;
   error:
      goto done ;
   }
开发者ID:hanjirui,项目名称:SequoiaDB,代码行数:27,代码来源:omagentNodeMgr.cpp

示例2: getIdentSize

    int64_t WiredTigerUtil::getIdentSize(WT_SESSION* s,
                                         const std::string& uri ) {
        BSONObjBuilder b;
        Status status = WiredTigerUtil::exportTableToBSON(s,
                                                          "statistics:" + uri,
                                                          "statistics=(fast)",
                                                          &b);
        if ( !status.isOK() ) {
            if ( status.code() == ErrorCodes::CursorNotFound ) {
                // ident gone, so its 0
                return 0;
            }
            uassertStatusOK( status );
        }

        BSONObj obj = b.obj();
        BSONObj sub = obj["block-manager"].Obj();
        BSONElement e = sub["file size in bytes"];
        invariant( e.type() );

        if ( e.isNumber() )
            return e.safeNumberLong();

        return strtoull( e.valuestrsafe(), NULL, 10 );
    }
开发者ID:CodeHub2,项目名称:mongo,代码行数:25,代码来源:wiredtiger_util.cpp

示例3: onDeleteOp

void CollectionShardingState::onDeleteOp(OperationContext* txn,
                                         const CollectionShardingState::DeleteState& deleteState) {
    dassert(txn->lockState()->isCollectionLockedForMode(_nss.ns(), MODE_IX));

    if (txn->writesAreReplicated() && serverGlobalParams.clusterRole == ClusterRole::ShardServer &&
        _nss == NamespaceString::kConfigCollectionNamespace) {
        if (auto idElem = deleteState.idDoc["_id"]) {
            uassert(40070,
                    "cannot delete shardIdentity document while in --shardsvr mode",
                    idElem.str() != ShardIdentityType::IdName);
        }
    }

    // For backwards compatibility, cancel a pending asynchronous addShard task created on the
    // primary config as a result of a 3.2 mongos doing addShard for the shard with id
    // deletedDocId.
    if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer &&
        _nss == ShardType::ConfigNS) {
        BSONElement idElement = deleteState.idDoc["_id"];
        invariant(!idElement.eoo());
        auto shardIdStr = idElement.valuestrsafe();
        txn->recoveryUnit()->registerChange(
            new RemoveShardLogOpHandler(txn, ShardId(std::move(shardIdStr))));
    }

    checkShardVersionOrThrow(txn);

    if (_sourceMgr && deleteState.isMigrating) {
        _sourceMgr->getCloner()->onDeleteOp(txn, deleteState.idDoc);
    }
}
开发者ID:GYGit,项目名称:mongo,代码行数:31,代码来源:collection_sharding_state.cpp

示例4: run

    void run() {
        OperationContextImpl txn;
        Client::WriteContext ctx(&txn, _ns);

        int numFinishedIndexesStart = _catalog->numIndexesReady(&txn);

        Helpers::ensureIndex(&txn, _coll, BSON("x" << 1), false, "_x_0");
        Helpers::ensureIndex(&txn, _coll, BSON("y" << 1), false, "_y_0");

        ASSERT_TRUE(_catalog->numIndexesReady(&txn) == numFinishedIndexesStart+2);

        IndexCatalog::IndexIterator ii = _catalog->getIndexIterator(&txn,false);
        int indexesIterated = 0;
        bool foundIndex = false;
        while (ii.more()) {
            IndexDescriptor* indexDesc = ii.next();
            indexesIterated++;
            BSONObjIterator boit(indexDesc->infoObj());
            while (boit.more() && !foundIndex) {
                BSONElement e = boit.next();
                if (str::equals(e.fieldName(), "name") &&
                        str::equals(e.valuestrsafe(), "_y_0")) {
                    foundIndex = true;
                    break;
                }
            }
        }

        ctx.commit();
        ASSERT_TRUE(indexesIterated == _catalog->numIndexesReady(&txn));
        ASSERT_TRUE(foundIndex);
    }
开发者ID:dpercy,项目名称:mongo,代码行数:32,代码来源:indexcatalogtests.cpp

示例5: set

        virtual Status set( const BSONElement& newValueElement ) {
            if (!theReplSet) {
                return Status( ErrorCodes::BadValue, "replication is not enabled" );
            }

            std::string prefetch = newValueElement.valuestrsafe();
            return setFromString( prefetch );
        }
开发者ID:MohdVara,项目名称:mongo,代码行数:8,代码来源:rs.cpp

示例6: getLanguageToUse

 string FTSSpec::getLanguageToUse( const BSONObj& userDoc ) const {
     BSONElement e = userDoc[_languageOverrideField];
     if ( e.type() == String ) {
         const char * x = e.valuestrsafe();
         if ( strlen( x ) > 0 )
             return x;
     }
     return _defaultLanguage;
 }
开发者ID:ahopedog,项目名称:mongo,代码行数:9,代码来源:fts_spec.cpp

示例7: set

    virtual Status set(const BSONElement& newValueElement) {
        if (getGlobalReplicationCoordinator()->getReplicationMode() !=
            ReplicationCoordinator::modeReplSet) {
            return Status(ErrorCodes::BadValue, "replication is not enabled");
        }

        std::string prefetch = newValueElement.valuestrsafe();
        return setFromString(prefetch);
    }
开发者ID:DavidAlphaFox,项目名称:mongodb,代码行数:9,代码来源:prefetch.cpp

示例8: dassert

const FTSLanguage& FTSSpec::_getLanguageToUseV1(const BSONObj& userDoc) const {
    BSONElement e = userDoc[_languageOverrideField];
    if (e.type() == String) {
        const char* x = e.valuestrsafe();
        if (strlen(x) > 0) {
            StatusWithFTSLanguage swl = FTSLanguage::make(x, TEXT_INDEX_VERSION_1);
            dassert(swl.isOK());  // make() w/ TEXT_INDEX_VERSION_1 guaranteed to not fail.
            return *swl.getValue();
        }
    }
    return *_defaultLanguage;
}
开发者ID:AlexOreshkevich,项目名称:mongo,代码行数:12,代码来源:fts_spec_legacy.cpp

示例9: Status

StatusWith<ParsedDistinct> ParsedDistinct::parse(OperationContext* txn,
                                                 const NamespaceString& nss,
                                                 const BSONObj& cmdObj,
                                                 const ExtensionsCallback& extensionsCallback,
                                                 bool isExplain) {
    // Extract the key field.
    BSONElement keyElt;
    auto statusKey = bsonExtractTypedField(cmdObj, kKeyField, BSONType::String, &keyElt);
    if (!statusKey.isOK()) {
        return {statusKey};
    }
    auto key = keyElt.valuestrsafe();

    auto qr = stdx::make_unique<QueryRequest>(nss);

    // Extract the query field. If the query field is nonexistent, an empty query is used.
    if (BSONElement queryElt = cmdObj[kQueryField]) {
        if (queryElt.type() == BSONType::Object) {
            qr->setFilter(queryElt.embeddedObject());
        } else if (queryElt.type() != BSONType::jstNULL) {
            return Status(ErrorCodes::TypeMismatch,
                          str::stream() << "\"" << kQueryField << "\" had the wrong type. Expected "
                                        << typeName(BSONType::Object)
                                        << " or "
                                        << typeName(BSONType::jstNULL)
                                        << ", found "
                                        << typeName(queryElt.type()));
        }
    }

    // Extract the collation field, if it exists.
    if (BSONElement collationElt = cmdObj[kCollationField]) {
        if (collationElt.type() != BSONType::Object) {
            return Status(ErrorCodes::TypeMismatch,
                          str::stream() << "\"" << kCollationField
                                        << "\" had the wrong type. Expected "
                                        << typeName(BSONType::Object)
                                        << ", found "
                                        << typeName(collationElt.type()));
        }
        qr->setCollation(collationElt.embeddedObject());
    }

    qr->setExplain(isExplain);

    auto cq = CanonicalQuery::canonicalize(txn, std::move(qr), extensionsCallback);
    if (!cq.isOK()) {
        return cq.getStatus();
    }

    return ParsedDistinct(std::move(cq.getValue()), std::move(key));
}
开发者ID:AshishSanju,项目名称:mongo,代码行数:52,代码来源:parsed_distinct.cpp

示例10: Status

    /**
     * Used by explain() and run() to get the PlanExecutor for the query.
     */
    StatusWith<unique_ptr<PlanExecutor>> getPlanExecutor(OperationContext* txn,
                                                         Collection* collection,
                                                         const string& ns,
                                                         const BSONObj& cmdObj,
                                                         bool isExplain) const {
        // Extract the key field.
        BSONElement keyElt;
        auto statusKey = bsonExtractTypedField(cmdObj, kKeyField, BSONType::String, &keyElt);
        if (!statusKey.isOK()) {
            return {statusKey};
        }
        string key = keyElt.valuestrsafe();

        // Extract the query field. If the query field is nonexistent, an empty query is used.
        BSONObj query;
        if (BSONElement queryElt = cmdObj[kQueryField]) {
            if (queryElt.type() == BSONType::Object) {
                query = queryElt.embeddedObject();
            } else if (queryElt.type() != BSONType::jstNULL) {
                return Status(ErrorCodes::TypeMismatch,
                              str::stream() << "\"" << kQueryField
                                            << "\" had the wrong type. Expected "
                                            << typeName(BSONType::Object) << " or "
                                            << typeName(BSONType::jstNULL) << ", found "
                                            << typeName(queryElt.type()));
            }
        }

        // Extract the collation field, if it exists.
        // TODO SERVER-23473: Pass this collation spec object down so that it can be converted into
        // a CollatorInterface.
        BSONObj collation;
        if (BSONElement collationElt = cmdObj[kCollationField]) {
            if (collationElt.type() != BSONType::Object) {
                return Status(ErrorCodes::TypeMismatch,
                              str::stream() << "\"" << kCollationField
                                            << "\" had the wrong type. Expected "
                                            << typeName(BSONType::Object) << ", found "
                                            << typeName(collationElt.type()));
            }
            collation = collationElt.embeddedObject();
        }

        auto executor = getExecutorDistinct(
            txn, collection, ns, query, key, isExplain, PlanExecutor::YIELD_AUTO);
        if (!executor.isOK()) {
            return executor.getStatus();
        }

        return std::move(executor.getValue());
    }
开发者ID:AlexOreshkevich,项目名称:mongo,代码行数:54,代码来源:distinct.cpp

示例11: removeFile

BSONObj removeFile(const BSONObj& args, void* data) {
    BSONElement e = singleArg(args);
    bool found = false;

    boost::filesystem::path root(e.valuestrsafe());
    if (boost::filesystem::exists(root)) {
        found = true;
        boost::filesystem::remove_all(root);
    }

    BSONObjBuilder b;
    b.appendBool("removed", found);
    return b.obj();
}
开发者ID:AlexOreshkevich,项目名称:mongo,代码行数:14,代码来源:shell_utils_extended.cpp

示例12: _checkOperation

    /**
     * Returns true if 'e' contains a valid operation.
     */
    bool _checkOperation(const BSONElement& e, string& errmsg) {
        if (e.type() != Object) {
            errmsg = str::stream() << "op not an object: " << e.fieldName();
            return false;
        }
        BSONObj obj = e.Obj();
        // op - operation type
        BSONElement opElement = obj.getField("op");
        if (opElement.eoo()) {
            errmsg = str::stream()
                << "op does not contain required \"op\" field: " << e.fieldName();
            return false;
        }
        if (opElement.type() != mongol::String) {
            errmsg = str::stream() << "\"op\" field is not a string: " << e.fieldName();
            return false;
        }
        // operation type -- see logOp() comments for types
        const char* opType = opElement.valuestrsafe();
        if (*opType == '\0') {
            errmsg = str::stream() << "\"op\" field value cannot be empty: " << e.fieldName();
            return false;
        }

        // ns - namespace
        // Only operations of type 'n' are allowed to have an empty namespace.
        BSONElement nsElement = obj.getField("ns");
        if (nsElement.eoo()) {
            errmsg = str::stream()
                << "op does not contain required \"ns\" field: " << e.fieldName();
            return false;
        }
        if (nsElement.type() != mongol::String) {
            errmsg = str::stream() << "\"ns\" field is not a string: " << e.fieldName();
            return false;
        }
        if (nsElement.String().find('\0') != std::string::npos) {
            errmsg = str::stream() << "namespaces cannot have embedded null characters";
            return false;
        }
        if (*opType != 'n' && nsElement.String().empty()) {
            errmsg = str::stream()
                << "\"ns\" field value cannot be empty when op type is not 'n': " << e.fieldName();
            return false;
        }
        return true;
    }
开发者ID:stevelyall,项目名称:mongol-db,代码行数:50,代码来源:apply_ops.cpp

示例13: parse

Status WriteConcernOptions::parse(const BSONObj& obj) {
    reset();
    if (obj.isEmpty()) {
        return Status(ErrorCodes::FailedToParse, "write concern object cannot be empty");
    }

    BSONElement jEl = obj["j"];
    if (!jEl.eoo() && !jEl.isNumber() && jEl.type() != Bool) {
        return Status(ErrorCodes::FailedToParse, "j must be numeric or a boolean value");
    }

    const bool j = jEl.trueValue();

    BSONElement fsyncEl = obj["fsync"];
    if (!fsyncEl.eoo() && !fsyncEl.isNumber() && fsyncEl.type() != Bool) {
        return Status(ErrorCodes::FailedToParse, "fsync must be numeric or a boolean value");
    }

    const bool fsync = fsyncEl.trueValue();

    if (j && fsync)
        return Status(ErrorCodes::FailedToParse, "fsync and j options cannot be used together");

    if (j) {
        syncMode = SyncMode::JOURNAL;
    } else if (fsync) {
        syncMode = SyncMode::FSYNC;
    } else if (!jEl.eoo()) {
        syncMode = SyncMode::NONE;
    }

    BSONElement e = obj["w"];
    if (e.isNumber()) {
        wNumNodes = e.numberInt();
    } else if (e.type() == String) {
        wMode = e.valuestrsafe();
    } else if (e.eoo() || e.type() == jstNULL || e.type() == Undefined) {
        wNumNodes = 1;
    } else {
        return Status(ErrorCodes::FailedToParse, "w has to be a number or a string");
    }

    wTimeout = obj["wtimeout"].numberInt();

    return Status::OK();
}
开发者ID:CaffeineForCode,项目名称:mongo,代码行数:46,代码来源:write_concern_options.cpp

示例14: cat

        BSONObj cat(const BSONObj& args){
            BSONElement e = oneArg(args);
            stringstream ss;
            ifstream f(e.valuestrsafe());
            uassert(CANT_OPEN_FILE, "couldn't open file", f.is_open() );

            streamsize sz = 0;
            while( 1 ) {
                char ch = 0;
                // slow...maybe change one day
                f.get(ch);
                if( ch == 0 ) break;
                ss << ch;
                sz += 1;
                uassert(13301, "cat() : file to big to load as a variable", sz < 1024 * 1024 * 16);
            }
            return BSON( "" << ss.str() );
        }
开发者ID:jit,项目名称:mongo,代码行数:18,代码来源:shell_utils.cpp

示例15: BSON

        BSONObj md5sumFile(const BSONObj& args){
            BSONElement e = oneArg(args);
            stringstream ss;
            FILE* f = fopen(e.valuestrsafe(), "rb");
            uassert(CANT_OPEN_FILE, "couldn't open file", f );

            md5digest d;
            md5_state_t st;
            md5_init(&st);

            enum {BUFLEN = 4*1024};
            char buffer[BUFLEN];
            int bytes_read;
            while( (bytes_read = fread(buffer, 1, BUFLEN, f)) ) {
                md5_append( &st , (const md5_byte_t*)(buffer) , bytes_read );
            }

            md5_finish(&st, d);
            return BSON( "" << digestToString( d ) );
        }
开发者ID:jit,项目名称:mongo,代码行数:20,代码来源:shell_utils.cpp


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