IDS peak AFL v2.1.0
Loading...
Searching...
No Matches
peak_common_pipeline_base.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
10
11#include <fstream>
12#include <sstream>
13#include <string>
14
15namespace peak
16{
17namespace pipeline
18{
19
29class PipelineBase : public IPipeline
30{
31public:
40 void ExportSettingsToFile(const std::string& filePath) const override;
41
50 void ImportSettingsFromFile(const std::string& filePath) override;
51
59 PEAK_COMMON_NO_DISCARD peak::common::Any operator<<(const peak::common::Any& input) override;
60
69 PEAK_COMMON_NO_DISCARD peak::common::Any Process(const peak::common::Any& input) const override;
70};
71
72inline void PipelineBase::ExportSettingsToFile(const std::string& filePath) const
73{
74 std::ofstream stream;
75 stream.exceptions(std::ios::badbit | std::ios::failbit);
76
77 try
78 {
79 stream.open(filePath);
80
81 stream << ExportSettingsToString();
82 }
83 catch (const std::ios_base::failure& e)
84 {
85 throw peak::common::IOException("Saving settings to the file " + filePath + " failed: " + e.what());
86 }
87}
88
89inline void PipelineBase::ImportSettingsFromFile(const std::string& filePath)
90{
91 std::ifstream stream;
92 stream.exceptions(std::ios::badbit | std::ios::failbit);
93
94 try
95 {
96 stream.open(filePath);
97
98 std::stringstream ss;
99 ss << stream.rdbuf();
100
101 ImportSettingsFromString(ss.str());
102 }
103 catch (const std::ios_base::failure& e)
104 {
105 throw peak::common::IOException("Loading settings from the file " + filePath + " failed: " + e.what());
106 }
107}
108
110{
111 return Process(input);
112}
113
115{
116 auto data = input;
117
118 for (const auto& module : GetModules())
119 {
120 data = module->Process(data);
121 }
122
123 return data;
124}
125
126
127} // namespace pipeline
128} // namespace peak
A type-erased container for any copyable value.
Definition peak_common_any.hpp:31
Thrown when an input, output, file or device communication error occurs.
Definition peak_common_exceptions.hpp:140
Interface defining the structure and behavior of a processing pipeline.
Definition peak_common_ipipeline.hpp:49
virtual std::vector< std::shared_ptr< modules::IModule > > GetModules() const =0
Retrieves the list of all modules in the pipeline, in execution order.
virtual std::string ExportSettingsToString() const =0
Returns the current settings of the pipeline and its modules as a string.
virtual void ImportSettingsFromString(const std::string &settings)=0
Loads settings for the pipeline and its modules from a string.
Base class for implementing a custom pipeline.
Definition peak_common_pipeline_base.hpp:30
peak::common::Any operator<<(const peak::common::Any &input) override
Convenience operator for processing input using the pipeline.
Definition peak_common_pipeline_base.hpp:109
peak::common::Any Process(const peak::common::Any &input) const override
Processes the input through all pipeline modules and returns the result.
Definition peak_common_pipeline_base.hpp:114
void ImportSettingsFromFile(const std::string &filePath) override
Loads the settings of the pipeline and its modules from a file.
Definition peak_common_pipeline_base.hpp:89
void ExportSettingsToFile(const std::string &filePath) const override
Saves the current settings of the pipeline and its modules to a file.
Definition peak_common_pipeline_base.hpp:72
Interfaces and implementations for defining and controlling data processing pipelines.
Definition peak_afl_generic_auto_brightness.hpp:33