Skip to content

Commit e711a21

Browse files
authored
Include headers explicitly and add constructors to comply C++20 (minio#116)
* Added constructors to become C++20 * fixed: implementation details leak in headers
1 parent c43db14 commit e711a21

31 files changed

+411
-79
lines changed

.gitattributes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Set the default behavior, in case people don't have core.autocrlf set.
2+
* text=auto
3+
4+
# Declare files that will always have LF line endings on checkout.
5+
*.sh test eol=lf

examples/PutObject.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16+
#include <fstream>
17+
#include <iosfwd>
18+
#include <iostream>
19+
#include <ostream>
20+
21+
#include "args.h"
1622
#include "client.h"
23+
#include "providers.h"
24+
#include "request.h"
25+
#include "response.h"
1726

1827
int main() {
1928
// Create S3 base URL.

examples/PutObjectProgress.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16+
#include <fstream>
17+
#include <iosfwd>
18+
#include <iostream>
19+
#include <ostream>
20+
21+
#include "args.h"
1622
#include "client.h"
23+
#include "http.h"
24+
#include "providers.h"
25+
#include "request.h"
26+
#include "response.h"
1727

1828
int main() {
1929
// Create S3 base URL.

include/args.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@
1616
#ifndef _MINIO_S3_ARGS_H
1717
#define _MINIO_S3_ARGS_H
1818

19+
#include <functional>
20+
#include <list>
21+
#include <map>
22+
#include <string>
23+
#include <type_traits>
24+
25+
#include "error.h"
1926
#include "http.h"
20-
#include "signer.h"
2127
#include "sse.h"
2228
#include "types.h"
29+
#include "utils.h"
2330

2431
namespace minio {
2532
namespace s3 {

include/baseclient.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@
1616
#ifndef _MINIO_S3_BASE_CLIENT_H
1717
#define _MINIO_S3_BASE_CLIENT_H
1818

19+
#include <map>
20+
#include <string>
21+
#include <type_traits>
22+
1923
#include "args.h"
2024
#include "config.h"
25+
#include "error.h"
26+
#include "http.h"
27+
#include "providers.h"
2128
#include "request.h"
2229
#include "response.h"
23-
#include "select.h"
30+
#include "utils.h"
2431

2532
namespace minio {
2633
namespace s3 {

include/client.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
#ifndef _MINIO_S3_CLIENT_H
1717
#define _MINIO_S3_CLIENT_H
1818

19-
#include <fstream>
19+
#include <list>
20+
#include <string>
2021

2122
#include "args.h"
2223
#include "baseclient.h"
23-
#include "config.h"
24+
#include "error.h"
25+
#include "providers.h"
2426
#include "request.h"
2527
#include "response.h"
2628

include/credentials.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
#ifndef _MINIO_CREDS_CREDENTIALS_H
1717
#define _MINIO_CREDS_CREDENTIALS_H
1818

19+
#include <string>
20+
#include <type_traits>
21+
22+
#include "error.h"
1923
#include "utils.h"
2024

2125
namespace minio {
@@ -34,6 +38,30 @@ struct Credentials {
3438
utils::UtcTime expiration = {};
3539

3640
Credentials() = default;
41+
explicit Credentials(error::Error err) : err(std::move(err)) {}
42+
43+
explicit Credentials(error::Error err, std::string access_key,
44+
std::string secret_key)
45+
: err(std::move(err)),
46+
access_key(std::move(access_key)),
47+
secret_key(std::move(secret_key)) {}
48+
49+
explicit Credentials(error::Error err, std::string access_key,
50+
std::string secret_key, std::string session_token)
51+
: err(std::move(err)),
52+
access_key(std::move(access_key)),
53+
secret_key(std::move(secret_key)),
54+
session_token(std::move(session_token)) {}
55+
56+
explicit Credentials(error::Error err, std::string access_key,
57+
std::string secret_key, std::string session_token,
58+
utils::UtcTime expiration)
59+
: err(std::move(err)),
60+
access_key(std::move(access_key)),
61+
secret_key(std::move(secret_key)),
62+
session_token(std::move(session_token)),
63+
expiration(std::move(expiration)) {}
64+
3765
~Credentials() = default;
3866

3967
bool IsExpired() const { return expired(expiration); }

include/error.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <ostream>
2020
#include <string>
21+
#include <type_traits>
2122

2223
namespace minio {
2324
namespace error {
@@ -32,9 +33,9 @@ class Error {
3233
Error(const Error&) = default;
3334
Error& operator=(const Error&) = default;
3435

35-
Error(Error&& v) : msg_(std::move(v.msg_)) {}
36+
Error(Error&& v) noexcept : msg_(std::move(v.msg_)) {}
3637

37-
Error& operator=(Error&& v) {
38+
Error& operator=(Error&& v) noexcept {
3839
if (this != &v) {
3940
msg_ = std::move(v.msg_);
4041
}

include/http.h

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@
1616
#ifndef _MINIO_HTTP_H
1717
#define _MINIO_HTTP_H
1818

19-
#ifdef _WIN32
20-
#include <ws2tcpip.h>
21-
#else
22-
#include <arpa/inet.h>
23-
#endif
24-
2519
#include <curlpp/Easy.hpp>
2620
#include <curlpp/Multi.hpp>
27-
#include <curlpp/Options.hpp>
21+
#include <exception>
22+
#include <functional>
23+
#include <iostream>
24+
#include <string>
25+
#include <type_traits>
2826

27+
#include "error.h"
2928
#include "utils.h"
3029

3130
namespace minio {
@@ -65,6 +64,13 @@ struct Url {
6564
std::string query_string;
6665

6766
Url() = default;
67+
explicit Url(bool https, std::string host, unsigned int port,
68+
std::string path, std::string query_string)
69+
: https(https),
70+
host(std::move(host)),
71+
port(port),
72+
path(std::move(path)),
73+
query_string(std::move(query_string)) {}
6874
~Url() = default;
6975

7076
explicit operator bool() const { return !host.empty(); }
@@ -91,6 +97,16 @@ struct DataFunctionArgs {
9197
void* userdata = nullptr;
9298

9399
DataFunctionArgs() = default;
100+
explicit DataFunctionArgs(curlpp::Easy* handle, Response* response,
101+
void* userdata)
102+
: handle(handle), response(response), userdata(userdata) {}
103+
explicit DataFunctionArgs(curlpp::Easy* handle, Response* response,
104+
std::string datachunk, void* userdata)
105+
: handle(handle),
106+
response(response),
107+
datachunk(std::move(datachunk)),
108+
userdata(userdata) {}
109+
94110
~DataFunctionArgs() = default;
95111
}; // struct DataFunctionArgs
96112

include/providers.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
#ifndef _MINIO_CREDS_PROVIDERS_H
1717
#define _MINIO_CREDS_PROVIDERS_H
1818

19-
#include <sys/types.h>
20-
19+
#include <functional>
20+
#include <list>
2121
#include <string>
22+
#include <type_traits>
2223

2324
#include "credentials.h"
25+
#include "error.h"
2426
#include "http.h"
2527

2628
#define DEFAULT_DURATION_SECONDS (60 * 60 * 24) // 1 day.
@@ -34,6 +36,8 @@ struct Jwt {
3436
unsigned int expiry = 0;
3537

3638
Jwt() = default;
39+
explicit Jwt(std::string token, unsigned int expiry)
40+
: token(std::move(token)), expiry(expiry) {}
3741
~Jwt() = default;
3842

3943
explicit operator bool() const { return !token.empty(); }

include/request.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616
#ifndef _MINIO_REQUEST_H
1717
#define _MINIO_REQUEST_H
1818

19-
#include "credentials.h"
19+
#include <regex>
20+
#include <string>
21+
22+
#include "error.h"
23+
#include "http.h"
2024
#include "providers.h"
21-
#include "signer.h"
25+
#include "utils.h"
2226

2327
namespace minio {
2428
namespace s3 {

include/response.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@
1616
#ifndef _MINIO_S3_RESPONSE_H
1717
#define _MINIO_S3_RESPONSE_H
1818

19-
#include <pugixml.hpp>
19+
#include <list>
20+
#include <map>
21+
#include <string>
22+
#include <type_traits>
2023

24+
#include "error.h"
2125
#include "types.h"
26+
#include "utils.h"
2227

2328
namespace minio {
2429
namespace s3 {

include/select.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
#ifndef _MINIO_S3_SELECT_H
1717
#define _MINIO_S3_SELECT_H
1818

19-
#include <pugixml.hpp>
19+
#include <map>
20+
#include <string>
21+
#include <type_traits>
2022

23+
#include "error.h"
2124
#include "http.h"
2225
#include "types.h"
2326

include/signer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
#ifndef _MINIO_SIGNER_H
1717
#define _MINIO_SIGNER_H
1818

19-
#include <openssl/hmac.h>
19+
#include <string>
2020

2121
#include "http.h"
22+
#include "utils.h"
2223

2324
namespace minio {
2425
namespace signer {

include/sse.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#ifndef _MINIO_S3_SSE_H
1717
#define _MINIO_S3_SSE_H
1818

19+
#include <string>
20+
1921
#include "utils.h"
2022

2123
namespace minio {

include/types.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@
1616
#ifndef _MINIO_S3_TYPES_H
1717
#define _MINIO_S3_TYPES_H
1818

19+
#include <exception>
20+
#include <functional>
1921
#include <iostream>
20-
#include <nlohmann/json.hpp>
22+
#include <list>
23+
#include <map>
24+
#include <nlohmann/json_fwd.hpp>
2125
#include <ostream>
26+
#include <string>
27+
#include <type_traits>
2228

29+
#include "error.h"
2330
#include "utils.h"
2431

2532
namespace minio {
@@ -310,6 +317,8 @@ struct Bucket {
310317
utils::UtcTime creation_date;
311318

312319
Bucket() = default;
320+
explicit Bucket(std::string name, utils::UtcTime creation_date)
321+
: name(std::move(name)), creation_date(std::move(creation_date)) {}
313322
~Bucket() = default;
314323
}; // struct Bucket
315324

@@ -320,6 +329,8 @@ struct Part {
320329
size_t size = 0;
321330

322331
Part() = default;
332+
explicit Part(unsigned int number, std::string etag)
333+
: number(number), etag(std::move(etag)) {}
323334
~Part() = default;
324335
}; // struct Part
325336

include/utils.h

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,23 @@
2020
#include <pwd.h>
2121
#endif
2222

23-
#include <openssl/buffer.h>
24-
#include <openssl/evp.h>
25-
#include <sys/types.h>
26-
#include <zlib.h>
27-
28-
#include <array>
29-
#include <chrono>
30-
#include <cmath>
31-
#include <cstring>
3223
#include <ctime>
33-
#include <curlpp/cURLpp.hpp>
34-
#include <iomanip>
35-
#include <iostream>
24+
#include <ios>
3625
#include <list>
3726
#include <map>
38-
#include <ostream>
39-
#include <regex>
4027
#include <set>
41-
#include <sstream>
28+
#include <streambuf>
29+
#include <string>
30+
#include <vector>
4231

4332
#include "error.h"
4433

4534
namespace minio {
4635
namespace utils {
47-
inline constexpr unsigned int kMaxMultipartCount = 10000; // 10000 parts
48-
inline constexpr unsigned long long kMaxObjectSize = 5497558138880ULL; // 5TiB
49-
inline constexpr unsigned long long kMaxPartSize = 5368709120UL; // 5GiB
50-
inline constexpr unsigned int kMinPartSize = 5 * 1024 * 1024; // 5MiB
36+
inline constexpr unsigned int kMaxMultipartCount = 10000; // 10000 parts
37+
inline constexpr uint64_t kMaxObjectSize = 5'497'558'138'880; // 5TiB
38+
inline constexpr uint64_t kMaxPartSize = 5'368'709'120; // 5GiB
39+
inline constexpr unsigned int kMinPartSize = 5 * 1024 * 1024; // 5MiB
5140

5241
// GetEnv copies the environment variable name into var
5342
bool GetEnv(std::string& var, const char* name);
@@ -72,7 +61,7 @@ inline const char* BoolToString(bool b) { return b ? "true" : "false"; }
7261
// Trim trims leading and trailing character of a string.
7362
std::string Trim(std::string_view str, char ch = ' ');
7463

75-
// CheckNonemptystring checks whether string is not empty after trimming
64+
// CheckNonEmptyString checks whether string is not empty after trimming
7665
// whitespaces.
7766
bool CheckNonEmptyString(std::string_view str);
7867

0 commit comments

Comments
 (0)