|
| Module () |
|
tl::expected< void, std::error_code > | add_model (model_pointer model) noexcept |
|
tl::expected< void, std::error_code > | add_field (text &&alias, field_pointer field) noexcept |
|
tl::expected< void, std::error_code > | add_field (field_pointer field) noexcept |
|
model_pointer | get_model (const text &name) const noexcept |
|
template<typename Callable > |
void | get_model (const text &name, Callable &&cb) const noexcept |
|
const_model_iterator | begin_models () const |
|
const_model_iterator | end_models () const |
|
const_model_iterator | find_model (const text &name) const |
|
field_pointer | get_field (const text &name) const noexcept |
|
template<typename Callable > |
void | get_field (const text &name, Callable &&cb) const noexcept |
| Calls the callable function with a shared pointer to the field, if found.
|
|
const_field_iterator | begin_fields () const |
|
const_field_iterator | end_fields () const |
|
const_field_iterator | find_field (const text &name) const |
|
A Module is a repository of models, fields and constraints.
This allows to package lots of relevant fields and models in one object. This can be parsed and dumped which makes it easy to save in a file or send it over the wire.
In a module, no two records can exist with the same entity and they cannot be overriden. So if a Field has already been added by the name "Field", this cannot be exchanged for any other Field. This is mostly because other Model or Constraint instances might already depend on it.
module.
add_field(garlic::make_field(
"ID", { garlic::make_constraint<garlic::regex_tag>(
"\\d{1,3}") }));
auto user_model = garlic::make_model("User");
user_model->add_field(
"id", module.
get_field(
"UID"));
- Note
- Try not to add models or fields that depend on resources outside of this module. That would make it impossible to deserialize should that become necessary.