adtf_file_library  0.13.2
processor.h
Go to the documentation of this file.
1 
17 #pragma once
18 
19 #include <string>
21 #include <adtf_file/reader.h>
22 
23 namespace adtfdat_processing
24 {
25 
31 {
32 public:
36  virtual std::string getProcessorIdentifier() const = 0;
37 
41  virtual bool isCompatible(const adtf_file::Stream& stream) const = 0;
42 
52  virtual void open(const std::vector<adtf_file::Stream>& streams, const std::string& destination_url) = 0;
53 
58  virtual void process(const adtf_file::FileItem& item) = 0;
59 };
60 
65 {
66 public:
67 
76  void open(const std::vector<adtf_file::Stream>& streams, const std::string& destination_url) override
77  {
78  if (streams.size() != 1)
79  {
80  throw std::runtime_error("processor '" + getProcessorIdentifier() + "' supports a single input stream only. Open was called with " + std::to_string(streams.size()) + " streams.");
81  }
82  open(streams.front(), destination_url);
83  }
84 
91  virtual void open(const adtf_file::Stream& stream, const std::string& destination_url) = 0;
92 };
93 
94 
99 {
100 public:
104  virtual std::shared_ptr<Processor> makeProcessor() const = 0;
105 };
106 
110 template <typename PROCESSOR_CLASS>
112 {
113 public:
118  std::shared_ptr<Processor> makeProcessor() const override
119  {
120  return std::make_shared<PROCESSOR_CLASS>();
121  }
122 };
123 
128 {
129 public:
134  void add(const std::shared_ptr<const ProcessorFactory>& factory)
135  {
136  auto processor = factory->makeProcessor();
137  _factories[processor->getProcessorIdentifier()] = factory;
138  }
139 
145  std::shared_ptr<Processor> makeProcessor(const std::string& processor_id) const
146  {
147  auto factory = _factories.find(processor_id);
148  if (factory == _factories.end())
149  {
150  throw std::runtime_error("no factory for processor " + processor_id);
151  }
152 
153  return factory->second->makeProcessor();
154  }
155 
166  const std::function<bool(const std::shared_ptr<Processor>&)> callback_processor,
167  const adtf_file::Configuration& configuration = {}) const
168  {
169  for (auto& factory : _factories)
170  {
171  const auto processor = factory.second->makeProcessor();
172  processor->setConfiguration(configuration);
173  if (processor->isCompatible(stream))
174  {
175  if (!callback_processor(processor))
176  {
177  break;
178  }
179  }
180  }
181  }
186  const std::unordered_map<std::string, std::shared_ptr<const ProcessorFactory>>& getFactories() const
187  {
188  return _factories;
189  }
190 private:
191  std::unordered_map<std::string, std::shared_ptr<const ProcessorFactory>> _factories;
192 };
193 }
Definition: configuration.h:314
class to create or read a file item. This file item is either a sample, streamtype or trigger.
Definition: reader.h:156
base interface class for all available objects of the ADTF File Library that can be added to the obje...
Definition: object.h:33
class to create and describe a stream within a adtf_file::Reader. Each stream has an identifier strea...
Definition: reader.h:134
Definition: processor.h:128
std::shared_ptr< Processor > makeProcessor(const std::string &processor_id) const
make a processor with the given processor_id
Definition: processor.h:145
const std::unordered_map< std::string, std::shared_ptr< const ProcessorFactory > > & getFactories() const
Get the Factories.
Definition: processor.h:186
void add(const std::shared_ptr< const ProcessorFactory > &factory)
Definition: processor.h:134
void getCapableProcessors(const adtf_file::Stream &stream, const std::function< bool(const std::shared_ptr< Processor > &)> callback_processor, const adtf_file::Configuration &configuration={}) const
Get the capable and compatible processors for the given stream. It will make all capable processors a...
Definition: processor.h:165
std::shared_ptr< Processor > makeProcessor() const override
create a processor
Definition: processor.h:118
Definition: processor.h:99
virtual std::shared_ptr< Processor > makeProcessor() const =0
Definition: processor.h:31
virtual bool isCompatible(const adtf_file::Stream &stream) const =0
virtual void open(const std::vector< adtf_file::Stream > &streams, const std::string &destination_url)=0
virtual void process(const adtf_file::FileItem &item)=0
virtual std::string getProcessorIdentifier() const =0
virtual void open(const adtf_file::Stream &stream, const std::string &destination_url)=0
void open(const std::vector< adtf_file::Stream > &streams, const std::string &destination_url) override
Definition: processor.h:76
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
namespace for ADTF DAT Processing library.
Definition: ddl_helpers.h:38

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