AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AArrayView.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
15#include <cstdint>
16#include <cstddef>
17#include <cassert>
18#include <AUI/Common/AVector.h>
19#include <AUI/Common/AStaticVector.h>
20
24template<typename T>
25class AArrayView {
26public:
27 AArrayView(const T* data, std::size_t count) noexcept : mData(data), mCount(count) {}
28 AArrayView(const AVector<T>& vector) noexcept: mData(vector.data()), mCount(vector.size()) {
29
30 }
31
32 template<size_t Capacity>
33 AArrayView(const AStaticVector<T, Capacity>& vector) noexcept: mData(vector.data()), mCount(vector.size()) {
34
35 }
36
37 template<std::size_t N>
38 AArrayView(const T (&rawArray)[N]) noexcept: mData(rawArray), mCount(N) {}
39
40 template<std::size_t N>
41 AArrayView(const std::array<T, N>& array) noexcept: mData(array.data()), mCount(N) {}
42
43 [[nodiscard]]
44 const T* data() const noexcept {
45 return mData;
46 }
47
48 [[nodiscard]]
49 size_t size() const noexcept {
50 return mCount;
51 }
52 [[nodiscard]]
53 size_t sizeInBytes() const noexcept {
54 return mCount * sizeof(T);
55 }
56
57 const T& operator[](std::size_t index) const noexcept {
58 AUI_ASSERTX(index < mCount, "out of bounds");
59 return mData[index];
60 }
61
62 const T* begin() const noexcept {
63 return mData;
64 }
65
66 const T* end() const noexcept {
67 return mData + mCount;
68 }
69
70private:
71 const T* mData;
72 std::size_t mCount;
73};
Vector-like container up to maxSize elements inplace.
Definition AStaticVector.h:33
A std::vector with AUI extensions.
Definition AVector.h:39
#define AUI_ASSERTX(condition, what)
Asserts that the passed condition evaluates to true. Adds extra message string.
Definition Assert.h:74