mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
Merge branch 'master' of git@github.com:mongodb/mongo
Conflicts: db/jsobj.h
This commit is contained in:
commit
73ee41d32d
36
db/jsobj.h
36
db/jsobj.h
@ -43,7 +43,7 @@ namespace mongo {
|
||||
class BSONArrayBuilder;
|
||||
class BSONObjBuilderValueStream;
|
||||
struct BSONArray; // empty subclass of BSONObj useful for overloading
|
||||
|
||||
class BSONObjIterator;
|
||||
extern BSONObj maxKey;
|
||||
extern BSONObj minKey;
|
||||
|
||||
@ -1143,6 +1143,8 @@ namespace mongo {
|
||||
bool owned() const {
|
||||
return &b == &buf_;
|
||||
}
|
||||
|
||||
BSONObjIterator iterator() const ;
|
||||
|
||||
private:
|
||||
// Append the provided arr object as an array.
|
||||
@ -1267,29 +1269,35 @@ namespace mongo {
|
||||
BSONObjIterator(const BSONObj& jso) {
|
||||
int sz = jso.objsize();
|
||||
if ( sz == 0 ) {
|
||||
pos = theend = 0;
|
||||
_pos = _theend = 0;
|
||||
return;
|
||||
}
|
||||
pos = jso.objdata() + 4;
|
||||
theend = jso.objdata() + sz;
|
||||
_pos = jso.objdata() + 4;
|
||||
_theend = jso.objdata() + sz;
|
||||
}
|
||||
|
||||
BSONObjIterator( const char * start , const char * end ){
|
||||
_pos = start + 4;
|
||||
_theend = end;
|
||||
}
|
||||
|
||||
/** @return true if more elements exist to be enumerated. */
|
||||
bool moreWithEOO() {
|
||||
return pos < theend;
|
||||
return _pos < _theend;
|
||||
}
|
||||
bool more(){
|
||||
return pos < theend && pos[0];
|
||||
return _pos < _theend && _pos[0];
|
||||
}
|
||||
/** @return the next element in the object. For the final element, element.eoo() will be true. */
|
||||
BSONElement next( bool checkEnd = false ) {
|
||||
assert( pos < theend );
|
||||
BSONElement e( pos, checkEnd ? (int)(theend - pos) : -1 );
|
||||
pos += e.size( checkEnd ? (int)(theend - pos) : -1 );
|
||||
assert( _pos < _theend );
|
||||
BSONElement e( _pos, checkEnd ? (int)(_theend - _pos) : -1 );
|
||||
_pos += e.size( checkEnd ? (int)(_theend - _pos) : -1 );
|
||||
return e;
|
||||
}
|
||||
private:
|
||||
const char *pos;
|
||||
const char *theend;
|
||||
const char* _pos;
|
||||
const char* _theend;
|
||||
};
|
||||
|
||||
/* iterator a BSONObj which is an array, in array order.
|
||||
@ -1502,6 +1510,12 @@ namespace mongo {
|
||||
dotted2nested(b, obj);
|
||||
return b.obj();
|
||||
}
|
||||
|
||||
inline BSONObjIterator BSONObjBuilder::iterator() const {
|
||||
const char * s = b.buf() + offset_;
|
||||
const char * e = b.buf() + b.len();
|
||||
return BSONObjIterator( s , e );
|
||||
}
|
||||
|
||||
/* WARNING: nested/dotted conversions are not 100% reversible
|
||||
* nested2dotted(dotted2nested({a.b: {c:1}})) -> {a.b.c: 1}
|
||||
|
@ -1480,6 +1480,38 @@ namespace JsobjTests {
|
||||
}
|
||||
};
|
||||
|
||||
class BuilderPartialItearte {
|
||||
public:
|
||||
void run(){
|
||||
{
|
||||
BSONObjBuilder b;
|
||||
b.append( "x" , 1 );
|
||||
b.append( "y" , 2 );
|
||||
|
||||
BSONObjIterator i = b.iterator();
|
||||
ASSERT( i.more() );
|
||||
ASSERT_EQUALS( 1 , i.next().numberInt() );
|
||||
ASSERT( i.more() );
|
||||
ASSERT_EQUALS( 2 , i.next().numberInt() );
|
||||
ASSERT( ! i.more() );
|
||||
|
||||
b.append( "z" , 3 );
|
||||
|
||||
i = b.iterator();
|
||||
ASSERT( i.more() );
|
||||
ASSERT_EQUALS( 1 , i.next().numberInt() );
|
||||
ASSERT( i.more() );
|
||||
ASSERT_EQUALS( 2 , i.next().numberInt() );
|
||||
ASSERT( i.more() );
|
||||
ASSERT_EQUALS( 3 , i.next().numberInt() );
|
||||
ASSERT( ! i.more() );
|
||||
|
||||
ASSERT_EQUALS( BSON( "x" << 1 << "y" << 2 << "z" << 3 ) , b.obj() );
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
class All : public Suite {
|
||||
public:
|
||||
All() : Suite( "jsobj" ){
|
||||
@ -1574,6 +1606,7 @@ namespace JsobjTests {
|
||||
add< InvalidIDFind >();
|
||||
add< ElementSetTest >();
|
||||
add< EmbeddedNumbers >();
|
||||
add< BuilderPartialItearte >();
|
||||
}
|
||||
} myall;
|
||||
|
||||
|
@ -102,10 +102,6 @@ namespace mongo {
|
||||
append( (void *)str.c_str(), str.length() + 1 );
|
||||
}
|
||||
|
||||
void append( int val , int padding ){
|
||||
|
||||
}
|
||||
|
||||
int len() const {
|
||||
return l;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user