本文整理汇总了C++中BSONElement::_numberDouble方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONElement::_numberDouble方法的具体用法?C++ BSONElement::_numberDouble怎么用?C++ BSONElement::_numberDouble使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONElement
的用法示例。
在下文中一共展示了BSONElement::_numberDouble方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compareElements
int BSONElement::compareElements(const BSONElement& l,
const BSONElement& r,
ComparisonRulesSet rules,
const StringData::ComparatorInterface* comparator) {
switch (l.type()) {
case BSONType::EOO:
case BSONType::Undefined: // EOO and Undefined are same canonicalType
case BSONType::jstNULL:
case BSONType::MaxKey:
case BSONType::MinKey: {
auto f = l.canonicalType() - r.canonicalType();
if (f < 0)
return -1;
return f == 0 ? 0 : 1;
}
case BSONType::Bool:
return *l.value() - *r.value();
case BSONType::bsonTimestamp:
// unsigned compare for timestamps - note they are not really dates but (ordinal +
// time_t)
if (l.timestamp() < r.timestamp())
return -1;
return l.timestamp() == r.timestamp() ? 0 : 1;
case BSONType::Date:
// Signed comparisons for Dates.
{
const Date_t a = l.Date();
const Date_t b = r.Date();
if (a < b)
return -1;
return a == b ? 0 : 1;
}
case BSONType::NumberInt: {
// All types can precisely represent all NumberInts, so it is safe to simply convert to
// whatever rhs's type is.
switch (r.type()) {
case NumberInt:
return compareInts(l._numberInt(), r._numberInt());
case NumberLong:
return compareLongs(l._numberInt(), r._numberLong());
case NumberDouble:
return compareDoubles(l._numberInt(), r._numberDouble());
case NumberDecimal:
return compareIntToDecimal(l._numberInt(), r._numberDecimal());
default:
MONGO_UNREACHABLE;
}
}
case BSONType::NumberLong: {
switch (r.type()) {
case NumberLong:
return compareLongs(l._numberLong(), r._numberLong());
case NumberInt:
return compareLongs(l._numberLong(), r._numberInt());
case NumberDouble:
return compareLongToDouble(l._numberLong(), r._numberDouble());
case NumberDecimal:
return compareLongToDecimal(l._numberLong(), r._numberDecimal());
default:
MONGO_UNREACHABLE;
}
}
case BSONType::NumberDouble: {
switch (r.type()) {
case NumberDouble:
return compareDoubles(l._numberDouble(), r._numberDouble());
case NumberInt:
return compareDoubles(l._numberDouble(), r._numberInt());
case NumberLong:
return compareDoubleToLong(l._numberDouble(), r._numberLong());
case NumberDecimal:
return compareDoubleToDecimal(l._numberDouble(), r._numberDecimal());
default:
MONGO_UNREACHABLE;
}
}
case BSONType::NumberDecimal: {
switch (r.type()) {
case NumberDecimal:
return compareDecimals(l._numberDecimal(), r._numberDecimal());
case NumberInt:
return compareDecimalToInt(l._numberDecimal(), r._numberInt());
case NumberLong:
return compareDecimalToLong(l._numberDecimal(), r._numberLong());
case NumberDouble:
return compareDecimalToDouble(l._numberDecimal(), r._numberDouble());
default:
MONGO_UNREACHABLE;
}
}
case BSONType::jstOID:
return memcmp(l.value(), r.value(), OID::kOIDSize);
case BSONType::Code:
return compareElementStringValues(l, r);
case BSONType::Symbol:
//.........这里部分代码省略.........
示例2: i
// fromBSON to Key format
KeyV1Owned::KeyV1Owned(const BSONObj& obj) {
BSONObj::iterator i(obj);
unsigned char bits = 0;
while( 1 ) {
BSONElement e = i.next();
if( i.more() )
bits |= cHASMORE;
switch( e.type() ) {
case MinKey:
b.appendUChar(cminkey|bits);
break;
case jstNULL:
b.appendUChar(cnull|bits);
break;
case MaxKey:
b.appendUChar(cmaxkey|bits);
break;
case Bool:
b.appendUChar( (e.boolean()?ctrue:cfalse) | bits );
break;
case jstOID:
b.appendUChar(coid|bits);
b.appendBuf(&e.__oid(), sizeof(OID));
break;
case BinData:
{
int t = e.binDataType();
// 0-7 and 0x80 to 0x87 are supported by Key
if( (t & 0x78) == 0 && t != ByteArrayDeprecated ) {
int len;
const char * d = e.binData(len);
if( len <= BinDataLenMax ) {
int code = BinDataLengthToCode[len];
if( code >= 0 ) {
if( t >= 128 )
t = (t-128) | 0x08;
dassert( (code&t) == 0 );
b.appendUChar( cbindata|bits );
b.appendUChar( code | t );
b.appendBuf(d, len);
break;
}
}
}
traditional(obj);
return;
}
case Date:
b.appendUChar(cdate|bits);
b.appendStruct(e.date());
break;
case String:
{
b.appendUChar(cstring|bits);
// note we do not store the terminating null, to save space.
unsigned x = (unsigned) e.valuestrsize() - 1;
if( x > 255 ) {
traditional(obj);
return;
}
b.appendUChar(x);
b.appendBuf(e.valuestr(), x);
break;
}
case NumberInt:
b.appendUChar(cint|bits);
b.appendNum((double) e._numberInt());
break;
case NumberLong:
{
long long n = e._numberLong();
long long m = 2LL << 52;
DEV {
long long d = m-1;
verify( ((long long) ((double) -d)) == -d );
}
if( n >= m || n <= -m ) {
// can't represent exactly as a double
traditional(obj);
return;
}
b.appendUChar(clong|bits);
b.appendNum((double) n);
break;
}
case NumberDouble:
{
double d = e._numberDouble();
if( isNaN(d) ) {
traditional(obj);
return;
}
b.appendUChar(cdouble|bits);
b.appendNum(d);
break;
}
default:
// if other types involved, store as traditional BSON
traditional(obj);
//.........这里部分代码省略.........
示例3: i
// fromBSON to Key format
KeyV1Owned::KeyV1Owned(const BSONObj& obj) {
BSONObj::iterator i(obj);
assert( i.more() );
unsigned char bits = 0;
while( 1 ) {
BSONElement e = i.next();
if( i.more() )
bits |= cHASMORE;
switch( e.type() ) {
case MinKey:
b.appendUChar(cminkey|bits);
break;
case jstNULL:
b.appendUChar(cnull|bits);
break;
case MaxKey:
b.appendUChar(cmaxkey|bits);
break;
case Bool:
b.appendUChar( (e.boolean()?ctrue:cfalse) | bits );
break;
case jstOID:
b.appendUChar(coid|bits);
b.appendBuf(&e.__oid(), sizeof(OID));
break;
case BinData:
{
int t = e.binDataType();
// 0-7 and 0x80 to 0x87 are supported by Key
if( (t & 0x78) == 0 && t != ByteArrayDeprecated ) {
int len;
const char * d = e.binData(len);
int code = BinDataLengthToCode[len];
if( code >= 0 ) {
if( t >= 128 )
t = (t-128) | 0x08;
dassert( (code&t) == 0 );
b.appendUChar( cbindata|bits );
b.appendUChar( code | t );
b.appendBuf(d, len);
break;
}
}
traditional(obj);
return;
}
case Date:
b.appendUChar(cdate|bits);
b.appendStruct(e.date());
break;
case String:
{
b.appendUChar(cstring|bits);
// note we do not store the terminating null, to save space.
unsigned x = (unsigned) e.valuestrsize() - 1;
if( x > 255 ) {
traditional(obj);
return;
}
b.appendUChar(x);
b.appendBuf(e.valuestr(), x);
break;
}
case NumberInt:
b.appendUChar(cint|bits);
b.appendNum((double) e._numberInt());
break;
case NumberLong:
{
long long n = e._numberLong();
double d = (double) n;
if( d != n ) {
traditional(obj);
return;
}
b.appendUChar(clong|bits);
b.appendNum(d);
break;
}
case NumberDouble:
{
double d = e._numberDouble();
bool nan = !( d <= numeric_limits< double >::max() &&
d >= -numeric_limits< double >::max() );
if( !nan ) {
b.appendUChar(cdouble|bits);
b.appendNum(d);
break;
}
// else fall through and return a traditional BSON obj so our compressed keys need not check for nan
}
default:
// if other types involved, store as traditional BSON
traditional(obj);
return;
}
if( !i.more() )
break;
bits = 0;
//.........这里部分代码省略.........