Skip to content

Commit 00ba4cc

Browse files
committed
Updated a bunch of C style casts to C++ static_cast in winrt file streams.
1 parent c2c2e80 commit 00ba4cc

File tree

2 files changed

+46
-46
lines changed

2 files changed

+46
-46
lines changed

Release/include/cpprest/interopstream.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ namespace Concurrency { namespace streams {
223223
typedef typename traits::pos_type pos_type;
224224
typedef typename traits::off_type off_type;
225225

226-
basic_async_streambuf(streams::streambuf<CharType> async_buf) : m_buffer(async_buf)
226+
basic_async_streambuf(const streams::streambuf<CharType> &async_buf) : m_buffer(async_buf)
227227
{
228228
}
229229
protected:
@@ -391,7 +391,7 @@ namespace Concurrency { namespace streams {
391391
/// </typeparam>
392392
/// <param name="astream">The asynchronous stream whose stream buffer should be used for I/O</param>
393393
template <typename AlterCharType>
394-
async_ostream(streams::basic_ostream<AlterCharType> astream)
394+
async_ostream(const streams::basic_ostream<AlterCharType> &astream)
395395
: std::basic_ostream<CharType>(&m_strbuf),
396396
m_strbuf(astream.streambuf())
397397
{
@@ -405,7 +405,7 @@ namespace Concurrency { namespace streams {
405405
/// </typeparam>
406406
/// <param name="strbuf">The asynchronous stream buffer to use for I/O</param>
407407
template <typename AlterCharType>
408-
async_ostream(streams::streambuf<AlterCharType> strbuf)
408+
async_ostream(const streams::streambuf<AlterCharType> &strbuf)
409409
: std::basic_ostream<CharType>(&m_strbuf),
410410
m_strbuf(strbuf)
411411
{
@@ -433,7 +433,7 @@ namespace Concurrency { namespace streams {
433433
/// </typeparam>
434434
/// <param name="astream">The asynchronous stream whose stream buffer should be used for I/O</param>
435435
template <typename AlterCharType>
436-
async_istream(streams::basic_istream<AlterCharType> astream)
436+
async_istream(const streams::basic_istream<AlterCharType> &astream)
437437
: std::basic_istream<CharType>(&m_strbuf),
438438
m_strbuf(astream.streambuf())
439439
{
@@ -447,7 +447,7 @@ namespace Concurrency { namespace streams {
447447
/// </typeparam>
448448
/// <param name="strbuf">The asynchronous stream buffer to use for I/O</param>
449449
template <typename AlterCharType>
450-
async_istream(streams::streambuf<AlterCharType> strbuf)
450+
async_istream(const streams::streambuf<AlterCharType> &strbuf)
451451
: std::basic_istream<CharType>(&m_strbuf),
452452
m_strbuf(strbuf)
453453
{
@@ -471,7 +471,7 @@ namespace Concurrency { namespace streams {
471471
/// Constructor
472472
/// </summary>
473473
/// <param name="strbuf">The asynchronous stream buffer to use for I/O</param>
474-
async_iostream(streams::streambuf<CharType> strbuf)
474+
async_iostream(const streams::streambuf<CharType> &strbuf)
475475
: std::basic_iostream<CharType>(&m_strbuf),
476476
m_strbuf(strbuf)
477477
{
@@ -500,7 +500,7 @@ namespace Concurrency { namespace streams {
500500
/// The stream buffer is shared with the caller, allowing data to be passed between the two contexts. For
501501
/// example, using a <c>producer_consumer_buffer</c>, a Casablanca-based caller can pass data to a WinRT component.
502502
/// </remarks>
503-
_ASYNCRTIMP static Windows::Storage::Streams::IInputStream^ __cdecl create_input_stream(concurrency::streams::streambuf<uint8_t> buffer);
503+
_ASYNCRTIMP static Windows::Storage::Streams::IInputStream^ __cdecl create_input_stream(const concurrency::streams::streambuf<uint8_t> &buffer);
504504

505505
/// <summary>
506506
/// Creates a WinRT <c>IOutputStream</c> reference from an asynchronous stream buffer.
@@ -512,7 +512,7 @@ namespace Concurrency { namespace streams {
512512
/// The stream buffer is shared with the caller, allowing data to be passed between the two contexts. For
513513
/// example, using a <c>producer_consumer_buffer</c>, a Casablanca-based caller can retrieve data from a WinRT component.
514514
/// </remarks>
515-
_ASYNCRTIMP static Windows::Storage::Streams::IOutputStream^ __cdecl create_output_stream(concurrency::streams::streambuf<uint8_t> buffer);
515+
_ASYNCRTIMP static Windows::Storage::Streams::IOutputStream^ __cdecl create_output_stream(const concurrency::streams::streambuf<uint8_t> &buffer);
516516

517517
/// <summary>
518518
/// Creates a WinRT <c>IRandomAccessStream reference from an asynchronous input stream.
@@ -524,7 +524,7 @@ namespace Concurrency { namespace streams {
524524
/// example, using a <c>producer_consumer_buffer</c>, a Casablanca-based caller can pass data to and retrieve data
525525
/// from a WinRT component.
526526
/// </remarks>
527-
_ASYNCRTIMP static Windows::Storage::Streams::IRandomAccessStream^ __cdecl create_random_access_stream(concurrency::streams::streambuf<uint8_t> buffer);
527+
_ASYNCRTIMP static Windows::Storage::Streams::IRandomAccessStream^ __cdecl create_random_access_stream(const concurrency::streams::streambuf<uint8_t> &buffer);
528528
};
529529

530530
#endif

Release/src/streams/fileio_winrt.cpp

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ bool __cdecl _sync_fsb_winrt(_In_ Concurrency::streams::details::_file_info *inf
156156
{
157157
_ASSERTE(info != nullptr);
158158

159-
_file_info_impl *fInfo = (_file_info_impl *)info;
159+
_file_info_impl *fInfo = static_cast<_file_info_impl *>(info);
160160

161161
pplx::extensibility::scoped_recursive_lock_t lck(fInfo->m_lock);
162162

@@ -172,7 +172,7 @@ bool __cdecl _sync_fsb_winrt(_In_ Concurrency::streams::details::_file_info *inf
172172
fInfo->m_buffill = 0;
173173
return writer->FlushAsync();
174174
}).then([=] (pplx::task<bool> result) {
175-
// Rethrow exception if no callback attatched.
175+
// Rethrow exception if no callback attached.
176176
if (callback == nullptr)
177177
result.wait();
178178
else
@@ -206,7 +206,7 @@ bool __cdecl _close_fsb_nolock(_In_ _file_info **info, _In_ Concurrency::streams
206206
_ASSERTE(info != nullptr);
207207
_ASSERTE(*info != nullptr);
208208

209-
_file_info_impl *fInfo = (_file_info_impl *)*info;
209+
_file_info_impl *fInfo = static_cast<_file_info_impl *>(*info);
210210

211211
*info = nullptr;
212212

@@ -265,25 +265,25 @@ size_t __cdecl _read_file_async(_In_ Concurrency::streams::details::_file_info_i
265265

266266
auto reader = ref new Streams::DataReader(fInfo->m_stream->GetInputStreamAt(offset));
267267

268-
pplx::create_task(reader->LoadAsync((unsigned int)count)).then(
269-
[=] (pplx::task<unsigned int> result)
268+
pplx::create_task(reader->LoadAsync(static_cast<unsigned int>(count))).then(
269+
[=](pplx::task<unsigned int> result)
270+
{
271+
try
270272
{
271-
try
272-
{
273-
auto read = result.get();
274-
275-
if ( read > 0 )
276-
{
277-
reader->ReadBytes(Platform::ArrayReference<unsigned char>(static_cast<unsigned char *>(ptr), read));
278-
}
273+
auto read = result.get();
279274

280-
callback->on_completed(read);
281-
}
282-
catch (Platform::Exception^ exc)
275+
if (read > 0)
283276
{
284-
callback->on_error(std::make_exception_ptr(utility::details::create_system_error(exc->HResult)));
277+
reader->ReadBytes(Platform::ArrayReference<unsigned char>(static_cast<unsigned char *>(ptr), read));
285278
}
286-
});
279+
280+
callback->on_completed(read);
281+
}
282+
catch (Platform::Exception^ exc)
283+
{
284+
callback->on_error(std::make_exception_ptr(utility::details::create_system_error(exc->HResult)));
285+
}
286+
});
287287

288288
return 0;
289289
}
@@ -293,7 +293,7 @@ template<typename Func>
293293
class _filestream_callback_fill_buffer : public _filestream_callback
294294
{
295295
public:
296-
_filestream_callback_fill_buffer(_In_ _file_info *info, Func func) : m_func(func), m_info(info) { }
296+
_filestream_callback_fill_buffer(_In_ _file_info *info, const Func &func) : m_func(func), m_info(info) { }
297297

298298
virtual void on_completed(size_t result)
299299
{
@@ -307,7 +307,7 @@ class _filestream_callback_fill_buffer : public _filestream_callback
307307
};
308308

309309
template<typename Func>
310-
_filestream_callback_fill_buffer<Func> *create_callback(_In_ _file_info *info, Func func)
310+
_filestream_callback_fill_buffer<Func> *create_callback(_In_ _file_info *info, const Func &func)
311311
{
312312
return new _filestream_callback_fill_buffer<Func>(info, func);
313313
}
@@ -484,7 +484,7 @@ size_t __cdecl _getn_fsb(_In_ Concurrency::streams::details::_file_info *info, _
484484
_ASSERTE(info != nullptr);
485485
_ASSERTE(count > 0);
486486

487-
_file_info_impl *fInfo = (_file_info_impl *)info;
487+
_file_info_impl *fInfo = static_cast<_file_info_impl *>(info);
488488

489489
pplx::extensibility::scoped_recursive_lock_t lck(info->m_lock);
490490

@@ -496,19 +496,19 @@ size_t __cdecl _getn_fsb(_In_ Concurrency::streams::details::_file_info *info, _
496496
auto sz = count*char_size;
497497
auto copy = (read < sz) ? read : sz;
498498
auto bufoff = fInfo->m_rdpos - fInfo->m_bufoff;
499-
memcpy((void *)ptr, fInfo->m_buffer+bufoff*char_size, copy);
499+
memcpy(ptr, fInfo->m_buffer+bufoff*char_size, copy);
500500
fInfo->m_atend = copy < sz;
501501
callback->on_completed(copy);
502502
});
503503

504-
int read = (int)_fill_buffer_fsb(fInfo, cb, count, char_size);
504+
size_t read = _fill_buffer_fsb(fInfo, cb, count, char_size);
505505

506506
if ( read > 0 )
507507
{
508508
auto sz = count*char_size;
509-
auto copy = ((size_t)read < sz) ? (size_t)read : sz;
509+
auto copy = (read < sz) ? read : sz;
510510
auto bufoff = fInfo->m_rdpos - fInfo->m_bufoff;
511-
memcpy((void *)ptr, fInfo->m_buffer+bufoff*char_size, copy);
511+
memcpy(ptr, fInfo->m_buffer+bufoff*char_size, copy);
512512
fInfo->m_atend = copy < sz;
513513
return copy;
514514
}
@@ -536,7 +536,7 @@ size_t __cdecl _putn_fsb(_In_ Concurrency::streams::details::_file_info *info, _
536536
_ASSERTE(info != nullptr);
537537
_ASSERTE(count > 0);
538538

539-
_file_info_impl *fInfo = (_file_info_impl *)info;
539+
_file_info_impl *fInfo = static_cast<_file_info_impl *>(info);
540540

541541
pplx::extensibility::scoped_recursive_lock_t lck(fInfo->m_lock);
542542

@@ -622,11 +622,11 @@ size_t __cdecl _seekrdpos_fsb(_In_ Concurrency::streams::details::_file_info *in
622622
{
623623
_ASSERTE(info != nullptr);
624624

625-
_file_info_impl *fInfo = (_file_info_impl *)info;
625+
_file_info_impl *fInfo = static_cast<_file_info_impl *>(info);
626626

627627
pplx::extensibility::scoped_recursive_lock_t lck(info->m_lock);
628628

629-
if ( fInfo->m_stream == nullptr) return (size_t)-1;;
629+
if ( fInfo->m_stream == nullptr) return static_cast<size_t>(-1);;
630630

631631
if ( pos < fInfo->m_bufoff || pos > (fInfo->m_bufoff+fInfo->m_buffill) )
632632
{
@@ -650,7 +650,7 @@ size_t __cdecl _seekrdpos_fsb(_In_ Concurrency::streams::details::_file_info *in
650650
_ASYNCRTIMP size_t __cdecl _seekrdtoend_fsb(_In_ Concurrency::streams::details::_file_info *info, int64_t offset, size_t char_size)
651651
{
652652
_ASSERTE(info != nullptr);
653-
_file_info_impl *fInfo = (_file_info_impl *)info;
653+
_file_info_impl *fInfo = static_cast<_file_info_impl *>(info);
654654

655655
return _seekrdpos_fsb(info, static_cast<size_t>(fInfo->m_stream->Size / char_size + offset), char_size);
656656
}
@@ -659,7 +659,7 @@ utility::size64_t __cdecl _get_size(_In_ concurrency::streams::details::_file_in
659659
{
660660
_ASSERTE(info != nullptr);
661661

662-
_file_info_impl *fInfo = (_file_info_impl *)info;
662+
_file_info_impl *fInfo = static_cast<_file_info_impl *>(info);
663663

664664
pplx::extensibility::scoped_recursive_lock_t lck(info->m_lock);
665665

@@ -678,11 +678,11 @@ size_t __cdecl _seekwrpos_fsb(_In_ Concurrency::streams::details::_file_info *in
678678
{
679679
_ASSERTE(info != nullptr);
680680

681-
_file_info_impl *fInfo = (_file_info_impl *)info;
681+
_file_info_impl *fInfo = static_cast<_file_info_impl *>(info);
682682

683683
pplx::extensibility::scoped_recursive_lock_t lck(info->m_lock);
684684

685-
if ( fInfo->m_stream == nullptr) return (size_t)-1;;
685+
if ( fInfo->m_stream == nullptr) return static_cast<size_t>(-1);
686686

687687
fInfo->m_wrpos = pos;
688688

@@ -793,14 +793,14 @@ ref class IRandomAccessStream_bridge sealed : public Windows::Storage::Streams::
793793

794794
internal:
795795

796-
IRandomAccessStream_bridge(concurrency::streams::streambuf<uint8_t> buffer) :
796+
IRandomAccessStream_bridge(const concurrency::streams::streambuf<uint8_t> &buffer) :
797797
m_buffer(buffer),
798798
m_remembered_size(0),
799799
m_position(0)
800800
{
801801
}
802802

803-
IRandomAccessStream_bridge(concurrency::streams::streambuf<uint8_t> buffer,
803+
IRandomAccessStream_bridge(const concurrency::streams::streambuf<uint8_t> &buffer,
804804
concurrency::streams::streambuf<uint8_t>::pos_type position) :
805805
m_buffer(buffer),
806806
m_remembered_size(0),
@@ -1026,17 +1026,17 @@ IRandomAccessStream_bridge::FlushAsync()
10261026

10271027
}}} // namespaces
10281028

1029-
Windows::Storage::Streams::IInputStream^ Concurrency::streams::winrt_stream::create_input_stream(concurrency::streams::streambuf<uint8_t> buffer)
1029+
Windows::Storage::Streams::IInputStream^ Concurrency::streams::winrt_stream::create_input_stream(const concurrency::streams::streambuf<uint8_t> &buffer)
10301030
{
10311031
return ref new ::Concurrency::streams::details::IRandomAccessStream_bridge(buffer,0);
10321032
}
10331033

1034-
Windows::Storage::Streams::IOutputStream^ Concurrency::streams::winrt_stream::create_output_stream(concurrency::streams::streambuf<uint8_t> buffer)
1034+
Windows::Storage::Streams::IOutputStream^ Concurrency::streams::winrt_stream::create_output_stream(const concurrency::streams::streambuf<uint8_t> &buffer)
10351035
{
10361036
return ref new Concurrency::streams::details::IRandomAccessStream_bridge(buffer,0);
10371037
}
10381038

1039-
Windows::Storage::Streams::IRandomAccessStream^ Concurrency::streams::winrt_stream::create_random_access_stream(concurrency::streams::streambuf<uint8_t> buffer)
1039+
Windows::Storage::Streams::IRandomAccessStream^ Concurrency::streams::winrt_stream::create_random_access_stream(const concurrency::streams::streambuf<uint8_t> &buffer)
10401040
{
10411041
return ref new Concurrency::streams::details::IRandomAccessStream_bridge(buffer);
10421042
}

0 commit comments

Comments
 (0)