|
14 | 14 | #include <cstdint> |
15 | 15 | #include <map> |
16 | 16 | #include <memory> |
| 17 | +#include <optional> |
17 | 18 | #include <ranges> |
18 | 19 | #include <source_location> |
19 | 20 | #include <span> |
|
23 | 24 |
|
24 | 25 | namespace cucumber_cpp::library |
25 | 26 | { |
26 | | - |
27 | 27 | enum struct HookType |
28 | 28 | { |
29 | 29 | beforeAll, |
@@ -74,7 +74,7 @@ namespace cucumber_cpp::library |
74 | 74 | { |
75 | 75 | struct Definition |
76 | 76 | { |
77 | | - Definition(std::string id, HookType type, std::string_view expression, HookFactory factory, std::source_location sourceLocation); |
| 77 | + Definition(std::string id, HookType type, std::optional<std::string_view> expression, std::optional<std::string_view> name, HookFactory factory, std::source_location sourceLocation); |
78 | 78 |
|
79 | 79 | HookType type; |
80 | 80 | std::unique_ptr<tag_expression::Expression> tagExpression; |
@@ -112,91 +112,11 @@ namespace cucumber_cpp::library |
112 | 112 | const Definition& GetDefinitionById(std::string id) const; |
113 | 113 |
|
114 | 114 | private: |
115 | | - void Register(std::string id, HookType type, std::string_view expression, HookFactory factory, std::source_location sourceLocation); |
| 115 | + void Register(std::string id, HookType type, std::optional<std::string_view> expression, std::optional<std::string_view> name, HookFactory factory, std::source_location sourceLocation); |
116 | 116 |
|
117 | 117 | cucumber::gherkin::id_generator_ptr idGenerator; |
118 | 118 | std::map<std::string, Definition> registry; |
119 | 119 | }; |
120 | | - |
121 | | - struct GlobalHook |
122 | | - { |
123 | | - std::string_view name{ "anonymous" }; |
124 | | - std::int32_t order{ 0 }; |
125 | | - }; |
126 | | - |
127 | | - struct Hook |
128 | | - { |
129 | | - std::string_view tagExpression{ "" }; |
130 | | - std::string_view name{ "anonymous" }; |
131 | | - std::int32_t order{ 0 }; |
132 | | - }; |
133 | | - |
134 | | - struct HookRegistration |
135 | | - { |
136 | | - private: |
137 | | - HookRegistration() = default; |
138 | | - |
139 | | - public: |
140 | | - static inline HookRegistration& Instance() |
141 | | - { |
142 | | - static HookRegistration instance; |
143 | | - return instance; |
144 | | - } |
145 | | - |
146 | | - struct Entry |
147 | | - { |
148 | | - Entry(HookType type, std::string_view expression, HookFactory factory, std::source_location sourceLocation) |
149 | | - : type(type) |
150 | | - , expression{ expression } |
151 | | - , factory(factory) |
152 | | - , sourceLocation{ sourceLocation } |
153 | | - {} |
154 | | - |
155 | | - HookType type; |
156 | | - std::string_view expression; |
157 | | - HookFactory factory; |
158 | | - std::source_location sourceLocation; |
159 | | - std::string id{ "unassigned" }; |
160 | | - }; |
161 | | - |
162 | | - template<class T> |
163 | | - static std::size_t Register(std::string_view tagExpression, HookType hookType, std::source_location sourceLocation = std::source_location::current()); |
164 | | - template<class T> |
165 | | - static std::size_t Register(Hook hook, HookType hookType, std::source_location sourceLocation = std::source_location::current()); |
166 | | - template<class T> |
167 | | - static std::size_t Register(GlobalHook hook, HookType hookType, std::source_location sourceLocation = std::source_location::current()); |
168 | | - |
169 | | - std::span<Entry> GetEntries(); |
170 | | - [[nodiscard]] std::span<const Entry> GetEntries() const; |
171 | | - |
172 | | - private: |
173 | | - std::vector<Entry> registry; |
174 | | - }; |
175 | | - |
176 | | - ////////////////////////// |
177 | | - // implementation // |
178 | | - ////////////////////////// |
179 | | - |
180 | | - template<class T> |
181 | | - std::size_t HookRegistration::Register(std::string_view tagExpression, HookType hookType, std::source_location sourceLocation) |
182 | | - { |
183 | | - Instance().registry.emplace_back(hookType, tagExpression, HookBodyFactory<T>, sourceLocation); |
184 | | - return Instance().registry.size(); |
185 | | - } |
186 | | - |
187 | | - template<class T> |
188 | | - std::size_t HookRegistration::Register(Hook hook, HookType hookType, std::source_location sourceLocation) |
189 | | - { |
190 | | - Instance().registry.emplace_back(hookType, hook.tagExpression, HookBodyFactory<T>, sourceLocation); |
191 | | - return Instance().registry.size(); |
192 | | - } |
193 | | - |
194 | | - template<class T> |
195 | | - std::size_t HookRegistration::Register(GlobalHook hook, HookType hookType, std::source_location sourceLocation) |
196 | | - { |
197 | | - Instance().registry.emplace_back(hookType, "", HookBodyFactory<T>, sourceLocation); |
198 | | - return Instance().registry.size(); |
199 | | - } |
200 | 120 | } |
201 | 121 |
|
202 | 122 | #endif |
0 commit comments