MongoDB C++ Driver 4.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bsoncxx::string::view_or_value Class Reference

#include <bsoncxx/v_noabi/bsoncxx/string/view_or_value.hpp>

Description

A view-or-value variant type for strings.

Derived From

This class adds several string-specific methods to the bsoncxx::v_noabi::view_or_value template:

  • a constructor overload for char const*
  • a constructor overload for std::string by l-value reference
  • a safe c_str() operation to return null-terminated c-style strings.

Public Member Functions

 view_or_value ()=default
 Default constructor, equivalent to using an empty string.
 
 view_or_value (char const *str)
 Construct a string::view_or_value using a null-terminated const char *. The resulting view_or_value will keep a string_view of 'str', so it is important that the passed-in string outlive this object.
 
 view_or_value (std::string const &str)
 Allow construction with an l-value reference to a std::string. The resulting view_or_value will keep a string_view of 'str', so it is important that the passed-in string outlive this object.
 
char const * data () const
 Call data() on this view_or_value's string_view. This method is not guaranteed to return a null-terminated string unless it is used in combination with terminated().
 
view_or_value terminated () const
 Return a string_view_or_value that is guaranteed to hold a null-terminated string. The lifetime of the returned object must be a subset of this object's lifetime, because the new view_or_value might hold a view into this one.
 
- Public Member Functions inherited from bsoncxx::v_noabi::view_or_value< stdx::string_view, std::string >
 view_or_value ()=default
 Default-constructs a view_or_value. This is equivalent to constructing a view_or_value with a default-constructed View.
 
 view_or_value ()=default
 Default-constructs a view_or_value. This is equivalent to constructing a view_or_value with a default-constructed View.
 
 view_or_value ()=default
 Default-constructs a view_or_value. This is equivalent to constructing a view_or_value with a default-constructed View.
 
 view_or_value (std::string &&value)
 Constructs a view_or_value from a Value type. This object owns the passed-in Value.
 
 view_or_value (std::string &&value)
 Constructs a view_or_value from a Value type. This object owns the passed-in Value.
 
 view_or_value (std::string &&value)
 Constructs a view_or_value from a Value type. This object owns the passed-in Value.
 
 view_or_value (stdx::string_view view)
 Construct a view_or_value from a View. When constructed with a View, this object is non-owning. The Value underneath the given View must outlive this object.
 
 view_or_value (stdx::string_view view)
 Construct a view_or_value from a View. When constructed with a View, this object is non-owning. The Value underneath the given View must outlive this object.
 
 view_or_value (stdx::string_view view)
 Construct a view_or_value from a View. When constructed with a View, this object is non-owning. The Value underneath the given View must outlive this object.
 
 view_or_value (view_or_value &&other) noexcept
 Construct a view_or_value from a moved-in view_or_value.
 
 view_or_value (view_or_value &&other) noexcept
 Construct a view_or_value from a moved-in view_or_value.
 
 view_or_value (view_or_value &&other) noexcept
 Construct a view_or_value from a moved-in view_or_value.
 
 view_or_value (view_or_value const &other)
 Construct a view_or_value from a copied view_or_value.
 
 view_or_value (view_or_value const &other)
 Construct a view_or_value from a copied view_or_value.
 
 view_or_value (view_or_value const &other)
 Construct a view_or_value from a copied view_or_value.
 
 ~view_or_value ()=default
 View must be constructible from an instance of class Value.
 
 ~view_or_value ()=default
 View must be constructible from an instance of class Value.
 
 ~view_or_value ()=default
 View must be constructible from an instance of class Value.
 
bool is_owning () const noexcept
 Return whether or not this view_or_value owns an underlying Value.
 
bool is_owning () const noexcept
 Return whether or not this view_or_value owns an underlying Value.
 
bool is_owning () const noexcept
 Return whether or not this view_or_value owns an underlying Value.
 
 operator stdx::string_view () const
 This type may be used as a View.
 
 operator stdx::string_view () const
 This type may be used as a View.
 
 operator stdx::string_view () const
 This type may be used as a View.
 
view_or_valueoperator= (view_or_value &&other) noexcept
 Assign to this view_or_value from a moved-in view_or_value.
 
view_or_valueoperator= (view_or_value &&other) noexcept
 Assign to this view_or_value from a moved-in view_or_value.
 
view_or_valueoperator= (view_or_value &&other) noexcept
 Assign to this view_or_value from a moved-in view_or_value.
 
view_or_valueoperator= (view_or_value const &other)
 Assign to this view_or_value from a copied view_or_value.
 
view_or_valueoperator= (view_or_value const &other)
 Assign to this view_or_value from a copied view_or_value.
 
view_or_valueoperator= (view_or_value const &other)
 Assign to this view_or_value from a copied view_or_value.
 
stdx::string_view const & view () const
 Get a View for the type.
 
stdx::string_view const & view () const
 Get a View for the type.
 
stdx::string_view const & view () const
 Get a View for the type.
 

Related Symbols

(Note that these are not member symbols.)

bool operator== (view_or_value const &lhs, char const *rhs)
 Comparison operators for comparing string::view_or_value directly with char const*.
 
bool operator== (char const *lhs, view_or_value const &rhs)
 Comparison operators for comparing string::view_or_value directly with char const*.
 
bool operator!= (view_or_value const &lhs, char const *rhs)
 Comparison operators for comparing string::view_or_value directly with char const*.
 
bool operator!= (char const *lhs, view_or_value const &rhs)
 Comparison operators for comparing string::view_or_value directly with char const*.
 

Constructor & Destructor Documentation

◆ view_or_value() [1/3]

bsoncxx::v_noabi::string::view_or_value::view_or_value ( )
default

Default constructor, equivalent to using an empty string.

◆ view_or_value() [2/3]

bsoncxx::v_noabi::string::view_or_value::view_or_value ( char const * str)
inline

Construct a string::view_or_value using a null-terminated const char *. The resulting view_or_value will keep a string_view of 'str', so it is important that the passed-in string outlive this object.

Parameters
strA null-terminated string

◆ view_or_value() [3/3]

bsoncxx::v_noabi::string::view_or_value::view_or_value ( std::string const & str)
inline

Allow construction with an l-value reference to a std::string. The resulting view_or_value will keep a string_view of 'str', so it is important that the passed-in string outlive this object.

Construction calls passing a std::string by r-value reference will use the constructor defined in the parent view_or_value class.

Parameters
strA std::string l-value reference.

Member Function Documentation

◆ data()

char const * bsoncxx::v_noabi::string::view_or_value::data ( ) const

Call data() on this view_or_value's string_view. This method is not guaranteed to return a null-terminated string unless it is used in combination with terminated().

Returns
A char const* of this string.

◆ terminated()

view_or_value bsoncxx::v_noabi::string::view_or_value::terminated ( ) const

Return a string_view_or_value that is guaranteed to hold a null-terminated string. The lifetime of the returned object must be a subset of this object's lifetime, because the new view_or_value might hold a view into this one.

It is recommended that this method be used before calling .data() on a view_or_value, as that method may return a non-null-terminated string.

Returns
A new view_or_value object.

Friends And Related Symbol Documentation

◆ operator!=() [1/2]

bool operator!= ( char const * lhs,
view_or_value const & rhs )
related

Comparison operators for comparing string::view_or_value directly with char const*.

◆ operator!=() [2/2]

bool operator!= ( view_or_value const & lhs,
char const * rhs )
related

Comparison operators for comparing string::view_or_value directly with char const*.

◆ operator==() [1/2]

bool operator== ( char const * lhs,
view_or_value const & rhs )
related

Comparison operators for comparing string::view_or_value directly with char const*.

◆ operator==() [2/2]

bool operator== ( view_or_value const & lhs,
char const * rhs )
related

Comparison operators for comparing string::view_or_value directly with char const*.


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