本文整理汇总了C++中BSONElement::rawdata方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONElement::rawdata方法的具体用法?C++ BSONElement::rawdata怎么用?C++ BSONElement::rawdata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONElement
的用法示例。
在下文中一共展示了BSONElement::rawdata方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toString
string BSONObj::toString() const {
if ( isEmpty() ) return "{}";
stringstream s;
s << "{ ";
BSONObjIterator i(*this);
bool first = true;
while ( 1 ) {
massert( "Object does not end with EOO", i.more() );
BSONElement e = i.next( true );
massert( "Invalid element size", e.size() > 0 );
massert( "Element too large", e.size() < ( 1 << 30 ) );
int offset = e.rawdata() - this->objdata();
massert( "Element extends past end of object",
e.size() + offset <= this->objsize() );
e.validate();
bool end = ( e.size() + offset == this->objsize() );
if ( e.eoo() ) {
massert( "EOO Before end of object", end );
break;
}
if ( first )
first = false;
else
s << ", ";
s << e.toString();
}
s << " }";
return s.str();
}
示例2: _processData
int ixmBucketManager::_processData(BSONObj &record,
dmsRecordID &recordID,
unsigned int &hashNum,
ixmEleHash &eleHash,
unsigned int &random)
{
int rc = EDB_OK;
BSONElement element = record.getField(IXM_KEY_FIELDNAME);
// check if _id exists and correct
if(element.eoo()||
(element.type() != NumberInt && element.type() != String))
{
rc = EDB_INVALIDARG;
PD_LOG(PDERROR, "record must be with _id");
goto error;
}
// hash _id
hashNum = ossHash(element.value(), element.valuesize());
random = hashNum % IXM_HASH_MAP_SIZE;
eleHash.data = element.rawdata();
eleHash.recordID = recordID;
done:
return rc;
error:
goto done;
}
示例3: binaryEqual
bool BSONElement::binaryEqual(const BSONElement& rhs) const {
const int elemSize = size();
if (elemSize != rhs.size()) {
return false;
}
return (elemSize == 0) || (memcmp(data, rhs.rawdata(), elemSize) == 0);
}
示例4: _getKeys
void IndexSpec::_getKeys( vector<const char*> fieldNames , vector<BSONElement> fixed , const BSONObj &obj, BSONObjSetDefaultOrder &keys ) const {
BSONElement arrElt;
unsigned arrIdx = ~0;
for( unsigned i = 0; i < fieldNames.size(); ++i ) {
if ( *fieldNames[ i ] == '\0' )
continue;
BSONElement e = obj.getFieldDottedOrArray( fieldNames[ i ] );
if ( e.eoo() )
e = _nullElt; // no matching field
if ( e.type() != Array )
fieldNames[ i ] = ""; // no matching field or non-array match
if ( *fieldNames[ i ] == '\0' )
fixed[ i ] = e; // no need for further object expansion (though array expansion still possible)
if ( e.type() == Array && arrElt.eoo() ) { // we only expand arrays on a single path -- track the path here
arrIdx = i;
arrElt = e;
}
// enforce single array path here
uassert( 10088 , "cannot index parallel arrays", e.type() != Array || e.rawdata() == arrElt.rawdata() );
}
bool allFound = true; // have we found elements for all field names in the key spec?
for( vector<const char*>::const_iterator i = fieldNames.begin(); i != fieldNames.end(); ++i ){
if ( **i != '\0' ){
allFound = false;
break;
}
}
bool insertArrayNull = false;
if ( allFound ) {
if ( arrElt.eoo() ) {
// no terminal array element to expand
BSONObjBuilder b(_sizeTracker);
for( vector< BSONElement >::iterator i = fixed.begin(); i != fixed.end(); ++i )
b.appendAs( *i, "" );
keys.insert( b.obj() );
}
else {
// terminal array element to expand, so generate all keys
BSONObjIterator i( arrElt.embeddedObject() );
if ( i.more() ){
while( i.more() ) {
BSONObjBuilder b(_sizeTracker);
for( unsigned j = 0; j < fixed.size(); ++j ) {
if ( j == arrIdx )
b.appendAs( i.next(), "" );
else
b.appendAs( fixed[ j ], "" );
}
keys.insert( b.obj() );
}
}
else if ( fixed.size() > 1 ){
insertArrayNull = true;
}
}
} else {
// nonterminal array element to expand, so recurse
assert( !arrElt.eoo() );
BSONObjIterator i( arrElt.embeddedObject() );
if ( i.more() ){
while( i.more() ) {
BSONElement e = i.next();
if ( e.type() == Object ){
_getKeys( fieldNames, fixed, e.embeddedObject(), keys );
}
}
}
else {
insertArrayNull = true;
}
}
if ( insertArrayNull ) {
// x : [] - need to insert undefined
BSONObjBuilder b(_sizeTracker);
for( unsigned j = 0; j < fixed.size(); ++j ) {
if ( j == arrIdx ){
b.appendUndefined( "" );
}
else {
BSONElement e = fixed[j];
if ( e.eoo() )
b.appendNull( "" );
else
b.appendAs( e , "" );
}
}
keys.insert( b.obj() );
}
}
示例5: b
void BtreeKeyGeneratorV1::getKeysImplWithArray(
std::vector<const char*> fieldNames,
std::vector<BSONElement> fixed,
const BSONObj& obj,
BSONObjSet* keys,
unsigned numNotFound,
const std::vector<PositionalPathInfo>& positionalInfo,
MultikeyPaths* multikeyPaths) const {
BSONElement arrElt;
// A set containing the position of any indexed fields in the key pattern that traverse through
// the 'arrElt' array value.
std::set<size_t> arrIdxs;
// A vector with size equal to the number of elements in the index key pattern. Each element in
// the vector, if initialized, refers to the component within the indexed field that traverses
// through the 'arrElt' array value. We say that this component within the indexed field
// corresponds to a path that causes the index to be multikey if the 'arrElt' array value
// contains multiple elements.
//
// For example, consider the index {'a.b': 1, 'a.c'} and the document
// {a: [{b: 1, c: 'x'}, {b: 2, c: 'y'}]}. The path "a" causes the index to be multikey, so we'd
// have a std::vector<boost::optional<size_t>>{{0U}, {0U}}.
//
// Furthermore, due to how positional key patterns are specified, it's possible for an indexed
// field to cause the index to be multikey at a different component than another indexed field
// that also traverses through the 'arrElt' array value. It's then also possible for an indexed
// field not to cause the index to be multikey, even if it traverses through the 'arrElt' array
// value, because only a particular element would be indexed.
//
// For example, consider the index {'a.b': 1, 'a.b.0'} and the document {a: {b: [1, 2]}}. The
// path "a.b" causes the index to be multikey, but the key pattern "a.b.0" only indexes the
// first element of the array, so we'd have a
// std::vector<boost::optional<size_t>>{{1U}, boost::none}.
std::vector<boost::optional<size_t>> arrComponents(fieldNames.size());
bool mayExpandArrayUnembedded = true;
for (size_t i = 0; i < fieldNames.size(); ++i) {
if (*fieldNames[i] == '\0') {
continue;
}
bool arrayNestedArray;
// Extract element matching fieldName[ i ] from object xor array.
BSONElement e =
extractNextElement(obj, positionalInfo[i], &fieldNames[i], &arrayNestedArray);
if (e.eoo()) {
// if field not present, set to null
fixed[i] = nullElt;
// done expanding this field name
fieldNames[i] = "";
numNotFound++;
} else if (e.type() == Array) {
arrIdxs.insert(i);
if (arrElt.eoo()) {
// we only expand arrays on a single path -- track the path here
arrElt = e;
} else if (e.rawdata() != arrElt.rawdata()) {
// enforce single array path here
assertParallelArrays(e.fieldName(), arrElt.fieldName());
}
if (arrayNestedArray) {
mayExpandArrayUnembedded = false;
}
} else {
// not an array - no need for further expansion
fixed[i] = e;
}
}
if (arrElt.eoo()) {
// No array, so generate a single key.
if (_isSparse && numNotFound == fieldNames.size()) {
return;
}
BSONObjBuilder b(_sizeTracker);
for (std::vector<BSONElement>::iterator i = fixed.begin(); i != fixed.end(); ++i) {
CollationIndexKey::collationAwareIndexKeyAppend(*i, _collator, &b);
}
keys->insert(b.obj());
} else if (arrElt.embeddedObject().firstElement().eoo()) {
// We've encountered an empty array.
if (multikeyPaths && mayExpandArrayUnembedded) {
// Any indexed path which traverses through the empty array must be recorded as an array
// component.
for (auto i : arrIdxs) {
// We need to determine which component of the indexed field causes the index to be
// multikey as a result of the empty array. Indexed empty arrays are considered
// multikey and may occur mid-path. For instance, the indexed path "a.b.c" has
// multikey components {0, 1} given the document {a: [{b: []}, {b: 1}]}.
size_t fullPathLength = _pathLengths[i];
size_t suffixPathLength = FieldRef{fieldNames[i]}.numParts();
invariant(suffixPathLength < fullPathLength);
arrComponents[i] = fullPathLength - suffixPathLength - 1;
}
}
// For an empty array, set matching fields to undefined.
_getKeysArrEltFixed(&fieldNames,
//.........这里部分代码省略.........
示例6: _getKeys
/**
* @param fieldNames - fields to index, may be postfixes in recursive calls
* @param fixed - values that have already been identified for their index fields
* @param obj - object from which keys should be extracted, based on names in fieldNames
* @param keys - set where index keys are written
* @param numNotFound - number of index fields that have already been identified as missing
* @param array - array from which keys should be extracted, based on names in fieldNames
* If obj and array are both nonempty, obj will be one of the elements of array.
*/
void _getKeys( vector<const char*> fieldNames , vector<BSONElement> fixed , const BSONObj &obj, BSONObjSet &keys, int numNotFound = 0, const BSONObj &array = BSONObj() ) const {
BSONElement arrElt;
set<unsigned> arrIdxs;
bool mayExpandArrayUnembedded = true;
for( unsigned i = 0; i < fieldNames.size(); ++i ) {
if ( *fieldNames[ i ] == '\0' ) {
continue;
}
bool arrayNestedArray;
// Extract element matching fieldName[ i ] from object xor array.
BSONElement e = extractNextElement( obj, array, fieldNames[ i ], arrayNestedArray );
if ( e.eoo() ) {
// if field not present, set to null
fixed[ i ] = _spec._nullElt;
// done expanding this field name
fieldNames[ i ] = "";
numNotFound++;
}
else if ( e.type() == Array ) {
arrIdxs.insert( i );
if ( arrElt.eoo() ) {
// we only expand arrays on a single path -- track the path here
arrElt = e;
}
else if ( e.rawdata() != arrElt.rawdata() ) {
// enforce single array path here
assertParallelArrays( e.fieldName(), arrElt.fieldName() );
}
if ( arrayNestedArray ) {
mayExpandArrayUnembedded = false;
}
}
else {
// not an array - no need for further expansion
fixed[ i ] = e;
}
}
if ( arrElt.eoo() ) {
// No array, so generate a single key.
if ( _spec._sparse && numNotFound == _spec._nFields ) {
return;
}
BSONObjBuilder b(_spec._sizeTracker);
for( vector< BSONElement >::iterator i = fixed.begin(); i != fixed.end(); ++i ) {
b.appendAs( *i, "" );
}
keys.insert( b.obj() );
}
else if ( arrElt.embeddedObject().firstElement().eoo() ) {
// Empty array, so set matching fields to undefined.
_getKeysArrEltFixed( fieldNames, fixed, _spec._undefinedElt, keys, numNotFound, arrElt, arrIdxs, true );
}
else {
// Non empty array that can be expanded, so generate a key for each member.
BSONObj arrObj = arrElt.embeddedObject();
BSONObjIterator i( arrObj );
while( i.more() ) {
_getKeysArrEltFixed( fieldNames, fixed, i.next(), keys, numNotFound, arrElt, arrIdxs, mayExpandArrayUnembedded );
}
}
}