adtf_file_library  0.13.2
reader.h
Go to the documentation of this file.
1 
17 #pragma once
18 
19 #include <chrono>
20 #include <memory>
21 #include <vector>
22 #include <unordered_map>
23 #include <istream>
24 #include <string>
25 #include <optional>
26 #include <ifhd/ifhd.h>
27 #include "stream_item.h"
28 #include "object.h"
29 #include "default_sample.h"
30 #include "stream_type.h"
31 #include "configuration.h"
32 
33 namespace adtf_file
34 {
35 
39 namespace exceptions
40 {
45 }
46 
55 class Extension
56 {
57 public:
59  std::string name;
61  uint16_t stream_id;
63  uint32_t user_id;
65  uint32_t type_id;
67  uint32_t version_id;
69  size_t data_size;
71  const void* data;
72 };
73 
78 {
79  public:
84  virtual std::shared_ptr<StreamType> build() const = 0;
85 };
86 
91 template <typename STREAM_TYPE_CLASS>
93 {
94  public:
95  std::shared_ptr<StreamType> build() const override
96  {
97  return std::make_shared<STREAM_TYPE_CLASS>();
98  }
99 };
100 
105 {
106  public:
111  virtual std::shared_ptr<Sample> build() const = 0;
112 };
113 
118 template <typename SAMPLE_CLASS>
120 {
121  public:
122  std::shared_ptr<Sample> build() const override
123  {
124  return std::make_shared<SAMPLE_CLASS>();
125  }
126 };
127 
133 class Stream
134 {
135 public:
137  uint16_t stream_id;
139  std::string name;
141  uint64_t item_count;
143  std::chrono::nanoseconds timestamp_of_first_item;
145  std::chrono::nanoseconds timestamp_of_last_item;
147  std::shared_ptr<const StreamType> initial_type;
148 };
149 
155 class FileItem
156 {
157 public:
159  uint16_t stream_id;
161  std::chrono::nanoseconds time_stamp;
164  std::shared_ptr<const StreamItem> stream_item;
165 };
166 
172 class Reader : public Configurable
173 {
174 public:
179  virtual std::string getReaderIdentifier() const = 0;
180 
190  virtual void open(const std::string& filename,
191  std::shared_ptr<SampleFactory> sample_factory,
192  std::shared_ptr<StreamTypeFactory> stream_type_factory) = 0;
193 
202  virtual FileItem getNextItem() = 0;
203 
211  virtual uint32_t getFileVersion() const
212  {
213  return ifhd::v201_v301::version_id;
214  }
215 
219  virtual std::string getDescription() const
220  {
221  return {};
222  }
223 
228  virtual std::vector<Extension> getExtensions() const
229  {
230  return {};
231  }
232 
237  virtual std::vector<Stream> getStreams() const
238  {
239  return {};
240  }
241 
248  virtual std::optional<uint64_t> getItemCount() const
249  {
250  return {};
251  }
252 
257  virtual std::optional<double> getProgress() const
258  {
259  return {};
260  }
261 };
262 
266 class SeekableReader : public Reader
267 {
268 public:
277  virtual uint64_t getItemIndexForTimeStamp(std::chrono::nanoseconds time_stamp) = 0;
278 
290  virtual uint64_t getItemIndexForStreamItemIndex(uint16_t stream_id, uint64_t stream_item_index) = 0;
291 
302  virtual std::shared_ptr<const StreamType> getStreamTypeBefore(uint64_t item_index, uint16_t stream_id) = 0;
303 
311  virtual void seekTo(uint64_t item_index) = 0;
312 };
313 
318 {};
319 
323 class ReaderFactory: public Object
324 {
325 public:
330  virtual std::shared_ptr<Reader> makeReader() const = 0;
331 };
332 
337 template<typename T>
339 {
340 public:
345  std::shared_ptr<adtf_file::Reader> makeReader() const override
346  {
347  return std::make_shared<T>();
348  }
349 };
350 
355 {
356 public:
361  void add(const std::shared_ptr<const adtf_file::ReaderFactory>& factory);
362 
367  void remove(const std::string& reader_id);
368 
376  std::shared_ptr<adtf_file::Reader> makeReader(const std::string& reader_id) const;
377 
392  std::shared_ptr<adtf_file::Reader> openReader(const std::string& filename,
393  const adtf_file::Configuration& configuration = {},
394  std::shared_ptr<adtf_file::SampleFactory> sample_factory = {},
395  std::shared_ptr<adtf_file::StreamTypeFactory> stream_type_factory = {},
396  std::optional<std::string> reader_id = {}) const;
397 
411  void getCapableReaders(const std::string& filename,
412  const std::function<bool(const std::shared_ptr<Reader>&)>& capable_reader_callback,
413  const adtf_file::Configuration& configuration = {},
414  std::shared_ptr<adtf_file::SampleFactory> sample_factory = {},
415  std::shared_ptr<adtf_file::StreamTypeFactory> stream_type_factory = {}) const;
416 
421  const std::unordered_map<std::string, std::shared_ptr<const ReaderFactory>>& getFactories() const;
422 
423 private:
424  std::unordered_map<std::string, std::shared_ptr<const ReaderFactory>> _factories;
425 };
426 
433 Stream findStream(const Reader& reader, const std::string& stream_name);
434 
440 std::chrono::nanoseconds getFirstTimeOfStreams(const std::vector<Stream>& streams);
441 
447 std::chrono::nanoseconds getLastTimeOfStreams(const std::vector<Stream>& streams);
448 
454 }
455 
456 
Definition: configuration.h:314
Definition: reader.h:318
Extension class for file extension. These extension are i.e.:
Definition: reader.h:56
uint32_t user_id
the user id (if needed)
Definition: reader.h:63
uint32_t type_id
the type id (if needed)
Definition: reader.h:65
const void * data
reference pointer to the data of the extension
Definition: reader.h:71
std::string name
the name of the extension
Definition: reader.h:59
uint32_t version_id
the version id (if needed)
Definition: reader.h:67
uint16_t stream_id
the stream id the extension belongs to
Definition: reader.h:61
size_t data_size
the extension size in bytes
Definition: reader.h:69
class to create or read a file item. This file item is either a sample, streamtype or trigger.
Definition: reader.h:156
std::shared_ptr< const StreamItem > stream_item
Definition: reader.h:164
std::chrono::nanoseconds time_stamp
time stamp of the file item
Definition: reader.h:161
uint16_t stream_id
stream id the file items belongs to
Definition: reader.h:159
base interface class for all available objects of the ADTF File Library that can be added to the obje...
Definition: object.h:33
Definition: reader.h:355
std::shared_ptr< adtf_file::Reader > openReader(const std::string &filename, const adtf_file::Configuration &configuration={}, std::shared_ptr< adtf_file::SampleFactory > sample_factory={}, std::shared_ptr< adtf_file::StreamTypeFactory > stream_type_factory={}, std::optional< std::string > reader_id={}) const
Creates an instance for the given reader_id, sets the given configuration and opens the reader with g...
const std::unordered_map< std::string, std::shared_ptr< const ReaderFactory > > & getFactories() const
Get the Factories.
void remove(const std::string &reader_id)
void add(const std::shared_ptr< const adtf_file::ReaderFactory > &factory)
std::shared_ptr< adtf_file::Reader > makeReader(const std::string &reader_id) const
create an instance for the given reader_id
void getCapableReaders(const std::string &filename, const std::function< bool(const std::shared_ptr< Reader > &)> &capable_reader_callback, const adtf_file::Configuration &configuration={}, std::shared_ptr< adtf_file::SampleFactory > sample_factory={}, std::shared_ptr< adtf_file::StreamTypeFactory > stream_type_factory={}) const
Get all capable readers can open the given file (filename). It will make and open all capable Reader ...
Default Reader factory implementation for readers using a standard default CTOR.
Definition: reader.h:339
std::shared_ptr< adtf_file::Reader > makeReader() const override
make a reader T.
Definition: reader.h:345
Reader Factory interface to create a reader.
Definition: reader.h:324
virtual std::shared_ptr< Reader > makeReader() const =0
Creates a reader.
Definition: reader.h:173
virtual std::string getDescription() const
Definition: reader.h:219
virtual uint32_t getFileVersion() const
Definition: reader.h:211
virtual std::optional< uint64_t > getItemCount() const
Get the Item Count. This gets the overall count of all items (samples, stream types and triggers) of ...
Definition: reader.h:248
virtual std::string getReaderIdentifier() const =0
Get the Reader Identifier of the Reader.
virtual std::optional< double > getProgress() const
Get the Progress, a relative file position between 0.0 and 1.0.
Definition: reader.h:257
virtual std::vector< Stream > getStreams() const
Get the Streams.
Definition: reader.h:237
virtual std::vector< Extension > getExtensions() const
Get the Extensions if any.
Definition: reader.h:228
virtual FileItem getNextItem()=0
virtual void open(const std::string &filename, std::shared_ptr< SampleFactory > sample_factory, std::shared_ptr< StreamTypeFactory > stream_type_factory)=0
opens a file by the given filename. The given factories must be used to create samples and streamtype...
Base class for a sample factory to create sample used by the Reader.
Definition: reader.h:105
virtual std::shared_ptr< Sample > build() const =0
Creates a sample.
Interface for seekable Reader, where the file position can be adapted.
Definition: reader.h:267
virtual uint64_t getItemIndexForStreamItemIndex(uint16_t stream_id, uint64_t stream_item_index)=0
virtual std::shared_ptr< const StreamType > getStreamTypeBefore(uint64_t item_index, uint16_t stream_id)=0
virtual void seekTo(uint64_t item_index)=0
virtual uint64_t getItemIndexForTimeStamp(std::chrono::nanoseconds time_stamp)=0
Base class for a streamtype factory to create streamtypes used by the Reader.
Definition: reader.h:78
virtual std::shared_ptr< StreamType > build() const =0
Creates a streamtype.
class to create and describe a stream within a adtf_file::Reader. Each stream has an identifier strea...
Definition: reader.h:134
uint64_t item_count
the amount of stream items within the stream
Definition: reader.h:141
std::string name
the stream name
Definition: reader.h:139
std::chrono::nanoseconds timestamp_of_first_item
time stamp of the first stream item within the stream
Definition: reader.h:143
uint16_t stream_id
the stream id
Definition: reader.h:137
std::chrono::nanoseconds timestamp_of_last_item
time stamp of the last stream item within the stream
Definition: reader.h:145
std::shared_ptr< const StreamType > initial_type
the initial stream type of the stream
Definition: reader.h:147
template class for a sample factory to create sample with implementation type SAMPLE_CLASS
Definition: reader.h:120
std::shared_ptr< Sample > build() const override
Creates a sample.
Definition: reader.h:122
template class for a streamtype factory to create streamtypes with implementation type STREAM_TYPE_CL...
Definition: reader.h:93
std::shared_ptr< StreamType > build() const override
Creates a streamtype.
Definition: reader.h:95
namespace for ADTF File library
Definition: adtf2_adtf_core_media_sample_deserializer.h:25
std::chrono::nanoseconds getLastTimeOfStreams(const std::vector< Stream > &streams)
Get the Last Time Of the given Streams.
Stream findStream(const Reader &reader, const std::string &stream_name)
std::chrono::nanoseconds getFirstTimeOfStreams(const std::vector< Stream > &streams)
Get the First Time Of the given Streams.
ReaderFactories getReaderFactories()
Get the Reader Factories from the Objects instance.
std::unordered_map< std::string, PropertyValue > Configuration
Configuration class as set of key - property value pairs This configuration is used to adjust the rea...
Definition: configuration.h:143
utils5ext::exceptions::EndOfFile EndOfFile
Exception to indicate the end of file was reached.
Definition: indexedfile_types.h:114

Copyright © CARIAD SE.
Generated on Mon Jun 10 2024 by doxygen 1.9.1
GIT Commit Hash: eb3af397a6b49ad6fcad9a60d8277d909b458b48