AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AMimedData.h
1/*
2 * AUI Framework - Declarative UI toolkit for modern C++20
3 * Copyright (C) 2020-2024 Alex2772 and Contributors
4 *
5 * SPDX-License-Identifier: MPL-2.0
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 */
11
12#pragma once
13
14#include <AUI/Common/AMap.h>
15#include <AUI/Common/AByteBuffer.h>
16#include <AUI/Url/AUrl.h>
17
22class API_AUI_VIEWS AMimedData {
23public:
24 AOptional<AString> text() const;
25
29 void setText(const AString& text);
30
31
32 void setData(const AString& mimeType, AByteBuffer data) {
33 mStorage[mimeType] = std::move(data);
34 }
35
36 [[nodiscard]]
37 const AMap<AString, AByteBuffer>& data() const noexcept {
38 return mStorage;
39 }
40
41 AOptional<AVector<AUrl>> urls() const;
42 void setUrls(const AVector<AUrl>& urls);
43
44 void clear() noexcept {
45 mStorage.clear();
46 }
47
48private:
50
51 AOptional<AByteBufferView> findFirstOccurrence(const AStringVector& items) const {
52 for (const auto& item : items) {
53 if (auto c = mStorage.contains(item)) {
54 return c->second;
55 }
56 }
57 return std::nullopt;
58 }
59};
60
61
std::vector-like growing array for byte storage.
Definition AByteBuffer.h:31
A std::map with AUI extensions.
Definition AMap.h:218
Mime-type data associated storage.
Definition AMimedData.h:22
void setText(const AString &text)
Sets "text/plain".
Definition AMimedData.cpp:19
Utility wrapper implementing the stack-allocated (fast) optional idiom.
Definition AOptional.h:32
An AVector with string-related functions.
Definition AStringVector.h:22
Represents a Unicode character string.
Definition AString.h:37
A std::vector with AUI extensions.
Definition AVector.h:39