22 #if defined (SDB_ENGINE) || defined (SDB_CLIENT)
30 #include "lib/atomic_int.h"
31 #include "util/builder.h"
32 #include "stringdata.h"
34 #include "bsonnoncopyable.h"
35 #include "bsonintrusiveptr.h"
36 #include "bsonDecimal.h"
43 typedef set< BSONElement, BSONElementCmpWithoutField > BSONElementSet;
46 typedef multiset< BSONElement, BSONElementCmpWithoutField > BSONElementMSet;
88 #if defined (SDB_ENGINE) || defined (SDB_CLIENT)
89 class BSONObj :
public SDBObject {
98 explicit BSONObj(
const char *msgdata,
bool check=
true) {
100 init(msgdata, check);
164 return _holder.get() != 0;
180 string toString(
bool isArray =
false,
bool full=
false )
const;
181 void toString(StringBuilder& s,
bool isArray =
false,
bool full=
false )
187 string jsonString( JsonStringFormat format = Strict,
int pretty = 0 )
218 void getFieldsDotted(
const StringData& name, BSONElementSet &ret)
const;
219 void getFieldsDotted(
const StringData& name, BSONElementMSet &ret)
const;
293 BSONObj filterFieldsUndotted(
const BSONObj &filter,
bool inFilter)
296 BSONElement getFieldUsingIndexNames(
const char *fieldName,
297 const BSONObj &indexKey)
const;
305 {
return *(
reinterpret_cast<const int*
>(
objdata())); }
329 bool considerFieldName=
true)
const;
337 bool considerFieldName=
true)
const;
339 bool operator<(
const BSONObj& other )
const
341 bool operator<=(
const BSONObj& other )
const
343 bool operator>(
const BSONObj& other )
const
345 bool operator>=(
const BSONObj& other )
const
353 bool useDotted=
false )
const;
355 bool equal(
const BSONObj& r)
const;
362 if ( os == r.objsize() ) {
363 return (os == 0 || memcmp(
objdata(),r.objdata(),os)==0);
376 return *p == EOO ?
"" : p+1;
390 for (
int i = 0; i <
objsize(); i++ )
392 return (x & 0x7fffffff) | 0x8000000;
399 BSONObj clientReadable()
const;
411 bool operator==(
const BSONObj& other )
const {
return equal( other ); }
437 void elems(vector<BSONElement> &)
const;
439 void elems(list<BSONElement> &)
const;
451 void Vals(vector<T> &)
const;
455 void Vals(list<T> &)
const;
460 void vals(vector<T> &)
const;
464 void vals(list<T> &)
const;
466 friend class BSONObjIterator;
467 typedef BSONObjIterator iterator;
475 BSONObjIterator
begin()
const;
477 void appendSelfToBufBuilder(BufBuilder& b)
const {
479 b.appendBuf(reinterpret_cast<const void *>(
objdata() ),
objsize());
486 mongo::AtomicUInt refCount;
490 void zero() { refCount.zero(); }
497 friend void intrusive_ptr_add_ref(
Holder* h) { h->refCount++; }
498 friend void intrusive_ptr_release(
Holder* h) {
499 #if defined(_DEBUG) // cant use dassert or DEV here
500 assert((
int)h->refCount > 0);
502 if(--(h->refCount) == 0){
510 void init(
const char *data,
bool check=
true ) {
523 _jsCompatibility = compatible;
531 return _jsCompatibility;
535 SDB_EXPORT
static bool _jsCompatibility;
539 const char *_objdata;
541 bson_intrusive_ptr< Holder > _holder;
543 void _assertInvalid()
const;
545 void init(Holder *holder) {
552 ostream& operator<<( ostream &s,
const BSONObj &o );
553 ostream& operator<<( ostream &s,
const BSONElement &e );
555 StringBuilder& operator<<( StringBuilder &s,
const BSONObj &o );
556 StringBuilder& operator<<( StringBuilder &s,
const BSONElement &e );