mongo::BSONObjBuilder Class Reference

#include <bsonobjbuilder.h>

List of all members.

Classes

struct  ForceExplicitString

Public Member Functions

template<class T >
BSONObjBuilderappend (const StringData &fieldName, const list< T > &vals)
template<class T >
BSONObjBuilderappend (const StringData &fieldName, const vector< T > &vals)
BSONObjBuilderappend (const StringData &fieldName, const string &str)
BSONObjBuilderappend (const StringData &fieldName, const char *str)
BSONObjBuilderappend (const StringData &fieldName, const char *str, int len)
BSONObjBuilderappend (const StringData &fieldName, Date_t dt)
BSONObjBuilderappend (const StringData &fieldName, OID oid)
BSONObjBuilderappend (const StringData &fieldName, double n)
BSONObjBuilderappend (const StringData &fieldName, long long n)
BSONObjBuilderappend (const StringData &fieldName, unsigned n)
BSONObjBuilderappend (const StringData &fieldName, int n)
BSONObjBuilderappend (const StringData &fieldName, bool val)
BSONObjBuilderappend (const StringData &fieldName, BSONArray arr)
BSONObjBuilderappend (const StringData &fieldName, BSONObj subObj)
BSONObjBuilderappend (const BSONElement &e)
BSONObjBuilderappendArray (const StringData &fieldName, const BSONObj &subObj)
BSONObjBuilderappendAs (const BSONElement &e, const StringData &fieldName)
bool appendAsNumber (const StringData &fieldName, const string &data)
BSONObjBuilderappendBinData (const StringData &fieldName, int len, BinDataType type, const unsigned char *data)
BSONObjBuilderappendBinData (const StringData &fieldName, int len, BinDataType type, const char *data)
BSONObjBuilderappendBinDataArrayDeprecated (const char *fieldName, const char *data, int len)
BSONObjBuilderappendBool (const StringData &fieldName, int val)
BSONObjBuilderappendCode (const StringData &fieldName, const StringData &code)
BSONObjBuilderappendCodeWScope (const StringData &fieldName, const StringData &code, const BSONObj &scope)
BSONObjBuilderappendDate (const StringData &fieldName, Date_t dt)
BSONObjBuilderappendDBRef (const StringData &fieldName, const StringData &ns, const OID &oid)
BSONObjBuilderappendElements (BSONObj x)
BSONObjBuilderappendElementsUnique (BSONObj x)
BSONObjBuilderappendIntOrLL (const StringData &fieldName, long long n)
void appendKeys (const BSONObj &keyPattern, const BSONObj &values)
void appendMaxForType (const StringData &fieldName, int type)
BSONObjBuilderappendMaxKey (const StringData &fieldName)
void appendMinForType (const StringData &fieldName, int type)
BSONObjBuilderappendMinKey (const StringData &fieldName)
BSONObjBuilderappendNull (const StringData &fieldName)
BSONObjBuilderappendNumber (const StringData &fieldName, long long l)
BSONObjBuilderappendNumber (const StringData &fieldName, size_t n)
BSONObjBuilderappendNumber (const StringData &fieldName, double d)
BSONObjBuilderappendNumber (const StringData &fieldName, int n)
BSONObjBuilderappendObject (const StringData &fieldName, const char *objdata, int size=0)
BSONObjBuilderappendOID (const StringData &fieldName, OID *oid=0, bool generateIfBlank=false)
BSONObjBuilderappendRegex (const StringData &fieldName, const StringData &regex, const StringData &options="")
BSONObjBuilderappendSymbol (const StringData &fieldName, const StringData &symbol)
BSONObjBuilderappendTimestamp (const StringData &fieldName, unsigned long long time, unsigned int inc)
BSONObjBuilderappendTimestamp (const StringData &fieldName, unsigned long long val)
BSONObjBuilderappendTimestamp (const StringData &fieldName)
BSONObjBuilderappendTimeT (const StringData &fieldName, time_t dt)
void appendUndefined (const StringData &fieldName)
void appendWhere (const StringData &code, const BSONObj &scope)
BSONObj asTempObj ()
 BSONObjBuilder (const BSONSizeTracker &tracker)
 BSONObjBuilder (BufBuilder &baseBuilder)
 BSONObjBuilder (int initsize=512)
void decouple ()
char * decouple (int &l)
BSONObj done ()
void doneFast ()
BSONObjBuildergenOID ()
bool hasField (const StringData &name) const
BSONObjIterator iterator () const
int len () const
BSONObj obj ()
template<typename T >
BSONObjBuilderoperator<< (const BSONFieldValue< T > &v)
template<typename T >
BSONObjBuilderValueStreamoperator<< (const BSONField< T > &f)
Labeler operator<< (const Labeler::Label &l)
BSONObjBuilderValueStreamoperator<< (const ForceExplicitString &name)
BSONObjBuilderoperator<< (GENOIDLabeler)
BSONObjBuilderValueStreamoperator<< (const char *name)
bool owned () const
BufBuildersubarrayStart (const StringData &fieldName)
BufBuildersubobjStart (const StringData &fieldName)
 ~BSONObjBuilder ()

Static Public Member Functions

static string numStr (int i)

Private Member Functions

char * _done ()

Private Attributes

BufBuilder_b
BufBuilder _buf
bool _doneCalled
int _offset
BSONObjBuilderValueStream _s
BSONSizeTracker_tracker

Static Private Attributes

static const string numStrs [100]

Detailed Description

Utility for creating a BSONObj. See also the BSON() and BSON_ARRAY() macros.

Definition at line 81 of file bsonobjbuilder.h.


Constructor & Destructor Documentation

mongo::BSONObjBuilder::BSONObjBuilder ( int  initsize = 512  )  [inline]
Parameters:
initsize this is just a hint as to the final size of the object

Definition at line 84 of file bsonobjbuilder.h.

mongo::BSONObjBuilder::BSONObjBuilder ( BufBuilder baseBuilder  )  [inline]
Parameters:
baseBuilder construct a BSONObjBuilder using an existing BufBuilder

Definition at line 90 of file bsonobjbuilder.h.

mongo::BSONObjBuilder::BSONObjBuilder ( const BSONSizeTracker tracker  )  [inline]

Definition at line 94 of file bsonobjbuilder.h.

mongo::BSONObjBuilder::~BSONObjBuilder (  )  [inline]

Definition at line 98 of file bsonobjbuilder.h.


Member Function Documentation

char* mongo::BSONObjBuilder::_done (  )  [inline, private]

Definition at line 627 of file bsonobjbuilder.h.

template<class T >
BSONObjBuilder & mongo::BSONObjBuilder::append ( const StringData fieldName,
const list< T > &  vals 
) [inline]

Definition at line 753 of file bsonobjbuilder.h.

template<class T >
BSONObjBuilder & mongo::BSONObjBuilder::append ( const StringData fieldName,
const vector< T > &  vals 
) [inline]

Append an array of values.

Definition at line 744 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::append ( const StringData fieldName,
const string &  str 
) [inline]

Append a string element

Definition at line 382 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::append ( const StringData fieldName,
const char *  str 
) [inline]

Append a string element

Definition at line 378 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::append ( const StringData fieldName,
const char *  str,
int  len 
) [inline]

Append a string element. len DOES include terminating nul

Definition at line 370 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::append ( const StringData fieldName,
Date_t  dt 
) [inline]

Definition at line 345 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::append ( const StringData fieldName,
OID  oid 
) [inline]

Append a BSON Object ID.

Parameters:
fieldName Field name, e.g., "_id".
Returns:
the builder object

Definition at line 302 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::append ( const StringData fieldName,
double  n 
) [inline]

Append a double element

Definition at line 265 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::append ( const StringData fieldName,
long long  n 
) [inline]

Append a NumberLong

Definition at line 209 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::append ( const StringData fieldName,
unsigned  n 
) [inline]

Append a 32 bit unsigned element - cast to a signed int.

Definition at line 204 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::append ( const StringData fieldName,
int  n 
) [inline]

Append a 32 bit integer element

Definition at line 196 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::append ( const StringData fieldName,
bool  val 
) [inline]

Append a boolean element

Definition at line 188 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::append ( const StringData fieldName,
BSONArray  arr 
) [inline]

Definition at line 167 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::append ( const StringData fieldName,
BSONObj  subObj 
) [inline]

add a subobject as a member

Definition at line 127 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::append ( const BSONElement e  )  [inline]

append element to the object we are building

Definition at line 111 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendArray ( const StringData fieldName,
const BSONObj subObj 
) [inline]

add a subobject as a member with type Array. Thus arr object should have "0", "1", ... style fields in it.

Definition at line 161 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendAs ( const BSONElement e,
const StringData fieldName 
) [inline]

append an element but with a new name

Definition at line 118 of file bsonobjbuilder.h.

bool mongo::BSONObjBuilder::appendAsNumber ( const StringData fieldName,
const string &  data 
)

tries to append the data as a number

Returns:
true if the data was able to be converted to a number
BSONObjBuilder& mongo::BSONObjBuilder::appendBinData ( const StringData fieldName,
int  len,
BinDataType  type,
const unsigned char *  data 
) [inline]

Definition at line 464 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendBinData ( const StringData fieldName,
int  len,
BinDataType  type,
const char *  data 
) [inline]

Append a binary data element

Parameters:
fieldName name of the field
len length of the binary data in bytes
subtype subtype information for the data.
See also:
enum BinDataType in bsontypes.h. Use BinDataGeneral if you don't care about the type.
Parameters:
data the byte array

Definition at line 456 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendBinDataArrayDeprecated ( const char *  fieldName,
const char *  data,
int  len 
) [inline]

Subtype 2 is deprecated. Append a BSON bindata bytearray element.

Parameters:
data a byte array
len the length of data

Definition at line 474 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendBool ( const StringData fieldName,
int  val 
) [inline]

Append a boolean element

Definition at line 180 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendCode ( const StringData fieldName,
const StringData code 
) [inline]

Definition at line 361 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendCodeWScope ( const StringData fieldName,
const StringData code,
const BSONObj scope 
) [inline]

Append to the BSON object a field of type CodeWScope. This is a javascript code fragment accompanied by some scope that goes with it.

Definition at line 487 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendDate ( const StringData fieldName,
Date_t  dt 
) [inline]

Append a date.

Parameters:
dt a Java-style 64 bit date value, that is the number of milliseconds since January 1, 1970, 00:00:00 GMT

Definition at line 331 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendDBRef ( const StringData fieldName,
const StringData ns,
const OID oid 
) [inline]

Definition at line 440 of file bsonobjbuilder.h.

BSONObjBuilder & mongo::BSONObjBuilder::appendElements ( BSONObj  x  )  [inline]

add all the fields from the object specified to this object

Definition at line 113 of file bson-inl.h.

BSONObjBuilder & mongo::BSONObjBuilder::appendElementsUnique ( BSONObj  x  )  [inline]

add all the fields from the object specified to this object if they don't exist already

Definition at line 124 of file bson-inl.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendIntOrLL ( const StringData fieldName,
long long  n 
) [inline]

appends a number. if n < max(int)/2 then uses int, otherwise long long

Definition at line 217 of file bsonobjbuilder.h.

void mongo::BSONObjBuilder::appendKeys ( const BSONObj keyPattern,
const BSONObj values 
)
void mongo::BSONObjBuilder::appendMaxForType ( const StringData fieldName,
int  type 
)
BSONObjBuilder& mongo::BSONObjBuilder::appendMaxKey ( const StringData fieldName  )  [inline]

Definition at line 408 of file bsonobjbuilder.h.

void mongo::BSONObjBuilder::appendMinForType ( const StringData fieldName,
int  type 
)

these are the min/max when comparing, not strict min/max elements for a given type

BSONObjBuilder& mongo::BSONObjBuilder::appendMinKey ( const StringData fieldName  )  [inline]

Definition at line 402 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendNull ( const StringData fieldName  )  [inline]

Append a Null element to the object

Definition at line 395 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendNumber ( const StringData fieldName,
long long  l 
) [inline]

Definition at line 251 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendNumber ( const StringData fieldName,
size_t  n 
) [inline]

Definition at line 240 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendNumber ( const StringData fieldName,
double  d 
) [inline]

Definition at line 236 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendNumber ( const StringData fieldName,
int  n 
) [inline]

appendNumber is a series of method for appending the smallest sensible type mostly for JS

Definition at line 232 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendObject ( const StringData fieldName,
const char *  objdata,
int  size = 0 
) [inline]

add a subobject as a member

Definition at line 135 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendOID ( const StringData fieldName,
OID oid = 0,
bool  generateIfBlank = false 
) [inline]

Append a BSON Object ID (OID type).

Deprecated:
Generally, it is preferred to use the append append(name, oid) method for this.

Definition at line 281 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendRegex ( const StringData fieldName,
const StringData regex,
const StringData options = "" 
) [inline]

Append a regular expression value

Parameters:
regex the regular expression pattern
regex options such as "i" or "g"

Definition at line 353 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendSymbol ( const StringData fieldName,
const StringData symbol 
) [inline]

Definition at line 386 of file bsonobjbuilder.h.

BSONObjBuilder & mongo::BSONObjBuilder::appendTimestamp ( const StringData fieldName,
unsigned long long  time,
unsigned int  inc 
) [inline]

Timestamps are a special BSON datatype that is used internally for replication. Append a timestamp element to the object being ebuilt.

Parameters:
time - in millis (but stored in seconds)

Definition at line 36 of file bson_db.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendTimestamp ( const StringData fieldName,
unsigned long long  val 
) [inline]

Definition at line 422 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendTimestamp ( const StringData fieldName  )  [inline]

Definition at line 415 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::appendTimeT ( const StringData fieldName,
time_t  dt 
) [inline]

Append a time_t date.

Parameters:
dt a C-style 32 bit date value, that is the number of seconds since January 1, 1970, 00:00:00 GMT

Definition at line 321 of file bsonobjbuilder.h.

void mongo::BSONObjBuilder::appendUndefined ( const StringData fieldName  )  [inline]

Definition at line 497 of file bsonobjbuilder.h.

void mongo::BSONObjBuilder::appendWhere ( const StringData code,
const BSONObj scope 
) [inline]

Definition at line 503 of file bsonobjbuilder.h.

BSONObj mongo::BSONObjBuilder::asTempObj (  )  [inline]

Peek at what is in the builder, but leave the builder ready for more appends. The returned object is only valid until the next modification or destruction of the builder. Intended use case: append a field if not already there.

Definition at line 550 of file bsonobjbuilder.h.

void mongo::BSONObjBuilder::decouple (  )  [inline]

Definition at line 565 of file bsonobjbuilder.h.

char* mongo::BSONObjBuilder::decouple ( int &  l  )  [inline]

Definition at line 558 of file bsonobjbuilder.h.

BSONObj mongo::BSONObjBuilder::done (  )  [inline]

Fetch the object we have built. BSONObjBuilder still frees the object when the builder goes out of scope -- very important to keep in mind. Use obj() if you would like the BSONObj to last longer than the builder.

Definition at line 537 of file bsonobjbuilder.h.

void mongo::BSONObjBuilder::doneFast (  )  [inline]

Definition at line 542 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::genOID (  )  [inline]

Generate and assign an object id for the _id field. _id should be the first element in the object for good performance.

Definition at line 313 of file bsonobjbuilder.h.

bool mongo::BSONObjBuilder::hasField ( const StringData name  )  const [inline]

Definition at line 227 of file bson-inl.h.

BSONObjIterator mongo::BSONObjBuilder::iterator (  )  const [inline]

Definition at line 221 of file bson-inl.h.

int mongo::BSONObjBuilder::len (  )  const [inline]

Definition at line 624 of file bsonobjbuilder.h.

static string mongo::BSONObjBuilder::numStr ( int  i  )  [inline, static]

Definition at line 571 of file bsonobjbuilder.h.

BSONObj mongo::BSONObjBuilder::obj (  )  [inline]

destructive The returned BSONObj will free the buffer when it is finished.

Returns:
owned BSONObj

Definition at line 525 of file bsonobjbuilder.h.

template<typename T >
BSONObjBuilder& mongo::BSONObjBuilder::operator<< ( const BSONFieldValue< T > &  v  )  [inline]

Definition at line 611 of file bsonobjbuilder.h.

template<typename T >
BSONObjBuilderValueStream& mongo::BSONObjBuilder::operator<< ( const BSONField< T > &  f  )  [inline]

Definition at line 605 of file bsonobjbuilder.h.

Labeler mongo::BSONObjBuilder::operator<< ( const Labeler::Label l  )  [inline]

Definition at line 599 of file bsonobjbuilder.h.

BSONObjBuilderValueStream& mongo::BSONObjBuilder::operator<< ( const ForceExplicitString name  )  [inline]

Stream oriented way to add field names and values.

Definition at line 595 of file bsonobjbuilder.h.

BSONObjBuilder& mongo::BSONObjBuilder::operator<< ( GENOIDLabeler   )  [inline]

Stream oriented way to add field names and values.

Definition at line 586 of file bsonobjbuilder.h.

BSONObjBuilderValueStream& mongo::BSONObjBuilder::operator<< ( const char *  name  )  [inline]

Stream oriented way to add field names and values.

Definition at line 580 of file bsonobjbuilder.h.

bool mongo::BSONObjBuilder::owned (  )  const [inline]
Returns:
true if we are using our own bufbuilder, and not an alternate that was given to us in our constructor

Definition at line 618 of file bsonobjbuilder.h.

BufBuilder& mongo::BSONObjBuilder::subarrayStart ( const StringData fieldName  )  [inline]

add header for a new subarray and return bufbuilder for writing to the subarray's body

Definition at line 173 of file bsonobjbuilder.h.

BufBuilder& mongo::BSONObjBuilder::subobjStart ( const StringData fieldName  )  [inline]

add header for a new subobject and return bufbuilder for writing to the subobject's body

Definition at line 152 of file bsonobjbuilder.h.


Member Data Documentation

Definition at line 642 of file bsonobjbuilder.h.

Definition at line 643 of file bsonobjbuilder.h.

Definition at line 647 of file bsonobjbuilder.h.

Definition at line 644 of file bsonobjbuilder.h.

Definition at line 645 of file bsonobjbuilder.h.

Definition at line 646 of file bsonobjbuilder.h.

const string mongo::BSONObjBuilder::numStrs[100] [static, private]

Definition at line 649 of file bsonobjbuilder.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


mongodb
Author(s): Nate Koenig
autogenerated on Fri Jan 11 12:15:53 2013