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