21#include "nlohmann/json_fwd.hpp"
27namespace shamrock::patch {
72 std::vector<var_t> fields;
92 [[nodiscard]]
bool has_field_name(
const std::string &field_name)
const;
102 FieldDescriptor<T>
get_field(
const std::string &field_name);
185 template<
class Functor>
187 for (
auto &f : fields) {
188 f.visit([&](
auto &arg) {
204 }
else if (type ==
"f32_2") {
206 }
else if (type ==
"f32_3") {
208 }
else if (type ==
"f32_4") {
210 }
else if (type ==
"f32_8") {
212 }
else if (type ==
"f32_16") {
214 }
else if (type ==
"f64") {
216 }
else if (type ==
"f64_2") {
218 }
else if (type ==
"f64_3") {
220 }
else if (type ==
"f64_4") {
222 }
else if (type ==
"f64_8") {
224 }
else if (type ==
"f64_16") {
226 }
else if (type ==
"u32") {
228 }
else if (type ==
"u64") {
230 }
else if (type ==
"u32_3") {
232 }
else if (type ==
"u64_3") {
234 }
else if (type ==
"i64_3") {
238 "the select type is not recognized");
266 void to_json(nlohmann::json &j,
const PatchDataLayerLayout &p);
277 void from_json(
const nlohmann::json &j, PatchDataLayerLayout &p);
291 bool operator==(
const PatchDataLayerLayout &lhs,
const PatchDataLayerLayout &rhs);
299 const std::string &field_name) {
301 for (var_t &fvar : fields) {
302 if (FieldDescriptor<T> *pval = std::get_if<FieldDescriptor<T>>(&fvar.value)) {
303 if (pval->name == field_name) {
316 if (FieldDescriptor<T> *pval = std::get_if<FieldDescriptor<T>>(&fields[idx].value)) {
321 "the required type does no match at index " + std::to_string(idx)
327 var_t &tmp = fields[idx];
329 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.
bool has_field_name(const std::string &field_name) const
Check whether a field with the given name already exists.
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