djiparsetxt
FieldDatabase.hh
Go to the documentation of this file.
1 /**********
2 This program is free software: you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation, either version 3 of the License, or
5 (at your option) any later version.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11 
12 You should have received a copy of the GNU General Public License
13 along with this program. If not, see <http://www.gnu.org/licenses/>.
14 **********/
15 /*
16  A C++ program to parse DJI's ".txt" log files (recorded by the "DJI Go 4" app).
17  Version 2021-05-20
18 
19  Copyright (c) 2021 Live Networks, Inc. All rights reserved.
20  For the latest version of this program (and more information), visit http://djilogs.live555.com
21 
22  A database that stores values of fields. (Each field is indexed by a 'label' (column name).)
23  Header File.
24 */
25 
26 #ifndef _FIELD_DATABASE_HH
27 #define _FIELD_DATABASE_HH
28 
29 #ifndef _INTERPRETATION_TABLE_HH
30 #include "InterpretationTable.hh"
31 #endif
32 
33 // How each field value is represented:
34 enum FieldType {
48  };
49 
50 class FieldValue {
51 public:
52  FieldValue(FieldType type, u_int8_t val);
53  FieldValue(FieldType type, u_int16_t val);
54  FieldValue(FieldType type, u_int32_t val);
55  FieldValue(FieldType type, u_int64_t val);
56  FieldValue(FieldType type, float val);
57  FieldValue(FieldType type, double val);
58  FieldValue(FieldType type, char const* str);
59 
60  virtual ~FieldValue();
61 
62 private:
63  friend class FieldDatabase;
65  union {
66  u_int8_t fByte;
67  u_int16_t fBytes2;
68  u_int32_t fBytes4;
69  u_int64_t fBytes8;
70  float fFloat;
71  double fDouble;
72  char const* fStr;
73  };
74 };
75 
77 public:
78  FieldDatabase();
79  virtual ~FieldDatabase();
80 
81 public:
82  // Routines for entering field values into the database:
83  void addByteField(char const* label, u_int8_t value, int isSigned);
84  void add2ByteField(char const* label, u_int16_t value, int isSigned);
85  void add2ByteDateField(char const* label, u_int16_t value);
86  void add4ByteField(char const* label, u_int32_t value, int isSigned);
87  void add4ByteVersionField(char const* label, u_int32_t value);
88  void addFloatField(char const* label, float value);
89  void addDoubleField(char const* label, double value);
90  void add8ByteTimestampField(char const* label, u_int64_t value, int isInMilliseconds);
91  void addStringField(char const* label, char const* str);
92 
93  // Routines for outputting field values (to 'stdout'):
94  void outputField(char const* label, unsigned numFractionalDigits = 0);
95  void outputFieldAsBoolean(char const* label);
96  void outputFieldInterpreted(char const* label, char const* interpretedLabel);
97 
98 private:
99  void addFieldValue(char const* label, FieldValue* fieldValue);
100  FieldValue const* lookupFieldValue(char const* label); // returns NULL if not found
101 
102  void initializeInterpretationTables(); // called by our constructor
104  newInterpretationTable(char const* interpretedLabel,
105  char const* defaultResultString); // called by the above
106 
107 private:
108  // Implement the database using an 'unordered map' - i.e., a hash table:
109  std::unordered_map<char const*, FieldValue*> fUMap;
110 
111  // We also use an 'unordered map' to look up "InterpretationTable"s:
112  std::unordered_map<char const*, InterpretationTable*> fInterpretationTableMap;
113 };
114 
115 #endif
std::unordered_map< char const *, FieldValue * > fUMap
FieldType fType
void initializeInterpretationTables()
char const * fStr
u_int64_t fBytes8
FieldType
InterpretationTable * newInterpretationTable(char const *interpretedLabel, char const *defaultResultString)
void outputFieldInterpreted(char const *label, char const *interpretedLabel)
double fDouble
void add2ByteDateField(char const *label, u_int16_t value)
void add8ByteTimestampField(char const *label, u_int64_t value, int isInMilliseconds)
u_int16_t fBytes2
void addStringField(char const *label, char const *str)
void addFieldValue(char const *label, FieldValue *fieldValue)
std::unordered_map< char const *, InterpretationTable * > fInterpretationTableMap
u_int32_t fBytes4
void addByteField(char const *label, u_int8_t value, int isSigned)
void add4ByteVersionField(char const *label, u_int32_t value)
void add2ByteField(char const *label, u_int16_t value, int isSigned)
FieldValue(FieldType type, u_int8_t val)
void addFloatField(char const *label, float value)
u_int8_t fByte
void outputField(char const *label, unsigned numFractionalDigits=0)
Definition: fieldOutput.cpp:30
void addDoubleField(char const *label, double value)
virtual ~FieldValue()
void outputFieldAsBoolean(char const *label)
void add4ByteField(char const *label, u_int32_t value, int isSigned)
FieldValue const * lookupFieldValue(char const *label)
virtual ~FieldDatabase()