-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFieldDatabase.hh
115 lines (97 loc) · 3.69 KB
/
FieldDatabase.hh
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
/**********
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**********/
/*
A C++ program to parse DJI's ".txt" log files (recorded by the "DJI Go 4" app).
Version 2019-02-08
Copyright (c) 2019 Live Networks, Inc. All rights reserved.
For the latest version of this program (and more information), visit http://djilogs.live555.com
A database that stores values of fields. (Each field is indexed by a 'label' (column name).)
Header File.
*/
#ifndef _FIELD_DATABASE_HH
#define _FIELD_DATABASE_HH
#ifndef _INTERPRETATION_TABLE_HH
#include "InterpretationTable.hh"
#endif
// How each field value is represented:
enum FieldType {
IntegerByteUnsigned,
IntegerByteSigned,
Integer2ByteUnsigned,
Integer2ByteSigned,
Date2Byte,
Integer4ByteUnsigned,
Integer4ByteSigned,
Version4Byte,
Float,
Double,
Timestamp8ByteInSeconds,
Timestamp8ByteInMilliseconds,
String
};
class FieldValue {
public:
FieldValue(FieldType type, u_int8_t val);
FieldValue(FieldType type, u_int16_t val);
FieldValue(FieldType type, u_int32_t val);
FieldValue(FieldType type, u_int64_t val);
FieldValue(FieldType type, float val);
FieldValue(FieldType type, double val);
FieldValue(FieldType type, char const* str);
virtual ~FieldValue();
private:
friend class FieldDatabase;
FieldType fType;
union {
u_int8_t fByte;
u_int16_t fBytes2;
u_int32_t fBytes4;
u_int64_t fBytes8;
float fFloat;
double fDouble;
char const* fStr;
};
};
class FieldDatabase {
public:
FieldDatabase();
virtual ~FieldDatabase();
public:
// Routines for entering field values into the database:
void addByteField(char const* label, u_int8_t value, int isSigned);
void add2ByteField(char const* label, u_int16_t value, int isSigned);
void add2ByteDateField(char const* label, u_int16_t value);
void add4ByteField(char const* label, u_int32_t value, int isSigned);
void add4ByteVersionField(char const* label, u_int32_t value);
void addFloatField(char const* label, float value);
void addDoubleField(char const* label, double value);
void add8ByteTimestampField(char const* label, u_int64_t value, int isInMilliseconds);
void addStringField(char const* label, char const* str);
// Routines for outputting field values (to 'stdout'):
void outputField(char const* label, unsigned numFractionalDigits = 0);
void outputFieldAsBoolean(char const* label);
void outputFieldInterpreted(char const* label, char const* interpretedLabel);
private:
void addFieldValue(char const* label, FieldValue* fieldValue);
FieldValue const* lookupFieldValue(char const* label); // returns NULL if not found
void initializeInterpretationTables(); // called by our constructor
InterpretationTable*
newInterpretationTable(char const* interpretedLabel,
char const* defaultResultString); // called by the above
private:
// Implement the database using an 'unordered map' - i.e., a hash table:
std::unordered_map<char const*, FieldValue*> fUMap;
// We also use an 'unordered map' to look up "InterpretationTable"s:
std::unordered_map<char const*, InterpretationTable*> fInterpretationTableMap;
};
#endif