AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
mediaType.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 standard
3 Copyright (C) 2026 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <https://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include "anch-codec-export.hpp"
23
24#include <map>
25#include <optional>
26#include <string>
27#include <string_view>
28#include <vector>
29
30namespace anch::codec {
31
41 class ANCH_CODEC_EXPORT MediaType {
42
43 // Attributes +
44 private:
46 std::string _type;
47
49 std::string _subtype;
50
52 std::map<std::string, std::string> _parameters;
53
55 double _quality;
56 // Attributes -
57
58 // Constructors +
59 public:
66 MediaType(std::string_view type, std::string_view subtype);
67 // Constructors -
68
69 // Methods +
70 public:
78 static std::optional<anch::codec::MediaType> parse(std::string_view value);
79
89 static std::vector<anch::codec::MediaType> parseAccept(std::string_view value);
90
99 bool includes(const anch::codec::MediaType& other) const noexcept;
100
106 int specificity() const noexcept;
107
113 std::string essence() const;
114
120 std::string toString() const;
121
129 bool operator==(const anch::codec::MediaType& other) const noexcept;
130 // Methods -
131
132 // Accessors +
133 public:
139 const std::string& getType() const noexcept;
140
146 const std::string& getSubtype() const noexcept;
147
153 const std::map<std::string, std::string>& getParameters() const noexcept;
154
162 std::optional<std::string_view> getParameter(std::string_view name) const;
163
170 void setParameter(std::string_view name, std::string_view value);
171
177 double getQuality() const noexcept;
178 // Accessors -
179
180 };
181
192 ANCH_CODEC_EXPORT std::optional<std::size_t> negotiate(const std::vector<anch::codec::MediaType>& accept,
193 const std::vector<anch::codec::MediaType>& available);
194
195}
196
197namespace anch::codec::media {
198
200 inline constexpr std::string_view APP_JSON = "application/json";
202 inline constexpr std::string_view APP_OCTET_STREAM = "application/octet-stream";
204 inline constexpr std::string_view APP_FORM_URLENCODED = "application/x-www-form-urlencoded";
206 inline constexpr std::string_view APP_XML = "application/xml";
208 inline constexpr std::string_view MULTIPART_FORM_DATA = "multipart/form-data";
210 inline constexpr std::string_view TEXT_CSV = "text/csv";
212 inline constexpr std::string_view TEXT_HTML = "text/html";
214 inline constexpr std::string_view TEXT_PLAIN = "text/plain";
215
216}
Definition mediaType.hpp:41
std::string toString() const
const std::string & getType() const noexcept
void setParameter(std::string_view name, std::string_view value)
MediaType(std::string_view type, std::string_view subtype)
const std::string & getSubtype() const noexcept
std::string essence() const
static std::optional< anch::codec::MediaType > parse(std::string_view value)
bool includes(const anch::codec::MediaType &other) const noexcept
double getQuality() const noexcept
int specificity() const noexcept
static std::vector< anch::codec::MediaType > parseAccept(std::string_view value)
const std::map< std::string, std::string > & getParameters() const noexcept
std::optional< std::string_view > getParameter(std::string_view name) const
Common media types.
constexpr std::string_view APP_FORM_URLENCODED
Definition mediaType.hpp:204
constexpr std::string_view MULTIPART_FORM_DATA
Definition mediaType.hpp:208
constexpr std::string_view TEXT_CSV
Definition mediaType.hpp:210
constexpr std::string_view APP_JSON
Definition mediaType.hpp:200
constexpr std::string_view TEXT_PLAIN
Definition mediaType.hpp:214
constexpr std::string_view APP_XML
Definition mediaType.hpp:206
constexpr std::string_view TEXT_HTML
Definition mediaType.hpp:212
constexpr std::string_view APP_OCTET_STREAM
Definition mediaType.hpp:202
AnCH codec library namespace.
Definition csv.hpp:31
std::optional< std::size_t > negotiate(const std::vector< anch::codec::MediaType > &accept, const std::vector< anch::codec::MediaType > &available)
AnCH framework base namespace.
Definition app.hpp:30