QtFit  0.1
Internal library development documentation
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
fitstreamreader_p.h
Go to the documentation of this file.
1 /*
2  Copyright 2021 Paul Colby
3 
4  This file is part of QtFit.
5 
6  QtFit is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  QtFit is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with QtFit. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 /*!
21  * \file
22  * Declares the FitStreamReaderPrivate class.
23  */
24 
25 #ifndef FITSTREAMREADER_P_H
26 #define FITSTREAMREADER_P_H
27 
28 #include "types_p.h"
29 
30 #include <QByteArray>
31 #include <QHash>
32 #include <QIODevice>
33 #include <QVersionNumber>
34 
36 
38 class FitStreamReader;
39 
41 
42 public:
43 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
44  typedef qsizetype size_t; ///< Size type for size-related operations.
45 #else
46  typedef int size_t; ///< Size type for size-related operations.
47 #endif
48 
49  QByteArray data; ///< FIT File data (alternative to \c device).
50  size_t dataOffset; ///< Current position within \c data.
51  QIODevice *device; ///< FIT File IO stream (alternative to \c data and \c dataOffset).
52 
53  explicit FitStreamReaderPrivate(FitStreamReader * const q);
54  virtual ~FitStreamReaderPrivate();
55 
56 protected:
57  FitStreamReader * const q_ptr; ///< Internal q-pointer.
58 
59  template<class T> size_t bytesAvailable() const;
60  template<class T> bool parseFileHeader();
61  template<class T> bool parseDefinitionMessage();
62  template<class T> AbstractDataMessage * parseDataMessage();
63  template<class T> quint8 peekByte(const int pos=0) const;
64  template<class T> QByteArray readBytes(const size_t size);
65  template<class T> QByteArray readFileHeader();
66  template<class T> AbstractDataMessage * readNextDataMessage();
67 
68  static inline quint16 fitChecksum(const QByteArray &data);
69  static inline bool isDefinitionMessage(const quint8 recordHeader);
70 
71 private:
72 // quint8 headerSize;
73  QVersionNumber protocolVersion; ///< Protocol version read from the parsed FIT file header.
74  QVersionNumber profileVersion; ///< Protocol version read from the parsed FIT file header.
75  quint32 expectedDataSize; ///< Total size, in bytes, expected to comprise the FIT file.
76 // quint32 expectedChecksum;
77 
78  QHash<int, DataDefinition> dataDefinitions; ///< Local message types to current data definitions.
79  QHash<int, int> recordSizes; ///< Local message types to current record sizes.
80 
81  Q_DECLARE_PUBLIC(FitStreamReader)
82  Q_DISABLE_COPY(FitStreamReaderPrivate)
83 
84 };
85 
87 
88 #endif // FITSTREAMREADER_P_H
#define QTFIT_END_NAMESPACE
Macro for ending the QtFit library's top-most namespace (if one is defined).
Definition: QtFit_global.h:78
#define QTFIT_BEGIN_NAMESPACE
Macro for starting the QtFit library's top-most namespace (if one is defined).
Definition: QtFit_global.h:77
The AbstractDataMessage class is the polymorphic base class for all FIT Data Message classes.
Provides private implementation for FitStreamReader.
quint32 expectedDataSize
Total size, in bytes, expected to comprise the FIT file.
AbstractDataMessage * readNextDataMessage()
Reads up to, and including, the next FIT Data Message.
QIODevice * device
FIT File IO stream (alternative to data and dataOffset).
static bool isDefinitionMessage(const quint8 recordHeader)
Returns true if recordHeader indicates a Definition Message, otherwise false.
bool parseDefinitionMessage()
Reads and parses a FIT Definition Message.
QByteArray data
FIT File data (alternative to device).
quint8 peekByte(const int pos=0) const
Peeks the next pos'th byte in the FIT stream.
FitStreamReader *const q_ptr
Internal q-pointer.
static quint16 fitChecksum(const QByteArray &data)
Calculates a checksum, as per the algorithm used by FIT file headers.
AbstractDataMessage * parseDataMessage()
Reads and parses a FIT Data Message.
QVersionNumber profileVersion
Protocol version read from the parsed FIT file header.
size_t bytesAvailable() const
Returns the number of bytes currently available for reading.
QByteArray readFileHeader()
Reads all bytes of the FIT stream file header.
QVersionNumber protocolVersion
Protocol version read from the parsed FIT file header.
size_t dataOffset
Current position within data.
QHash< int, DataDefinition > dataDefinitions
Local message types to current data definitions.
FitStreamReaderPrivate(FitStreamReader *const q)
Constructs a FitStreamReaderPrivate object, with public implementation q.
qsizetype size_t
Size type for size-related operations.
bool parseFileHeader()
Reads and parses the FIT stream's file header.
QByteArray readBytes(const size_t size)
Reads the next size bytes from the FIT stream.
virtual ~FitStreamReaderPrivate()
Destroys the FitStreamReaderPrivate object.
QHash< int, int > recordSizes
Local message types to current record sizes.
The FitStreamReader class provides a streaming parser for reading Garmin FIT files.
Internal types used by QtFit classes.