本文整理汇总了C++中MutableDocument::peek方法的典型用法代码示例。如果您正苦于以下问题:C++ MutableDocument::peek方法的具体用法?C++ MutableDocument::peek怎么用?C++ MutableDocument::peek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MutableDocument
的用法示例。
在下文中一共展示了MutableDocument::peek方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void run() {
MutableDocument md;
md.addField("foo", Value(1));
ASSERT_EQUALS(1U, md.peek().size());
ASSERT_EQUALS(1, md.peek()["foo"].getInt());
md.addField("bar", Value(99));
ASSERT_EQUALS(2U, md.peek().size());
ASSERT_EQUALS(99, md.peek()["bar"].getInt());
// No assertion is triggered by a duplicate field name.
md.addField("a", Value(5));
Document final = md.freeze();
ASSERT_EQUALS(3U, final.size());
assertRoundTrips(final);
}
示例2: out
boost::optional<Document> DocumentSourceProject::getNext() {
pExpCtx->checkForInterrupt();
boost::optional<Document> input = pSource->getNext();
if (!input)
return boost::none;
/* create the result document */
const size_t sizeHint = pEO->getSizeHint();
MutableDocument out (sizeHint);
out.copyMetaDataFrom(*input);
/*
Use the ExpressionObject to create the base result.
If we're excluding fields at the top level, leave out the _id if
it is found, because we took care of it above.
*/
_variables->setRoot(*input);
pEO->addToDocument(out, *input, _variables.get());
_variables->clearRoot();
#if defined(_DEBUG)
if (!_simpleProjection.getSpec().isEmpty()) {
// Make sure we return the same results as Projection class
BSONObj inputBson = input->toBson();
BSONObj outputBson = out.peek().toBson();
BSONObj projected = _simpleProjection.transform(inputBson);
if (projected != outputBson) {
log() << "$project applied incorrectly: " << getRaw() << endl;
log() << "input: " << inputBson << endl;
log() << "out: " << outputBson << endl;
log() << "projected: " << projected << endl;
verify(false); // exits in _DEBUG builds
}
}
#endif
return out.freeze();
}
示例3: getCurrent
Document DocumentSourceProject::getCurrent() {
Document pInDocument(pSource->getCurrent());
/* create the result document */
const size_t sizeHint = pEO->getSizeHint();
MutableDocument out (sizeHint);
/*
Use the ExpressionObject to create the base result.
If we're excluding fields at the top level, leave out the _id if
it is found, because we took care of it above.
*/
pEO->addToDocument(out, pInDocument, /*root=*/pInDocument);
#if defined(_DEBUG)
if (!_simpleProjection.getSpec().isEmpty()) {
// Make sure we return the same results as Projection class
BSONObjBuilder inputBuilder;
pSource->getCurrent()->toBson(&inputBuilder);
BSONObj input = inputBuilder.done();
BSONObjBuilder outputBuilder;
out.peek().toBson(&outputBuilder);
BSONObj output = outputBuilder.done();
BSONObj projected = _simpleProjection.transform(input);
if (projected != output) {
log() << "$project applied incorrectly: " << getRaw() << endl;
log() << "input: " << input << endl;
log() << "out: " << output << endl;
log() << "projected: " << projected << endl;
verify(false); // exits in _DEBUG builds
}
}
#endif
return out.freeze();
}