dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
MimeType.hpp
1// SPDX-FileCopyrightText: 2025 Vincent Leroy
2// SPDX-License-Identifier: MIT
3//
4// This file is part of dfx.
5//
6// Licensed under the MIT License. See the LICENSE file in the project root
7// for full license information.
8
9#pragma once
10
11// Standard includes
12#include <vector>
13
14// Project includes
16
17namespace dfx::Core
18{
44{
45public:
48 {
49 // Structured data
54
55 // Binary
57
58 // Text
62
63 // dfx related
65
66 // Wildcard
68 };
69
70public:
74
80 MimeType(std::string mimeType);
81
86
93 std::optional<StandardMimeType> standardType() const noexcept;
94
99 std::string const & toString() const noexcept { return _mimeType; }
100
103 bool isAny() const noexcept { return _mimeType.empty(); }
104
105public:
117 static void validateMimeTypeName(std::string_view name);
118
119public:
121 bool operator==(MimeType const & rhs) const noexcept = default;
123 auto operator<=>(MimeType const & rhs) const noexcept = default;
124
125private:
126 std::string _mimeType;
127};
128
130using MimeTypes = std::vector<MimeType>;
131} // !namespace dfx::Core
132
134
135template<>
136struct std::formatter<dfx::Core::MimeType> : public formatter<std::string_view>
137{
138 inline auto format(dfx::Core::MimeType const & m, format_context & ctx) const
139 { return formatter<std::string_view>::format(m.toString(), ctx); }
140};
Macro-based enum <-> string utilities for dfx.
#define DECLARE_ENUM_STRING_FUNCTIONS(E)
Declare the enum string API (and std::formatter) for enum type E.
Definition EnumString.hpp:327
MIME type value object.
Definition MimeType.hpp:44
std::string const & toString() const noexcept
Return the underlying MIME type string.
Definition MimeType.hpp:99
auto operator<=>(MimeType const &rhs) const noexcept=default
Three-way comparison.
bool operator==(MimeType const &rhs) const noexcept=default
Equality comparison.
MimeType(StandardMimeType mimeType)
Construct from a well-known MIME type enum.
StandardMimeType
Well-known MIME types understood by dfx.
Definition MimeType.hpp:48
@ DfxControl
"application/x-dfx-control"
Definition MimeType.hpp:64
@ PlainText
"text/plain"
Definition MimeType.hpp:59
@ Csv
"text/csv"
Definition MimeType.hpp:61
@ Xml
"application/xml"
Definition MimeType.hpp:53
@ Yaml
"application/x-yaml"
Definition MimeType.hpp:51
@ Markdown
"text/markdown"
Definition MimeType.hpp:60
@ Json
"application/json"
Definition MimeType.hpp:50
@ Toml
"application/toml"
Definition MimeType.hpp:52
@ Any
"" (empty string), meaning "accept anything"
Definition MimeType.hpp:67
@ OctetStream
"application/octet-stream"
Definition MimeType.hpp:56
static void validateMimeTypeName(std::string_view name)
Validate a MIME type string according to dfx rules.
std::optional< StandardMimeType > standardType() const noexcept
Try to map the stored string back to a StandardMimeType.
MimeType(std::string mimeType)
Construct from an explicit MIME type string.
MimeType()
Construct a MIME type with the default value. The default is OctetStream.
bool isAny() const noexcept
Whether this MIME type represents the wildcard "any".
Definition MimeType.hpp:103
Definition Channel.hpp:22
std::vector< MimeType > MimeTypes
Convenience alias for a list of MIME types.
Definition MimeType.hpp:130
Definition Message.hpp:21
STL namespace.