DF-0
DF-0: Data processing Framework with Zero-overhead
Toggle main menu visibility
Loading...
Searching...
No Matches
content_type.h
1
/**************************************************************************/
2
/* */
3
/* DF-0: Data processing Framework with Zero-overhead */
4
/* */
5
/* Copyright (c) DF-0 Team https://github.com/df0-io/df0 */
6
/* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-DF0-Commercial */
7
/* */
8
/**************************************************************************/
9
10
#ifndef DF0_CONTENT_TYPE_H
11
#define DF0_CONTENT_TYPE_H
12
13
#include "pipeline/element_base.hpp"
14
#include "content_type_by_signature.h"
15
#include "ref_or_owned.h"
16
37
namespace
df0::content_type
38
{
39
72
DF0_CONTENT_TYPE_EXPORT
void
detect
(
data_source
& data,
const
by_signature::database
& signatures_db_to_use =
by_signature::database
{});
73
104
class
detector
:
public
pipeline::transformer_element<detector>
105
{
106
public
:
107
118
detector
(
ref_or_owned<by_signature::database>
signatures_db_to_use =
by_signature::database
{})
119
: m_signatures_db_to_use(signatures_db_to_use) {}
120
121
continuation operator()(message_ptr msg,
const
message_callbacks
& emit_message)
122
{
123
try
124
{
125
if
(msg->is<
data_source
>())
126
{
127
data_source
& data = msg->get<
data_source
>();
128
content_type::detect
(data, m_signatures_db_to_use.get());
129
}
130
else
if
(msg->is<document::image>())
131
{
132
data_source& data = msg->get<document::image>().source;
133
content_type::detect
(data, m_signatures_db_to_use.get());
134
}
135
}
136
catch
(
const
std::exception& e)
137
{
138
emit_message(
make_nested_ptr
(std::current_exception(), DF0_MAKE_ERROR(
"Content type detection failed"
)));
139
}
140
return
emit_message(std::move(msg));
141
}
142
143
private
:
144
ref_or_owned<by_signature::database> m_signatures_db_to_use;
145
};
146
147
}
// namespace df0::content_type
148
149
#endif
// DF0_CONTENT_TYPE
df0::content_type::by_signature::database
Database of signatures.
Definition
content_type_by_signature.h:58
df0::content_type::detector::detector
detector(ref_or_owned< by_signature::database > signatures_db_to_use=by_signature::database{})
Constructs a new detector with the given database of signatures.
Definition
content_type.h:118
df0::data_source
Definition
data_source.h:136
df0::ref_or_owned
A utility class that simplifies declaring function attributes that need to be stored without requirin...
Definition
ref_or_owned.h:32
df0::content_type
Provides a multi-stage pipeline for content type detection.
df0::content_type::detect
DF0_CONTENT_TYPE_EXPORT void detect(data_source &data, const by_signature::database &signatures_db_to_use=by_signature::database{})
df0::errors::make_nested_ptr
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.
Definition
nested_exception.h:143
df0::message_callbacks
Callback bundle used by pipeline elements to emit messages.
Definition
message.h:90
content_type.h
Generated by
1.18.0