From 5a3f3e43a6c29c59efc5f7b9dfd3a3147df8af08 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sun, 21 May 2017 09:16:41 -0700 Subject: [PATCH] Fix C++03 build issues on PDU option --- include/tins/pdu_option.h | 8 ++++++++ src/pdu_option.cpp | 26 ++++++++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/include/tins/pdu_option.h b/include/tins/pdu_option.h index 4724e56..e866128 100644 --- a/include/tins/pdu_option.h +++ b/include/tins/pdu_option.h @@ -54,6 +54,8 @@ namespace Internals { namespace Converters { uint8_t convert(const uint8_t* ptr, uint32_t data_size, PDU::endian_type endian, type_to_type); + int8_t convert(const uint8_t* ptr, uint32_t data_size, PDU::endian_type endian, + type_to_type); uint16_t convert(const uint8_t* ptr, uint32_t data_size, PDU::endian_type endian, type_to_type); uint32_t convert(const uint8_t* ptr, uint32_t data_size, PDU::endian_type endian, @@ -110,6 +112,12 @@ namespace Internals { PDUType::endianness, type); } + template + static U do_convert(const PDUOption& opt, type_to_type type) { + return Converters::convert(opt.data_ptr(), opt.data_size(), + PDUType::endianness, type); + } + template static U do_convert(const PDUOption& opt, type_to_type type) { return Converters::convert(opt.data_ptr(), opt.data_size(), diff --git a/src/pdu_option.cpp b/src/pdu_option.cpp index 90b2450..de85404 100644 --- a/src/pdu_option.cpp +++ b/src/pdu_option.cpp @@ -81,11 +81,10 @@ vector convert_vector(const uint8_t* u8_ptr, uint32_t data_size, PDU::endian_ return output; } -template::value && - is_unsigned_integral::value>::type> -vector > convert_vector(const uint8_t* ptr, uint32_t data_size, - PDU::endian_type endian) { +template +typename enable_if::value && is_unsigned_integral::value, + vector > >::type +convert_vector(const uint8_t* ptr, uint32_t data_size, PDU::endian_type endian) { if (data_size % (sizeof(T) + sizeof(U)) != 0) { throw malformed_option(); } @@ -111,10 +110,10 @@ vector > convert_vector(const uint8_t* ptr, uint32_t data_size, return output; } -template::value && - is_unsigned_integral::value>::type> -std::pair convert_pair(const uint8_t* ptr, uint32_t data_size, PDU::endian_type endian) { +template +typename enable_if::value && is_unsigned_integral::value, + std::pair >::type +convert_pair(const uint8_t* ptr, uint32_t data_size, PDU::endian_type endian) { if (data_size != sizeof(T) + sizeof(U)) { throw malformed_option(); } @@ -139,6 +138,13 @@ uint8_t convert(const uint8_t* ptr, uint32_t data_size, PDU::endian_type, type_t return *ptr; } +int8_t convert(const uint8_t* ptr, uint32_t data_size, PDU::endian_type, type_to_type) { + if (data_size != 1) { + throw malformed_option(); + } + return *ptr; +} + uint16_t convert(const uint8_t* ptr, uint32_t data_size, PDU::endian_type endian, type_to_type) { return convert_to_integral(ptr, data_size, endian); @@ -250,7 +256,7 @@ vector convert(const uint8_t* ptr, uint32_t data_size, PDU::endian_ return output; } -vector> convert(const uint8_t* ptr, uint32_t data_size, +vector > convert(const uint8_t* ptr, uint32_t data_size, PDU::endian_type endian, type_to_type > >) { return convert_vector(ptr, data_size, endian);