1
1
/* **
2
2
* ==++==
3
3
*
4
- * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Copyright (c) Microsoft Corporation. All rights reserved.
5
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
6
* you may not use this file except in compliance with the License.
7
7
* You may obtain a copy of the License at
8
8
* http://www.apache.org/licenses/LICENSE-2.0
9
- *
9
+ *
10
10
* Unless required by applicable law or agreed to in writing, software
11
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35
35
#if defined(_MSC_VER) && (_MSC_VER >= 1800)
36
36
#include < ppltasks.h>
37
37
namespace pplx = Concurrency;
38
- #else
38
+ #else
39
39
#include " pplx/pplxtasks.h"
40
40
#endif
41
41
42
42
#include " cpprest/astreambuf.h"
43
43
#include " cpprest/streams.h"
44
- #ifdef _MS_WINDOWS
45
- #include < safeint.h>
46
- #endif
47
44
48
45
#ifndef _CONCRT_H
49
46
#ifndef _LWRCASE_CNCRRNCY
@@ -96,7 +93,7 @@ namespace Concurrency { namespace streams {
96
93
// / Destructor
97
94
// / </summary>
98
95
virtual ~basic_container_buffer ()
99
- {
96
+ {
100
97
// Invoke the synchronous versions since we need to
101
98
// purge the request queue before deleting the buffer
102
99
this ->_close_read ();
@@ -140,7 +137,7 @@ namespace Concurrency { namespace streams {
140
137
// / <param name="size">The size to use for internal buffering, 0 if no buffering should be done.</param>
141
138
// / <param name="direction">The direction of buffering (in or out)</param>
142
139
// / <remarks>An implementation that does not support buffering will silently ignore calls to this function and it will not have any effect on what is returned by subsequent calls to <see cref="::buffer_size method" />.</remarks>
143
- virtual void set_buffer_size (size_t , std::ios_base::openmode = std::ios_base::in)
140
+ virtual void set_buffer_size (size_t , std::ios_base::openmode = std::ios_base::in)
144
141
{
145
142
return ;
146
143
}
@@ -152,16 +149,13 @@ namespace Concurrency { namespace streams {
152
149
// / </summary>
153
150
virtual size_t in_avail () const
154
151
{
155
- // See the comment in seek around the restiction that we do not allow read head to
152
+ // See the comment in seek around the restriction that we do not allow read head to
156
153
// seek beyond the current write_end.
157
154
_ASSERTE (m_current_position <= m_size);
158
- #ifdef _MS_WINDOWS
159
- msl::utilities::SafeInt<size_t > readhead (m_current_position);
160
- msl::utilities::SafeInt<size_t > writeend (m_size);
161
- return (size_t )(writeend - readhead);
162
- #else
163
- return m_size - m_current_position;
164
- #endif
155
+
156
+ SafeSize readhead (m_current_position);
157
+ SafeSize writeend (m_size);
158
+ return (size_t )(writeend - readhead);
165
159
}
166
160
167
161
virtual pplx::task<bool > _sync ()
@@ -207,7 +201,7 @@ namespace Concurrency { namespace streams {
207
201
}
208
202
209
203
// / <summary>
210
- // / Gets a pointer to the next already allocated contiguous block of data.
204
+ // / Gets a pointer to the next already allocated contiguous block of data.
211
205
// / </summary>
212
206
// / <param name="ptr">A reference to a pointer variable that will hold the address of the block on success.</param>
213
207
// / <param name="count">The number of contiguous characters available at the address in 'ptr.'</param>
@@ -259,7 +253,7 @@ namespace Concurrency { namespace streams {
259
253
}
260
254
261
255
size_t _sgetn (_Out_writes_ (count) _CharType *ptr, _In_ size_t count)
262
- {
256
+ {
263
257
return this ->read (ptr, count);
264
258
}
265
259
@@ -272,7 +266,7 @@ namespace Concurrency { namespace streams {
272
266
{
273
267
return pplx::task_from_result (this ->read_byte (true ));
274
268
}
275
-
269
+
276
270
virtual int_type _sbumpc ()
277
271
{
278
272
return this ->read_byte (true );
@@ -282,7 +276,7 @@ namespace Concurrency { namespace streams {
282
276
{
283
277
return pplx::task_from_result (this ->read_byte (false ));
284
278
}
285
-
279
+
286
280
int_type _sgetc ()
287
281
{
288
282
return this ->read_byte (false );
@@ -293,7 +287,7 @@ namespace Concurrency { namespace streams {
293
287
this ->read_byte (true );
294
288
return pplx::task_from_result (this ->read_byte (false ));
295
289
}
296
-
290
+
297
291
virtual pplx::task<int_type> _ungetc ()
298
292
{
299
293
auto pos = seekoff (-1 , std::ios_base::cur, std::ios_base::in);
@@ -307,7 +301,7 @@ namespace Concurrency { namespace streams {
307
301
// / </summary>
308
302
// / <param name="direction">The I/O direction to seek (see remarks)</param>
309
303
// / <returns>The current position. EOF if the operation fails.</returns>
310
- // / <remarks>Some streams may have separate write and read cursors.
304
+ // / <remarks>Some streams may have separate write and read cursors.
311
305
// / For such streams, the direction parameter defines whether to move the read or the write cursor.</remarks>
312
306
virtual pos_type getpos (std::ios_base::openmode mode) const
313
307
{
@@ -332,7 +326,7 @@ namespace Concurrency { namespace streams {
332
326
// Inorder to support relative seeking from the end postion we need to fix an end position.
333
327
// Technically, there is no end for the stream buffer as new writes would just expand the buffer.
334
328
// For now, we assume that the current write_end is the end of the buffer. We use this aritifical
335
- // end to restrict the read head from seeking beyond what is available.
329
+ // end to restrict the read head from seeking beyond what is available.
336
330
337
331
pos_type end (m_size);
338
332
@@ -341,7 +335,7 @@ namespace Concurrency { namespace streams {
341
335
auto pos = static_cast <size_t >(position);
342
336
343
337
// Read head
344
- if ((mode & std::ios_base::in) && this ->can_read ())
338
+ if ((mode & std::ios_base::in) && this ->can_read ())
345
339
{
346
340
if (position <= end)
347
341
{
@@ -352,7 +346,7 @@ namespace Concurrency { namespace streams {
352
346
}
353
347
354
348
// Write head
355
- if ((mode & std::ios_base::out) && this ->can_write ())
349
+ if ((mode & std::ios_base::out) && this ->can_write ())
356
350
{
357
351
// Allocate space
358
352
resize_for_write (pos);
@@ -368,17 +362,17 @@ namespace Concurrency { namespace streams {
368
362
369
363
return static_cast <pos_type>(traits::eof ());
370
364
}
371
-
365
+
372
366
// / <summary>
373
367
// / Seeks to a position given by a relative offset.
374
368
// / </summary>
375
369
// / <param name="offset">The relative position to seek to</param>
376
370
// / <param name="way">The starting point (beginning, end, current) for the seek.</param>
377
371
// / <param name="mode">The I/O direction to seek (see remarks)</param>
378
372
// / <returns>The position. EOF if the operation fails.</returns>
379
- // / <remarks>Some streams may have separate write and read cursors.
373
+ // / <remarks>Some streams may have separate write and read cursors.
380
374
// / For such streams, the mode parameter defines whether to move the read or the write cursor.</remarks>
381
- virtual pos_type seekoff (off_type offset, std::ios_base::seekdir way, std::ios_base::openmode mode)
375
+ virtual pos_type seekoff (off_type offset, std::ios_base::seekdir way, std::ios_base::openmode mode)
382
376
{
383
377
pos_type beg = 0 ;
384
378
pos_type cur = static_cast <pos_type>(m_current_position);
@@ -406,7 +400,7 @@ namespace Concurrency { namespace streams {
406
400
// / <summary>
407
401
// / Constructor
408
402
// / </summary>
409
- basic_container_buffer (std::ios_base::openmode mode)
403
+ basic_container_buffer (std::ios_base::openmode mode)
410
404
: streambuf_state_manager<typename _CollectionType::value_type>(mode),
411
405
m_current_position (0 ),
412
406
m_size (0 )
@@ -417,7 +411,7 @@ namespace Concurrency { namespace streams {
417
411
// / <summary>
418
412
// / Constructor
419
413
// / </summary>
420
- basic_container_buffer (_CollectionType data, std::ios_base::openmode mode)
414
+ basic_container_buffer (_CollectionType data, std::ios_base::openmode mode)
421
415
: streambuf_state_manager<typename _CollectionType::value_type>(mode),
422
416
m_data (std::move(data)),
423
417
m_current_position ((mode & std::ios_base::in) ? 0 : m_data.size()),
@@ -471,7 +465,7 @@ namespace Concurrency { namespace streams {
471
465
472
466
auto readBegin = begin (m_data) + m_current_position;
473
467
auto readEnd = begin (m_data) + newPos;
474
-
468
+
475
469
#ifdef _MS_WINDOWS
476
470
// Avoid warning C4996: Use checked iterators under SECURE_SCL
477
471
std::copy (readBegin, readEnd, stdext::checked_array_iterator<_CharType *>(ptr, count));
@@ -495,7 +489,7 @@ namespace Concurrency { namespace streams {
495
489
if (!this ->can_write () || (count == 0 )) return 0 ;
496
490
497
491
auto newSize = m_current_position + count;
498
-
492
+
499
493
// Allocate space
500
494
resize_for_write (newSize);
501
495
@@ -557,7 +551,7 @@ namespace Concurrency { namespace streams {
557
551
// / <typeparam name="_CollectionType">
558
552
// / The type of the container.
559
553
// / </typeparam>
560
- // / <remarks>
554
+ // / <remarks>
561
555
// / This is a reference-counted version of <c>basic_container_buffer</c>.
562
556
// / </remarks>
563
557
template <typename _CollectionType>
@@ -571,7 +565,7 @@ namespace Concurrency { namespace streams {
571
565
// / </summary>
572
566
// / <param name="data">The collection that is the starting point for the buffer</param>
573
567
// / <param name="mode">The I/O mode that the buffer should use (in / out)</param>
574
- container_buffer (_CollectionType data, std::ios_base::openmode mode = std::ios_base::in)
568
+ container_buffer (_CollectionType data, std::ios_base::openmode mode = std::ios_base::in)
575
569
: streambuf<typename _CollectionType::value_type>(
576
570
std::shared_ptr<details::basic_container_buffer<_CollectionType>>(new streams::details::basic_container_buffer<_CollectionType>(std::move(data), mode)))
577
571
{
@@ -581,7 +575,7 @@ namespace Concurrency { namespace streams {
581
575
// / Creates a container_buffer starting from an empty collection.
582
576
// / </summary>
583
577
// / <param name="mode">The I/O mode that the buffer should use (in / out)</param>
584
- container_buffer (std::ios_base::openmode mode = std::ios_base::out)
578
+ container_buffer (std::ios_base::openmode mode = std::ios_base::out)
585
579
: streambuf<typename _CollectionType::value_type>(
586
580
std::shared_ptr<details::basic_container_buffer<_CollectionType>>(new details::basic_container_buffer<_CollectionType>(mode)))
587
581
{
@@ -609,7 +603,7 @@ namespace Concurrency { namespace streams {
609
603
610
604
typedef typename _CollectionType::value_type char_type;
611
605
typedef container_buffer<_CollectionType> buffer_type;
612
-
606
+
613
607
static concurrency::streams::basic_istream<char_type> open_istream (_CollectionType data)
614
608
{
615
609
return concurrency::streams::basic_istream<char_type>(buffer_type (std::move (data), std::ios_base::in));
@@ -637,7 +631,7 @@ namespace Concurrency { namespace streams {
637
631
class bytestream
638
632
{
639
633
public:
640
-
634
+
641
635
template <typename _CollectionType>
642
636
static concurrency::streams::istream open_istream (_CollectionType data)
643
637
{
@@ -651,7 +645,7 @@ namespace Concurrency { namespace streams {
651
645
}
652
646
};
653
647
654
-
648
+
655
649
}} // namespaces
656
650
657
651
#pragma warning(pop) // 4100
0 commit comments