Non-mutable BSON value representation.
Class provides non mutable access BSON value. For modification and construction of new BSON values use formats::bson::ValueBuilder.
Example usage:
const auto key1 = bson[
"key1"].
As<
int>();
ASSERT_EQ(key1, 1);
const auto key3 = bson[
"key2"][
"key3"].
As<std::string>();
ASSERT_EQ(key3, "val");
- See also
- Formats (JSON, YAML, BSON, ...)
- Examples
- samples/mongo_service/mongo_service.cpp.
Definition at line 40 of file value.hpp.
|
| Value () |
| Constructs a null value.
|
|
| Value (const Value &)=default |
|
| Value (Value &&) noexcept=default |
|
Value & | operator= (const Value &) &=default |
|
Value & | operator= (Value &&) &noexcept=default |
|
template<class T > |
Value & | operator= (T &&) && |
|
Value | operator[] (const std::string &name) const |
| Retrieves document field by name.
|
|
Value | operator[] (uint32_t index) const |
| Retrieves array element by index.
|
|
bool | HasMember (const std::string &name) const |
| Checks whether the document has a field.
|
|
const_iterator | begin () const |
| Returns an iterator to the first array element/document field.
|
|
const_iterator | end () const |
| Returns an iterator following the last array element/document field.
|
|
const_reverse_iterator | rbegin () const |
| Returns a reversed iterator to the last array element.
|
|
const_reverse_iterator | rend () const |
| Returns a reversed iterator following the first array element.
|
|
bool | IsEmpty () const |
| Returns whether the document/array is empty.
|
|
uint32_t | GetSize () const |
| Returns the number of elements in a document/array.
|
|
std::string | GetPath () const |
| Returns value path in a document.
|
|
bool | operator== (const Value &) const |
|
bool | operator!= (const Value &) const |
|
bool | IsMissing () const |
| Checks whether the selected element exists.
|
|
template<typename T > |
auto | As () const |
|
template<typename T , typename First , typename... Rest> |
auto | As (First &&default_arg, Rest &&... more_default_args) const |
|
template<typename T > |
auto | As (DefaultConstructed) const |
| Returns value of *this converted to T or T() if this->IsMissing().
|
|
template<typename T > |
T | ConvertTo () const |
| Extracts the specified type with relaxed type checks. For example, true may be converted to 1.0.
|
|
template<typename T , typename First , typename... Rest> |
T | ConvertTo (First &&default_arg, Rest &&... more_default_args) const |
|
void | SetDuplicateFieldsPolicy (DuplicateFieldsPolicy) |
| Changes parsing behavior when duplicate fields are encountered. Should not be used normally.
|
|
void | CheckNotMissing () const |
| Throws a MemberMissingException if the selected element does not exist.
|
|
void | CheckArrayOrNull () const |
| Throws a TypeMismatchException if the selected element is not an array or null.
|
|
void | CheckDocumentOrNull () const |
| Throws a TypeMismatchException if the selected element is not a document or null.
|
|
|
bool | IsArray () const |
|
bool | IsDocument () const |
|
bool | IsNull () const |
|
bool | IsBool () const |
|
bool | IsInt32 () const |
|
bool | IsInt64 () const |
|
bool | IsDouble () const |
|
bool | IsString () const |
|
bool | IsDateTime () const |
|
bool | IsOid () const |
|
bool | IsBinary () const |
|
bool | IsDecimal128 () const |
|
bool | IsMinKey () const |
|
bool | IsMaxKey () const |
|
bool | IsTimestamp () const |
|
bool | IsObject () const |
|
template<typename T , typename First , typename... Rest>
auto formats::bson::Value::As |
( |
First && | default_arg, |
|
|
Rest &&... | more_default_args ) const |
|
inline |
Extracts the specified type with strict type checks, or constructs the default value when the field is not present
Definition at line 180 of file value.hpp.
template<typename T , typename First , typename... Rest>
T formats::bson::Value::ConvertTo |
( |
First && | default_arg, |
|
|
Rest &&... | more_default_args ) const |
|
inline |
Extracts the specified type with strict type checks, or constructs the default value when the field is not present
Definition at line 219 of file value.hpp.