CaptureMoment 0.1.0
Free and open-source non-destructive photo editor
Loading...
Searching...
No Matches
pipeline_builder.cpp
Go to the documentation of this file.
1
9
10#include <spdlog/spdlog.h>
11#include <utility>
12
14
15std::unordered_map<PipelineType, PipelineBuilder::CreatorFunc>& PipelineBuilder::getRegistry()
16{
17 // Meyer's Singleton: Initialized on first use, destroyed on app exit.
18 // Thread-safe in C++11 and later.
19 static std::unordered_map<PipelineType, CreatorFunc> registry;
20 return registry;
21}
22
24{
25 // Register the creator function in the static map
26 getRegistry()[type] = std::move(creator);
27}
28
29std::unique_ptr<IPipelineExecutor> PipelineBuilder::build(PipelineType type)
30{
31 auto& registry = getRegistry();
32 auto it = registry.find(type);
33
34 // Check if the requested type has been registered
35 if (it == registry.end())
36 {
37 spdlog::error("[PipelineBuilder] No creator registered for pipeline type: {}", static_cast<int>(type));
38 return nullptr;
39 }
40
41 try
42 {
43 // Invoke the stored lambda/function to create the instance
44 // The creator is expected to call the default constructor of the concrete implementation.
45 return it->second();
46 }
47 catch (const std::exception& e)
48 {
49 spdlog::critical("[PipelineBuilder] Exception during instantiation of pipeline type {}: {}",
50 static_cast<int>(type), e.what());
51 return nullptr;
52 }
53}
54
55} // namespace CaptureMoment::Core::Pipeline
std::function< std::unique_ptr< IPipelineExecutor >()> CreatorFunc
Definition of the creator function signature.
static void registerCreator(PipelineType type, CreatorFunc creator)
Registers a creator function for a specific pipeline type.
static std::unique_ptr< IPipelineExecutor > build(PipelineType type)
Retrieves an instance of the executor for the specified type.
PipelineType
Identifies the specific technology or strategy used for image processing.
Central Registry and Factory for IPipelineExecutor instances.
CaptureMoment — footer