userver: formats::bson::Document Class Reference
Loading...
Searching...
No Matches
formats::bson::Document Class Reference

#include <userver/formats/bson/document.hpp>

Detailed Description

BSON document.

Definition at line 14 of file document.hpp.

+ Inheritance diagram for formats::bson::Document:
+ Collaboration diagram for formats::bson::Document:

Public Member Functions

 Document ()
 Constructs an empty document Equivalent to MakeDoc()
 
 Document (const Value &value)
 Unwraps document from Value.
 
- Public Member Functions inherited from formats::bson::Value
 Value ()
 Constructs a null value.
 
 Value (const Value &)=default
 
 Value (Value &&) noexcept=default
 
Valueoperator= (const Value &) &=default
 
Valueoperator= (Value &&) &noexcept=default
 
template<class T >
Valueoperator= (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 >
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>
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
 

Additional Inherited Members

- Public Types inherited from formats::bson::Value
enum class  DuplicateFieldsPolicy {
  kForbid ,
  kUseFirst ,
  kUseLast
}
 Selectors for duplicate fields parsing behavior. More...
 
using const_iterator
 
using const_reverse_iterator
 
using Exception = formats::bson::BsonException
 
using ParseException = formats::bson::ParseException
 
using ExceptionWithPath = formats::bson::ExceptionWithPath
 
using Builder = ValueBuilder
 
- Protected Member Functions inherited from formats::bson::Value
const impl::BsonHolder & GetBson () const
 

Constructor & Destructor Documentation

◆ Document()

formats::bson::Document::Document ( const Value & value)

Unwraps document from Value.

Exceptions
TypeMismatchExceptionif value is not a document

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