MDF Lib 2.2
Interface against MDF 3/4 files
Loading...
Searching...
No Matches
mdfreader.h
1/*
2 * Copyright 2021 Ingemar Hedvall
3 * SPDX-License-Identifier: MIT
4 */
5
6#pragma once
7#include <cstdio>
8#include <memory>
9#include <string>
10#include <functional>
11#include <vector>
12
14#include "mdf/mdffile.h"
16
17namespace mdf {
18
19class IChannelGroup;
20
22using ChannelObserverPtr = std::unique_ptr<IChannelObserver>;
24using ChannelObserverList = std::vector<ChannelObserverPtr>;
25
27[[nodiscard]] bool IsMdfFile(const std::string& filename);
28
31 const IDataGroup& data_group, const IChannelGroup& group,
32 const IChannel& channel);
42 const IDataGroup& dg_group, const std::string& channel_name);
43
46 const IChannelGroup& group,
48
62 ChannelObserverList& dest_list);
68class MdfReader {
69 public:
70 explicit MdfReader(
71 const std::string& filename);
73 virtual ~MdfReader();
74
75 MdfReader() = delete;
76 MdfReader(const MdfReader&) = delete;
77 MdfReader(MdfReader&&) = delete;
78 MdfReader& operator=(const MdfReader&) = delete;
79 MdfReader& operator=(MdfReader&&) = delete;
80
86 [[nodiscard]] int64_t Index() const { return index_; }
87
94 void Index(int64_t index) { index_ = index; }
95
98 [[nodiscard]] bool IsOk() const { return static_cast<bool>(instance_); }
99
106 [[nodiscard]] bool IsFinalized() const;
107
111 [[nodiscard]] const MdfFile* GetFile() const { return instance_.get(); }
112
114 [[nodiscard]] const IHeader* GetHeader() const;
116 [[nodiscard]] IDataGroup* GetDataGroup(size_t order) const;
117
118 [[nodiscard]] std::string ShortName()
119 const;
120
121 bool Open();
122 void Close();
123
124 bool ReadHeader();
127
129 bool ExportAttachmentData(const IAttachment& attachment,
130 const std::string& dest_file);
131
145 bool ReadData(IDataGroup& data_group);
146
166 bool ReadPartialData(IDataGroup& data_group, size_t min_sample,
167 size_t max_sample);
168
178
198 bool ReadVlsdData(IDataGroup &data_group,
199 IChannel &vlsd_channel,
200 const std::vector<uint64_t>& offset_list,
201 std::function<void(uint64_t,
202 const std::vector<uint8_t>&)>& callback);
203
204
205 private:
206 std::FILE* file_ = nullptr;
207 std::string filename_;
208 std::unique_ptr<MdfFile> instance_;
209 int64_t index_ = 0;
211};
212
213} // namespace mdf
Interface against an attached file.
Definition iattachment.h:21
Interface against a channel group (CG) block.
Definition ichannelgroup.h:66
Defines a MDF channel (CN) block.
Definition ichannel.h:126
Interface to a data group (DG) block.
Definition idatagroup.h:42
Interface class against an MDF HD block.
Definition iheader.h:34
Defines an interface to a sample reduction (SR) block.
Definition isamplereduction.h:58
Implements an user interface against a MDF file.
Definition mdffile.h:37
Reader interface to an MDF file.
Definition mdfreader.h:68
bool IsOk() const
Definition mdfreader.h:98
bool ReadPartialData(IDataGroup &data_group, size_t min_sample, size_t max_sample)
Reads a range of samples.
bool ReadVlsdData(IDataGroup &data_group, IChannel &vlsd_channel, const std::vector< uint64_t > &offset_list, std::function< void(uint64_t, const std::vector< uint8_t > &)> &callback)
Read in partial variable length data with an offset list.
bool ReadSrData(ISampleReduction &sr_group)
Reads in data bytes to a sample reduction (SR) block.
bool ReadData(IDataGroup &data_group)
Reads all sample, sample reduction and signal data into memory.
bool ReadHeader()
Reads the ID and the HD block.
bool ReadMeasurementInfo()
Reads everything but not CG and raw data.
void Index(int64_t index)
Definition mdfreader.h:94
const MdfFile * GetFile() const
Definition mdfreader.h:111
bool ReadEverythingButData()
Reads all blocks but not raw data.
bool ExportAttachmentData(const IAttachment &attachment, const std::string &dest_file)
Export the attachment data to a detination file.
virtual ~MdfReader()
Destructor that close any open file and destructs.
std::string ShortName() const
Returns the file name without paths.
IDataGroup * GetDataGroup(size_t order) const
Returns the data group (DG) block.
bool Open()
Opens the file stream for reading.
const IHeader * GetHeader() const
Returns the header (HD) block.
MdfReader(const std::string &filename)
void Close()
Closes the file stream.
int64_t Index() const
Definition mdfreader.h:86
bool IsFinalized() const
Return true if the file is marked as finalized.
A channel observer is holds a list of channel samples for a channel.
Interface against an MDF file object.
Main namespace for the MDF library.
Definition canmessage.h:17
ChannelObserverPtr CreateChannelObserver(const IDataGroup &data_group, const IChannelGroup &group, const IChannel &channel)
Creates and attaches a channel sample observer.
bool IsMdfFile(const std::string &filename)
Returns true if the file is an MDF file.
std::unique_ptr< IChannelObserver > ChannelObserverPtr
Smart pointer to an observer.
Definition mdfreader.h:22
std::vector< ChannelObserverPtr > ChannelObserverList
List of observer.
Definition mdfreader.h:24
void CreateChannelObserverForChannelGroup(const IDataGroup &data_group, const IChannelGroup &group, ChannelObserverList &dest)
Creates a channel observer.
void CreateChannelObserverForDataGroup(const IDataGroup &data_group, ChannelObserverList &dest_list)
Creates channel observers for all channels within a data group.