IDS peak IPL v1.17.2
Loading...
Searching...
No Matches
peak_common_pipeline_base.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
15
16#include <fstream>
17#include <sstream>
18#include <string>
19
20namespace peak
21{
22namespace pipeline
23{
24
34class PipelineBase : public IPipeline
35{
36public:
45 void ExportSettingsToFile(const std::string& filePath) const override;
46
55 void ImportSettingsFromFile(const std::string& filePath) override;
56
65
75};
76
77inline void PipelineBase::ExportSettingsToFile(const std::string& filePath) const
78{
79 std::ofstream stream;
80 stream.exceptions(std::ios::badbit | std::ios::failbit);
81
82 try
83 {
84 stream.open(filePath);
85
86 stream << ExportSettingsToString();
87 }
88 catch (const std::ios_base::failure& e)
89 {
90 throw peak::common::IOException("Saving settings to the file " + filePath + " failed: " + e.what());
91 }
92}
93
94inline void PipelineBase::ImportSettingsFromFile(const std::string& filePath)
95{
96 std::ifstream stream;
97 stream.exceptions(std::ios::badbit | std::ios::failbit);
98
99 try
100 {
101 stream.open(filePath);
102
103 std::stringstream ss;
104 ss << stream.rdbuf();
105
106 ImportSettingsFromString(ss.str());
107 }
108 catch (const std::ios_base::failure& e)
109 {
110 throw peak::common::IOException("Loading settings from the file " + filePath + " failed: " + e.what());
111 }
112}
113
115{
116 return Process(input);
117}
118
120{
121 auto data = input;
122
123 for (const auto& module : GetModules())
124 {
125 data = module->Process(data);
126 }
127
128 return data;
129}
130
131
132} // namespace pipeline
133} // namespace peak
A type-erased container for any copyable value.
Definition peak_common_any.hpp:36
Thrown when an input, output, file or device communication error occurs.
Definition peak_common_exceptions.hpp:145
Interface defining the structure and behavior of a processing pipeline.
Definition peak_common_ipipeline.hpp:54
virtual PEAK_COMMON_NO_DISCARD std::string ExportSettingsToString() const =0
Returns the current settings of the pipeline and its modules as a string.
virtual PEAK_COMMON_NO_DISCARD std::vector< std::shared_ptr< modules::IModule > > GetModules() const =0
Retrieves the list of all modules in the pipeline, in execution order.
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:35
PEAK_COMMON_NO_DISCARD peak::common::Any operator<<(const peak::common::Any &input) override
Convenience operator for processing input using the pipeline.
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:94
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:77
PEAK_COMMON_NO_DISCARD 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:119
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
Definition peak_common_defines.h:86
Interfaces and implementations for defining and controlling data processing pipelines.
Definition peak_common_iautofeature_module.hpp:21