View on GitHub
jbson
C++11/1y BSON library
Public Types | Public Member Functions | Friends | List of all members
jbson::basic_document< Container, ElementContainer > Class Template Reference

BSON document. More...

#include <document.hpp>

+ Inheritance diagram for jbson::basic_document< Container, ElementContainer >:

Public Types

using const_iterator = typename detail::document_iter< const element_type, typename container_type::const_iterator >
 Forward iterator for traversal of elements. More...
 
using container_type = std::decay_t< Container >
 Type of underlying storage container/range.
 
using element_type = basic_element< ElementContainer >
 Type of constituent elements.
 
using iterator = const_iterator
 Forward iterator for traversal of elements. More...
 
using value_type = element_type
 Type of constituent elements. Enables usage in STL/Boost algorithms.
 

Public Member Functions

 basic_document ()
 Default constructor. More...
 
template<typename SomeType >
 basic_document (SomeType &&c, std::enable_if_t< std::is_same< container_type, std::decay_t< SomeType >>::value > *=nullptr)
 Constructs a document with an existing container of data. More...
 
template<typename OtherContainer >
 basic_document (const basic_document< OtherContainer > &other, std::enable_if_t< std::is_constructible< container_type, OtherContainer >::value > *=nullptr) noexcept(std::is_nothrow_constructible< container_type, OtherContainer >::value)
 Copy constructor from a basic_document with a different container_type. More...
 
template<typename OtherContainer >
 basic_document (const basic_document< OtherContainer > &other, std::enable_if_t<!std::is_constructible< container_type, OtherContainer >::value &&detail::container_has_push_back< container_type >::value &&std::is_constructible< container_type, typename OtherContainer::const_iterator, typename OtherContainer::const_iterator >::value > *=nullptr)
 Copy constructor from a basic_document with a different container_type. More...
 
template<size_t N>
 basic_document (std::array< char, N >, std::enable_if_t<(N< 5)> *=nullptr)=delete
 Disallows construction from arrays of invalid document size.
 
template<typename ForwardRange >
 basic_document (ForwardRange &&rng, std::enable_if_t< detail::is_range_of_same_value< ForwardRange, char >::value > *=nullptr, std::enable_if_t< std::conditional_t< detail::is_iterator_range< container_type >::value, detail::is_range_of_iterator< ForwardRange, boost::mpl::bind< detail::quote< std::is_constructible >, typename container_type::iterator, boost::mpl::_1 >>, std::true_type >::value > *=nullptr, std::enable_if_t<!std::is_same< container_type, std::decay_t< ForwardRange >>::value &&detail::is_range_of_iterator< ForwardRange, boost::mpl::bind< detail::quote< std::is_constructible >, container_type, boost::mpl::_1, boost::mpl::_1 >>::value > *=nullptr)
 Constructs a document from a range of char. More...
 
template<typename ForwardRange >
 basic_document (ForwardRange &&rng, std::enable_if_t< boost::mpl::and_< detail::is_range_of_value< ForwardRange, boost::mpl::quote1< detail::is_element >>, detail::container_has_push_back< container_type >, boost::mpl::not_< detail::is_document< std::decay_t< ForwardRange >>>>::type::value > *=nullptr)
 Constructs a document from a range of basic_element. More...
 
template<typename ForwardIterator >
 basic_document (ForwardIterator first, ForwardIterator last, std::enable_if_t< std::is_constructible< basic_document, boost::iterator_range< ForwardIterator >>::value > *=nullptr)
 Constructs a document from two iterators. Forwards to the range-based constructors.
 
const_iterator begin () const
 Returns an iterator to the first element of the container. More...
 
const container_typedata () const &noexcept
 
container_type data () const &&noexcept(std::is_nothrow_copy_constructible< container_type >::value)
 
container_type && data ()&&noexcept(std::is_nothrow_move_constructible< container_type >::value)
 
template<typename... Args>
const_iterator emplace (const const_iterator &it, Args &&...args)
 Inserts an element in-place directly before another. More...
 
const_iterator end () const noexcept
 
const_iterator erase (const const_iterator &it)
 Removes the element at it. More...
 
const_iterator find (boost::string_ref elem_name) const
 Find an element with the specified name. More...
 
template<typename EContainer >
const_iterator insert (const const_iterator &it, const basic_element< EContainer > &el)
 Inserts an element directly before another. More...
 
template<typename EContainer >
 operator basic_document_set< EContainer > () const
 basic_document_set conversion. Allows explicit conversion to document_set and other instantiations.
 
template<typename C , typename EC >
bool operator== (const basic_document< C, EC > &other) const
 Determines equality with another basic_document.
 
int32_t size () const noexcept
 Returns data's size in bytes. More...
 
void swap (basic_document &other) noexcept
 Swaps contents with another basic_document.
 
bool valid (const validity_level lvl=validity_level::bson_size, const bool recurse=true) const
 Validates document/array according to a validity_level. More...
 

Friends

template<typename , typename >
class basic_document
 
template<typename , typename >
class basic_array
 

Detailed Description

template<class Container, class ElementContainer>
class jbson::basic_document< Container, ElementContainer >

BSON document.

basic_document represents a range of BSON elements

Template Parameters
ContainerType of underlying storage container/range. Must be range of char.
ElementContainerType of underlying storage of constituent elements.

Definition at line 191 of file document.hpp.

Member Typedef Documentation

template<class Container, class ElementContainer>
using jbson::basic_document< Container, ElementContainer >::const_iterator = typename detail::document_iter<const element_type, typename container_type::const_iterator>

Forward iterator for traversal of elements.

See also
detail::document_iter

Definition at line 200 of file document.hpp.

template<class Container, class ElementContainer>
using jbson::basic_document< Container, ElementContainer >::iterator = const_iterator

Forward iterator for traversal of elements.

See also
detail::document_iter

Definition at line 202 of file document.hpp.

Constructor & Destructor Documentation

template<class Container, class ElementContainer>
jbson::basic_document< Container, ElementContainer >::basic_document ( )
inline

Default constructor.

Note
When container_type is able to own data, this results in a valid, empty document.
Otherwise (e.g. is boost::iterator_range<>), results in an invalid document.

Definition at line 211 of file document.hpp.

template<class Container, class ElementContainer>
template<typename SomeType >
jbson::basic_document< Container, ElementContainer >::basic_document ( SomeType &&  c,
std::enable_if_t< std::is_same< container_type, std::decay_t< SomeType >>::value > *  = nullptr 
)
inlineexplicit

Constructs a document with an existing container of data.

Note
Only available when SomeType decays to container_type.
Template Parameters
SomeTypeType which decays to container_type.
Parameters
cAccepts all forms of container_type.

Forwards c to container_type initialiser.

Exceptions
invalid_document_sizeWhen the size of c is insufficient. When the size of c differs from the size specified by c's data.

Definition at line 226 of file document.hpp.

template<class Container, class ElementContainer>
template<typename OtherContainer >
jbson::basic_document< Container, ElementContainer >::basic_document ( const basic_document< OtherContainer > &  other,
std::enable_if_t< std::is_constructible< container_type, OtherContainer >::value > *  = nullptr 
)
inlinenoexcept

Copy constructor from a basic_document with a different container_type.

Template Parameters
OtherContainerbasic_document container from which container_type can be constructed.

Definition at line 245 of file document.hpp.

template<class Container, class ElementContainer>
template<typename OtherContainer >
jbson::basic_document< Container, ElementContainer >::basic_document ( const basic_document< OtherContainer > &  other,
std::enable_if_t<!std::is_constructible< container_type, OtherContainer >::value &&detail::container_has_push_back< container_type >::value &&std::is_constructible< container_type, typename OtherContainer::const_iterator, typename OtherContainer::const_iterator >::value > *  = nullptr 
)
inline

Copy constructor from a basic_document with a different container_type.

Template Parameters
OtherContainerbasic_document container from whose iterator_type container_type can be constructed.

Definition at line 256 of file document.hpp.

template<class Container, class ElementContainer>
template<typename ForwardRange >
jbson::basic_document< Container, ElementContainer >::basic_document ( ForwardRange &&  rng,
std::enable_if_t< detail::is_range_of_same_value< ForwardRange, char >::value > *  = nullptr,
std::enable_if_t< std::conditional_t< detail::is_iterator_range< container_type >::value, detail::is_range_of_iterator< ForwardRange, boost::mpl::bind< detail::quote< std::is_constructible >, typename container_type::iterator, boost::mpl::_1 >>, std::true_type >::value > *  = nullptr,
std::enable_if_t<!std::is_same< container_type, std::decay_t< ForwardRange >>::value &&detail::is_range_of_iterator< ForwardRange, boost::mpl::bind< detail::quote< std::is_constructible >, container_type, boost::mpl::_1, boost::mpl::_1 >>::value > *  = nullptr 
)
inlineexplicit

Constructs a document from a range of char.

Template Parameters
ForwardRangeRange of char (not container_type)

Definition at line 272 of file document.hpp.

template<class Container, class ElementContainer>
template<typename ForwardRange >
jbson::basic_document< Container, ElementContainer >::basic_document ( ForwardRange &&  rng,
std::enable_if_t< boost::mpl::and_< detail::is_range_of_value< ForwardRange, boost::mpl::quote1< detail::is_element >>, detail::container_has_push_back< container_type >, boost::mpl::not_< detail::is_document< std::decay_t< ForwardRange >>>>::type::value > *  = nullptr 
)
inlineexplicit

Constructs a document from a range of basic_element.

Other basic_documents are excluded. Only enabled when container_type is an actual container as it needs to be able to own data.

Template Parameters
ForwardRangeRange whose value_type is basic_element<...>.

Definition at line 295 of file document.hpp.

Member Function Documentation

template<class Container, class ElementContainer>
const_iterator jbson::basic_document< Container, ElementContainer >::begin ( ) const
inline

Returns an iterator to the first element of the container.

Returns
const_iterator representing the first element in the document, or end() of sequence of document is empty.
Exceptions
invalid_document_sizeWhen container size is smaller than necessary for iteration.

Definition at line 331 of file document.hpp.

template<class Container, class ElementContainer>
const container_type& jbson::basic_document< Container, ElementContainer >::data ( ) const
inlinenoexcept

Returns reference to BSON data.

Note
const lvalue overload

Definition at line 446 of file document.hpp.

template<class Container, class ElementContainer>
container_type jbson::basic_document< Container, ElementContainer >::data ( ) const
inlinenoexcept

Returns copy of BSON data.

Note
const rvalue overload

Definition at line 450 of file document.hpp.

template<class Container, class ElementContainer>
container_type&& jbson::basic_document< Container, ElementContainer >::data ( )
inlinenoexcept

Returns rvalue reference to BSON data.

Note
rvalue overload

Definition at line 454 of file document.hpp.

template<class Container, class ElementContainer>
template<typename... Args>
const_iterator jbson::basic_document< Container, ElementContainer >::emplace ( const const_iterator it,
Args &&...  args 
)
inline

Inserts an element in-place directly before another.

General advice to follow: All iterators and referenced basic_elements are invalidated. Actaul behaviour depends on container_type::insert(pos, elem_data.begin(), elem_data.end()).

Parameters
itIterator to the location before which the element will be inserted. Can be end().
argsArguments to construct an element in-place.
Warning
Strong exception guarantee.
Returns
const_iterator to the inserted element.

Definition at line 419 of file document.hpp.

template<class Container, class ElementContainer>
const_iterator jbson::basic_document< Container, ElementContainer >::end ( ) const
inlinenoexcept
Returns
const_iterator representing the end of the document.
Note
Incrementing is a no-op.
Attempting to dereference results in undefined behaviour.

Definition at line 342 of file document.hpp.

template<class Container, class ElementContainer>
const_iterator jbson::basic_document< Container, ElementContainer >::erase ( const const_iterator it)
inline

Removes the element at it.

General advice to follow: All iterators and referenced basic_elements are invalidated. Actaul behaviour depends on container_type::erase(elem_data.begin(), elem_data.end()).

Parameters
itIterator to the element to remove. Cannot be end().
Returns
const_iterator following the last removed element.

Asserts in debug mode that it != end()

Definition at line 366 of file document.hpp.

template<class Container, class ElementContainer>
const_iterator jbson::basic_document< Container, ElementContainer >::find ( boost::string_ref  elem_name) const
inline

Find an element with the specified name.

Parameters
elem_nameName of required element.
Returns
const_iterator to item with specified name, or end().

Definition at line 352 of file document.hpp.

template<class Container, class ElementContainer>
template<typename EContainer >
const_iterator jbson::basic_document< Container, ElementContainer >::insert ( const const_iterator it,
const basic_element< EContainer > &  el 
)
inline

Inserts an element directly before another.

General advice to follow: All iterators and referenced basic_elements are invalidated. Actaul behaviour depends on container_type::insert(pos, elem_data.begin(), elem_data.end()).

Parameters
itIterator to the location before which the element will be inserted. Can be end().
elElement to be inserted.
Warning
Strong exception guarantee.
Returns
const_iterator to the inserted element.

Definition at line 392 of file document.hpp.

template<class Container, class ElementContainer>
int32_t jbson::basic_document< Container, ElementContainer >::size ( ) const
inlinenoexcept

Returns data's size in bytes.

Note
To determine the number of elements contained, use either of:
boost::distance(doc);
std::distance(doc.begin(), doc.end());

Definition at line 442 of file document.hpp.

template<class Container, class ElementContainer>
bool jbson::basic_document< Container, ElementContainer >::valid ( const validity_level  lvl = validity_level::bson_size,
const bool  recurse = true 
) const
inline

Validates document/array according to a validity_level.

Parameters
lvlLevel of validity to check for. Defaults to validity_level::bson_size.
recurseboolean controlling whether or not to recurse to child documents/arrays. Defaults to true.
Returns
boolean indicating validity
See also
validity_level

Definition at line 467 of file document.hpp.


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