2
3
4
5
6
7
8
11#ifndef _GLSL_STRUCT_PARSER_HPP_
12 #define _GLSL_STRUCT_PARSER_HPP_
14 #include <glslstruct/config.hpp>
17_GLSL_STRUCT_ERROR(
"This is only available for c++17 and greater and when parser functionality is not disabled!");
20 #include <glslstruct/struct/base_struct.hpp>
25 #pragma region BASE_PARSER_PATTERNS
28
29
30
40 pcre2cpp::
regex(R"(^\s*+(?>(?<scalar>[idbuf])?mat(?<cols>[2-4])(?>(?:x(?<rows>[2-4]))?))\s*+$)");
44 R"(^\s*+(?>(?<type>[a-zA-Z_]\w*+))\s++(?>(?<name>[a-zA-Z_]\w*+))\s*+(?>(?<array>\[\s*+(?<count>\d+)?\s*+\]))?\s*+(?>;?)\s*+$)"
49 R"((?>(?<=^|;))\s*+(?<var>[a-zA-Z_]\w*+\s++[a-zA-Z_]\w*+(?>(?:\s*+\[\s*+\d*+\s*+\])*+))\s*+(?:;|$))",
55 pcre2cpp::
regex(R"(^\s*+(?>(?>struct)\s++(?>(?<name>[a-zA-Z_]\w*+))\s*+(?>\{(?<body>[^}]*+)\})\s*+;)\s*+$)");
59 R"(\s*+(?<struct>(?>struct|layout\s*+\([^)]*+\)\s*+(?>uniform|(?:\w++\s++)?buffer))\s++(?>(?:[a-zA-Z_]\w*+))\s*+\{(?>[^}]*+)\}\s*+(?>(?:\w*+\s*+));\s*+))",
66 #pragma region UBO_PARSER_PATTERN
68
69
70
74 template<
class Layout, std::enable_if_t<is_glsl_layout_v<Layout>,
bool> =
true>
80
81
82
87 R"(^\s*+layout\s*+\((?>(?:(?:std140|set\s*+=\s*+\d++)\s*+,\s*+)?)\s*+binding\s*+=\s*+\d++\s*+\)\s*+uniform\s*+(?<name>[a-zA-Z_]\w*+)\s*+\{(?<body>[^}]*+)\}\s*+(?>(?:[a-zA-Z_]\w*+)?)\s*+;\s*+$)"
93
94
95
102
103
104
110
111
112
113 template<
class Layout,
class =
void>
114 struct has_ubo_pattern : std::false_type {};
122
123
124
125 template<
class Layout>
130 #pragma region SSBO_PARSER_PATTERN
132
133
134
138 template<
class Layout, std::enable_if_t<is_glsl_layout_v<Layout>,
bool> =
true>
144
145
146
150 R"(^\s*+layout\s*+\((?>std140(?>\s*+,\s*+set\s*+=\s*+\d++)?)\s*+,\s*+binding\s*+=\s*+\d++\s*+\)\s*+(?>(?:[a-zA-Z]++\s++)?buffer)\s++(?<name>[a-zA-Z_]\w*+)\s*+\{(?<body>[^}]*+)\}\s*+(?>(?:[a-zA-Z_]\w*+)?)\s*+;\s*+$)"
155
156
157
161 R"(^\s*+layout\s*+\((?>std430(?>\s*+,\s*+set\s*+=\s*+\d++)?)\s*+,\s*+binding\s*+=\s*+\d++\s*+\)\s*+(?>(?:[a-zA-Z]++\s++)?buffer)\s++(?<name>[a-zA-Z_]\w*+)\s*+\{(?<body>[^}]*+)\}\s*+(?>(?:[a-zA-Z_]\w*+)?)\s*+;\s*+$)"
166
167
168
172 R"(^\s*+layout\s*+\((?>scalar(?>\s*+,\s*+set\s*+=\s*+\d++)?)\s*+,\s*+binding\s*+=\s*+\d++\s*+\)\s*+(?>(?:[a-zA-Z]++\s++)?buffer)\s++(?<name>[a-zA-Z_]\w*+)\s*+\{(?<body>[^}]*+)\}\s*+(?>(?:[a-zA-Z_]\w*+)?)\s*+;\s*+$)"
178
179
180
187
188
189
195
196
197
198 template<
class Layout,
class =
void>
199 struct has_ssbo_pattern : std::false_type {};
208
209
210
211 template<
class Layout>
218
219
220
221
225 template<
class Layout, std::enable_if_t<is_glsl_layout_v<Layout>,
bool> =
true>
248 #pragma region GENERAL_VARIABLE_FUNCTIONS
267 template<
class T,
class S>
278 #pragma region SCALAR_VARIABLE
283 const size_t count) {
296 #pragma region VEC_VARIABLE
299 template<
class T,
class S>
301 const size_t count) {
313 const std::string_view name,
const size_t count) {
326 #pragma region MAT_VARIABLE
329 template<
class T, size_t Cols,
class S>
331 const size_t count) {
341 template<
class T,
class S>
343 const std::string_view name,
const size_t count) {
355 const std::string_view name,
const size_t count) {
368 #pragma region EXTRACT_STRUCTS
409 #pragma region LAYOUT
429 #pragma region CONTAINS
451 #pragma region PARSE_AND_ADD_VARIABLES
456 const size_t count = 0) {
535 #pragma region VARIABLE_PARSER
539 const std::string_view name,
const size_t count) {
551 const std::string_view name) {
583 #pragma region STRUCTS_PARSER
683
684
685
688
689
690
693
694
695
base template class of structs parser
Definition base_parser.hpp:227
_GLSL_STRUCT_CONSTEXPR17 _layout_type create_struct_layout(const std::string_view varsStr)
creates layout with given variables
Definition base_parser.hpp:602
_GLSL_STRUCT_CONSTEXPR17 _struct_type create_struct(const std::string_view varsStr)
creates struct with given variables
Definition base_parser.hpp:608
_GLSL_STRUCT_CONSTEXPR20 std::vector< _struct_type > get_structs(const std::vector< std::string_view > &structsNames)
gets structs with names in array
Definition base_parser.hpp:670
_GLSL_STRUCT_CONSTEXPR20 std::vector< _layout_type > get_structs_layouts(const std::vector< std::string > &structsNames)
gets layouts with names in array
Definition base_parser.hpp:660
_GLSL_STRUCT_CONSTEXPR17 _struct_type & add_variable(_struct_type &structRef, const std::string_view varStr)
adds variable to struct
Definition base_parser.hpp:567
static _GLSL_STRUCT_CONSTEXPR17 S & _add_mat_variable(S &ref, const size_t cols, const size_t rows, const std::string_view name, const size_t count)
adds mat with name and with provided columns and rows to struct or layout
Definition base_parser.hpp:342
_GLSL_STRUCT_CONSTEXPR17 bool _contains_struct_body(const std::string_view name)
returns true if struct with given name is in _structsBodies
Definition base_parser.hpp:432
_GLSL_STRUCT_CONSTEXPR17 _struct_type & add_variable(_struct_type &structRef, const std::string_view type, const std::string_view name)
adds variable to struct
Definition base_parser.hpp:556
std::unordered_map< std::string, _layout_type > _structsLayouts
loaded and converted to layouts structs
Definition base_parser.hpp:246
_GLSL_STRUCT_CONSTEXPR17 _layout_type & add_variables(_layout_type &layoutRef, const std::string_view varsStr)
adds variables to layout
Definition base_parser.hpp:572
_GLSL_STRUCT_CONSTEXPR20 std::vector< std::string > _extract_structs(const std::string_view structsStr)
extracts struct strings from structs list
Definition base_parser.hpp:394
_GLSL_STRUCT_CONSTEXPR17 _struct_type & add_variables(_struct_type &structRef, const std::string_view varsStr)
adds variables to struct
Definition base_parser.hpp:577
_GLSL_STRUCT_CONSTEXPR17 std::vector< _struct_type > create_structs(const std::vector< std::string > &structsStrs)
creates structs from strings array
Definition base_parser.hpp:644
static _GLSL_STRUCT_CONSTEXPR17 S & _add_vec_variable(S &ref, const ValueType type, const size_t length, const std::string_view name, const size_t count)
adds vec with name and of type based on ValueType and with provided length to struct or layout
Definition base_parser.hpp:312
_GLSL_STRUCT_CONSTEXPR17 std::vector< _layout_type > create_structs_layouts(const std::string_view structsStr)
creates layouts from string
Definition base_parser.hpp:639
_GLSL_STRUCT_CONSTEXPR20 S & _add_variable(S &ref, const std::string_view varStr)
adds variable given in string
Definition base_parser.hpp:501
_GLSL_STRUCT_CONSTEXPR17 _struct_type get_struct(const std::string_view structName)
get struct earlier defined
Definition base_parser.hpp:623
_GLSL_STRUCT_CONSTEXPR17 std::vector< _struct_type > create_structs(const std::string_view structsStr)
creates structs from string
Definition base_parser.hpp:655
static _GLSL_STRUCT_CONSTEXPR17 bool has_ssbo_pattern
returns true if given layout can be used by ssbo
Definition base_parser.hpp:241
_GLSL_STRUCT_CONSTEXPR17 void add_structs_definitions(const std::string_view structsStr)
adds structs definitions
Definition base_parser.hpp:597
static _GLSL_STRUCT_CONSTEXPR17 ValueType _get_value_type_from_string(const std::string_view type) noexcept
returns ValueType based on type in string
Definition base_parser.hpp:251
_GLSL_STRUCT_CONSTEXPR17 _layout_type & add_variable(_layout_type &layoutRef, const std::string_view type, const std::string_view name, const size_t count)
adds variable array to layout
Definition base_parser.hpp:538
_GLSL_STRUCT_CONSTEXPR17 bool _contains_struct_layout(const std::string_view name)
returns true if struct with given name is in _structsLayouts
Definition base_parser.hpp:441
_GLSL_STRUCT_CONSTEXPR17 _layout_type & add_variable(_layout_type &layoutRef, const std::string_view type, const std::string_view name)
adds variable to layout
Definition base_parser.hpp:550
_GLSL_STRUCT_CONSTEXPR20 std::pair< std::string, std::string > _extract_struct_data(const std::string_view structStr)
extracts name and body of structure from string
Definition base_parser.hpp:371
_GLSL_STRUCT_CONSTEXPR20 std::vector< _layout_type > create_structs_layouts(const std::vector< std::string > &structs)
creates layouts from strings array
Definition base_parser.hpp:628
_GLSL_STRUCT_CONSTEXPR17 _layout_type _create_layout(const std::string_view varsStr)
creates layout with variables in vars list
Definition base_parser.hpp:412
_GLSL_STRUCT_CONSTEXPR17 bool _load_layout(const std::string_view structName)
loads layout from structsBodies to structsLayouts and returns if there is a layout with given name in...
Definition base_parser.hpp:418
std::unordered_map< std::string, std::string > _structsBodies
loaded and not converted to layouts structs bodies
Definition base_parser.hpp:244
static _GLSL_STRUCT_CONSTEXPR17 S & _add_vec_variable(S &ref, const size_t length, const std::string_view name, const size_t count)
adds vec with name and with provided length to struct or layout
Definition base_parser.hpp:300
_GLSL_STRUCT_CONSTEXPR20 S & _add_variable(S &ref, const std::string_view type, const std::string_view name, const size_t count=0)
adds variable of type given in string and with name and count
Definition base_parser.hpp:455
_GLSL_STRUCT_CONSTEXPR17 _layout_type get_struct_layout(const std::string_view structName)
get layout of struct earlier defined
Definition base_parser.hpp:613
_GLSL_STRUCT_CONSTEXPR17 base_parser()=default
default constructor
Layout _layout_type
layout type
Definition base_parser.hpp:230
_GLSL_STRUCT_CONSTEXPR20 S & _add_variables(S &ref, const std::string_view varsStr)
adds variables given in var list string
Definition base_parser.hpp:517
static _GLSL_STRUCT_CONSTEXPR17 S & _add_scalar_variable(S &ref, const ValueType type, const std::string_view name, const size_t count)
adds scalar with name and of type based on ValueType to struct or layout
Definition base_parser.hpp:282
_GLSL_STRUCT_CONSTEXPR17 _layout_type & add_variable(_layout_type &layoutRef, const std::string_view varStr)
adds variable to layout
Definition base_parser.hpp:562
_GLSL_STRUCT_CONSTEXPR17 void add_struct_definition(const std::string_view structStr)
adds struct definition
Definition base_parser.hpp:591
static _GLSL_STRUCT_CONSTEXPR17 S & _add_mat_variable(S &ref, const size_t rows, const std::string_view name, const size_t count)
adds mat with name and with provided rows to struct or layout
Definition base_parser.hpp:330
_GLSL_STRUCT_CONSTEXPR17 void add_struct_definition(const std::string_view name, const std::string_view varsStr)
adds struct definition
Definition base_parser.hpp:586
_GLSL_STRUCT_CONSTEXPR17 _struct_type & add_variable(_struct_type &structRef, const std::string_view type, const std::string_view name, const size_t count)
adds variable array to struct
Definition base_parser.hpp:544
static _GLSL_STRUCT_CONSTEXPR17 bool has_ubo_pattern
returns true if given layout can be used by ubo
Definition base_parser.hpp:239
static _GLSL_STRUCT_CONSTEXPR17 S & _add_variable(S &ref, const std::string_view name, const size_t count)
adds variable of type T to struct or layout (if count != 0 then it adds array of variables of type T)
Definition base_parser.hpp:268
static _GLSL_STRUCT_CONSTEXPR17 S & _add_mat_variable(S &ref, const ValueType type, const size_t cols, const size_t rows, const std::string_view name, const size_t count)
adds mat with name and of type based on ValueType and with provided columns and rows to struct or lay...
Definition base_parser.hpp:354
utils::base_parser_patterns _base_patterns
Definition base_parser.hpp:234
#define _GLSL_STRUCT_HAS_PARSER
check if user want to include parser functionality
Definition config.hpp:186
#define _GLSL_STRUCT_CONSTEXPR20
constexpr keyword for c++20 and higher
Definition config.hpp:213
#define glsl_struct_assert(expression,...)
glslstruct assert
Definition assert.hpp:33
#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_CONSTEXPR17
constexpr for c++17 and higher
Definition config.hpp:196
Main namespace of glslstruct library.
Definition contexts.hpp:20
all parser patterns in one struct
Definition base_parser.hpp:31
static const auto structPattern
pattern to get struct data
Definition base_parser.hpp:54
static const auto vecPattern
pattern to get vec data
Definition base_parser.hpp:36
static const auto multiStructsPattern
pattern to get multiple structs
Definition base_parser.hpp:58
static const auto matPattern
pattern to get mat data
Definition base_parser.hpp:39
static const auto scalarsPattern
pattern to get scalar data
Definition base_parser.hpp:33
static const auto variablePattern
pattern to get variable data
Definition base_parser.hpp:43
static const auto multiVariablesPattern
pattern to get multiple variables
Definition base_parser.hpp:48
container for ssbo parser pattern
Definition base_parser.hpp:140
container for ubo parser pattern
Definition base_parser.hpp:76