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
output.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_OUTPUT_H
13 #define DOCWIRE_OUTPUT_H
14 
15 #include "chain_element.h"
16 #include <concepts>
17 #include <ostream>
18 #include "parsing_chain.h"
19 #include <type_traits>
20 #include <variant>
21 #include <vector>
22 
23 namespace docwire
24 {
25 
26 template<class T>
27 concept OStreamDerived = std::derived_from<T, std::ostream>;
28 
29 template<typename T>
30 concept ostream_derived_ref_qualified = OStreamDerived<std::remove_reference_t<T>>;
31 
38 class DOCWIRE_CORE_EXPORT output_chain_element : public chain_element
39 {
40 public:
45  : m_out_obj{out_stream}
46  {}
47 
48  output_chain_element(ref_or_owned<std::vector<message_ptr>> out_vector)
49  : m_out_obj{out_vector}
50  {}
51 
52  bool is_leaf() const override
53  {
54  return true;
55  }
56 
57  virtual continuation operator()(message_ptr msg, const message_callbacks& emit_message) override;
58 
59 private:
60  std::variant<ref_or_owned<std::ostream>, ref_or_owned<std::vector<message_ptr>>> m_out_obj;
61 };
62 
63 inline parsing_chain operator|(ref_or_owned<chain_element> element, ref_or_owned<std::ostream> stream)
64 {
65  return element | output_chain_element(stream);
66 }
67 
68 inline parsing_chain& operator|=(parsing_chain& chain, ref_or_owned<std::ostream> stream)
69 {
70  return chain |= output_chain_element(stream);
71 }
72 
73 inline parsing_chain operator|(ref_or_owned<chain_element> element, ref_or_owned<std::vector<message_ptr>> vector)
74 {
75  return element | output_chain_element(vector);
76 }
77 
78 inline parsing_chain& operator|=(parsing_chain& chain, ref_or_owned<std::vector<message_ptr>> vector)
79 {
80  return chain |= output_chain_element(vector);
81 }
82 
83 } // namespace docwire
84 
85 #endif //DOCWIRE_OUTPUT_H
output_chain_element class is responsible for saving data from parsing chain to an output stream.
Definition: output.h:39
bool is_leaf() const override
Check if chain element is a leaf (last element which doesn't produce any messages)....
Definition: output.h:52
output_chain_element(ref_or_owned< std::ostream > out_stream)
Definition: output.h:44
A utility class that simplifies declaring function attributes that need to be stored without requirin...
Definition: ref_or_owned.h:34
auto operator|(V &&value, F &&function)
Binds a value to a function, enabling the creation of a function call chain.
Definition: chaining.h:91
The main namespace for the DocWire SDK.
Definition: ai_elements.h:19