ores.cpp.convention-family.unit
Table of Contents
One translation unit for one convention family. apply_<key> decodes one
staged payload into the family's own type, stamps the session's party on it and
writes it in the family's mode: a party family replaces the party's rows, a
by-id family replaces the rows the payload names, and a world family adds only
the rows the tenant lacks. read_<key>_payloads serialises the family's live
rows the way the wire carries them. The unit includes one repository header and
reflects one type.
See the Template variable reference for the complete list of available variables and their semantics.
1. Template
The full template source. Edit here and re-tangle with
compass build --direct tangle_codegen_templates to regenerate
library/templates/cpp_convention_family_unit.cpp.mustache.
{{! GENERATED FILE — tangled from projects/ores.codegen/library/templates/ores.cpp.convention-family.unit.org. Edit the org source. }}
{{{cpp_license}}}
{{#convention_unit}}
#include "convention_family_units.hpp"
#include "conventions_row_helpers.hpp"
#include "ores.refdata.core/repository/{{entity}}_repository.hpp"
#include "ores.service/messaging/handler_helpers.hpp"
{{#has_wire_codec}}
#include "{{codec_include}}"
{{/has_wire_codec}}
#include "ores.utility/codec/json_codec.hpp"
#include <stdexcept>
#include <utility>
#include <vector>
namespace ores::refdata::service::convention_family {
void apply_{{key}}(const ores::database::context& ctx,
const std::string& payload,
{{^is_world}}[[maybe_unused]] {{/is_world}}conventions_apply_result& result) {
const auto decoded = ores::utility::codec::json::try_read<{{domain_type}}>(payload);
if (!decoded)
throw std::runtime_error(
"Staged conventions payload for family "
"\"{{key}}\" does not decode.");
auto rows = std::vector<{{domain_type}}>{std::move(*decoded)};
// A grouped row keeps its security fields in a member, so the stamp has
// to walk into it; stamp_document does, and leaves a flat row alone.
ores::service::messaging::stamp_document(rows.front(), ctx);
{{#is_world}}
add_missing_world_rows(ctx,
ores::refdata::repository::{{entity}}_repository(),
std::move(rows),
result.world_kept);
{{/is_world}}
{{^is_world}}
{{#is_party}}replace_party_rows{{/is_party}}{{#is_by_id}}replace_rows_by_id{{/is_by_id}}(ctx,
ores::refdata::repository::{{entity}}_repository(),
std::move(rows));
{{/is_world}}
}
std::vector<std::string> read_{{key}}_payloads(const ores::database::context& ctx) {
std::vector<std::string> payloads;
for (const auto& row : ores::refdata::repository::{{entity}}_repository().read_latest(ctx))
payloads.push_back(
ores::utility::codec::json::write(row));
return payloads;
}
}
{{/convention_unit}}
2. See also
- Parent facet: ores.cpp.convention-family
- ores.cpp.convention-registry.unit_declarations — the declarations this unit defines.
- Template variable reference