-
Notifications
You must be signed in to change notification settings - Fork 0
/
processor.hpp
46 lines (39 loc) · 1.71 KB
/
processor.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* A Processor defines a processing operation from an input feature to an output feature.
*
* (C) 2021 Malcolm Tyrrell
*
* Licensed under the GPLv3.0. See LICENSE file.
**/
#pragma once
#include <memory>
namespace babelwires {
struct UserLogger;
class ValueFeature;
struct ProjectContext;
class TypeRef;
class SimpleValueFeature;
/// Defines a processing operation from an input feature to an output feature.
/// This should not store any state.
// TODO: Perhaps the design could be re-done in terms of const functions.
class Processor {
public:
Processor(const ProjectContext& projectContext, const TypeRef& inputTypeRef, const TypeRef& outputTypeRef);
virtual ~Processor();
/// Set values in the output feature based on values in the input feature.
/// Implementation of process are allowed to throw. If they do, the ProcessorElement will be marked as failed,
/// the exception will be logged, and the output feature will be set to default.
void process(UserLogger& userLogger);
ValueFeature& getInputFeature();
ValueFeature& getOutputFeature();
const ValueFeature& getInputFeature() const;
const ValueFeature& getOutputFeature() const;
protected:
/// Note: Implementations do not need to worry about backing-up or resolving changes in the output feature.
virtual void processValue(UserLogger& userLogger, const ValueFeature& inputFeature,
ValueFeature& outputFeature) const = 0;
protected:
std::unique_ptr<SimpleValueFeature> m_inputFeature;
std::unique_ptr<SimpleValueFeature> m_outputFeature;
};
} // namespace babelwires