DocWire SDK
DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, document analysis. Offline processing possible for security and confidentiality
transformer_func.h
1 /*********************************************************************************************************************************************/
2 /* DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. */
3 /* Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, */
4 /* document analysis. Offline processing possible for security and confidentiality */
5 /* */
6 /* Copyright (c) SILVERCODERS Ltd, http://silvercoders.com */
7 /* Project homepage: https://github.com/docwire/docwire */
8 /* */
9 /* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-DocWire-Commercial */
10 /*********************************************************************************************************************************************/
11 
12 #ifndef DOCWIRE_TRANSFORMER_FUNC_H
13 #define DOCWIRE_TRANSFORMER_FUNC_H
14 
15 #include "chain_element.h"
16 #include "core_export.h"
17 #include "parsing_chain.h"
18 #include "ref_or_owned.h"
19 
20 namespace docwire
21 {
22 
23 using message_transform_func = std::function<continuation(message_ptr, const message_callbacks& emit_message)>;
24 
28 class DOCWIRE_CORE_EXPORT transformer_func : public chain_element, public with_pimpl<transformer_func>
29 {
30 public:
34  transformer_func(message_transform_func transformer_function);
35 
42  virtual continuation operator()(message_ptr msg, const message_callbacks& emit_message) override;
43 
44  bool is_leaf() const override
45  {
46  return false;
47  }
48 
49 private:
52 };
53 
54 template <typename T>
55 requires (
56  std::is_convertible_v<T, message_transform_func> &&
57  !std::is_base_of_v<chain_element, std::remove_cvref_t<T>>
58 )
59 parsing_chain operator|(ref_or_owned<chain_element> element, T func)
60 {
61  return element | transformer_func{func};
62 }
63 
64 template <typename T>
65 requires (
66  std::is_convertible_v<T, message_transform_func> &&
67  !std::is_base_of_v<chain_element, std::remove_cvref_t<T>>
68 )
69 parsing_chain& operator|=(parsing_chain& chain, T func)
70 {
71  return chain |= transformer_func{func};
72 }
73 
74 } // namespace docwire
75 
76 #endif //DOCWIRE_TRANSFORMER_FUNC_H
Wraps single function (tag_transform_func) into chain_element object.
bool is_leaf() const override
Check if chain element is a leaf (last element which doesn't produce any messages)....
transformer_func(message_transform_func transformer_function)
virtual continuation operator()(message_ptr msg, const message_callbacks &emit_message) override
Executes transform on the given message.
The main namespace for the DocWire SDK.
Definition: ai_elements.h:19
requires(!string_method_equipped< T >) struct stringifier< T >
Specialization for types that are streamable to std::ostream.