|
10 | 10 | #include <vector>
|
11 | 11 |
|
12 | 12 | namespace Ios3 {
|
13 |
| -namespace helpers { |
14 |
| - |
15 |
| -struct HelperParameters { |
16 |
| - std::string endpoint { "" }; |
17 |
| - std::string profile { "" }; |
18 |
| - std::string ca_file { "" }; |
19 |
| - bool use_ca_file { false }; |
20 |
| - bool use_transfer_manager { false }; |
21 |
| - bool enable_aws_tracing { false }; |
22 |
| - bool disable_ec2_lookup { true }; |
23 |
| -}; |
24 |
| - |
25 |
| -struct HelperContext { |
26 |
| - bool use_transfer_manager; |
27 |
| - |
28 |
| - //The Aws::SDKOptions struct contains SDK configuration options. |
29 |
| - //An instance of Aws::SDKOptions is passed to the Aws::InitAPI and |
30 |
| - //Aws::ShutdownAPI methods. The same instance should be sent to both methods. |
31 |
| - Aws::SDKOptions options; |
32 |
| - |
33 |
| - std::shared_ptr<Aws::S3::S3Client> client; |
34 |
| - std::shared_ptr<Aws::Utils::Threading::PooledThreadExecutor> executor; |
35 |
| - std::shared_ptr<Aws::Transfer::TransferManager> transfer_manager; |
36 |
| -}; |
37 |
| - |
38 |
| -// From https://stackoverflow.com/questions/21028299/is-this-behavior-of-vectorresizesize-type-n-under-c11-and-boost-container/21028912#21028912 |
39 |
| -// |
40 |
| -// Allocator adaptor that interposes construct() calls to |
41 |
| -// convert value initialization into default initialization. |
42 |
| -template <typename T, typename A=std::allocator<T>> |
43 |
| -class default_init_allocator : public A { |
44 |
| - typedef std::allocator_traits<A> a_t; |
45 |
| -public: |
46 |
| - template <typename U> struct rebind { |
47 |
| - using other = |
48 |
| - default_init_allocator< |
49 |
| - U, typename a_t::template rebind_alloc<U> |
50 |
| - >; |
51 |
| - }; |
52 |
| - |
53 |
| - using A::A; |
54 |
| - |
55 |
| - template <typename U> |
56 |
| - void construct(U* ptr) |
57 |
| - noexcept(std::is_nothrow_default_constructible<U>::value) { |
58 |
| - ::new(static_cast<void*>(ptr)) U; |
59 |
| - } |
60 |
| - template <typename U, typename...Args> |
61 |
| - void construct(U* ptr, Args&&... args) { |
62 |
| - a_t::construct(static_cast<A&>(*this), |
63 |
| - ptr, std::forward<Args>(args)...); |
64 |
| - } |
65 |
| -}; |
66 |
| - |
67 |
| -// A vector that doesn't initialize new elements when resized. |
68 |
| -template <typename T> |
69 |
| -using UninitializedVector = std::vector<T,default_init_allocator<T>>; |
70 |
| - |
71 |
| -void print_params(const HelperParameters ¶ms); |
72 |
| - |
73 |
| -std::string cleanBucketName(const std::string &name); |
74 |
| - |
75 |
| -void getParamsFromEnvVars(HelperParameters ¶ms); |
76 |
| - |
77 |
| -std::shared_ptr<HelperContext> createContext(const HelperParameters ¶ms); |
78 |
| - |
79 |
| -void destroyContext(std::shared_ptr<HelperContext> context); |
80 |
| - |
81 |
| -int createBucket(std::shared_ptr<HelperContext> context, |
82 |
| - const std::string &bucket); |
83 |
| - |
84 |
| -int waitBucket(std::shared_ptr<HelperContext> context, |
85 |
| - const std::string &bucket, |
86 |
| - uint64_t wait_usec); |
87 |
| - |
88 |
| -int deleteBucket(std::shared_ptr<HelperContext> context, |
89 |
| - const std::string &bucket); |
90 |
| - |
91 |
| -int listBuckets(std::shared_ptr<HelperContext> context, |
92 |
| - std::vector<std::string> &bucket_names); |
93 |
| - |
94 |
| -template<typename T, typename A> |
95 |
| -int putValue(std::shared_ptr<HelperContext> context, |
96 |
| - const std::string &bucket, |
97 |
| - const std::string &key, |
98 |
| - const std::vector<T,A> &value); |
99 |
| - |
100 |
| -template<typename T, typename A> |
101 |
| -int getValue(std::shared_ptr<HelperContext> context, |
102 |
| - const std::string &bucket, |
103 |
| - const std::string &key, |
104 |
| - std::vector<T,A> &value); |
105 |
| - |
106 |
| -int putValue(std::shared_ptr<HelperContext> context, |
107 |
| - const std::string &bucket, |
108 |
| - const std::string &key, |
109 |
| - const std::string &filename); |
110 |
| - |
111 |
| -int getValue(std::shared_ptr<HelperContext> context, |
112 |
| - const std::string &bucket, |
113 |
| - const std::string &key, |
114 |
| - std::string &filename); |
115 |
| - |
116 |
| -int deleteValue(std::shared_ptr<HelperContext> context, |
117 |
| - const std::string &bucket, |
118 |
| - const std::string &key); |
119 |
| - |
120 |
| -int listKeys(std::shared_ptr<HelperContext> context, |
121 |
| - const std::string &bucket, |
122 |
| - std::vector<std::string> &keys); |
123 |
| - |
124 |
| -int listKeys(std::shared_ptr<HelperContext> context, |
125 |
| - const std::string &bucket, |
126 |
| - const std::string &key_prefix, |
127 |
| - std::vector<std::string> &keys); |
128 |
| - |
129 |
| -int putBucketPolicy(std::shared_ptr<HelperContext> context, |
130 |
| - const std::string &bucket, |
131 |
| - const std::string &policy); |
132 |
| - |
133 |
| -int getBucketPolicy(std::shared_ptr<HelperContext> context, |
134 |
| - const std::string &bucket, |
135 |
| - std::string &policy); |
136 |
| - |
137 |
| -int deleteBucketPolicy(std::shared_ptr<HelperContext> context, |
138 |
| - const std::string &bucket); |
139 |
| - |
140 |
| -} |
141 |
| -} |
| 13 | + namespace helpers { |
| 14 | + |
| 15 | + struct HelperParameters |
| 16 | + { |
| 17 | + std::string endpoint{""}; |
| 18 | + std::string profile{""}; |
| 19 | + std::string ca_file{""}; |
| 20 | + bool use_ca_file{false}; |
| 21 | + bool use_transfer_manager{false}; |
| 22 | + bool enable_aws_tracing{false}; |
| 23 | + bool disable_ec2_lookup{true}; |
| 24 | + }; |
| 25 | + |
| 26 | + struct HelperContext |
| 27 | + { |
| 28 | + bool use_transfer_manager; |
| 29 | + |
| 30 | + // The Aws::SDKOptions struct contains SDK configuration options. |
| 31 | + // An instance of Aws::SDKOptions is passed to the Aws::InitAPI and |
| 32 | + // Aws::ShutdownAPI methods. The same instance should be sent to both methods. |
| 33 | + Aws::SDKOptions options; |
| 34 | + |
| 35 | + std::shared_ptr<Aws::S3::S3Client> client; |
| 36 | + std::shared_ptr<Aws::Utils::Threading::PooledThreadExecutor> executor; |
| 37 | + std::shared_ptr<Aws::Transfer::TransferManager> transfer_manager; |
| 38 | + }; |
| 39 | + |
| 40 | + // From |
| 41 | + // https://stackoverflow.com/questions/21028299/is-this-behavior-of-vectorresizesize-type-n-under-c11-and-boost-container/21028912#21028912 |
| 42 | + // |
| 43 | + // Allocator adaptor that interposes construct() calls to |
| 44 | + // convert value initialization into default initialization. |
| 45 | + template <typename T, typename A = std::allocator<T>> class default_init_allocator : public A |
| 46 | + { |
| 47 | + typedef std::allocator_traits<A> a_t; |
| 48 | + |
| 49 | + public: |
| 50 | + template <typename U> struct rebind |
| 51 | + { |
| 52 | + using other = default_init_allocator<U, typename a_t::template rebind_alloc<U>>; |
| 53 | + }; |
| 54 | + |
| 55 | + using A::A; |
| 56 | + |
| 57 | + template <typename U> |
| 58 | + void construct(U *ptr) noexcept(std::is_nothrow_default_constructible<U>::value) |
| 59 | + { |
| 60 | + ::new (static_cast<void *>(ptr)) U; |
| 61 | + } |
| 62 | + template <typename U, typename... Args> void construct(U *ptr, Args &&...args) |
| 63 | + { |
| 64 | + a_t::construct(static_cast<A &>(*this), ptr, std::forward<Args>(args)...); |
| 65 | + } |
| 66 | + }; |
| 67 | + |
| 68 | + // A vector that doesn't initialize new elements when resized. |
| 69 | + template <typename T> using UninitializedVector = std::vector<T, default_init_allocator<T>>; |
| 70 | + |
| 71 | + void print_params(const HelperParameters ¶ms); |
| 72 | + |
| 73 | + std::string cleanBucketName(const std::string &name); |
| 74 | + |
| 75 | + void getParamsFromEnvVars(HelperParameters ¶ms); |
| 76 | + |
| 77 | + std::shared_ptr<HelperContext> createContext(const HelperParameters ¶ms); |
| 78 | + |
| 79 | + void destroyContext(std::shared_ptr<HelperContext> context); |
| 80 | + |
| 81 | + int createBucket(std::shared_ptr<HelperContext> context, const std::string &bucket); |
| 82 | + |
| 83 | + int waitBucket(std::shared_ptr<HelperContext> context, const std::string &bucket, |
| 84 | + uint64_t wait_usec); |
| 85 | + |
| 86 | + int deleteBucket(std::shared_ptr<HelperContext> context, const std::string &bucket); |
| 87 | + |
| 88 | + int listBuckets(std::shared_ptr<HelperContext> context, std::vector<std::string> &bucket_names); |
| 89 | + |
| 90 | + template <typename T, typename A> |
| 91 | + int putValue(std::shared_ptr<HelperContext> context, const std::string &bucket, |
| 92 | + const std::string &key, const std::vector<T, A> &value); |
| 93 | + |
| 94 | + template <typename T, typename A> |
| 95 | + int getValue(std::shared_ptr<HelperContext> context, const std::string &bucket, |
| 96 | + const std::string &key, std::vector<T, A> &value); |
| 97 | + |
| 98 | + int putValue(std::shared_ptr<HelperContext> context, const std::string &bucket, |
| 99 | + const std::string &key, const std::string &filename); |
| 100 | + |
| 101 | + int getValue(std::shared_ptr<HelperContext> context, const std::string &bucket, |
| 102 | + const std::string &key, std::string &filename); |
| 103 | + |
| 104 | + int deleteValue(std::shared_ptr<HelperContext> context, const std::string &bucket, |
| 105 | + const std::string &key); |
| 106 | + |
| 107 | + int listKeys(std::shared_ptr<HelperContext> context, const std::string &bucket, |
| 108 | + std::vector<std::string> &keys); |
| 109 | + |
| 110 | + int listKeys(std::shared_ptr<HelperContext> context, const std::string &bucket, |
| 111 | + const std::string &key_prefix, std::vector<std::string> &keys); |
| 112 | + |
| 113 | + int putBucketPolicy(std::shared_ptr<HelperContext> context, const std::string &bucket, |
| 114 | + const std::string &policy); |
| 115 | + |
| 116 | + int getBucketPolicy(std::shared_ptr<HelperContext> context, const std::string &bucket, |
| 117 | + std::string &policy); |
| 118 | + |
| 119 | + int deleteBucketPolicy(std::shared_ptr<HelperContext> context, const std::string &bucket); |
| 120 | + |
| 121 | + } // namespace helpers |
| 122 | +} // namespace Ios3 |
0 commit comments