MDF Lib 2.2
Interface against MDF 3/4 files
Loading...
Searching...
No Matches
idatagroup.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 Ingemar Hedvall
3 * SPDX-License-Identifier: MIT
4 */
5
10#pragma once
11#include <string>
12#include <vector>
13#include <map>
14
15#include "mdf/iblock.h"
16
17
18namespace mdf {
19
20class IMetaData;
21class ISampleObserver;
22class IChannelGroup;
23class IChannel;
42class IDataGroup : public IBlock {
43 public:
44
46 virtual void Description(const std::string& desc);
48 [[nodiscard]] virtual std::string Description() const;
49
52 virtual void RecordIdSize(uint8_t id_size);
54 [[nodiscard]] virtual uint8_t RecordIdSize() const;
55
57 [[nodiscard]] virtual std::vector<IChannelGroup*> ChannelGroups() const = 0;
58
60 [[nodiscard]] virtual IChannelGroup* CreateChannelGroup() = 0;
61
64 const std::string_view& name);
65
67 [[nodiscard]] IChannelGroup* GetChannelGroup(const std::string_view& name) const;
68
70 [[nodiscard]] IChannelGroup* GetChannelGroup(uint64_t record_id) const;
71
73 [[nodiscard]] virtual IMetaData* CreateMetaData();
75 [[nodiscard]] virtual IMetaData* MetaData() const;
76
81 void DetachSampleObserver(const ISampleObserver* observer) const;
85 bool NotifySampleObservers(size_t sample, uint64_t record_id,
86 const std::vector<uint8_t>& record) const;
87
95 virtual void ClearData();
96
98 void SetAsRead(bool mark_as_read = true) const {
99 mark_as_read_ = mark_as_read;
100 }
101
103 [[nodiscard]] bool IsEmpty() const;
104
107 [[nodiscard]] bool IsRead() const { return mark_as_read_; }
108
112 [[nodiscard]] virtual IChannelGroup *FindParentChannelGroup(
113 const IChannel &channel) const = 0;
114
120 [[nodiscard]] bool IsSubscribingOnRecord(uint64_t record_id) const;
121
127 [[nodiscard]] bool IsSubscribingOnChannel(const IChannel& channel) const;
128
134 [[nodiscard]] bool IsSubscribingOnChannelVlsd(const IChannel& channel) const;
135 protected:
136 mutable std::vector<ISampleObserver*> observer_list_;
137
141 std::map<uint64_t, std::vector<ISampleObserver*> > fast_observer_list_;
142
143 ~IDataGroup() override = default;
144
152
153 private:
154 mutable bool mark_as_read_ = false;
155
156
157};
158
159} // namespace mdf
Base class for all MDF blocks.
Definition iblock.h:19
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
virtual void RecordIdSize(uint8_t id_size)
Sets size of the record ID (bytes). Note that record ID and its size, is automatically set when writi...
virtual IChannelGroup * FindParentChannelGroup(const IChannel &channel) const =0
Support function that return the first CG block that contains a specific CN block.
void SetAsRead(bool mark_as_read=true) const
Set the DG blocks data as read.
Definition idatagroup.h:98
bool NotifySampleObservers(size_t sample, uint64_t record_id, const std::vector< uint8_t > &record) const
Notifies the observer that a new sample record have been read.
bool IsSubscribingOnChannelVlsd(const IChannel &channel) const
Checks if this data group subscribes on a specific channels VLSD raw data.
virtual uint8_t RecordIdSize() const
Returns the record ID size in bytes.
virtual std::vector< IChannelGroup * > ChannelGroups() const =0
Returns a list of channel groups.
virtual void ClearData()
Clear all temporary sample and data buffers.
bool IsSubscribingOnRecord(uint64_t record_id) const
Checks if this data group subscribes on a specific record.
void DetachAllSampleObservers() const
Detaches all observers from the measurement.
virtual void Description(const std::string &desc)
Sets the descriptive text for the measurement.
virtual std::string Description() const
Return the descriptive text.
bool IsSubscribingOnChannel(const IChannel &channel) const
Checks if this data group subscribes on a specific channel.
void DetachSampleObserver(const ISampleObserver *observer) const
Detach an observer from the measurement.
IChannelGroup * GetChannelGroup(const std::string_view &name) const
Returns the existing group by its name.
IChannelGroup * CreateChannelGroup(const std::string_view &name)
Create a new channel group or return the existing group.
std::map< uint64_t, std::vector< ISampleObserver * > > fast_observer_list_
The fast observer list is used internally when reading data.
Definition idatagroup.h:141
IChannelGroup * GetChannelGroup(uint64_t record_id) const
Return a channel group by its record id.
std::vector< ISampleObserver * > observer_list_
List of observers.
Definition idatagroup.h:136
~IDataGroup() override=default
Default destructor.
void InitFastObserverList()
The function optimize the observer list before reading data.
bool IsRead() const
Return true if the DG blocks data has been read not the DG block itself.
Definition idatagroup.h:107
bool IsEmpty() const
Returns true if no samples has been stored yet.
void AttachSampleObserver(ISampleObserver *observer) const
Internal function that attach a sample observer to the measurement block.
virtual IMetaData * MetaData() const
Returns the existing meta-data (MD) block if it exist.
virtual IMetaData * CreateMetaData()
Create or return the existing meta-data (MD) block.
virtual IChannelGroup * CreateChannelGroup()=0
Create a new empty channel group.
Interface against an meta data block (MD) in a MDF4 file.
Definition imetadata.h:27
Interface to a sample observer that handle incoming samples events.
Definition isampleobserver.h:23
All MDF blocks inherits from the IBlock class. The interface class is used internally in lists....
Main namespace for the MDF library.
Definition canmessage.h:17