24#include <nlohmann/json.hpp>
29namespace shamrock::patch {
74 std::vector<var_t> fields;
96 FieldDescriptor<T>
get_field(
const std::string &field_name);
179 template<
class Functor>
181 for (
auto &f : fields) {
182 f.visit([&](
auto &arg) {
198 }
else if (type ==
"f32_2") {
200 }
else if (type ==
"f32_3") {
202 }
else if (type ==
"f32_4") {
204 }
else if (type ==
"f32_8") {
206 }
else if (type ==
"f32_16") {
208 }
else if (type ==
"f64") {
210 }
else if (type ==
"f64_2") {
212 }
else if (type ==
"f64_3") {
214 }
else if (type ==
"f64_4") {
216 }
else if (type ==
"f64_8") {
218 }
else if (type ==
"f64_16") {
220 }
else if (type ==
"u32") {
222 }
else if (type ==
"u64") {
224 }
else if (type ==
"u32_3") {
226 }
else if (type ==
"u64_3") {
228 }
else if (type ==
"i64_3") {
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",
317 fields.push_back(var_t{FieldDescriptor<T>(field_name, nvar)});
322 const std::string &field_name) {
324 for (var_t &fvar : fields) {
325 if (FieldDescriptor<T> *pval = std::get_if<FieldDescriptor<T>>(&fvar.value)) {
326 if (pval->name == field_name) {
339 if (FieldDescriptor<T> *pval = std::get_if<FieldDescriptor<T>>(&fields[idx].value)) {
344 "the required type does no match at index " + std::to_string(idx)
350 for (
u32 i = 0; i < fields.size(); i++) {
351 if (
const FieldDescriptor<T> *pval
352 = std::get_if<FieldDescriptor<T>>(&fields[i].value)) {
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++) {
370 if (
const FieldDescriptor<T> *pval
371 = std::get_if<FieldDescriptor<T>>(&fields[i].value)) {
372 if ((pval->name == field_name) && (pval->nvar == nvar)) {
384 var_t &tmp = fields[idx];
386 FieldDescriptor<T> *pval = std::get_if<FieldDescriptor<T>>(&tmp.
value);
Field variant object to instanciate a variant on the patch types.
void to_json(nlohmann::json &j, const PatchSchedulerConfig &p)
Converts a PatchSchedulerConfig object to a JSON object.
void from_json(const nlohmann::json &j, PatchSchedulerConfig &p)
Deserializes a PatchSchedulerConfig object from a JSON object.
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.
ExcptTypes make_except_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Create an exception with a message and a location.
provide information about the source location
std::string format_one_line() const
format the location in a one liner