24#include <nlohmann/json.hpp>
29namespace shamrock::patch {
74 std::vector<var_t> fields;
149 return check_field_type<T>(0);
179 template<
class Functor>
181 for (
auto &f : fields) {
182 f.visit([&](
auto &arg) {
197 add_field<f32>(fname, nvar);
198 }
else if (type ==
"f32_2") {
199 add_field<f32_2>(fname, nvar);
200 }
else if (type ==
"f32_3") {
201 add_field<f32_3>(fname, nvar);
202 }
else if (type ==
"f32_4") {
203 add_field<f32_4>(fname, nvar);
204 }
else if (type ==
"f32_8") {
205 add_field<f32_8>(fname, nvar);
206 }
else if (type ==
"f32_16") {
207 add_field<f32_16>(fname, nvar);
208 }
else if (type ==
"f64") {
209 add_field<f64>(fname, nvar);
210 }
else if (type ==
"f64_2") {
211 add_field<f64_2>(fname, nvar);
212 }
else if (type ==
"f64_3") {
213 add_field<f64_3>(fname, nvar);
214 }
else if (type ==
"f64_4") {
215 add_field<f64_4>(fname, nvar);
216 }
else if (type ==
"f64_8") {
217 add_field<f64_8>(fname, nvar);
218 }
else if (type ==
"f64_16") {
219 add_field<f64_16>(fname, nvar);
220 }
else if (type ==
"u32") {
221 add_field<u32>(fname, nvar);
222 }
else if (type ==
"u64") {
223 add_field<u64>(fname, nvar);
224 }
else if (type ==
"u32_3") {
225 add_field<u32_3>(fname, nvar);
226 }
else if (type ==
"u64_3") {
227 add_field<u64_3>(fname, nvar);
228 }
else if (type ==
"i64_3") {
229 add_field<i64_3>(fname, nvar);
232 "the select type is not recognized");
260 void to_json(nlohmann::json &j,
const PatchDataLayerLayout &p);
271 void from_json(
const nlohmann::json &j, PatchDataLayerLayout &p);
285 bool operator==(
const PatchDataLayerLayout &lhs,
const PatchDataLayerLayout &rhs);
296 for (
var_t &fvar : fields) {
297 fvar.visit([&](
auto &arg) {
298 if (field_name == arg.name) {
306 "add_field -> the name already exists");
310 "PatchDataLayerLayout",
322 const std::string &field_name) {
324 for (
var_t &fvar : fields) {
326 if (pval->name == field_name) {
344 "the required type does no match at index " + std::to_string(idx)
350 for (
u32 i = 0; i < fields.size(); i++) {
353 if (pval->name == field_name) {
360 "the requested field does not exists\n the function : {}\n the field name : {}\n "
361 " current table : \n{}",
369 for (
u32 i = 0; i < fields.size(); i++) {
372 if ((pval->name == field_name) && (pval->nvar == nvar)) {
384 var_t &tmp = fields[idx];
Field variant object to instanciate a variant on the patch types.
std::uint32_t u32
32 bit unsigned integer
Structure describing a field in a patch data layout.
T field_T
The type of the field mirrored from the template type.
std::string name
The name of the field.
FieldDescriptor(std::string name, u32 nvar)
Constructor with a given name and number of variables.
u32 nvar
The number of variables of the field per object.
FieldDescriptor()
Default constructor.
u32 get_field_idx(const std::string &field_name) const
Get the field id if matching name & type.
friend bool operator==(const PatchDataLayerLayout &lhs, const PatchDataLayerLayout &rhs)
Overloaded equality operator for PatchDataLayerLayout class.
void add_field(const std::string &field_name, u32 nvar, SourceLocation loc=SourceLocation{})
add a field of type T to the layout
const var_t & get_main_field_any() const
Get the main field description as a variant object.
bool check_field_type(u32 idx)
check that field of id @idx is of type T
bool check_main_field_type()
check that main field (id=0)is of type T
FieldDescriptor< T > get_field(const std::string &field_name)
Get the field description id if matching name & type.
std::vector< std::string > get_field_names()
Get the list of field names.
void for_each_field_any(Functor &&func) const
for each visit of each field
void add_field_t(std::string fname, u32 nvar, std::string type)
Add a field with type specified as a string.
std::string get_description_str() const
Get the description of the layout.
This header file contains utility functions related to exception handling in the code.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
provide information about the source location
std::string format_one_line() const
format the location in a one liner