Skip to content

Commit 3c3f8f2

Browse files
CXX-739 Apply string::view_or_value elsewhere in codebase
1 parent 60054f3 commit 3c3f8f2

File tree

9 files changed

+45
-42
lines changed

9 files changed

+45
-42
lines changed

src/bsoncxx/oid.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ oid::oid(init_tag_t) : _is_valid(true) {
3434
std::memcpy(_bytes, oid.bytes, sizeof(oid.bytes));
3535
}
3636

37-
oid::oid(stdx::string_view str) : _is_valid(bson_oid_is_valid(str.data(), str.length())) {
37+
oid::oid(const string::view_or_value& str)
38+
: _is_valid(bson_oid_is_valid(str.data(), str.view().length())) {
3839
if (_is_valid) {
3940
bson_oid_t oid;
40-
bson_oid_init_from_string(&oid, str.data());
41+
bson_oid_init_from_string(&oid, str.terminated().data());
4142
memcpy(_bytes, oid.bytes, sizeof(_bytes));
4243
}
4344
}

src/bsoncxx/oid.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <ctime>
2121
#include <string>
2222

23-
#include <bsoncxx/stdx/string_view.hpp>
23+
#include <bsoncxx/string/view_or_value.hpp>
2424

2525
namespace bsoncxx {
2626
BSONCXX_INLINE_NAMESPACE_BEGIN
@@ -64,12 +64,12 @@ class BSONCXX_API oid {
6464
explicit oid(const char* bytes, std::size_t len);
6565

6666
///
67-
/// Constructs and oid an initializes it from the provided hex string.
67+
/// Constructs an oid and initializes it from the provided hex string.
6868
///
6969
/// @param str
70-
/// A string_view of a hexadecimal representation of a valid ObjectId.
70+
/// A string of a hexadecimal representation of a valid ObjectId.
7171
///
72-
explicit oid(stdx::string_view str);
72+
explicit oid(const string::view_or_value& str);
7373

7474
///
7575
/// Converts this oid to a hexadecimal string.

src/mongocxx/collection.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <cstdint>
1919
#include <limits>
2020
#include <tuple>
21-
#include <unordered_set>
2221
#include <utility>
2322

2423
#include <bsoncxx/builder/stream/document.hpp>

src/mongocxx/hint.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ MONGOCXX_INLINE_NAMESPACE_BEGIN
2424
hint::hint(bsoncxx::document::view_or_value index) : _index_doc(std::move(index)) {
2525
}
2626

27-
hint::hint(stdx::string_view index) : _index_string(std::move(index)) {
27+
hint::hint(bsoncxx::string::view_or_value index) : _index_string(std::move(index)) {
2828
}
2929

3030
bsoncxx::document::value hint::to_document() const {
@@ -42,7 +42,7 @@ bsoncxx::document::value hint::to_document() const {
4242
}
4343

4444
bool operator==(const hint& index_hint, std::string index) {
45-
return index_hint._index_string && index_hint._index_string->to_string() == index;
45+
return ((index_hint._index_string) && (*(index_hint._index_string) == index));
4646
}
4747

4848
bool operator==(std::string index, const hint& index_hint) {

src/mongocxx/hint.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <bsoncxx/builder/stream/helpers.hpp>
2323
#include <bsoncxx/builder/stream/key_context.hpp>
2424
#include <bsoncxx/stdx/optional.hpp>
25+
#include <bsoncxx/string/view_or_value.hpp>
2526
#include <mongocxx/stdx.hpp>
2627

2728
namespace mongocxx {
@@ -49,7 +50,7 @@ class MONGOCXX_API hint {
4950
/// @param index
5051
/// String representing the name of the index to be used.
5152
///
52-
explicit hint(stdx::string_view index);
53+
explicit hint(bsoncxx::string::view_or_value index);
5354

5455
friend bool operator==(const hint& index_hint, std::string index);
5556
friend bool operator==(const hint& index_hint, bsoncxx::document::view index);
@@ -64,7 +65,7 @@ class MONGOCXX_API hint {
6465

6566
private:
6667
stdx::optional<bsoncxx::document::view_or_value> _index_doc;
67-
stdx::optional<stdx::string_view> _index_string;
68+
stdx::optional<bsoncxx::string::view_or_value> _index_string;
6869
};
6970

7071
///

src/mongocxx/options/find.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ void find::batch_size(std::int32_t batch_size) {
3030
_batch_size = batch_size;
3131
}
3232

33-
void find::comment(std::string comment) {
34-
_comment = comment;
33+
void find::comment(bsoncxx::string::view_or_value comment) {
34+
_comment = std::move(comment);
3535
}
3636

3737
void find::cursor_type(enum find::cursor_type cursor_type) {
@@ -90,7 +90,7 @@ const stdx::optional<std::int32_t>& find::batch_size() const {
9090
return _batch_size;
9191
}
9292

93-
const stdx::optional<std::string>& find::comment() const {
93+
const stdx::optional<bsoncxx::string::view_or_value>& find::comment() const {
9494
return _comment;
9595
}
9696

src/mongocxx/options/find.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <bsoncxx/document/view_or_value.hpp>
2323
#include <bsoncxx/stdx/optional.hpp>
24+
#include <bsoncxx/string/view_or_value.hpp>
2425
#include <mongocxx/hint.hpp>
2526
#include <mongocxx/read_preference.hpp>
2627

@@ -83,7 +84,7 @@ class MONGOCXX_API find {
8384
///
8485
/// @see http://docs.mongodb.org/manual/reference/operator/meta/comment/
8586
///
86-
void comment(std::string comment);
87+
void comment(bsoncxx::string::view_or_value comment);
8788

8889
///
8990
/// Gets the current comment attached to this query.
@@ -92,7 +93,7 @@ class MONGOCXX_API find {
9293
///
9394
/// @see http://docs.mongodb.org/manual/reference/operator/meta/comment/
9495
///
95-
const stdx::optional<std::string>& comment() const;
96+
const stdx::optional<bsoncxx::string::view_or_value>& comment() const;
9697

9798
///
9899
/// Indicates the type of cursor to use for this query.
@@ -311,7 +312,7 @@ class MONGOCXX_API find {
311312
private:
312313
stdx::optional<bool> _allow_partial_results;
313314
stdx::optional<std::int32_t> _batch_size;
314-
stdx::optional<std::string> _comment;
315+
stdx::optional<bsoncxx::string::view_or_value> _comment;
315316
stdx::optional<enum cursor_type> _cursor_type;
316317
stdx::optional<class hint> _hint;
317318
stdx::optional<std::int32_t> _limit;

src/mongocxx/options/ssl.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,43 @@ namespace mongocxx {
2020
MONGOCXX_INLINE_NAMESPACE_BEGIN
2121
namespace options {
2222

23-
void ssl::pem_file(std::string pem_file) {
23+
void ssl::pem_file(bsoncxx::string::view_or_value pem_file) {
2424
_pem_file = std::move(pem_file);
2525
}
2626

27-
const stdx::optional<std::string>& ssl::pem_file() const {
27+
const stdx::optional<bsoncxx::string::view_or_value>& ssl::pem_file() const {
2828
return _pem_file;
2929
}
3030

31-
void ssl::pem_password(std::string pem_password) {
31+
void ssl::pem_password(bsoncxx::string::view_or_value pem_password) {
3232
_pem_password = std::move(pem_password);
3333
}
3434

35-
const stdx::optional<std::string>& ssl::pem_password() const {
35+
const stdx::optional<bsoncxx::string::view_or_value>& ssl::pem_password() const {
3636
return _pem_password;
3737
}
3838

39-
void ssl::ca_file(std::string ca_file) {
39+
void ssl::ca_file(bsoncxx::string::view_or_value ca_file) {
4040
_ca_file = std::move(ca_file);
4141
}
4242

43-
const stdx::optional<std::string>& ssl::ca_file() const {
43+
const stdx::optional<bsoncxx::string::view_or_value>& ssl::ca_file() const {
4444
return _ca_file;
4545
}
4646

47-
void ssl::ca_dir(std::string ca_dir) {
47+
void ssl::ca_dir(bsoncxx::string::view_or_value ca_dir) {
4848
_ca_dir = std::move(ca_dir);
4949
}
5050

51-
const stdx::optional<std::string>& ssl::ca_dir() const {
51+
const stdx::optional<bsoncxx::string::view_or_value>& ssl::ca_dir() const {
5252
return _ca_dir;
5353
}
5454

55-
void ssl::crl_file(std::string crl_file) {
55+
void ssl::crl_file(bsoncxx::string::view_or_value crl_file) {
5656
_crl_file = std::move(crl_file);
5757
}
5858

59-
const stdx::optional<std::string>& ssl::crl_file() const {
59+
const stdx::optional<bsoncxx::string::view_or_value>& ssl::crl_file() const {
6060
return _crl_file;
6161
}
6262

src/mongocxx/options/ssl.hpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <string>
2020

2121
#include <bsoncxx/stdx/optional.hpp>
22+
#include <bsoncxx/string/view_or_value.hpp>
2223

2324
#include <mongocxx/stdx.hpp>
2425

@@ -38,29 +39,29 @@ class MONGOCXX_API ssl {
3839
/// @param pem_file
3940
/// The path to the .pem file.
4041
///
41-
void pem_file(std::string pem_file);
42+
void pem_file(bsoncxx::string::view_or_value pem_file);
4243

4344
///
4445
/// Retrieves the current path to the .pem file.
4546
///
4647
/// @return The path to the .pem file.
4748
///
48-
const stdx::optional<std::string>& pem_file() const;
49+
const stdx::optional<bsoncxx::string::view_or_value>& pem_file() const;
4950

5051
///
5152
/// The pass phrase used to decrypt an encrypted PEM file.
5253
///
5354
/// @param pem_password
5455
/// The pass phrase.
5556
///
56-
void pem_password(std::string pem_password);
57+
void pem_password(bsoncxx::string::view_or_value pem_password);
5758

5859
///
5960
/// Retrieves the current decryption pass phrase.
6061
///
6162
/// @return The pass phrase.
6263
///
63-
const stdx::optional<std::string>& pem_password() const;
64+
const stdx::optional<bsoncxx::string::view_or_value>& pem_password() const;
6465

6566
///
6667
/// The path to the .pem file that contains the root certificate chain from the Certificate
@@ -69,44 +70,44 @@ class MONGOCXX_API ssl {
6970
/// @param ca_file
7071
/// The path to the CA file.
7172
///
72-
void ca_file(std::string ca_file);
73+
void ca_file(bsoncxx::string::view_or_value ca_file);
7374

7475
///
7576
/// Retrieves the current path to the CA file.
7677
///
7778
/// @return The path to the CA file.
7879
///
79-
const stdx::optional<std::string>& ca_file() const;
80+
const stdx::optional<bsoncxx::string::view_or_value>& ca_file() const;
8081

8182
///
8283
/// The path to the Certificate Authority directory.
8384
///
8485
/// @param ca_dir
8586
/// The path to the CA directory.
8687
///
87-
void ca_dir(std::string ca_dir);
88+
void ca_dir(bsoncxx::string::view_or_value ca_dir);
8889

8990
///
9091
/// Retrieves the current path to the CA directory.
9192
///
9293
/// @return The path to the CA directory.
9394
///
94-
const stdx::optional<std::string>& ca_dir() const;
95+
const stdx::optional<bsoncxx::string::view_or_value>& ca_dir() const;
9596

9697
///
9798
/// The path to the .pem file that contains revoked certificates.
9899
///
99100
/// @param crl_file
100101
/// The path to the PEM file.
101102
///
102-
void crl_file(std::string crl_file);
103+
void crl_file(bsoncxx::string::view_or_value crl_file);
103104

104105
///
105106
/// Retrieves the current path to the .pem file that contains revoked certificates.
106107
///
107108
/// @return The path to the revoked certificates file.
108109
///
109-
const stdx::optional<std::string>& crl_file() const;
110+
const stdx::optional<bsoncxx::string::view_or_value>& crl_file() const;
110111

111112
///
112113
/// If false, the driver will not verify the server's CA file.
@@ -124,11 +125,11 @@ class MONGOCXX_API ssl {
124125
const stdx::optional<bool>& allow_invalid_certificates() const;
125126

126127
private:
127-
stdx::optional<std::string> _pem_file;
128-
stdx::optional<std::string> _pem_password;
129-
stdx::optional<std::string> _ca_file;
130-
stdx::optional<std::string> _ca_dir;
131-
stdx::optional<std::string> _crl_file;
128+
stdx::optional<bsoncxx::string::view_or_value> _pem_file;
129+
stdx::optional<bsoncxx::string::view_or_value> _pem_password;
130+
stdx::optional<bsoncxx::string::view_or_value> _ca_file;
131+
stdx::optional<bsoncxx::string::view_or_value> _ca_dir;
132+
stdx::optional<bsoncxx::string::view_or_value> _crl_file;
132133
stdx::optional<bool> _allow_invalid_certificates;
133134
};
134135

0 commit comments

Comments
 (0)