MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
view_or_value.hpp
Go to the documentation of this file.
1// Copyright 2009-present MongoDB, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <string>
18
19#include <bsoncxx/string/view_or_value-fwd.hpp> // IWYU pragma: export
20
22#include <bsoncxx/view_or_value.hpp> // IWYU pragma: export
23
25
26namespace bsoncxx {
27namespace v_noabi {
28namespace string {
29
41class view_or_value : public v_noabi::view_or_value<stdx::string_view, std::string> {
42 public:
47
51 view_or_value() = default;
52
61
72 view_or_value(std::string const& str)
74
86
94 BSONCXX_ABI_EXPORT_CDECL(char const*) data() const;
95};
96
101
103inline bool operator==(view_or_value const& lhs, char const* rhs) {
104 return lhs.view() == stdx::string_view(rhs);
105}
106
108inline bool operator!=(view_or_value const& lhs, char const* rhs) {
109 return !(lhs == rhs);
110}
111
113inline bool operator==(char const* lhs, view_or_value const& rhs) {
114 return rhs == lhs;
115}
116
118inline bool operator!=(char const* lhs, view_or_value const& rhs) {
119 return !(rhs == lhs);
120}
121
124
125} // namespace string
126} // namespace v_noabi
127} // namespace bsoncxx
128
129namespace bsoncxx {
130namespace string {
131
132using v_noabi::string::operator==;
133using v_noabi::string::operator!=;
134
135} // namespace string
136} // namespace bsoncxx
137
139
#define BSONCXX_ABI_EXPORT_CDECL(...)
Equivalent to BSONCXX_ABI_EXPORT with BSONCXX_ABI_CDECL.
Definition export.hpp:52
The bsoncxx v_noabi macro guard postlude header.
The bsoncxx v_noabi macro guard prelude header.
view_or_value()=default
Default constructor, equivalent to using an empty string.
A polyfill for std::string_view.
Definition string_view.hpp:412
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 ...
Definition view_or_value.hpp:72
view_or_value()=default
Default constructor, equivalent to using an empty string.
bool operator!=(char const *lhs, view_or_value const &rhs)
Comparison operators for comparing string::view_or_value directly with char const*.
Definition view_or_value.hpp:118
bool operator!=(view_or_value const &lhs, char const *rhs)
Comparison operators for comparing string::view_or_value directly with char const*.
Definition view_or_value.hpp:108
view_or_value(char const *str)
Construct a string::view_or_value using a null-terminated const char *. The resulting view_or_value w...
Definition view_or_value.hpp:60
char const * data() const
Call data() on this view_or_value's string_view. This method is not guaranteed to return a null-termi...
bool operator==(char const *lhs, view_or_value const &rhs)
Comparison operators for comparing string::view_or_value directly with char const*.
Definition view_or_value.hpp:113
view_or_value terminated() const
Return a string_view_or_value that is guaranteed to hold a null-terminated string....
bool operator==(view_or_value const &lhs, char const *rhs)
Comparison operators for comparing string::view_or_value directly with char const*.
Definition view_or_value.hpp:103
A view-or-value variant type.
Definition view_or_value.hpp:32
operator stdx::string_view() const
Definition view_or_value.hpp:126
Declares C++17 standard library polyfills.
Declares entities related to handling string types.
Declares entities whose ABI stability is NOT guaranteed.
The top-level namespace within which all bsoncxx library entities are declared.
Declares bsoncxx::v_noabi::string::view_or_value.
Provides std::string_view-related polyfills for library API usage.
Provides bsoncxx::v_noabi::view_or_value.