diff options
author | Dwight Merriman <dwight@10gen.com> | 2010-04-25 17:48:49 -0400 |
---|---|---|
committer | Dwight Merriman <dwight@10gen.com> | 2010-04-25 17:48:49 -0400 |
commit | 8fb9289813b63ea5fcfc5800264f8b4e939c48ed (patch) | |
tree | 8d834ee02292b93b3b7d8f44a88c10819f9e5bbb /bson/bsoninlines.h | |
parent | 81649832c4f7a8cf11856e756d2e037782226cc9 (diff) | |
download | mongo-8fb9289813b63ea5fcfc5800264f8b4e939c48ed.tar.gz |
bson cleaning
Diffstat (limited to 'bson/bsoninlines.h')
-rw-r--r-- | bson/bsoninlines.h | 74 |
1 files changed, 72 insertions, 2 deletions
diff --git a/bson/bsoninlines.h b/bson/bsoninlines.h index 0faedca4950..85d9443d28f 100644 --- a/bson/bsoninlines.h +++ b/bson/bsoninlines.h @@ -170,8 +170,8 @@ namespace mongo { } inline BSONObjIterator BSONObjBuilder::iterator() const { - const char * s = b.buf() + offset_; - const char * e = b.buf() + b.len(); + const char * s = _b.buf() + _offset; + const char * e = _b.buf() + _b.len(); return BSONObjIterator( s , e ); } @@ -489,4 +489,74 @@ namespace mongo { _objdata = p; } + inline BSONObj BSONElement::Obj() const { return embeddedObjectUserCheck(); } + + inline BSONElement BSONElement::operator[] (const string& field) const { + BSONObj o = Obj(); + return o[field]; + } + + inline void BSONObj::elems(vector<BSONElement> &v) const { + BSONObjIterator i(*this); + while( i.more() ) + v.push_back(i.next()); + } + + inline void BSONObj::elems(list<BSONElement> &v) const { + BSONObjIterator i(*this); + while( i.more() ) + v.push_back(i.next()); + } + + template <class T> + void BSONObj::Vals(vector<T>& v) const { + BSONObjIterator i(*this); + while( i.more() ) { + T t; + i.next().Val(t); + v.push_back(t); + } + } + template <class T> + void BSONObj::Vals(list<T>& v) const { + BSONObjIterator i(*this); + while( i.more() ) { + T t; + i.next().Val(t); + v.push_back(t); + } + } + + template <class T> + void BSONObj::vals(vector<T>& v) const { + BSONObjIterator i(*this); + while( i.more() ) { + try { + T t; + i.next().Val(t); + v.push_back(t); + } catch(...) { } + } + } + template <class T> + void BSONObj::vals(list<T>& v) const { + BSONObjIterator i(*this); + while( i.more() ) { + try { + T t; + i.next().Val(t); + v.push_back(t); + } catch(...) { } + } + } + + inline ostream& operator<<( ostream &s, const BSONObj &o ) { + return s << o.toString(); + } + + inline ostream& operator<<( ostream &s, const BSONElement &e ) { + return s << e.toString(); + } + + inline void BSONElement::Val(BSONObj& v) const { v = Obj(); } } |