summaryrefslogtreecommitdiff
path: root/src/mongo/bson/bsonmisc.h
diff options
context:
space:
mode:
authorTess Avitabile <tess.avitabile@mongodb.com>2016-04-11 13:14:11 -0400
committerTess Avitabile <tess.avitabile@mongodb.com>2016-04-12 07:27:03 -0400
commite4f203ba6753f88e786403f46525f4ad2748cfd1 (patch)
tree0e064e1af131ecf38a75ba1f3ed7b1950a07e142 /src/mongo/bson/bsonmisc.h
parent95d6f8c8a4e8a3645d3e9e42f070a28eaaf5c97e (diff)
downloadmongo-e4f203ba6753f88e786403f46525f4ad2748cfd1.tar.gz
SERVER-23348 Add a parameter of type StringData::ComparatorInterface* to the constructors of BSONElementCmpWithoutField and BSONObjCmp
Diffstat (limited to 'src/mongo/bson/bsonmisc.h')
-rw-r--r--src/mongo/bson/bsonmisc.h28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/mongo/bson/bsonmisc.h b/src/mongo/bson/bsonmisc.h
index f32319965f1..55d80e7821f 100644
--- a/src/mongo/bson/bsonmisc.h
+++ b/src/mongo/bson/bsonmisc.h
@@ -36,17 +36,36 @@ namespace mongo {
int getGtLtOp(const BSONElement& e);
-struct BSONElementCmpWithoutField {
+class BSONElementCmpWithoutField {
+public:
+ /**
+ * If 'stringComparator' is null, the default binary comparator will be used for comparing
+ * string elements. A custom string comparator may be provided, but it must outlive the
+ * constructed BSONElementCmpWithoutField.
+ */
+ BSONElementCmpWithoutField(StringData::ComparatorInterface* stringComparator = nullptr)
+ : _stringComparator(stringComparator) {}
+
bool operator()(const BSONElement& l, const BSONElement& r) const {
- return l.woCompare(r, false) < 0;
+ return l.woCompare(r, false, _stringComparator) < 0;
}
+
+private:
+ StringData::ComparatorInterface* _stringComparator;
};
class BSONObjCmp {
public:
- BSONObjCmp(const BSONObj& order = BSONObj()) : _order(order) {}
+ /**
+ * If 'stringComparator' is null, the default binary comparator will be used for comparing
+ * string elements. A custom string comparator may be provided, but it must outlive the
+ * constructed BSONElementCmpWithoutField.
+ */
+ BSONObjCmp(const BSONObj& order = BSONObj(),
+ StringData::ComparatorInterface* stringComparator = nullptr)
+ : _order(order), _stringComparator(stringComparator) {}
bool operator()(const BSONObj& l, const BSONObj& r) const {
- return l.woCompare(r, _order) < 0;
+ return l.woCompare(r, _order, true, _stringComparator) < 0;
}
BSONObj order() const {
return _order;
@@ -54,6 +73,7 @@ public:
private:
BSONObj _order;
+ StringData::ComparatorInterface* _stringComparator;
};
typedef std::set<BSONObj, BSONObjCmp> BSONObjSet;