MongoDB C++ Driver mongocxx-3.11.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
20
23
25
26namespace bsoncxx {
27namespace v_noabi {
28namespace string {
29
41class view_or_value : public bsoncxx::v_noabi::view_or_value<stdx::string_view, std::string> {
42 public:
47
52
60 view_or_value(const char* str)
61 : bsoncxx::v_noabi::view_or_value<stdx::string_view, std::string>(stdx::string_view(str)) {}
62
73 view_or_value(const std::string& str)
74 : bsoncxx::v_noabi::view_or_value<stdx::string_view, std::string>(stdx::string_view(str)) {}
75
87
95 BSONCXX_ABI_EXPORT_CDECL(const char*) data() const;
96};
97
102
104inline bool operator==(const view_or_value& lhs, const char* rhs) {
105 return lhs.view() == stdx::string_view(rhs);
106}
107
109inline bool operator!=(const view_or_value& lhs, const char* rhs) {
110 return !(lhs == rhs);
111}
112
114inline bool operator==(const char* lhs, const view_or_value& rhs) {
115 return rhs == lhs;
116}
117
119inline bool operator!=(const char* lhs, const view_or_value& rhs) {
120 return !(rhs == lhs);
121}
122
125
126} // namespace string
127} // namespace v_noabi
128} // namespace bsoncxx
129
130namespace bsoncxx {
131namespace string {
132
133using ::bsoncxx::v_noabi::string::operator==;
134using ::bsoncxx::v_noabi::string::operator!=;
135
136} // namespace string
137} // namespace bsoncxx
138
140
145
146#if defined(BSONCXX_PRIVATE_DOXYGEN_PREPROCESSOR)
147
148namespace bsoncxx {
149namespace string {
150
152inline bool operator==(const v_noabi::string::view_or_value& lhs, const char* rhs);
153
155inline bool operator!=(const v_noabi::string::view_or_value& lhs, const char* rhs);
156
158inline bool operator==(const char* lhs, const v_noabi::string::view_or_value& rhs);
159
161inline bool operator!=(const char* lhs, const v_noabi::string::view_or_value& rhs);
162
163} // namespace string
164} // namespace bsoncxx
165
166#endif // defined(BSONCXX_PRIVATE_DOXYGEN_PREPROCESSOR)
The bsoncxx macro guard postlude header.
The bsoncxx macro guard prelude header.
A polyfill for std::string_view.
Definition string_view.hpp:503
Class representing a view-or-value variant type for strings.
Definition view_or_value.hpp:41
view_or_value()=default
Default constructor, equivalent to using an empty string.
const char * data() const
Call data() on this view_or_value's string_view. This method is not guaranteed to return a null-termi...
bool operator!=(const char *lhs, const view_or_value &rhs)
Comparison operators for comparing string::view_or_value directly with const char*.
Definition view_or_value.hpp:119
view_or_value(const std::string &str)
Allow construction with an l-value reference to a std::string. The resulting view_or_value will keep ...
Definition view_or_value.hpp:73
bool operator==(const char *lhs, const view_or_value &rhs)
Comparison operators for comparing string::view_or_value directly with const char*.
Definition view_or_value.hpp:114
bool operator==(const view_or_value &lhs, const char *rhs)
Comparison operators for comparing string::view_or_value directly with const char*.
Definition view_or_value.hpp:104
bool operator!=(const view_or_value &lhs, const char *rhs)
Comparison operators for comparing string::view_or_value directly with const char*.
Definition view_or_value.hpp:109
view_or_value terminated() const
Return a string_view_or_value that is guaranteed to hold a null-terminated string....
Class representing a view-or-value variant type.
Definition view_or_value.hpp:32
operator stdx::string_view() const
Definition view_or_value.hpp:129
const View & view() const
Get a View for the type.
Definition view_or_value.hpp:138
#define BSONCXX_ABI_EXPORT_CDECL(...)
Equivalent to BSONCXX_ABI_EXPORT with BSONCXX_ABI_CDECL.
Definition fwd.hpp:225
bool operator!=(const v_noabi::string::view_or_value &lhs, const char *rhs)
bsoncxx::v_noabi::string::operator!=(const v_noabi::string::view_or_value& lhs, const char* rhs)
bool operator==(const v_noabi::string::view_or_value &lhs, const char *rhs)
bsoncxx::v_noabi::string::operator==(const v_noabi::string::view_or_value& lhs, const char* rhs)
The top-level namespace within which all bsoncxx library entities are declared.
The top-level namespace reserved for the C++ standard library.
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.