summaryrefslogtreecommitdiff
path: root/src/mongo/bson/bsonobjbuilder.h
diff options
context:
space:
mode:
authorRaymond Jacobson <raymond.jacobson@10gen.com>2015-07-31 16:22:25 -0400
committerRaymond Jacobson <raymond.jacobson@10gen.com>2015-08-07 00:06:34 -0400
commit2174be1681377e745baafa958c205ab02c1fd657 (patch)
tree1897a4196f412f842303654ce06845061e441345 /src/mongo/bson/bsonobjbuilder.h
parentbca1ffecf68cc6e4c929c23f0b3dc9aa682ca96f (diff)
downloadmongo-2174be1681377e745baafa958c205ab02c1fd657.tar.gz
SERVER-19624 Add Decimal128 type support to mongo/bson layer
Diffstat (limited to 'src/mongo/bson/bsonobjbuilder.h')
-rw-r--r--src/mongo/bson/bsonobjbuilder.h20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/mongo/bson/bsonobjbuilder.h b/src/mongo/bson/bsonobjbuilder.h
index 1cb8e7fbb51..3713cf8c313 100644
--- a/src/mongo/bson/bsonobjbuilder.h
+++ b/src/mongo/bson/bsonobjbuilder.h
@@ -44,6 +44,7 @@
#include "mongo/bson/bsonelement.h"
#include "mongo/bson/bsonmisc.h"
#include "mongo/bson/bsonobj.h"
+#include "mongo/platform/decimal128.h"
namespace mongo {
@@ -235,6 +236,14 @@ public:
return append(fieldName, (int)n);
}
+ /** Append a NumberDecimal */
+ BSONObjBuilder& append(StringData fieldName, Decimal128 n) {
+ _b.appendNum(static_cast<char>(NumberDecimal));
+ _b.appendStr(fieldName);
+ _b.appendNum(n);
+ return *this;
+ }
+
/** Append a NumberLong */
BSONObjBuilder& append(StringData fieldName, long long n) {
_b.appendNum((char)NumberLong);
@@ -270,7 +279,6 @@ public:
BSONObjBuilder& appendNumber(StringData fieldName, size_t n) {
static const size_t maxInt = (1 << 30);
-
if (n < maxInt)
append(fieldName, static_cast<int>(n));
else
@@ -278,6 +286,10 @@ public:
return *this;
}
+ BSONObjBuilder& appendNumber(StringData fieldName, Decimal128 decNumber) {
+ return append(fieldName, decNumber);
+ }
+
BSONObjBuilder& appendNumber(StringData fieldName, long long llNumber) {
static const long long maxInt = (1LL << 30);
static const long long minInt = -maxInt;
@@ -895,7 +907,6 @@ inline BSONObjBuilder& BSONObjBuilder::append(StringData fieldName, const std::m
return *this;
}
-
template <class L>
inline BSONArrayBuilder& _appendArrayIt(BSONArrayBuilder& _this, const L& vals) {
for (typename L::const_iterator i = vals.begin(); i != vals.end(); i++)
@@ -920,7 +931,6 @@ inline BSONFieldValue<BSONObj> BSONField<T>::query(const char* q, const T& t) co
return BSONFieldValue<BSONObj>(_name, b.obj());
}
-
// $or helper: OR(BSON("x" << GT << 7), BSON("y" << LT 6));
inline BSONObj OR(const BSONObj& a, const BSONObj& b) {
return BSON("$or" << BSON_ARRAY(a << b));
@@ -962,7 +972,6 @@ inline BSONObjBuilder& BSONObjBuilderValueStream::operator<<(const UndefinedLabe
return *_builder;
}
-
inline BSONObjBuilder& BSONObjBuilderValueStream::operator<<(const MinKeyLabeler& id) {
_builder->appendMinKey(_fieldName);
_fieldName = StringData();
@@ -1001,4 +1010,5 @@ inline BSONObjBuilder& BSONObjBuilder::appendTimestamp(StringData fieldName,
unsigned long long val) {
return append(fieldName, Timestamp(val));
}
-}
+
+} // namespace mongo