Skip to content

Commit ad19ece

Browse files
committed
Use std::optional if available.
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. Relates-To: NLAM-23 Signed-off-by: sopov <[email protected]>
1 parent a03183a commit ad19ece

File tree

71 files changed

+685
-802
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

+685
-802
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
@@ -25,7 +25,7 @@
2525

2626
#include <olp/dataservice/read/DataServiceReadApi.h>
2727
#include <olp/dataservice/read/FetchOptions.h>
28-
#include <boost/optional.hpp>
28+
#include <olp/core/porting/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 & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <string>
2424
#include <utility>
2525

26-
#include <boost/optional.hpp>
26+
#include <olp/core/porting/optional.hpp>
2727

2828
#include "DataServiceReadApi.h"
2929
#include "FetchOptions.h"
@@ -57,7 +57,7 @@ class DATASERVICE_READ_API CatalogVersionRequest final {
5757
*
5858
* @return A reference to the updated `CatalogVersionRequest` instance.
5959
*/
60-
inline CatalogVersionRequest& WithStartVersion(int64_t startVersion) {
60+
CatalogVersionRequest& WithStartVersion(int64_t startVersion) {
6161
start_version_ = startVersion;
6262
return *this;
6363
}
@@ -69,10 +69,10 @@ class DATASERVICE_READ_API CatalogVersionRequest final {
6969
* billing records together. If supplied, it must be 4–16 characters
7070
* long and contain only alphanumeric ASCII characters [A-Za-z0-9].
7171
*
72-
* @return The `BillingTag` string or `boost::none` if the billing tag is not
73-
* set.
72+
* @return The `BillingTag` string or `olp::porting::none` if the billing tag
73+
* is not set.
7474
*/
75-
inline const boost::optional<std::string>& GetBillingTag() const {
75+
const porting::optional<std::string>& GetBillingTag() const {
7676
return billing_tag_;
7777
}
7878

@@ -81,28 +81,13 @@ class DATASERVICE_READ_API CatalogVersionRequest final {
8181
*
8282
* @see `GetBillingTag()` for information on usage and format.
8383
*
84-
* @param billingTag The `BillingTag` string or `boost::none`.
84+
* @param billingTag The `BillingTag` string or `olp::porting::none`.
8585
*
8686
* @return A reference to the updated `CatalogVersionRequest` instance.
8787
*/
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`.
101-
*
102-
* @return A reference to the updated `CatalogVersionRequest` instance.
103-
*/
104-
inline CatalogVersionRequest& WithBillingTag(std::string&& billingTag) {
105-
billing_tag_ = std::move(billingTag);
88+
template <class T = porting::optional<std::string>>
89+
CatalogVersionRequest& WithBillingTag(T&& billingTag) {
90+
billing_tag_ = std::forward<T>(billingTag);
10691
return *this;
10792
}
10893

@@ -114,7 +99,7 @@ class DATASERVICE_READ_API CatalogVersionRequest final {
11499
*
115100
* @return The fetch option.
116101
*/
117-
inline FetchOptions GetFetchOption() const { return fetch_option_; }
102+
FetchOptions GetFetchOption() const { return fetch_option_; }
118103

119104
/**
120105
* @brief Sets the fetch option that you can use to set the source from
@@ -126,7 +111,7 @@ class DATASERVICE_READ_API CatalogVersionRequest final {
126111
*
127112
* @return A reference to the updated `CatalogVersionRequest` instance.
128113
*/
129-
inline CatalogVersionRequest& WithFetchOption(FetchOptions fetchoption) {
114+
CatalogVersionRequest& WithFetchOption(FetchOptions fetchoption) {
130115
fetch_option_ = fetchoption;
131116
return *this;
132117
}
@@ -136,13 +121,13 @@ class DATASERVICE_READ_API CatalogVersionRequest final {
136121
*
137122
* @return A string representation of the request.
138123
*/
139-
inline std::string CreateKey() const {
124+
std::string CreateKey() const {
140125
std::stringstream out;
141126

142127
out << "@" << GetStartVersion();
143128

144129
if (GetBillingTag()) {
145-
out << "$" << GetBillingTag().get();
130+
out << "$" << *GetBillingTag();
146131
}
147132

148133
out << "^" << GetFetchOption();
@@ -152,7 +137,7 @@ class DATASERVICE_READ_API CatalogVersionRequest final {
152137

153138
private:
154139
int64_t start_version_{-1};
155-
boost::optional<std::string> billing_tag_;
140+
porting::optional<std::string> billing_tag_;
156141
FetchOptions fetch_option_{OnlineIfNotFound};
157142
};
158143

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

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

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

3030
namespace olp {
3131
namespace dataservice {

0 commit comments

Comments
 (0)