Coverage Report

Created: 2021-08-28 18:14

D:\git\skunkworks\herald-for-cpp\herald\include\herald\payload\extended\extended_data.h
Line
Count
Source (jump to first uncovered line)
1
//  Copyright 2020-2021 Herald Project Contributors
2
//  SPDX-License-Identifier: Apache-2.0
3
//
4
5
#ifndef HERALD_EXTENDED_DATA_H
6
#define HERALD_EXTENDED_DATA_H
7
8
#include "../../datatype/data.h"
9
#include "../../datatype/payload_data.h"
10
#include "../../datatype/payload_timestamp.h"
11
12
#include <optional>
13
#include <cstdint>
14
15
namespace herald {
16
namespace payload {
17
namespace extended {
18
19
using namespace herald::datatype;
20
21
using ExtendedDataSegmentCode = uint8_t;
22
23
// Abstract class only
24
class ExtendedData {
25
public:
26
8
  ExtendedData() = default;
27
8
  virtual ~ExtendedData() = default;
28
29
  virtual bool hasData() const = 0;
30
  virtual void addSection(ExtendedDataSegmentCode code, uint8_t value) = 0;
31
  virtual void addSection(ExtendedDataSegmentCode code, uint16_t value) = 0;
32
  virtual void addSection(ExtendedDataSegmentCode code, float value) = 0;
33
  virtual void addSection(ExtendedDataSegmentCode code, const std::string value) = 0;
34
  virtual void addSection(ExtendedDataSegmentCode code, const Data& value) = 0;
35
36
  virtual PayloadData payload() = 0;
37
};
38
39
// V1 Concrete types
40
// enum class ExtendedDataSegmentCodesV1 : ExtendedDataSegmentCode {
41
//   TextPremises = 0x10,
42
//   TextLocation = 0x11,
43
//   TextArea = 0x12,
44
//   LocationUrl = 0x13
45
// };
46
47
// operator ExtendedDataSegmentCode(const ExtendedDataSegmentCodesV1& from) {
48
//   return static_cast<uint8_t>(from);
49
// };
50
struct ExtendedDataSegmentCodesV1 {
51
  uint8_t value;
52
53
0
  constexpr ExtendedDataSegmentCodesV1(uint8_t v = 0) : value(v) {}
54
3
  constexpr operator uint8_t() const { return value; }
55
56
  static const ExtendedDataSegmentCodesV1 TextPremises, TextLocation, TextArea, LocationUrl;
57
};
58
59
constexpr const ExtendedDataSegmentCodesV1 
60
ExtendedDataSegmentCodesV1::TextPremises(0x10),
61
ExtendedDataSegmentCodesV1::TextLocation(0x11),
62
ExtendedDataSegmentCodesV1::TextArea(0x12),
63
ExtendedDataSegmentCodesV1::LocationUrl(0x13)
64
;
65
66
struct ConcreteExtendedDataSectionV1 {
67
  uint8_t code;
68
  uint8_t length;
69
  Data data;
70
71
32
  ConcreteExtendedDataSectionV1() : code(0), length(0), data() {}
72
73
  ConcreteExtendedDataSectionV1(uint8_t code,uint8_t length,const Data data)
74
    : code(code), length(length), data(data)
75
0
  {
76
0
    ;
77
0
  }
78
79
  ConcreteExtendedDataSectionV1(uint8_t code,const std::string& from) 
80
    : code(code), length(from.size()), data(from)
81
0
  {
82
0
    ;
83
0
  }
84
85
  ConcreteExtendedDataSectionV1(ConcreteExtendedDataSectionV1&& other)
86
    : code(other.code), length(other.length), data(std::move(other.data))
87
0
  {
88
0
    ;
89
0
  }
90
91
  ConcreteExtendedDataSectionV1(const ConcreteExtendedDataSectionV1& other)
92
    : code(other.code), length(other.length), data(other.data)
93
35
  {
94
35
    ;
95
35
  }
96
97
  ConcreteExtendedDataSectionV1& operator=(const ConcreteExtendedDataSectionV1& other) = default;
98
};
99
100
class ConcreteExtendedDataV1 : public ExtendedData {
101
public:
102
  ConcreteExtendedDataV1();
103
  ConcreteExtendedDataV1(const ConcreteExtendedDataV1& other); // copy ctor
104
  ConcreteExtendedDataV1(ConcreteExtendedDataV1&& other); // move ctor
105
  // ConcreteExtendedDataV1& operator=(const ConcreteExtendedDataV1& other); // copy assign
106
  // ConcreteExtendedDataV1& operator=(ConcreteExtendedDataV1&& other); // move assign
107
  ~ConcreteExtendedDataV1();
108
109
  // Overrides
110
  bool hasData() const override;
111
  void addSection(ExtendedDataSegmentCode code, uint8_t value) override;
112
  void addSection(ExtendedDataSegmentCode code, uint16_t value) override;
113
  void addSection(ExtendedDataSegmentCode code, float value) override;
114
  void addSection(ExtendedDataSegmentCode code, const std::string value) override;
115
  void addSection(ExtendedDataSegmentCode code, const Data& value) override;
116
  PayloadData payload() override;
117
118
  // V1 only methods
119
  const std::size_t getSectionCount() const;
120
  const ConcreteExtendedDataSectionV1& getSection(std::size_t index) const;
121
122
private:
123
  // bool mHasData;
124
  std::array<ConcreteExtendedDataSectionV1,8> sections;
125
  std::size_t inUse;
126
};
127
128
}
129
}
130
}
131
132
#endif