Explorar el Código

Make endian_wrapper copy ctor/assignment trivial

master
Emil-Jarosz hace 3 años
padre
commit
d76ee8c6a9
Se han modificado 2 ficheros con 14 adiciones y 19 borrados
  1. +3
    -4
      include/gp/ipc/envelope/cbor.hpp
  2. +11
    -15
      include/gp/math/boolean/bitops.hpp

+ 3
- 4
include/gp/ipc/envelope/cbor.hpp Ver fichero

@ -126,19 +126,19 @@ namespace gp {
} else if(norm_v < (1ll<<16ll)) {
endian_wrapper<uint16_t, endian::big> wrapper = norm_v;
src.push_back(header+25);
for(auto byte : wrapper.bytes) {
for(auto byte : wrapper.bytes()) {
src.push_back(byte);
}
} else if(norm_v < (1ll<<32ll)) {
endian_wrapper<uint32_t, endian::big> wrapper = norm_v;
src.push_back(header+26);
for(auto byte : wrapper.bytes) {
for(auto byte : wrapper.bytes()) {
src.push_back(byte);
}
} else {
endian_wrapper<uint64_t, endian::big> wrapper = norm_v;
src.push_back(header+27);
for(auto byte : wrapper.bytes) {
for(auto byte : wrapper.bytes()) {
src.push_back(byte);
}
}
@ -477,4 +477,3 @@ namespace gp {
}
}
}

+ 11
- 15
include/gp/math/boolean/bitops.hpp Ver fichero

@ -29,35 +29,31 @@ T swap_endian(T value) noexcept {
template<typename T, endian mode = endian::big>
struct endian_wrapper {
T value = 0;
union {
T value;
gp::array<uint8_t, sizeof(T)> bytes;
};
endian_wrapper() noexcept
: value{0} {}
constexpr endian_wrapper() noexcept = default;
endian_wrapper(T v) noexcept
: value{adjust(v)} {}
endian_wrapper(const endian_wrapper& v) noexcept
: value{v.value} {}
endian_wrapper& operator=(T v) noexcept {
value = adjust(v);
return *this;
}
endian_wrapper& operator=(const endian_wrapper& v) noexcept {
value = v.value;
return *this;
}
operator T() const noexcept {
return adjust(value);
}
auto bytes() const noexcept -> gp::array<uint8_t, sizeof(T)> {
union {
T t;
gp::array<uint8_t, sizeof(T)> bytes;
} tmp {.t = value};
return tmp.bytes;
}
// arithmetic assignment operators
endian_wrapper& operator+=(T rhs) noexcept {

Cargando…
Cancelar
Guardar