PLCnext API Documentation 25.0.2.69
ByteConverter.hpp
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include <algorithm>
9
10namespace Arp { namespace Base { namespace Core
11{
12
14class ARP_EXPORT ByteConverter
15{
16private: // construction/destruction
17 ByteConverter(void) = delete;
18 ByteConverter(const ByteConverter& arg) = delete;
19 ByteConverter& operator=(const ByteConverter& arg) = delete;
20 ~ByteConverter(void) = delete;
21
22public: // static operations
23 template<class T>
24 static void Swap(T& value);
25 static void Swap(byte* pBuffer, size_t size);
26
27 template<class T>
28 static void ReverseCopy(const T& source, T& target);
29 static void ReverseCopy(const byte* pSource, byte* pTarget, size_t size);
30};
31
33// inline methods of class ByteConverter
34
38template<class T>
39inline void ByteConverter::Swap(T& value)
40{
41 Swap(reinterpret_cast<byte*>(&value), sizeof(T));
42}
43
47template<class T>
48inline void ByteConverter::ReverseCopy(const T& source, T& target)
49{
50 const byte* pSource = reinterpret_cast<const byte*>(&source);
51 byte* pTarget = reinterpret_cast<byte*>(&target);
52 ReverseCopy(pSource, pTarget, sizeof(T));
53}
54
55}}} // end of namespace Arp::Base::Core
56
57namespace Arp {
60}
This pure static class provides operations for byte converting from little to big endian and vice ver...
Definition: ByteConverter.hpp:15
static void ReverseCopy(const T &source, T &target)
Copies the reverted bytes of the source argument to the target argument.
Definition: ByteConverter.hpp:48
static void Swap(T &value)
Swaps the bytes of the as argument passed value of any primitive type.
Definition: ByteConverter.hpp:39
Root namespace for the PLCnext API