本文整理汇总了C++中BSONElement::fieldNameSize方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONElement::fieldNameSize方法的具体用法?C++ BSONElement::fieldNameSize怎么用?C++ BSONElement::fieldNameSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONElement
的用法示例。
在下文中一共展示了BSONElement::fieldNameSize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: documentFromBsonWithDeps
Document DocumentSource::documentFromBsonWithDeps(const BSONObj& bson,
const ParsedDeps& neededFields) {
MutableDocument md(neededFields.size());
BSONObjIterator it(bson);
while (it.more()) {
BSONElement bsonElement (it.next());
StringData fieldName (bsonElement.fieldName(), bsonElement.fieldNameSize()-1);
Value isNeeded = neededFields[fieldName];
if (isNeeded.missing())
continue;
if (isNeeded.getType() == Bool) {
md.addField(fieldName, Value(bsonElement));
continue;
}
dassert(isNeeded.getType() == Object);
if (bsonElement.type() == Object) {
Document sub = documentFromBsonWithDeps(bsonElement.embeddedObject(),
isNeeded.getDocument());
md.addField(fieldName, Value(sub));
}
if (bsonElement.type() == Array) {
md.addField(fieldName, arrayHelper(bsonElement.embeddedObject(),
isNeeded.getDocument()));
}
}
return md.freeze();
}
示例2: isValidSortOrder
// static
bool LiteParsedQuery::isValidSortOrder(const BSONObj& sortObj) {
BSONObjIterator i(sortObj);
while (i.more()) {
BSONElement e = i.next();
// fieldNameSize() includes NULL terminator. For empty field name,
// we should be checking for 1 instead of 0.
if (1 == e.fieldNameSize()) {
return false;
}
if (isTextScoreMeta(e)) {
continue;
}
long long n = e.safeNumberLong();
if (!(e.isNumber() && (n == -1LL || n == 1LL))) {
return false;
}
}
return true;
}
示例3: recursiveHash
void BSONElementHasher::recursiveHash( Hasher* h ,
const BSONElement& e ,
bool includeFieldName ) {
int canonicalType = e.canonicalType();
h->addData( &canonicalType , sizeof( canonicalType ) );
if ( includeFieldName ){
h->addData( e.fieldName() , e.fieldNameSize() );
}
if ( !e.mayEncapsulate() ){
//if there are no embedded objects (subobjects or arrays),
//compute the hash, squashing numeric types to 64-bit ints
if ( e.isNumber() ){
long long int i = e.safeNumberLong(); //well-defined for troublesome doubles
h->addData( &i , sizeof( i ) );
}
else {
h->addData( e.value() , e.valuesize() );
}
}
else {
//else identify the subobject.
//hash any preceding stuff (in the case of codeWscope)
//then each sub-element
//then finish with the EOO element.
BSONObj b;
if ( e.type() == CodeWScope ) {
h->addData( e.codeWScopeCode() , e.codeWScopeCodeLen() );
b = e.codeWScopeObject();
}
else {
b = e.embeddedObject();
}
BSONObjIterator i(b);
while( i.moreWithEOO() ) {
BSONElement el = i.next();
recursiveHash( h , el , true );
}
}
}