GLSL Struct 1.4.0
glslstruct
Loading...
Searching...
No Matches
vec_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_VEC_TYPE_HPP_
12 #define _GLSL_STRUCT_VEC_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
24namespace glslstruct {
25 /**
26 * @brief vec type container
27 * @ingroup glsl_types
28 */
29 class vec_type : public type<vec_type> {
30 private:
31 friend struct std::hash<vec_type>;
32
33 using base_type = type;
34
35 /// @brief length of vec
36 size_t _length;
37 /// @brief scalar type of vec
38 ValueType _type;
39
40 public:
41 /// @brief constructor with scalar type and length of vec and size of type
42 vec_type(ValueType type, size_t length, size_t size) noexcept;
43 /// @brief default copy constructor
44 vec_type(const vec_type& other) noexcept;
45 /// @brief default move constructor
46 vec_type(vec_type&& other) noexcept;
47 /// @brief default destructor
48 ~vec_type() noexcept override;
49
50 /// @brief default copy assign operator
51 vec_type& operator=(const vec_type& other) noexcept;
52 /// @brief default move assign operator
53 vec_type& operator=(vec_type&& other) noexcept;
54
55 /// @brief accept function for type visitors
57 template<type_visitor T>
58 #else
59 template<class T, std::enable_if_t<is_type_visitor_v<T>, bool> = true>
60 #endif
61 void accept(T& visitor) const {
62 visitor.visit(*this);
63 }
64
65 /// @brief returns scalar type of vec
66 [[nodiscard]] ValueType get_type() const noexcept;
67 /// @brief returns length of vec
68 [[nodiscard]] size_t get_length() const noexcept;
69
70 /// @brief converts type to string
71 [[nodiscard]] std::string to_string() const noexcept override;
72
73 friend bool operator==(const vec_type& lhs, const vec_type& rhs) noexcept;
74 friend bool operator!=(const vec_type& lhs, const vec_type& rhs) noexcept;
75 };
76
77 /**
78 * @brief checks if two vec types are equal
79 * @ingroup glsl_types
80 */
81 [[nodiscard]] bool operator==(const vec_type& lhs, const vec_type& rhs) noexcept;
82 /**
83 * @brief checks if two vec types are not equal
84 * @ingroup glsl_types
85 */
86 [[nodiscard]] bool operator!=(const vec_type& lhs, const vec_type& rhs) noexcept;
87} // namespace glslstruct
88
89/**
90 * @brief std::hash overload for vec_type
91 * @ingroup glsl_types
92 */
93template<>
94struct std::hash<glslstruct::vec_type> {
95 [[nodiscard]] size_t operator()(const glslstruct::vec_type& value) const noexcept;
96};
97 #endif
98#endif
#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