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
input.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_INPUT_H
13 #define DOCWIRE_INPUT_H
14 
15 #include <iostream>
16 #include "chain_element.h"
17 #include "data_source.h"
18 #include "parsing_chain.h"
19 
20 namespace docwire
21 {
22 
23 template<class T>
24 concept IStreamDerived = std::derived_from<T, std::istream>;
25 
26 template<typename T>
27 concept istream_derived_ref_qualified = IStreamDerived<std::remove_reference_t<T>>;
28 
29 class DOCWIRE_CORE_EXPORT input_chain_element : public chain_element
30 {
31 public:
33  : m_data{data}
34  {}
35 
36  virtual continuation operator()(message_ptr msg, const message_callbacks& emit_message) override;
37  bool is_leaf() const override { return false; }
38  bool is_generator() const override { return true; }
39 
40 private:
41  ref_or_owned<data_source> m_data;
42 };
43 
44 inline parsing_chain operator|(ref_or_owned<data_source> data, ref_or_owned<chain_element> chain_element)
45 {
46  return input_chain_element{data} | chain_element;
47 }
48 
49 inline parsing_chain operator|(ref_or_owned<std::istream> stream, ref_or_owned<chain_element> chain_element)
50 {
51  return input_chain_element{data_source{seekable_stream_ptr{stream.to_shared_ptr()}}} | chain_element.to_shared_ptr();
52 }
53 
54 template<data_source_compatible_type_ref_qualified T>
55 parsing_chain operator|(T&& v, ref_or_owned<chain_element> chain_element)
56 {
57  return data_source{std::forward<T>(v)} | chain_element;
58 }
59 
60 }
61 #endif //DOCWIRE_INPUT_H
bool is_leaf() const override
Check if chain element is a leaf (last element which doesn't produce any messages)....
Definition: input.h:37
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