-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsection1.cpp
More file actions
125 lines (106 loc) · 2.77 KB
/
section1.cpp
File metadata and controls
125 lines (106 loc) · 2.77 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <iostream>
#include <chrono>
#include <cstdint>
#include "section1.h"
using namespace std::chrono;
using namespace std::chrono_literals;
std::istream& operator>>(std::istream& is, Section1& s)
{
char buffer[7];
// Size of section
is.read(buffer, 3);
if (is) {
s.m_size = (buffer[0] << 16) + (buffer[1] << 8) + buffer[2];
if (s.m_size < 22 && s.m_size > 23) {
is.setstate(std::ios_base::failbit);
}
}
// master table in use
is.read(buffer, 1);
if (is) {
s.m_masterTable = static_cast<uint8_t>(buffer[0]);
}
// originating centre
is.read(buffer, 2);
if (is) {
s.m_origCentre = (unsigned(buffer[0]) << 8) + unsigned(buffer[1]);
}
// originating subcentre
is.read(buffer, 2);
if (is) {
s.m_origSubcentre = (unsigned(buffer[0]) << 8) + unsigned(buffer[1]);
}
// update
is.read(buffer, 1);
if (is) {
s.m_update = static_cast<uint8_t>(buffer[0]);
}
// optional section 2 presence flag
is.read(buffer, 1);
if (is) {
s.m_optionalSection2 = static_cast<uint8_t>(buffer[0]);
}
// data category
is.read(buffer, 1);
if (is) {
s.m_dataCategory = static_cast<uint8_t>(buffer[0]);
}
// data subcategory
is.read(buffer, 1);
if (is) {
s.m_dataSubcategory = static_cast<uint8_t>(buffer[0]);
}
// local data subcategory
is.read(buffer, 1);
if (is) {
s.m_localDataSubcategory = static_cast<uint8_t>(buffer[0]);
}
// master table version
is.read(buffer, 1);
if (is) {
s.m_masterTableVersion = static_cast<uint8_t>(buffer[0]);
}
// local table version
is.read(buffer, 1);
if (is) {
s.m_localTableVersion = static_cast<uint8_t>(buffer[0]);
}
// date
is.read(buffer, 7);
if (is) {
s.m_time = sys_days{
std::chrono::year_month_day{
year{(uint8_t(buffer[0]) << 8) + uint8_t(buffer[1])}/buffer[2]/buffer[3]
}
} +
hours{buffer[4]} +
minutes{buffer[5]} +
seconds{buffer[6]};
}
// optional field
if (is && s.m_size > 22) {
is.read(buffer, 1);
if (is) {
s.m_optionalLocalField = static_cast<uint8_t>(buffer[0]);
}
}
return is;
}
std::ostream& operator<<(std::ostream& os, const Section1& s)
{
std::println(os, "size: {}", s.m_size);
std::println(os, "master table: {}", s.m_masterTable);
std::println(os, "originating centre: {}", s.m_origCentre);
std::println(os, "originating subcentre: {}", s.m_origSubcentre);
std::println(os, "update: {}", s.m_update);
std::println(os, "section 2 present: {}", s.m_optionalSection2);
std::println(os, "data category: {}", s.m_dataCategory);
std::println(os, "data subcategory: {}", s.m_dataSubcategory);
std::println(os, "master table version: {}", s.m_masterTableVersion);
std::println(os, "local table version: {}", s.m_localTableVersion);
std::println(os, "time: {}", s.m_time);
if (s.m_size > 22) {
std::println(os, "local field: {}", s.m_optionalLocalField);
}
return os;
}