lib/mdflib/docs/manual/html/mdfreader_8h_source.html
| 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
13#include "mdf/ichannelobserver.h"
14#include "mdf/mdffile.h"
15#include "mdf/isamplereduction.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
30[[nodiscard]] ChannelObserverPtr CreateChannelObserver(
31const IDataGroup& data_group, const IChannelGroup& group,
32const IChannel& channel);
41[[nodiscard]] ChannelObserverPtr CreateChannelObserver(
42const IDataGroup& dg_group, const std::string& channel_name);
43
45void CreateChannelObserverForChannelGroup(const IDataGroup& data_group,
46const IChannelGroup& group,
47ChannelObserverList& dest);
48
61void CreateChannelObserverForDataGroup(const IDataGroup& data_group,
62ChannelObserverList& dest_list);
69 public:
71const std::string& filename);
73virtual ~MdfReader();
74
75MdfReader() = delete;
76MdfReader(const MdfReader&) = delete;
77MdfReader(MdfReader&&) = delete;
78MdfReader& operator=(const MdfReader&) = delete;
79MdfReader& operator=(MdfReader&&) = delete;
80
86 [[nodiscard]] int64_t Index() const { return index_; }
87
94void 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()
119const;
120
123
124bool ReadHeader();
125bool ReadMeasurementInfo();
126bool ReadEverythingButData();
127
129bool ExportAttachmentData(const IAttachment& attachment,
130const std::string& dest_file);
131
145bool ReadData(IDataGroup& data_group);
146
166bool ReadPartialData(IDataGroup& data_group, size_t min_sample,
167size_t max_sample);
168
177bool ReadSrData(ISampleReduction& sr_group);
178
198bool ReadVlsdData(IDataGroup &data_group,
199IChannel &vlsd_channel,
200const std::vector<uint64_t>& offset_list,
201 std::function<void(uint64_t,
202const 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
mdf::MdfReader::ReadPartialData
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.
mdf::MdfReader::ReadMeasurementInfo
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
mdf::MdfReader::ReadEverythingButData
bool ReadEverythingButData()
Reads all blocks but not raw data.
mdf::MdfReader::ExportAttachmentData
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
mdf::CreateChannelObserverForChannelGroup
void CreateChannelObserverForChannelGroup(const IDataGroup &data_group, const IChannelGroup &group, ChannelObserverList &dest)
Creates a channel observer.
mdf::CreateChannelObserverForDataGroup
void CreateChannelObserverForDataGroup(const IDataGroup &data_group, ChannelObserverList &dest_list)
Creates channel observers for all channels within a data group.