| 1 |
/* |
| 2 |
* Copyright (c) 2025 The Khronos Group Inc. |
| 3 |
* Copyright (c) 2025 Valve Corporation |
| 4 |
* Copyright (c) 2025 LunarG, Inc. |
| 5 |
* |
| 6 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 |
* of this software and/or associated documentation files (the "Materials"), to |
| 8 |
* deal in the Materials without restriction, including without limitation the |
| 9 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 |
* sell copies of the Materials, and to permit persons to whom the Materials are |
| 11 |
* furnished to do so, subject to the following conditions: |
| 12 |
* |
| 13 |
* The above copyright notice(s) and this permission notice shall be included in |
| 14 |
* all copies or substantial portions of the Materials. |
| 15 |
* |
| 16 |
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 19 |
* |
| 20 |
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 21 |
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 22 |
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE |
| 23 |
* USE OR OTHER DEALINGS IN THE MATERIALS. |
| 24 |
* |
| 25 |
*/ |
| 26 |
|
| 27 |
#pragma once |
| 28 |
|
| 29 |
#include <vector> |
| 30 |
|
| 31 |
// Macro to ease the definition of variables with builder member functions |
| 32 |
// type = type of the variable |
| 33 |
// name = name of the variable |
| 34 |
// default_value = value to default initialize, use {} if nothing else makes sense |
| 35 |
#define BUILDER_VALUE_WITH_DEFAULT(type, name, default_value) \ |
| 36 |
type name = default_value; \ |
| 37 |
auto set_##name(type const& name)->decltype(*this) { \ |
| 38 |
this->name = name; \ |
| 39 |
return *this; \ |
| 40 |
} |
| 41 |
|
| 42 |
#define BUILDER_VALUE(type, name) BUILDER_VALUE_WITH_DEFAULT(type, name, {}) |
| 43 |
|
| 44 |
// Macro to ease the definition of vectors with builder member functions |
| 45 |
// type = type of the variable |
| 46 |
// name = name of the variable |
| 47 |
// singular_name = used for the `add_singular_name` member function |
| 48 |
#define BUILDER_VECTOR(type, name, singular_name) \ |
| 49 |
std::vector<type> name; \ |
| 50 |
auto add_##singular_name(type const& singular_name)->decltype(*this) { \ |
| 51 |
this->name.push_back(singular_name); \ |
| 52 |
return *this; \ |
| 53 |
} \ |
| 54 |
auto add_##singular_name##s(std::vector<type> const& singular_name)->decltype(*this) { \ |
| 55 |
for (auto& elem : singular_name) this->name.push_back(elem); \ |
| 56 |
return *this; \ |
| 57 |
} |
| 58 |
// Like BUILDER_VECTOR but for move only types - where passing in means giving up ownership |
| 59 |
#define BUILDER_VECTOR_MOVE_ONLY(type, name, singular_name) \ |
| 60 |
std::vector<type> name; \ |
| 61 |
auto add_##singular_name(type&& singular_name)->decltype(*this) { \ |
| 62 |
this->name.push_back(std::move(singular_name)); \ |
| 63 |
return *this; \ |
| 64 |
} |