diff --git a/data/FixedSizeData.h b/data/FixedSizeData.h index c5aa84fe..e48e8127 100644 --- a/data/FixedSizeData.h +++ b/data/FixedSizeData.h @@ -9,14 +9,14 @@ namespace cpputils { -template +template class FixedSizeData final { public: //Non-virtual destructor because we want objects to be small ~FixedSizeData() {} - static constexpr unsigned int BINARY_LENGTH = SIZE; - static constexpr unsigned int STRING_LENGTH = 2 * BINARY_LENGTH; // Hex encoding + static constexpr size_t BINARY_LENGTH = SIZE; + static constexpr size_t STRING_LENGTH = 2 * BINARY_LENGTH; // Hex encoding //TODO Test Null() static FixedSizeData Null(); @@ -35,27 +35,27 @@ public: private: FixedSizeData() {} - template friend class FixedSizeData; + template friend class FixedSizeData; unsigned char _data[BINARY_LENGTH]; }; -template bool operator==(const FixedSizeData &lhs, const FixedSizeData &rhs); -template bool operator!=(const FixedSizeData &lhs, const FixedSizeData &rhs); +template bool operator==(const FixedSizeData &lhs, const FixedSizeData &rhs); +template bool operator!=(const FixedSizeData &lhs, const FixedSizeData &rhs); // ----- Implementation ----- -template constexpr unsigned int FixedSizeData::BINARY_LENGTH; -template constexpr unsigned int FixedSizeData::STRING_LENGTH; +template constexpr size_t FixedSizeData::BINARY_LENGTH; +template constexpr size_t FixedSizeData::STRING_LENGTH; -template +template FixedSizeData FixedSizeData::Null() { FixedSizeData result; std::memset(result._data, 0, BINARY_LENGTH); return result; } -template +template FixedSizeData FixedSizeData::FromString(const std::string &data) { ASSERT(data.size() == STRING_LENGTH, "Wrong string size for parsing FixedSizeData"); FixedSizeData result; @@ -67,7 +67,7 @@ FixedSizeData FixedSizeData::FromString(const std::string &data) { return result; } -template +template std::string FixedSizeData::ToString() const { std::string result; CryptoPP::ArraySource(_data, BINARY_LENGTH, true, @@ -79,29 +79,29 @@ std::string FixedSizeData::ToString() const { return result; } -template +template const unsigned char *FixedSizeData::data() const { return _data; } -template +template unsigned char *FixedSizeData::data() { return const_cast(const_cast*>(this)->data()); } -template +template void FixedSizeData::ToBinary(void *target) const { std::memcpy(target, _data, BINARY_LENGTH); } -template +template FixedSizeData FixedSizeData::FromBinary(const void *source) { FixedSizeData result; std::memcpy(result._data, source, BINARY_LENGTH); return result; } -template template +template template FixedSizeData FixedSizeData::take() const { static_assert(size <= SIZE, "Out of bounds"); FixedSizeData result; @@ -109,7 +109,7 @@ FixedSizeData FixedSizeData::take() const { return result; } -template template +template template FixedSizeData FixedSizeData::drop() const { static_assert(size <= SIZE, "Out of bounds"); FixedSizeData result; @@ -117,12 +117,12 @@ FixedSizeData FixedSizeData::drop() const { return result; } -template +template bool operator==(const FixedSizeData &lhs, const FixedSizeData &rhs) { return 0 == std::memcmp(lhs.data(), rhs.data(), FixedSizeData::BINARY_LENGTH); } -template +template bool operator!=(const FixedSizeData &lhs, const FixedSizeData &rhs) { return !operator==(lhs, rhs); }