GLSL Struct 1.4.0
glslstruct
Loading...
Searching...
No Matches
array_type.hpp
1/*
2 * glslstruct - a C++ library designed to easily represent GLSL's Uniform Buffer Objects (UBOs) and Shader Storage Buffer Objects (SSBOs) in C++.
3 *
4 * Licensed under the BSD 3-Clause License with Attribution Requirement.
5 * See the LICENSE file for details: https://github.com/MAIPA01/glslstruct/blob/main/LICENSE
6 *
7 * Copyright (c) 2025, Patryk Antosik (MAIPA01)
8 */
9
10#pragma once
11#ifndef _GLSL_STRUCT_ARRAY_TYPE_HPP_
12 #define _GLSL_STRUCT_ARRAY_TYPE_HPP_
13
14 #include <glslstruct/config.hpp>
15
17_GLSL_STRUCT_ERROR(
18 "This is only available for c++17 and greater and when types are not disabled with defined GLSL_STRUCT_DISABLE_TYPES!"
19);
20 #else
21
22 #include <glslstruct/type/containers/type.hpp>
23 #include <glslstruct/var_data/var_data.hpp>
24
25namespace glslstruct {
26 /**
27 * @brief array type container
28 * @ingroup glsl_types
29 */
30 class array_type : public type<array_type> {
31 private:
32 friend struct std::hash<array_type>;
33
34 using base_type = type;
35
36 /// @brief handle to array elem type
37 base_type_handle _type = nullptr;
38 /// @brief count of array elements
39 size_t _count = 0;
40
41 public:
42 /// @brief constructs scalar array type
43 array_type(ValueType type, size_t scalarSize, size_t count, size_t size) noexcept;
44 /// @brief constructs vec array type
45 array_type(ValueType type, size_t length, size_t vecSize, size_t count, size_t size) noexcept;
46 /// @brief constructs mat array type
47 array_type(ValueType type, size_t cols, size_t rows, size_t matSize, size_t count, size_t size) noexcept;
48 /// @brief constructs struct array type
49 array_type(const mstd::ordered_map<std::string, var_data>& values, size_t structSize, size_t count, size_t size) noexcept;
50 /// @brief constructs array with given elem type
51 array_type(const base_type_handle& type, size_t count, size_t size) noexcept;
52 /// @brief constructs array with given elem type
54 template<utils::glsl_type T>
55 #else
56 template<class T, std::enable_if_t<utils::is_glsl_type_v<T>, bool> = true>
57 #endif
58 _GLSL_STRUCT_CONSTEXPR20 array_type(const std::shared_ptr<T>& type, const size_t count, const size_t size) noexcept
59 : base_type(size), _type(std::dynamic_pointer_cast<glslstruct::base_type>(type)), _count(count) {
60 }
61
62 /// @brief default copy constructor
63 array_type(const array_type& other) noexcept;
64 /// @brief default move constructor
65 array_type(array_type&& other) noexcept;
66 /// @brief default destructor
67 ~array_type() noexcept override;
68
69 /// @brief default copy assign operator
70 array_type& operator=(const array_type& other) noexcept;
71 /// @brief default move assign operator
72 array_type& operator=(array_type&& other) noexcept;
73
74 /// @brief accept function for type visitors
76 template<type_visitor T>
77 #else
78 template<class T, std::enable_if_t<is_type_visitor_v<T>, bool> = true>
79 #endif
80 void accept(T& visitor) const {
81 visitor.visit(*this);
82 }
83
84 /// @brief returns array elem type
85 [[nodiscard]] const base_type_handle& get_type() const noexcept;
86
87 /// @brief returns array elems count
88 [[nodiscard]] size_t get_count() const noexcept;
89
90 /// @brief converts type to string
91 [[nodiscard]] std::string to_string() const noexcept override;
92
93 friend bool operator==(const array_type& lhs, const array_type& rhs) noexcept;
94 friend bool operator!=(const array_type& lhs, const array_type& rhs) noexcept;
95 };
96
97 /**
98 * @brief checks if two array types are equal
99 * @ingroup glsl_types
100 */
101 [[nodiscard]] bool operator==(const array_type& lhs, const array_type& rhs) noexcept;
102 /**
103 * @brief checks if two array types are not equal
104 * @ingroup glsl_types
105 */
106 [[nodiscard]] bool operator!=(const array_type& lhs, const array_type& rhs) noexcept;
107} // namespace glslstruct
108
109/**
110 * @brief std::hash overload for array_type
111 * @ingroup glsl_types
112 */
113template<>
114struct std::hash<glslstruct::array_type> {
115 [[nodiscard]] size_t operator()(const glslstruct::array_type& type) const noexcept;
116};
117 #endif
118#endif
#define _GLSL_STRUCT_CONSTEXPR20
constexpr keyword for c++20 and higher
Definition config.hpp:213
#define _GLSL_STRUCT_HAS_CXX20
check if compiler has c++ version greater or equal to c++20 and if user enabled c++20 features using ...
Definition config.hpp:142
#define _GLSL_STRUCT_HAS_TYPES
check if user not disabled type containers using GLSL_STRUCT_DISABLE_TYPES
Definition config.hpp:162
Main namespace of glslstruct library.
Definition scalar_layout_traits.hpp:23