diff options
author | Sven Gothel <[email protected]> | 2021-10-28 02:23:55 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2021-10-28 02:23:55 +0200 |
commit | d787e6a4a93a61b4e7e2d28f8e7b6bd11674c01a (patch) | |
tree | 6870b295f3a96a836efa861107b0aac8e09d890f | |
parent | 4257942ad783c31ff1d6a390caee4b8c264eba8e (diff) |
TOctets: Add convenient memmove*, memset* and bzero* methods; Ensure all memory ops are either std:: or global namespace ::
-rw-r--r-- | include/jau/octets.hpp | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/include/jau/octets.hpp b/include/jau/octets.hpp index ded5759..883111a 100644 --- a/include/jau/octets.hpp +++ b/include/jau/octets.hpp @@ -406,25 +406,53 @@ namespace jau { void put_octets(const nsize_t i, const TROOctets & v) { check_range(i, v.size()); - memcpy(data() + i, v.get_ptr(), v.size()); + std::memcpy(data() + i, v.get_ptr(), v.size()); } void put_octets_nc(const nsize_t i, const TROOctets & v) noexcept { - memcpy(data() + i, v.get_ptr(), v.size()); + std::memcpy(data() + i, v.get_ptr(), v.size()); } void put_bytes(const nsize_t i, const uint8_t *source, const nsize_t byte_count) { check_range(i, byte_count); - memcpy(data() + i, source, byte_count); + std::memcpy(data() + i, source, byte_count); } void put_bytes_nc(const nsize_t i, const uint8_t *source, const nsize_t byte_count) noexcept { - memcpy(data() + i, source, byte_count); + std::memcpy(data() + i, source, byte_count); + } + + void memmove(const nsize_t i, const uint8_t *source, const nsize_t byte_count) { + check_range(i, byte_count); + std::memmove(data() + i, source, byte_count); + } + void memmove_nc(const nsize_t i, const uint8_t *source, const nsize_t byte_count) noexcept { + std::memmove(data() + i, source, byte_count); + } + + void memset(const nsize_t i, const uint8_t c, const nsize_t byte_count) { + check_range(i, byte_count); + std::memset(data() + i, c, byte_count); + } + void memset_nc(const nsize_t i, const uint8_t c, const nsize_t byte_count) noexcept { + std::memset(data() + i, c, byte_count); + } + void bzero(const nsize_t i, const nsize_t byte_count) { + check_range(i, byte_count); + ::bzero(data() + i, byte_count); + } + void bzero_nc(const nsize_t i, const nsize_t byte_count) noexcept { + ::bzero(data() + i, byte_count); + } + void bzero() noexcept { + if( size() > 0 ) { + ::bzero(data(), size()); + } } void put_string(const nsize_t i, const std::string & v, const nsize_t max_len, const bool includeEOS) { const nsize_t size1 = v.size() + ( includeEOS ? 1 : 0 ); const nsize_t size = std::min(size1, max_len); check_range(i, size); - memcpy(data() + i, v.c_str(), size); + std::memcpy(data() + i, v.c_str(), size); if( size < size1 && includeEOS ) { *(data() + i + size - 1) = 0; // ensure EOS } @@ -432,7 +460,7 @@ namespace jau { void put_string_nc(const nsize_t i, const std::string & v, const nsize_t max_len, const bool includeEOS) noexcept { const nsize_t size1 = v.size() + ( includeEOS ? 1 : 0 ); const nsize_t size = std::min(size1, max_len); - memcpy(data() + i, v.c_str(), size); + std::memcpy(data() + i, v.c_str(), size); if( size < size1 && includeEOS ) { *(data() + i + size - 1) = 0; // ensure EOS } |