summaryrefslogtreecommitdiff
path: root/bson/bsonobjiterator.h
diff options
context:
space:
mode:
authordwight <dwight@10gen.com>2011-06-27 09:14:55 -0400
committerdwight <dwight@10gen.com>2011-06-27 09:14:55 -0400
commit4f87fbb17c2d24dd065c450f072669bd63856908 (patch)
treed6a6e6ebbdeec7f72273fa56ed670a63eeec9961 /bson/bsonobjiterator.h
parent1056d38ce5e9a8be098d41e1e887c8dce3527231 (diff)
downloadmongo-4f87fbb17c2d24dd065c450f072669bd63856908.tar.gz
move bson method to the right place for libs and include only use of bson
Diffstat (limited to 'bson/bsonobjiterator.h')
-rw-r--r--bson/bsonobjiterator.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/bson/bsonobjiterator.h b/bson/bsonobjiterator.h
index 371a209fcd3..69958cb6331 100644
--- a/bson/bsonobjiterator.h
+++ b/bson/bsonobjiterator.h
@@ -107,6 +107,29 @@ namespace mongo {
int _cur;
};
+ /** transform a BSON array into a vector of BSONElements.
+ we match array # positions with their vector position, and ignore
+ any fields with non-numeric field names.
+ */
+ inline vector<BSONElement> BSONElement::Array() const {
+ chk(mongo::Array);
+ vector<BSONElement> v;
+ BSONObjIterator i(Obj());
+ while( i.more() ) {
+ BSONElement e = i.next();
+ const char *f = e.fieldName();
+ try {
+ unsigned u = stringToNum(f);
+ assert( u < 1000000 );
+ if( u >= v.size() )
+ v.resize(u+1);
+ v[u] = e;
+ }
+ catch(unsigned) { }
+ }
+ return v;
+ }
+
/** Similar to BOOST_FOREACH
*
* because the iterator is defined outside of the for, you must use {} around