12 #ifndef DOCWIRE_CONTENT_TYPE_BY_SIGNATURE_H
13 #define DOCWIRE_CONTENT_TYPE_BY_SIGNATURE_H
15 #include "chain_element.h"
16 #include "content_type_export.h"
17 #include "data_source.h"
18 #include "document_elements.h"
19 #include "make_error.h"
20 #include "nested_exception.h"
21 #include "ref_or_owned.h"
110 : m_database_to_use(database_to_use), m_allow_multiple{allow_multiple} {}
112 continuation operator()(message_ptr msg,
const message_callbacks& emit_message)
override
116 if (msg->is<data_source>())
118 data_source& data = msg->get<data_source>();
119 detect(data, m_database_to_use.get(), m_allow_multiple);
121 else if (msg->is<document::image>())
123 data_source& data = msg->get<document::image>().source;
124 detect(data, m_database_to_use.get(), m_allow_multiple);
127 catch (
const std::exception& e)
129 emit_message(
make_nested_ptr(std::current_exception(), DOCWIRE_MAKE_ERROR(
"Content type detection by signature failed")));
131 return emit_message(std::move(msg));
friend DOCWIRE_CONTENT_TYPE_EXPORT void detect(data_source &data, const database &database_to_use, allow_multiple allow_multiple)
Detects and assigns content types to the provided data source using signatures-based content detectio...
detector(ref_or_owned< database > database_to_use=database{}, allow_multiple allow_multiple={false})
Constructs a new detector with the given database of signatures and multiple content type detection c...
bool is_leaf() const override
Check if chain element is a leaf (last element which doesn't produce any messages)....
A utility class that simplifies declaring function attributes that need to be stored without requirin...
Provides content type detection based on file signatures (magic bytes).
DOCWIRE_CONTENT_TYPE_EXPORT void detect(data_source &data, const database &database_to_use=database{}, allow_multiple allow_multiple={false})
Detects and assigns content types to the provided data source using signatures-based content detectio...
std::exception_ptr make_nested_ptr(Inner &&inner, Outer &&outer, Rest &&... rest)
Creates a pointer to a nested exception from an inner exception and an outer exception.