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
message_counters.h
1 #ifndef DOCWIRE_MESSAGE_COUNTERS_H
2 #define DOCWIRE_MESSAGE_COUNTERS_H
3 
4 #include "message.h"
5 #include "document_elements.h"
6 #include <exception>
7 
8 namespace docwire {
9 
11  size_t attempts = 0;
12  size_t successes = 0;
13 
14  bool all_failed() const {
15  return attempts > 0 && successes == 0;
16  }
17 };
18 
19 inline bool is_framing_message(const message_base& msg) {
20  return msg.is<document::document>() || msg.is<document::close_document>() ||
21  msg.is<document::page>() || msg.is<document::close_page>() ||
22  msg.is<document::break_line>() ||
23  msg.is<std::exception_ptr>();
24 }
25 
26 inline message_callbacks make_counted_message_callbacks(const message_callbacks& original, message_counters& counters) {
27  auto wrapper = [&original, &counters](message_ptr msg, bool is_back) -> continuation {
28  bool is_framing = is_framing_message(*msg);
29  if (!is_framing) counters.attempts++;
30  auto c = is_back ? original.back(std::move(msg)) : original.further(std::move(msg));
31  if (!is_framing) counters.successes++;
32  return c;
33  };
34 
35  return message_callbacks {
36  .m_further = [wrapper](message_ptr msg) { return wrapper(std::move(msg), false); },
37  .m_back = [wrapper](message_ptr msg) { return wrapper(std::move(msg), true); }
38  };
39 }
40 
41 }
42 
43 #endif
The main namespace for the DocWire SDK.
Definition: ai_elements.h:19