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;
89 #if defined (SDB_ENGINE) || defined (SDB_CLIENT)
90 class BSONObj :
public SDBObject {
101 mongo::AtomicUInt refCount ;
105 void zeroRef() { refCount.zero() ; }
106 void addRef () { refCount++ ; }
109 #if defined(_DEBUG) // cant use dassert or DEV here
111 assert( (
int)refCount > 0 ) ;
115 const char* dataptr()
const {
return &data[0] ; }
116 int datasize()
const {
return *(
int*)dataptr() ; }
118 static int refLen() {
return sizeof( mongo::AtomicUInt ) ; }
120 typedef bson_intrusive_ptr< Holder, TrivialAllocator > holder_type ;
127 explicit BSONObj(
const char *msgdata,
bool check=
true) {
129 init(msgdata, check);
191 return _holder.get() != 0;
207 string toString(
bool isArray =
false,
bool full=
false,
208 bool noThrow =
true )
const;
209 #if defined ( SDB_ENGINE ) || defined ( SDB_FMP ) || defined ( SDB_TOOL )
210 ossPoolString toPoolString(
bool isArray =
false,
bool full=
false,
211 bool noThrow =
true )
const ;
212 #endif //SDB_ENGINE || SDB_FMP || SDB_TOOL
214 void toString(StringBuilder& s,
bool isArray =
false,
bool full=
false )
220 string jsonString( JsonStringFormat format = Strict,
int pretty = 0 )
251 void getFieldsDotted(
const StringData& name, BSONElementSet &ret)
const;
252 void getFieldsDotted(
const StringData& name, BSONElementMSet &ret)
const;
327 BSONObj filterFieldsUndotted(
const BSONObj &filter,
bool inFilter)
330 BSONElement getFieldUsingIndexNames(
const char *fieldName,
331 const BSONObj &indexKey)
const;
339 {
return *(
reinterpret_cast<const int*
>(
objdata())); }
363 bool considerFieldName=
true)
const;
371 bool considerFieldName=
true)
const;
373 bool operator<(
const BSONObj& other )
const
375 bool operator<=(
const BSONObj& other )
const
377 bool operator>(
const BSONObj& other )
const
379 bool operator>=(
const BSONObj& other )
const
387 bool useDotted=
false )
const;
389 bool equal(
const BSONObj& r)
const;
396 if ( os == r.objsize() ) {
397 return (os == 0 || memcmp(
objdata(),r.objdata(),os)==0);
410 return *p == EOO ?
"" : p+1;
424 for (
int i = 0; i <
objsize(); i++ )
426 return (x & 0x7fffffff) | 0x8000000;
433 BSONObj clientReadable()
const;
445 bool operator==(
const BSONObj& other )
const {
return equal( other ); }
471 void elems(vector<BSONElement> &)
const;
473 void elems(list<BSONElement> &)
const;
485 void Vals(vector<T> &)
const;
489 void Vals(list<T> &)
const;
494 void vals(vector<T> &)
const;
498 void vals(list<T> &)
const;
500 friend class BSONObjIterator;
501 typedef BSONObjIterator iterator;
509 BSONObjIterator
begin()
const;
511 void appendSelfToBufBuilder(BufBuilder& b)
const {
513 b.appendBuf(reinterpret_cast<const void *>(
objdata() ),
objsize());
518 void init(
const char *data,
bool check=
true ) {
531 _jsCompatibility = compatible;
539 return _jsCompatibility;
543 SDB_EXPORT
static bool _jsCompatibility;
546 const char *_objdata ;
547 holder_type _holder ;
549 void _assertInvalid()
const;
551 void init( Holder *holder ) {
556 void init( holder_type holder ) {
558 init( _holder->data ) ;
562 ostream& operator<<( ostream &s,
const BSONObj &o );
563 ostream& operator<<( ostream &s,
const BSONElement &e );
565 StringBuilder& operator<<( StringBuilder &s,
const BSONObj &o );
566 StringBuilder& operator<<( StringBuilder &s,
const BSONElement &e );