summaryrefslogtreecommitdiff
path: root/src/mongo/bson/bsonobjiterator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/bson/bsonobjiterator.cpp')
-rw-r--r--src/mongo/bson/bsonobjiterator.cpp72
1 files changed, 34 insertions, 38 deletions
diff --git a/src/mongo/bson/bsonobjiterator.cpp b/src/mongo/bson/bsonobjiterator.cpp
index a15ceb707b0..944a55849d2 100644
--- a/src/mongo/bson/bsonobjiterator.cpp
+++ b/src/mongo/bson/bsonobjiterator.cpp
@@ -32,44 +32,40 @@
#include "mongo/util/stringutils.h"
namespace mongo {
- /** Compare two bson elements, provided as const char *'s, by field name. */
- class BSONIteratorSorted::ElementFieldCmp {
- public:
- ElementFieldCmp( bool isArray );
- bool operator()( const char *s1, const char *s2 ) const;
- private:
- LexNumCmp _cmp;
- };
-
- BSONIteratorSorted::ElementFieldCmp::ElementFieldCmp( bool isArray ) :
- _cmp( !isArray ) {
- }
+/** Compare two bson elements, provided as const char *'s, by field name. */
+class BSONIteratorSorted::ElementFieldCmp {
+public:
+ ElementFieldCmp(bool isArray);
+ bool operator()(const char* s1, const char* s2) const;
- bool BSONIteratorSorted::ElementFieldCmp::operator()( const char *s1, const char *s2 )
- const {
- // Skip the type byte and compare field names.
- return _cmp( s1 + 1, s2 + 1 );
- }
-
- BSONIteratorSorted::BSONIteratorSorted( const BSONObj &o, const ElementFieldCmp &cmp ) {
- _nfields = o.nFields();
- _fields = new const char*[_nfields];
- int x = 0;
- BSONObjIterator i( o );
- while ( i.more() ) {
- _fields[x++] = i.next().rawdata();
- verify( _fields[x-1] );
- }
- verify( x == _nfields );
- std::sort( _fields , _fields + _nfields , cmp );
- _cur = 0;
- }
-
- BSONObjIteratorSorted::BSONObjIteratorSorted( const BSONObj &object ) :
- BSONIteratorSorted( object, ElementFieldCmp( false ) ) {
- }
+private:
+ LexNumCmp _cmp;
+};
+
+BSONIteratorSorted::ElementFieldCmp::ElementFieldCmp(bool isArray) : _cmp(!isArray) {}
- BSONArrayIteratorSorted::BSONArrayIteratorSorted( const BSONArray &array ) :
- BSONIteratorSorted( array, ElementFieldCmp( true ) ) {
+bool BSONIteratorSorted::ElementFieldCmp::operator()(const char* s1, const char* s2) const {
+ // Skip the type byte and compare field names.
+ return _cmp(s1 + 1, s2 + 1);
+}
+
+BSONIteratorSorted::BSONIteratorSorted(const BSONObj& o, const ElementFieldCmp& cmp) {
+ _nfields = o.nFields();
+ _fields = new const char* [_nfields];
+ int x = 0;
+ BSONObjIterator i(o);
+ while (i.more()) {
+ _fields[x++] = i.next().rawdata();
+ verify(_fields[x - 1]);
}
-} // namespace mongo
+ verify(x == _nfields);
+ std::sort(_fields, _fields + _nfields, cmp);
+ _cur = 0;
+}
+
+BSONObjIteratorSorted::BSONObjIteratorSorted(const BSONObj& object)
+ : BSONIteratorSorted(object, ElementFieldCmp(false)) {}
+
+BSONArrayIteratorSorted::BSONArrayIteratorSorted(const BSONArray& array)
+ : BSONIteratorSorted(array, ElementFieldCmp(true)) {}
+} // namespace mongo