ACF $AcfVersion:0$
TMsbWord.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// ACF includes
6#include <iser/IArchive.h>
7
8
9namespace ibase
10{
11
12
13#pragma pack(push, 1)
14
15
19template <int Size>
21{
22public:
23 TMsbWord();
24 TMsbWord(quint32 inputValue);
25 TMsbWord(const TMsbWord& inputValue);
26
30 operator quint32() const;
31
35 quint32 GetLsb() const;
36
37 // pseudo-reimplemented (iser::ISerializable)
38 bool Serialize(iser::IArchive& archive);
39
40private:
41 quint8 m_bytes[Size];
42};
43
44
45#pragma pack(pop)
46
47
48// inline methods
49
50template <int Size>
52{
53 Q_ASSERT(Size > 0);
54 Q_ASSERT(Size <= 4);
55}
56
57
58template <int Size>
59inline TMsbWord<Size>::TMsbWord(quint32 inputValue)
60{
61 Q_ASSERT(Size > 0);
62 Q_ASSERT(Size <= 4);
63
64 for (int i = 0; i < Size; i++){
65 m_bytes[i] = quint8((inputValue >> (i * 8)) & 0xff);
66 }
67}
68
69
70template <int Size>
71inline TMsbWord<Size>::TMsbWord(const TMsbWord& inputValue)
72{
73 Q_ASSERT(Size > 0);
74 Q_ASSERT(Size <= 4);
75
76 std::memcpy(m_bytes, &inputValue.m_bytes, sizeof(m_bytes));
77}
78
79
80template <int Size>
81inline TMsbWord<Size>::operator quint32() const
82{
83 quint32 retVal = 0;
84
85 for (int i = 0; i < Size; i++){
86 retVal += quint32(m_bytes[i]) << (i * 8);
87 }
88
89 return retVal;
90}
91
92
93template <int Size>
94inline quint32 TMsbWord<Size>::GetLsb() const
95{
96 quint32 retVal = 0;
97
98 for (int i = 0; i < Size; i++){
99 retVal += quint32(m_bytes[Size - i - 1]) << (i * 8);
100 }
101
102 return retVal;
103}
104
105
106// pseudo-reimplemented (iser::ISerializable)
107
108template <int Size>
110{
111 return archive.ProcessData(m_bytes, int(sizeof(m_bytes)));
112}
113
114
117
118
119} // namespace ibase
120
121
122
123
This class represents double word type with network byte order (big endian, MSB first).
Definition TMsbWord.h:21
quint32 GetLsb() const
Returns the value as LSB.
Definition TMsbWord.h:94
bool Serialize(iser::IArchive &archive)
Definition TMsbWord.h:109
Represents an input/output persistence archive for object serialization.
Definition IArchive.h:164
virtual bool ProcessData(void *dataPtr, int size)=0
Process binary data block.
This namespace contains basic implementations of standard primitives on the component level.
TMsbWord< 2 > CMsbWord
Definition TMsbWord.h:116
TMsbWord< 4 > CMsbDWord
Definition TMsbWord.h:115