HM3
Hierarchical Multi-physics Multi-scale Methods
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
hm3::io::file Struct Reference

Description

Describes a single file.

Its JSON serialization contains the following:

  • group_name: file group name
  • index: index of the file within its group
  • dependency_group_name (optional): file group name of its dependency
  • dependency_index (optional): index of the dependency within its group
  • file fields:
    • name: field name
    • size: number of elements in the field
    • in_file [begin, end): location of data within the file
    • type: integer, number, boolean

Instances and minimal complete definitions

struct  id
 File identifier: More...
 

File fields

These functions allow setting the fields of a file for reading and writing If an operation has to be performed right before writing a file (such as computing something and storing it in a temporary buffer) these can be specified on the "before_write" function arguments.

bool has_field (string const &field_name) const
 
bool has_subfield (string const &field_name, string const &subfield_name) const
 
template<typename T >
filefield (string const &field_name, T value)
 Adds field named field_name of constant value:
 
template<typename T >
bool validate_array_field_in_file (string const &field_name, T *begin, T *end) const
 Validates an array field present in the file: More...
 
template<typename T >
filefield (string const &field_name, T *begin, T *end, std::function< void()> before_write=[](){})
 Add an array [begin, end) named field_name to the file.
 
template<typename T >
filefield (string const &field_name, T const &array, array_data_t)
 Add an array [data(array), data(array) + size) named field_name to the file.
 
template<typename T >
filefield (string const &field_name, T *data, std::size_t size)
 Add an array [data, data + size) named field_name to the file.
 

Read constant fields

These functions disambiguate reading from constant fields and return the result by value.

template<typename T , CONCEPT_REQUIRES_(Range< T >{}) >
auto constant (string const &constant_name, T=T{}) const -> T
 
template<typename T , CONCEPT_REQUIRES_(!Range< T >{}) >
auto constant (string const &constant_name, T=T{}) const -> T
 

Public Member Functions

bool has_dependency () const
 Does the file have a dependency?
 
string name () const
 File name.
 
string path () const
 Full file path.
 
string const & group_name () const
 Group name of the file.
 
index_t index () const
 File index.
 
void index (index_t i)
 Set file index.
 
string dependency_name () const
 File name.
 
string dependency_path () const
 Full file path.
 
string const & dependency_group_name () const
 Group name of the file.
 
index_t dependency_index () const
 Dependency file index.
 
void dependency_group_name (string const &g)
 Dependency group name.
 
void dependency_index (index_t i)
 Set dependency file index.
 
 file (string const &group_name, index_t index=index_t{})
 Creates a file without a dependency.
 
 file (const char *group_name)
 Creates a file without a dependency.
 
 file (io::json header)
 Serialize from json header.
 

Member Function Documentation

template<typename T >
bool hm3::io::file::validate_array_field_in_file ( string const &  field_name,
T *  begin,
T *  end 
) const

Validates an array field present in the file:

  • the field must be in the file
  • the field must contain the size amd in_file subfields
  • the byte size of the data-type stored in the file must match the byte size of the data-type to store it in memory
  • the number of elements in the file must match the number of elements in memory

References name().