BSON C++ API  2.5.1
uma::bson
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
uma::bson::ObjectId Class Reference

A POD that represents a MongoDB OID type. More...

#include <ObjectId.h>

+ Inheritance diagram for uma::bson::ObjectId:
+ Collaboration diagram for uma::bson::ObjectId:

Public Member Functions

 ObjectId (const Poco::Timestamp &ts=Poco::Timestamp())
 Default constructor. Create a new instance with the the current timestamp or specified value.
 
 ObjectId (const char(&value)[12])
 Create a new OID from the byte array specified.
 
 ObjectId (const std::string &str)
 Create oid from 24 char hex string.
 
 ObjectId (const Poco::Timestamp &date, const int random, const int sequence)
 Create a new OID with the three components that the OID bytes represent.
 
const Poco::Timestamp getTime () const
 Return the timestamp value encoded in this OID.
 
const std::string toString () const
 Return a 24 char hex representation of the OID.
 
void getBytes (char *bytes, const int max=12) const
 Populate the specified char array with the contents of the OID.
 
void setBytes (const char(&bytes)[12])
 Replaces the bytes represented in this instance with the specified byte array.
 
int32_t getSize () const
 Return the size in bytes of the BSON representation of this OID value.
 
Value::Type getType () const
 Returns the type for this instance as listed in the BSON specifications.
 
- Public Member Functions inherited from uma::bson::Value
virtual ~Value ()
 Virtual DTOR for sub-classes.
 
const std::string & getTypeName () const
 Returns a standard textual value for this type.
 

Additional Inherited Members

- Public Types inherited from uma::bson::Value
enum  Type {
  Eoo = 0, Double = 1, String = 2, Object = 3,
  Array = 4, BinData = 5, Undefined = 6, OID = 7,
  Boolean = 8, Date = 9, Null = 10, RegEx = 11,
  DbRef = 12, Code = 13, Symbol = 14, CodeWScope = 15,
  Integer = 16, Timestamp = 17, Long = 18
}
 
- Static Public Member Functions inherited from uma::bson::Value
static const std::string & getTypeName (const Type type)
 Return a descriptive text about the specified type.
 
- Protected Member Functions inherited from uma::bson::Value
 Value ()
 

Detailed Description

A POD that represents a MongoDB OID type.

A POD that represents a MongoDB OID type. OID's encode the creation time of the OID, and hence may be used as an efficient creation date property for the document.

Date
Created 2012/09/06 19:04
Author
Rakesh
Version
Id:
ObjectId.h 192 2012-12-23 22:51:30Z spt

Constructor & Destructor Documentation

uma::bson::ObjectId::ObjectId ( const Poco::Timestamp &  ts = Poco::Timestamp())
inlineexplicit

Default constructor. Create a new instance with the the current timestamp or specified value.

Note that this version stores the microsecond time part in the last 4 bytes of the OID. This allows a very precise timestamp for the OID value to be retrieved. The middle 4 bytes are still populated using a random sequence, which hopefully will make the generated OID value close to globally unique.

Parameters
tsThe timestamp to initialise the OID from. Defaults to current time.
uma::bson::ObjectId::ObjectId ( const char(&)  value[12])
inlineexplicit

Create a new OID from the byte array specified.

Parameters
(value)[]The 12 byte array to initialise from
uma::bson::ObjectId::ObjectId ( const std::string &  str)
inlineexplicit

Create oid from 24 char hex string.

Parameters
strThe string representation from which to initialise the OID
uma::bson::ObjectId::ObjectId ( const Poco::Timestamp &  date,
const int  random,
const int  sequence 
)
inline

Create a new OID with the three components that the OID bytes represent.

Parameters
dateThe time stamp used to initialise the instance. Note that only the seconds from UNIX epoch will be used to populate the first 4 bytes
randomThe random value used to populate the second 4 bytes.
sequenceThe sequence number used to populate the last 4 bytes.

Member Function Documentation

void uma::bson::ObjectId::getBytes ( char *  bytes,
const int  max = 12 
) const
inline

Populate the specified char array with the contents of the OID.

Parameters
bytesThe byte array (ideally 12 char in length) that is to be populated with the contents of the OID value.
maxThe optional maximum number of characters to write into the bytes array. Defaults to 12
int32_t uma::bson::ObjectId::getSize ( ) const
inlinevirtual

Return the size in bytes of the BSON representation of this OID value.

Returns
Return 12 as per specifications

Implements uma::bson::Value.

const Poco::Timestamp uma::bson::ObjectId::getTime ( ) const
inline

Return the timestamp value encoded in this OID.

Returns
The timestamp value.
Value::Type uma::bson::ObjectId::getType ( ) const
inlinevirtual

Returns the type for this instance as listed in the BSON specifications.

Returns
Returns uma::bson::Value::Type::OID

Implements uma::bson::Value.

void uma::bson::ObjectId::setBytes ( const char(&)  bytes[12])
inline

Replaces the bytes represented in this instance with the specified byte array.

Since
Version 2.3
Parameters
The12 byte char array to assign to this object id.
const std::string uma::bson::ObjectId::toString ( ) const
inline

Return a 24 char hex representation of the OID.

Returns
The hex representation

The documentation for this class was generated from the following file: