Browse Source

🧹 C++17: Use std::make_unique

pull/1594/head
Gleb Mazovetskiy 5 years ago committed by Anders Jenbo
parent
commit
4c0581ca5e
  1. 8
      Source/dvlnet/abstract_net.cpp
  2. 8
      Source/dvlnet/packet.h
  3. 4
      Source/mpqapi.cpp

8
Source/dvlnet/abstract_net.cpp

@ -16,15 +16,15 @@ namespace net {
std::unique_ptr<abstract_net> abstract_net::make_net(provider_t provider) std::unique_ptr<abstract_net> abstract_net::make_net(provider_t provider)
{ {
#ifdef NONET #ifdef NONET
return std::unique_ptr<abstract_net>(new loopback); return std::make_unique<loopback>();
#else #else
switch (provider) { switch (provider) {
case SELCONN_TCP: case SELCONN_TCP:
return std::unique_ptr<abstract_net>(new cdwrap<tcp_client>); return std::make_unique<cdwrap<tcp_client>>();
case SELCONN_ZT: case SELCONN_ZT:
return std::unique_ptr<abstract_net>(new cdwrap<base_protocol<protocol_zt>>); return std::make_unique<cdwrap<base_protocol<protocol_zt>>>();
case SELCONN_LOOPBACK: case SELCONN_LOOPBACK:
return std::unique_ptr<abstract_net>(new loopback); return std::make_unique<loopback>();
default: default:
ABORT(); ABORT();
} }

8
Source/dvlnet/packet.h

@ -342,19 +342,19 @@ public:
inline std::unique_ptr<packet> packet_factory::make_packet(buffer_t buf) inline std::unique_ptr<packet> packet_factory::make_packet(buffer_t buf)
{ {
std::unique_ptr<packet_in> ret(new packet_in(key)); auto ret = std::make_unique<packet_in>(key);
ret->create(std::move(buf)); ret->create(std::move(buf));
ret->decrypt(); ret->decrypt();
return std::unique_ptr<packet>(std::move(ret)); return ret;
} }
template <packet_type t, typename... Args> template <packet_type t, typename... Args>
std::unique_ptr<packet> packet_factory::make_packet(Args... args) std::unique_ptr<packet> packet_factory::make_packet(Args... args)
{ {
std::unique_ptr<packet_out> ret(new packet_out(key)); auto ret = std::make_unique<packet_out>(key);
ret->create<t>(args...); ret->create<t>(args...);
ret->encrypt(); ret->encrypt();
return std::unique_ptr<packet>(std::move(ret)); return ret;
} }
} // namespace net } // namespace net

4
Source/mpqapi.cpp

@ -553,7 +553,7 @@ static bool mpqapi_write_file_contents(const char *pszName, const BYTE *pbData,
// We populate the table of sector offset while we write the data. // We populate the table of sector offset while we write the data.
// We can't pre-populate it because we don't know the compressed sector sizes yet. // We can't pre-populate it because we don't know the compressed sector sizes yet.
// First offset is the start of the first sector, last offset is the end of the last sector. // First offset is the start of the first sector, last offset is the end of the last sector.
std::unique_ptr<uint32_t[]> sectoroffsettable(new uint32_t[num_sectors + 1]); auto sectoroffsettable = std::make_unique<uint32_t[]>(num_sectors + 1);
#ifdef CAN_SEEKP_BEYOND_EOF #ifdef CAN_SEEKP_BEYOND_EOF
if (!cur_archive.stream.seekp(pBlk->offset + offset_table_bytesize, std::ios::beg)) if (!cur_archive.stream.seekp(pBlk->offset + offset_table_bytesize, std::ios::beg))
@ -566,7 +566,7 @@ static bool mpqapi_write_file_contents(const char *pszName, const BYTE *pbData,
const std::uintmax_t cur_size = stream_end - cur_archive.stream_begin; const std::uintmax_t cur_size = stream_end - cur_archive.stream_begin;
if (cur_size < pBlk->offset + offset_table_bytesize) { if (cur_size < pBlk->offset + offset_table_bytesize) {
if (cur_size < pBlk->offset) { if (cur_size < pBlk->offset) {
std::unique_ptr<char[]> filler(new char[pBlk->offset - cur_size]); auto filler = std::make_unique<char[]>(pBlk->offset - cur_size);
if (!cur_archive.stream.write(filler.get(), pBlk->offset - cur_size)) if (!cur_archive.stream.write(filler.get(), pBlk->offset - cur_size))
return false; return false;
} }

Loading…
Cancel
Save