Skip to content

Commit 0678e1e

Browse files
authored
Use std::optional if available. (#1627)
Currently, SDK requires C++11 minimum. So, boost::optional type is used for optional values. For C++17 and above more convenient is to use std::optional instead. The task NLAM-23 is about making this type configurable. This commit is a third part of the task: olp-cpp-sdk-read. Also, initial name "optional.hpp" is changed to optional.h to avoid clang-format header sorting issue. Relates-To: NLAM-23 Signed-off-by: sopov <[email protected]>
1 parent ba2156c commit 0678e1e

File tree

71 files changed

+791
-872
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+791
-872
lines changed

olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/CatalogRequest.h

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
#include <string>
2424
#include <utility>
2525

26+
#include <olp/core/porting/optional.h>
2627
#include <olp/dataservice/read/DataServiceReadApi.h>
2728
#include <olp/dataservice/read/FetchOptions.h>
28-
#include <boost/optional.hpp>
2929

3030
namespace olp {
3131
namespace dataservice {
@@ -43,10 +43,10 @@ class DATASERVICE_READ_API CatalogRequest final {
4343
* billing records together. If supplied, it must be 4–16 characters
4444
* long and contain only alphanumeric ASCII characters [A-Za-z0-9].
4545
*
46-
* @return The `BillingTag` string or `boost::none` if the billing tag is not
47-
* set.
46+
* @return The `BillingTag` string or `olp::porting::none` if the billing tag
47+
* is not set.
4848
*/
49-
inline const boost::optional<std::string>& GetBillingTag() const {
49+
const porting::optional<std::string>& GetBillingTag() const {
5050
return billing_tag_;
5151
}
5252

@@ -55,27 +55,13 @@ class DATASERVICE_READ_API CatalogRequest final {
5555
*
5656
* @see `GetBillingTag()` for information on usage and format.
5757
*
58-
* @param tag The `BillingTag` string or `boost::none`.
58+
* @param tag The `BillingTag` string or `olp::porting::none`.
5959
*
6060
* @return A reference to the updated `CatalogRequest` instance.
6161
*/
62-
inline CatalogRequest& WithBillingTag(boost::optional<std::string> tag) {
63-
billing_tag_ = std::move(tag);
64-
return *this;
65-
}
66-
67-
/**
68-
* @brief Sets the billing tag for the request.
69-
*
70-
* @see `GetBillingTag()` for information on usage and format.
71-
*
72-
* @param tag The rvalue reference to the `BillingTag` string or
73-
* `boost::none`.
74-
*
75-
* @return A reference to the updated `CatalogRequest` instance.
76-
*/
77-
inline CatalogRequest& WithBillingTag(std::string&& tag) {
78-
billing_tag_ = std::move(tag);
62+
template <class T = porting::optional<std::string>>
63+
CatalogRequest& WithBillingTag(T&& tag) {
64+
billing_tag_ = std::forward<T>(tag);
7965
return *this;
8066
}
8167

@@ -87,7 +73,7 @@ class DATASERVICE_READ_API CatalogRequest final {
8773
*
8874
* @return The fetch option.
8975
*/
90-
inline FetchOptions GetFetchOption() const { return fetch_option_; }
76+
FetchOptions GetFetchOption() const { return fetch_option_; }
9177

9278
/**
9379
* @brief Sets the fetch option that you can use to set the source from
@@ -99,7 +85,7 @@ class DATASERVICE_READ_API CatalogRequest final {
9985
*
10086
* @return A reference to the updated `CatalogVersionRequest` instance.
10187
*/
102-
inline CatalogRequest& WithFetchOption(FetchOptions fetch_option) {
88+
CatalogRequest& WithFetchOption(const FetchOptions fetch_option) {
10389
fetch_option_ = fetch_option;
10490
return *this;
10591
}
@@ -109,17 +95,17 @@ class DATASERVICE_READ_API CatalogRequest final {
10995
*
11096
* @return A string representation of the request.
11197
*/
112-
inline std::string CreateKey() const {
98+
std::string CreateKey() const {
11399
std::stringstream out;
114100
if (GetBillingTag()) {
115-
out << "$" << GetBillingTag().get();
101+
out << "$" << *GetBillingTag();
116102
}
117103
out << "^" << GetFetchOption();
118104
return out.str();
119105
}
120106

121107
private:
122-
boost::optional<std::string> billing_tag_;
108+
porting::optional<std::string> billing_tag_;
123109
FetchOptions fetch_option_{OnlineIfNotFound};
124110
};
125111

olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/CatalogVersionRequest.h

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
#include <string>
2424
#include <utility>
2525

26-
#include <boost/optional.hpp>
27-
26+
#include <olp/core/porting/optional.h>
2827
#include "DataServiceReadApi.h"
2928
#include "FetchOptions.h"
3029

@@ -57,7 +56,7 @@ class DATASERVICE_READ_API CatalogVersionRequest final {
5756
*
5857
* @return A reference to the updated `CatalogVersionRequest` instance.
5958
*/
60-
inline CatalogVersionRequest& WithStartVersion(int64_t startVersion) {
59+
CatalogVersionRequest& WithStartVersion(int64_t startVersion) {
6160
start_version_ = startVersion;
6261
return *this;
6362
}
@@ -69,10 +68,10 @@ class DATASERVICE_READ_API CatalogVersionRequest final {
6968
* billing records together. If supplied, it must be 4–16 characters
7069
* long and contain only alphanumeric ASCII characters [A-Za-z0-9].
7170
*
72-
* @return The `BillingTag` string or `boost::none` if the billing tag is not
73-
* set.
71+
* @return The `BillingTag` string or `olp::porting::none` if the billing tag
72+
* is not set.
7473
*/
75-
inline const boost::optional<std::string>& GetBillingTag() const {
74+
const porting::optional<std::string>& GetBillingTag() const {
7675
return billing_tag_;
7776
}
7877

@@ -81,28 +80,13 @@ class DATASERVICE_READ_API CatalogVersionRequest final {
8180
*
8281
* @see `GetBillingTag()` for information on usage and format.
8382
*
84-
* @param billingTag The `BillingTag` string or `boost::none`.
85-
*
86-
* @return A reference to the updated `CatalogVersionRequest` instance.
87-
*/
88-
inline CatalogVersionRequest& WithBillingTag(
89-
boost::optional<std::string> billingTag) {
90-
billing_tag_ = std::move(billingTag);
91-
return *this;
92-
}
93-
94-
/**
95-
* @brief Sets the billing tag for the request.
96-
*
97-
* @see `GetBillingTag()` for information on usage and format.
98-
*
99-
* @param billingTag The rvalue reference to the `BillingTag` string or
100-
* `boost::none`.
83+
* @param billingTag The `BillingTag` string or `olp::porting::none`.
10184
*
10285
* @return A reference to the updated `CatalogVersionRequest` instance.
10386
*/
104-
inline CatalogVersionRequest& WithBillingTag(std::string&& billingTag) {
105-
billing_tag_ = std::move(billingTag);
87+
template <class T = porting::optional<std::string>>
88+
CatalogVersionRequest& WithBillingTag(T&& billingTag) {
89+
billing_tag_ = std::forward<T>(billingTag);
10690
return *this;
10791
}
10892

@@ -114,7 +98,7 @@ class DATASERVICE_READ_API CatalogVersionRequest final {
11498
*
11599
* @return The fetch option.
116100
*/
117-
inline FetchOptions GetFetchOption() const { return fetch_option_; }
101+
FetchOptions GetFetchOption() const { return fetch_option_; }
118102

119103
/**
120104
* @brief Sets the fetch option that you can use to set the source from
@@ -126,7 +110,7 @@ class DATASERVICE_READ_API CatalogVersionRequest final {
126110
*
127111
* @return A reference to the updated `CatalogVersionRequest` instance.
128112
*/
129-
inline CatalogVersionRequest& WithFetchOption(FetchOptions fetchoption) {
113+
CatalogVersionRequest& WithFetchOption(FetchOptions fetchoption) {
130114
fetch_option_ = fetchoption;
131115
return *this;
132116
}
@@ -136,13 +120,13 @@ class DATASERVICE_READ_API CatalogVersionRequest final {
136120
*
137121
* @return A string representation of the request.
138122
*/
139-
inline std::string CreateKey() const {
123+
std::string CreateKey() const {
140124
std::stringstream out;
141125

142126
out << "@" << GetStartVersion();
143127

144128
if (GetBillingTag()) {
145-
out << "$" << GetBillingTag().get();
129+
out << "$" << *GetBillingTag();
146130
}
147131

148132
out << "^" << GetFetchOption();
@@ -152,7 +136,7 @@ class DATASERVICE_READ_API CatalogVersionRequest final {
152136

153137
private:
154138
int64_t start_version_{-1};
155-
boost::optional<std::string> billing_tag_;
139+
porting::optional<std::string> billing_tag_;
156140
FetchOptions fetch_option_{OnlineIfNotFound};
157141
};
158142

olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/ConsumerProperties.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <vector>
2626

2727
#include <olp/dataservice/read/DataServiceReadApi.h>
28-
#include <boost/optional.hpp>
2928

3029
namespace olp {
3130
namespace dataservice {

0 commit comments

Comments
 (0)