mongo::OID Class Reference

#include <oid.h>

List of all members.

Classes

struct  MachineAndPid

Public Member Functions

Date_t asDateT ()
time_t asTimeT ()
void clear ()
int compare (const OID &other) const
const unsigned char * getData () const
void init (Date_t date, bool max=false)
void init (string s)
void init ()
bool isSet () const
 OID (const string &s)
 OID ()
bool operator!= (const OID &r) const
bool operator< (const OID &other) const
bool operator<= (const OID &other) const
bool operator== (const OID &r) const
string str () const
string toString () const

Static Public Member Functions

static OID gen ()
static unsigned getMachineId ()
static void justForked ()
static void regenMachineId ()

Static Private Member Functions

static void foldInPid (MachineAndPid &x)
static MachineAndPid genMachineAndPid ()
static unsigned ourPid ()

Private Attributes

union {
   struct {
      unsigned char   _inc [3]
      MachineAndPid   _machineAndPid
      unsigned char   _time [4]
   } 
   struct {
      long long   a
      unsigned   b
   } 
   unsigned char   data [12]
}; 

Static Private Attributes

static MachineAndPid ourMachine
static MachineAndPid ourMachineAndPid

Detailed Description

Object ID type. BSON objects typically have an _id field for the object id. This field should be the first member of the object when present. class OID is a special type that is a 12 byte id which is likely to be unique to the system. You may also use other types for _id's. When _id field is missing from a BSON object, on an insert the database may insert one automatically in certain circumstances.

Warning: You must call OID::newState() after a fork().

Typical contents of the BSON ObjectID is a 12-byte value consisting of a 4-byte timestamp (seconds since epoch), a 3-byte machine id, a 2-byte process id, and a 3-byte counter. Note that the timestamp and counter fields must be stored big endian unlike the rest of BSON. This is because they are compared byte-by-byte and we want to ensure a mostly increasing order.

Definition at line 39 of file oid.h.


Constructor & Destructor Documentation

mongo::OID::OID (  )  [inline]

Definition at line 41 of file oid.h.

mongo::OID::OID ( const string &  s  )  [inline, explicit]

init from a 24 char hex string

Definition at line 44 of file oid.h.


Member Function Documentation

Date_t mongo::OID::asDateT (  )  [inline]

Definition at line 73 of file oid.h.

time_t mongo::OID::asTimeT (  ) 
void mongo::OID::clear (  )  [inline]

initialize to 'null'

Definition at line 47 of file oid.h.

int mongo::OID::compare ( const OID other  )  const [inline]

Definition at line 53 of file oid.h.

static void mongo::OID::foldInPid ( MachineAndPid x  )  [static, private]
static OID mongo::OID::gen (  )  [inline, static]

Definition at line 61 of file oid.h.

static MachineAndPid mongo::OID::genMachineAndPid (  )  [static, private]
const unsigned char* mongo::OID::getData (  )  const [inline]

Definition at line 49 of file oid.h.

static unsigned mongo::OID::getMachineId (  )  [static]
void mongo::OID::init ( Date_t  date,
bool  max = false 
)

Set to the min/max OID that could be generated at given timestamp.

void mongo::OID::init ( string  s  ) 

init from a 24 char hex string

void mongo::OID::init (  ) 

sets the contents to a new oid / randomized value

bool mongo::OID::isSet (  )  const [inline]

Definition at line 75 of file oid.h.

static void mongo::OID::justForked (  )  [static]

call this after a fork to update the process id

bool mongo::OID::operator!= ( const OID r  )  const [inline]

Definition at line 52 of file oid.h.

bool mongo::OID::operator< ( const OID other  )  const [inline]

Definition at line 54 of file oid.h.

bool mongo::OID::operator<= ( const OID other  )  const [inline]

Definition at line 55 of file oid.h.

bool mongo::OID::operator== ( const OID r  )  const [inline]

Definition at line 51 of file oid.h.

static unsigned mongo::OID::ourPid (  )  [static, private]
static void mongo::OID::regenMachineId (  )  [static]
string mongo::OID::str (  )  const [inline]
Returns:
the object ID output as 24 hex digits

Definition at line 58 of file oid.h.

string mongo::OID::toString (  )  const [inline]

Definition at line 59 of file oid.h.


Member Data Documentation

union { ... } [private]
unsigned char mongo::OID::_inc[3]

Definition at line 95 of file oid.h.

Definition at line 94 of file oid.h.

unsigned char mongo::OID::_time[4]

Definition at line 93 of file oid.h.

long long mongo::OID::a

Definition at line 98 of file oid.h.

unsigned mongo::OID::b

Definition at line 99 of file oid.h.

unsigned char mongo::OID::data[12]

Definition at line 101 of file oid.h.

Definition at line 89 of file oid.h.

Definition at line 89 of file oid.h.


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


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