diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2013-06-30 16:55:15 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2013-06-30 22:55:43 +0900 |
| commit | 098f1571be6f9d30d394eb83d35cc67f8e9ebcb0 (patch) | |
| tree | 1fd7ae9d1173704f39291c5f438c3388a3ab3d65 /src/RangeBtMessage.h | |
| parent | abcb0745ed3c60f17942ce65fb63159a157854ea (diff) | |
Wrap BtMessage objects by std::unique_ptr instead of std::shared_ptr
Diffstat (limited to 'src/RangeBtMessage.h')
| -rw-r--r-- | src/RangeBtMessage.h | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/RangeBtMessage.h b/src/RangeBtMessage.h index 3ba2179f..a9c590e3 100644 --- a/src/RangeBtMessage.h +++ b/src/RangeBtMessage.h @@ -49,15 +49,14 @@ private: static const size_t MESSAGE_LENGTH = 17; protected: template<typename T> - static T* create(const unsigned char* data, size_t dataLength) + static std::unique_ptr<T> create(const unsigned char* data, + size_t dataLength) { bittorrent::assertPayloadLengthEqual(13, dataLength, T::NAME); bittorrent::assertID(T::ID, data, T::NAME); - T* message(new T()); - message->setIndex(bittorrent::getIntParam(data, 1)); - message->setBegin(bittorrent::getIntParam(data, 5)); - message->setLength(bittorrent::getIntParam(data, 9)); - return message; + return make_unique<T>(bittorrent::getIntParam(data, 1), + bittorrent::getIntParam(data, 5), + bittorrent::getIntParam(data, 9)); } public: RangeBtMessage(uint8_t id, const char* name, |
