本文整理汇总了C++中scoped_ptr类的典型用法代码示例。如果您正苦于以下问题:C++ scoped_ptr类的具体用法?C++ scoped_ptr怎么用?C++ scoped_ptr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了scoped_ptr类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: queryWithQueryOptimizer
/**
* Run a query with a cursor provided by the query optimizer, or FindingStartCursor.
* @yields the db lock.
*/
string queryWithQueryOptimizer( int queryOptions, const string& ns,
const BSONObj &jsobj, CurOp& curop,
const BSONObj &query, const BSONObj &order,
const shared_ptr<ParsedQuery> &pq_shared,
const BSONObj &oldPlan,
const ChunkVersion &shardingVersionAtStart,
scoped_ptr<PageFaultRetryableSection>& parentPageFaultSection,
scoped_ptr<NoPageFaultsAllowed>& noPageFault,
Message &result ) {
const ParsedQuery &pq( *pq_shared );
shared_ptr<Cursor> cursor;
QueryPlanSummary queryPlan;
if ( pq.hasOption( QueryOption_OplogReplay ) ) {
cursor = FindingStartCursor::getCursor( ns.c_str(), query, order );
}
else {
cursor = getOptimizedCursor( ns.c_str(),
query,
order,
QueryPlanSelectionPolicy::any(),
pq_shared,
false,
&queryPlan );
}
verify( cursor );
scoped_ptr<QueryResponseBuilder> queryResponseBuilder
( QueryResponseBuilder::make( pq, cursor, queryPlan, oldPlan ) );
bool saveClientCursor = false;
OpTime slaveReadTill;
ClientCursorHolder ccPointer( new ClientCursor( QueryOption_NoCursorTimeout, cursor,
ns ) );
for( ; cursor->ok(); cursor->advance() ) {
bool yielded = false;
if ( !ccPointer->yieldSometimes( ClientCursor::MaybeCovered, &yielded ) ||
!cursor->ok() ) {
cursor.reset();
queryResponseBuilder->noteYield();
// !!! TODO The queryResponseBuilder still holds cursor. Currently it will not do
// anything unsafe with the cursor in handoff(), but this is very fragile.
//
// We don't fail the query since we're fine with returning partial data if the
// collection was dropped.
// NOTE see SERVER-2454.
// TODO This is wrong. The cursor could be gone if the closeAllDatabases command
// just ran.
break;
}
if ( yielded ) {
queryResponseBuilder->noteYield();
}
if ( pq.getMaxScan() && cursor->nscanned() > pq.getMaxScan() ) {
break;
}
if ( !queryResponseBuilder->addMatch() ) {
continue;
}
// Note slave's position in the oplog.
if ( pq.hasOption( QueryOption_OplogReplay ) ) {
BSONObj current = cursor->current();
BSONElement e = current["ts"];
if ( e.type() == Date || e.type() == Timestamp ) {
slaveReadTill = e._opTime();
}
}
if ( !cursor->supportGetMore() || pq.isExplain() ) {
if ( queryResponseBuilder->enoughTotalResults() ) {
break;
}
}
else if ( queryResponseBuilder->enoughForFirstBatch() ) {
// if only 1 requested, no cursor saved for efficiency...we assume it is findOne()
if ( pq.wantMore() && pq.getNumToReturn() != 1 ) {
queryResponseBuilder->finishedFirstBatch();
if ( cursor->advance() ) {
saveClientCursor = true;
}
}
break;
}
}
if ( cursor ) {
if ( pq.hasOption( QueryOption_CursorTailable ) && pq.getNumToReturn() != 1 ) {
cursor->setTailable();
}
//.........这里部分代码省略.........
开发者ID:blueskyjerry,项目名称:mongo,代码行数:101,代码来源:query.cpp
示例2: parse_options
static void parse_options(int argc, char ** argv)
{
string skill_spec("");
string robot_spec("");
servo_rate = 500;
for (int ii(1); ii < argc; ++ii) {
if ((strlen(argv[ii]) < 2) || ('-' != argv[ii][0])) {
usage(EXIT_FAILURE, "problem with option `" + string(argv[ii]) + "'");
}
else
switch (argv[ii][1]) {
case 'h':
usage(EXIT_SUCCESS, "servo [-h] [-v] [-s skillspec] -r robotspec");
case 'v':
verbose = true;
break;
case 'r':
++ii;
if (ii >= argc) {
usage(EXIT_FAILURE, "-r requires parameter");
}
robot_spec = argv[ii];
break;
case 'f':
++ii;
if (ii >= argc) {
usage(EXIT_FAILURE, "-f requires parameter");
}
else {
istringstream is(argv[ii]);
is >> servo_rate;
if ( ! is) {
usage(EXIT_FAILURE, "failed to read servo rate from `" + string(argv[ii]) + "'");
}
if (0 >= servo_rate) {
usage(EXIT_FAILURE, "servo rate has to be positive");
}
}
break;
case 's':
++ii;
if (ii >= argc) {
usage(EXIT_FAILURE, "-s requires parameter");
}
skill_spec = argv[ii];
break;
default:
usage(EXIT_FAILURE, "invalid option `" + string(argv[ii]) + "'");
}
}
try {
if (robot_spec.empty()) {
usage(EXIT_FAILURE, "no robot specification (see option -r)");
}
if (verbose) {
warnx("reading robot spec from %s", robot_spec.c_str());
}
static bool const enable_coriolis_centrifugal(false);
model.reset(jspace::test::parse_sai_xml_file(robot_spec, enable_coriolis_centrifugal));
}
catch (runtime_error const & ee) {
errx(EXIT_FAILURE,
"exception while parsing robot specification\n"
" filename: %s\n"
" error: %s",
robot_spec.c_str(), ee.what());
}
factory.reset(new Factory());
Status st;
if (skill_spec.empty()) {
if (verbose) {
warnx("using fallback task/posture skill");
}
st = factory->parseString(opspace_fallback_str);
}
else {
if (verbose) {
warnx("reading skills from %s", skill_spec.c_str());
}
st = factory->parseFile(skill_spec);
}
if ( ! st) {
errx(EXIT_FAILURE,
"failed to parse skills\n"
" specification file: %s\n"
" error description: %s",
skill_spec.c_str(), st.errstr.c_str());
}
if (verbose) {
factory->dump(cout, "*** parsed tasks and skills", "* ");
//.........这里部分代码省略.........
开发者ID:jgp36,项目名称:WBC-UTAustin,代码行数:101,代码来源:servo.cpp
注:本文中的scoped_ptr类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论