-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleDataField.hpp
More file actions
86 lines (62 loc) · 2.4 KB
/
SimpleDataField.hpp
File metadata and controls
86 lines (62 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#if !defined SIMPLE_DATA_FIELD_HPP
#define SIMPLE_DATA_FIELD_HPP
#include <cstdint>
#include "DataField.hpp"
#include "misc.hpp"
template <class T>
class SimpleDataField : public DataField
{
public:
friend class SimpleDataField_test;
// Does nothing
explicit SimpleDataField();
// Takes an initial value
explicit SimpleDataField(const T& value);
// Copy constructor
explicit SimpleDataField(const SimpleDataField<T>& simple_data_field);
// Defines how to convert a SimpleDataField<T> to a T
operator T() const;
// Does nothing
virtual ~SimpleDataField();
// Reads the data field from the "buffer" memory location, swapping if the
// source byte order does not match the byte ordering of this field.
virtual unsigned long readRaw(std::uint8_t* buffer,
misc::ByteOrder source_byte_order);
// Const-compatible version of the above member function
virtual unsigned long readRaw(const std::uint8_t* buffer,
misc::ByteOrder source_byte_order);
// Writes the data field to the "buffer" memory location, swapping at the
// destination if the destination byte order does not match the byte
// ordering of this field.
virtual unsigned long writeRaw(
std::uint8_t* buffer,
misc::ByteOrder destination_byte_order) const;
// Returns the size of this data field in bits. This will equal the number
// of bits written by writeRaw() and read by readRaw().
virtual unsigned long getLengthBits() const;
// Field value retrieval for small T
T getValue() const;
// Field value retrieval for large T
void getValue(T& value) const;
// Field value mutator
void setValue(const T& value);
SimpleDataField<T>& operator=(const T& simple_type);
private:
T simple_data_field;
};
//==============================================================================
template <class T> inline T SimpleDataField<T>::getValue() const
{
return simple_data_field;
}
//==============================================================================
template <class T> inline void SimpleDataField<T>::getValue(T& value) const
{
value = simple_data_field;
}
//==============================================================================
template <class T> inline void SimpleDataField<T>::setValue(const T& value)
{
simple_data_field = value;
}
#endif