lintel 0.2.0
Loading...
Searching...
No Matches
Feature.h
Go to the documentation of this file.
1#ifndef LINTEL_FEATURE_H
2#define LINTEL_FEATURE_H
3
4#include <memory>
5#include <string>
6#include <string_view>
7#include <type_traits>
8#include <utility>
9
12
13namespace lintel {
14class Configuration;
15class ProcessName;
16
17// The DI container is only referenced through pointers/references in the
18// signatures below, so an incomplete type is enough. Implementations that
19// register or resolve types include "lintel/core/di/Container.h" themselves.
20}// namespace lintel
21namespace lintel {
22namespace di {
23 class Container;
24 class ContainerBuilder;
25}// namespace di
26}// namespace lintel
27
28namespace lintel {
31{
32public:
34 virtual ~FeatureInterface() = default;
35
38
50 const std::shared_ptr<Configuration> &configuration,
51 const std::shared_ptr<ProcessName> &processName)
52 {
54 (void)processName;
56 }
57
59 virtual void initialize(std::shared_ptr<lintel::di::Container> container) = 0;
60
62 virtual std::string_view getName() = 0;
63};
64
66template<typename T, std::enable_if_t<std::is_enum_v<T>> * = nullptr> class Feature : public FeatureInterface
67{
68private:
69 std::shared_ptr<Features> m_features;
70
71protected:
73 std::string_view m_name;
74
75public:
79 Feature(T type, std::shared_ptr<Features> features)
80 : m_name(std::string(magic_enum::enum_name(type))), m_features(std::move(features))
81 {
82 m_features->registerFeature(
83 type,
85 [&](std::shared_ptr<lintel::di::Container> container) { initialize(container); });
86 }
87
89 virtual ~Feature() = default;
90
93
95 virtual void initialize(std::shared_ptr<lintel::di::Container> container) = 0;
96
99 std::string_view getName() { return m_name; }
100};
101
102}// namespace lintel
103#endif// LINTEL_FEATURE_H
Definition Feature.h:31
virtual ~FeatureInterface()=default
virtual void initialize(std::shared_ptr< lintel::di::Container > container)=0
virtual void registerTypes(lintel::di::ContainerBuilder &builder, const std::shared_ptr< Configuration > &configuration, const std::shared_ptr< ProcessName > &processName)
Definition Feature.h:49
virtual std::string_view getName()=0
virtual void registerTypes(lintel::di::ContainerBuilder &builder)=0
Definition Feature.h:67
virtual ~Feature()=default
std::string_view getName()
Definition Feature.h:99
Feature(T type, std::shared_ptr< Features > features)
Definition Feature.h:79
virtual void registerTypes(lintel::di::ContainerBuilder &builder)=0
virtual void initialize(std::shared_ptr< lintel::di::Container > container)=0
std::string_view m_name
Definition Feature.h:73
Definition Container.h:282
Definition BaseFeature.h:6
constexpr std::string_view type_name()
Definition TypeName.h:9