9
9
10
10
#include < aws/core/utils/memory/AWSMemory.h>
11
11
#include < aws/core/utils/memory/stl/AWSVector.h>
12
+ #include < aws/core/utils/memory/stl/AWSString.h>
12
13
#include < aws/crt/Types.h>
13
14
#include < memory>
14
15
#include < cassert>
@@ -39,7 +40,7 @@ namespace Aws
39
40
* Create new empty array of size arraySize. Default argument is 0. If it is empty then no allocation happens.
40
41
*/
41
42
Array (size_t arraySize = 0 ) :
42
- m_size (arraySize),
43
+ m_capacity (arraySize),
43
44
m_length (arraySize),
44
45
m_data (arraySize > 0 ? Aws::MakeUniqueArray<T>(arraySize, ARRAY_ALLOCATION_TAG) : nullptr )
45
46
{
@@ -49,30 +50,25 @@ namespace Aws
49
50
* Create new array and initialize it to a raw array
50
51
*/
51
52
Array (const T* arrayToCopy, size_t arraySize) :
52
- m_size (arraySize),
53
+ m_capacity (arraySize),
53
54
m_length (arraySize),
54
55
m_data (nullptr )
55
56
{
56
- if (arrayToCopy != nullptr && m_size > 0 )
57
+ if (arrayToCopy != nullptr && m_capacity > 0 )
57
58
{
58
- m_data.reset (Aws::NewArray<T>(m_size, ARRAY_ALLOCATION_TAG));
59
-
60
- #ifdef _WIN32
61
- std::copy (arrayToCopy, arrayToCopy + arraySize, stdext::checked_array_iterator< T * >(m_data.get (), m_size));
62
- #else
59
+ m_data.reset (Aws::NewArray<T>(m_capacity, ARRAY_ALLOCATION_TAG));
63
60
std::copy (arrayToCopy, arrayToCopy + arraySize, m_data.get ());
64
- #endif // MSVC
65
61
}
66
62
}
67
63
68
64
/* *
69
65
* Create new array with a pointer and its dimensions.
70
66
*/
71
- Array (size_t m_size ,
72
- size_t m_length ,
67
+ Array (size_t capacity ,
68
+ size_t length ,
73
69
UniqueArrayPtr<T> m_data)
74
- : m_size(m_size ),
75
- m_length (m_length ),
70
+ : m_capacity(capacity ),
71
+ m_length (length ),
76
72
m_data(std::move(m_data))
77
73
{
78
74
}
@@ -88,20 +84,16 @@ namespace Aws
88
84
totalSize += array->m_length ;
89
85
}
90
86
91
- m_size = totalSize;
92
- m_data.reset (Aws::NewArray<T>(m_size , ARRAY_ALLOCATION_TAG));
87
+ m_capacity = totalSize;
88
+ m_data.reset (Aws::NewArray<T>(m_capacity , ARRAY_ALLOCATION_TAG));
93
89
94
90
size_t location = 0 ;
95
91
for (auto & arr : toMerge)
96
92
{
97
- if (arr->m_size > 0 && arr->m_data )
93
+ if (arr->m_capacity > 0 && arr->m_data )
98
94
{
99
95
size_t arraySize = arr->m_length ;
100
- #ifdef _WIN32
101
- std::copy (arr->m_data .get (), arr->m_data .get () + arraySize, stdext::checked_array_iterator< T * >(m_data.get () + location, m_length));
102
- #else
103
96
std::copy (arr->m_data .get (), arr->m_data .get () + arraySize, m_data.get () + location);
104
- #endif // MSVC
105
97
location += arraySize;
106
98
}
107
99
}
@@ -110,29 +102,24 @@ namespace Aws
110
102
111
103
Array (const Array& other)
112
104
{
113
- m_size = other.m_size ;
105
+ m_capacity = other.m_capacity ;
114
106
m_length = other.m_length ;
115
107
m_data = nullptr ;
116
108
117
- if (m_size > 0 )
109
+ if (m_capacity > 0 )
118
110
{
119
- m_data.reset (Aws::NewArray<T>(m_size, ARRAY_ALLOCATION_TAG));
120
-
121
- #ifdef _WIN32
122
- std::copy (other.m_data .get (), other.m_data .get () + other.m_size , stdext::checked_array_iterator< T * >(m_data.get (), m_size));
123
- #else
124
- std::copy (other.m_data .get (), other.m_data .get () + other.m_size , m_data.get ());
125
- #endif // MSVC
111
+ m_data.reset (Aws::NewArray<T>(m_capacity, ARRAY_ALLOCATION_TAG));
112
+ std::copy (other.m_data .get (), other.m_data .get () + other.m_capacity , m_data.get ());
126
113
}
127
114
}
128
115
129
116
// move c_tor
130
117
Array (Array&& other) noexcept :
131
- m_size (other.m_size ),
118
+ m_capacity (other.m_capacity ),
132
119
m_length(other.m_length),
133
120
m_data(std::move(other.m_data))
134
121
{
135
- other.m_size = 0 ;
122
+ other.m_capacity = 0 ;
136
123
other.m_data = nullptr ;
137
124
}
138
125
@@ -145,39 +132,43 @@ namespace Aws
145
132
return *this ;
146
133
}
147
134
148
- m_size = other.m_size ;
135
+ m_capacity = other.m_capacity ;
149
136
m_length = other.m_length ;
150
137
m_data = nullptr ;
151
138
152
- if (m_size > 0 )
139
+ if (m_capacity > 0 )
153
140
{
154
- m_data.reset (Aws::NewArray<T>(m_size, ARRAY_ALLOCATION_TAG));
155
-
156
- #ifdef _WIN32
157
- std::copy (other.m_data .get (), other.m_data .get () + other.m_length , stdext::checked_array_iterator< T * >(m_data.get (), m_size));
158
- #else
141
+ m_data.reset (Aws::NewArray<T>(m_capacity, ARRAY_ALLOCATION_TAG));
159
142
std::copy (other.m_data .get (), other.m_data .get () + other.m_length , m_data.get ());
160
- #endif // MSVC
161
143
}
162
144
163
145
return *this ;
164
146
}
165
147
166
148
Array& operator =(Array&& other) noexcept
167
149
{
168
- m_size = other.m_size ;
150
+ m_capacity = other.m_capacity ;
169
151
m_length = other.m_length ;
170
152
m_data = std::move (other.m_data );
171
153
172
154
return *this ;
173
155
}
174
156
157
+ Array (const Aws::String& string):
158
+ m_capacity (string.capacity()),
159
+ m_length (string.length()),
160
+ m_data (nullptr )
161
+ {
162
+ m_data.reset (Aws::NewArray<unsigned char >(m_capacity, ARRAY_ALLOCATION_TAG));
163
+ std::copy (string.c_str (), string.c_str () + string.length (), m_data.get ());
164
+ }
165
+
175
166
bool operator ==(const Array& other) const
176
167
{
177
168
if (this == &other)
178
169
return true ;
179
170
180
- if (m_size == 0 && other.m_size == 0 )
171
+ if (m_capacity == 0 && other.m_capacity == 0 )
181
172
{
182
173
return true ;
183
174
}
@@ -187,7 +178,7 @@ namespace Aws
187
178
return false ;
188
179
}
189
180
190
- if (m_length == other.m_length && m_size == other.m_size && m_data && other.m_data )
181
+ if (m_length == other.m_length && m_capacity == other.m_capacity && m_data && other.m_data )
191
182
{
192
183
for (unsigned i = 0 ; i < m_length; ++i)
193
184
{
@@ -235,7 +226,7 @@ namespace Aws
235
226
236
227
inline size_t GetSize () const
237
228
{
238
- return m_size ;
229
+ return m_capacity ;
239
230
}
240
231
241
232
inline T* GetUnderlyingData () const
@@ -249,7 +240,7 @@ namespace Aws
249
240
}
250
241
251
242
protected:
252
- size_t m_size ;
243
+ size_t m_capacity ;
253
244
size_t m_length;
254
245
Aws::UniqueArrayPtr<T> m_data;
255
246
};
@@ -285,7 +276,7 @@ namespace Aws
285
276
286
277
CryptoBuffer& operator =(Crt::ByteBuf&& other) noexcept
287
278
{
288
- m_size = other.len ;
279
+ m_capacity = other.len ;
289
280
m_length = other.len ;
290
281
m_data.reset (other.buffer );
291
282
other.capacity = 0 ;
0 commit comments