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