ores.cpp.domain.class_header
The entity's value type: members from the model's columns plus valid_from / valid_to. domain profile. A plain C++ aggregate `struct` — no user-declared constructors, copyable, movable, and aggregate-initialisable. Relies on reflect-cpp (via the companion `_json_io` archetype) for serialisation; the domain type itself carries no serialisation code.
See the Template variable reference for the complete list of available variables and their semantics.
Template
The full template source. Edit here and re-tangle with
compass build --direct tangle_codegen_templates to regenerate
library/templates/cpp_domain_type_class.hpp.mustache.
{{! GENERATED FILE — tangled from projects/ores.codegen/library/templates/cpp_domain.org. Edit the org source. }}
{{{cpp_license}}}
{{#domain_entity}}
#ifndef ORES_{{component_include_upper}}_DOMAIN_{{entity_singular_upper}}_HPP
#define ORES_{{component_include_upper}}_DOMAIN_{{entity_singular_upper}}_HPP
{{#cpp.includes.domain}}
#include {{{.}}}
{{/cpp.includes.domain}}
{{^has_identity_group}}
{{#has_tenant_id}}
#include "ores.utility/uuid/tenant_id.hpp"
{{/has_tenant_id}}
{{/has_identity_group}}
#include <string_view>
namespace ores::{{component}}::domain {
/**
* @brief {{{brief}}}
*
{{#description_lines}}
*{{#.}} {{{.}}}{{/.}}
{{/description_lines}}
*/
struct {{entity_singular}} final {
{{#has_identity_group}}
{{identity_group_type}} identity;
{{/has_identity_group}}
{{^has_identity_group}}
{{#has_audit_columns}}
/**
* @brief Version number for optimistic locking and change tracking.
*/
int version = 0;
{{/has_audit_columns}}
{{#has_tenant_id}}
/**
* @brief Tenant identifier for multi-tenancy isolation.
*/
utility::uuid::tenant_id tenant_id = utility::uuid::tenant_id::system();
{{/has_tenant_id}}
{{#has_workspace_id}}
/**
* @brief Workspace this record belongs to.
*
* Defaults to the Live workspace sentinel.
*/
boost::uuids::uuid workspace_id = utility::uuid::live_workspace_id();
{{/has_workspace_id}}
{{#primary_key.columns}}
/**
* @brief {{{description}}}
{{#detail}}
*
* {{{detail}}}
{{/detail}}
*/
{{{cpp_type}}} {{column}};
{{/primary_key.columns}}
{{#natural_keys}}
/**
* @brief {{{description}}}
{{#detail}}
*
* {{{detail}}}
{{/detail}}
*/
{{{cpp_type}}} {{column}}{{#default_value}} = {{{default_value}}}{{/default_value}};
{{/natural_keys}}
{{/has_identity_group}}
{{#columns}}
{{^is_identity_group_column}}
/**
* @brief {{{description}}}
{{#detail}}
*
* {{{detail}}}
{{/detail}}
*/
{{{cpp_type}}} {{name}}{{#default_value}} = {{{default_value}}}{{/default_value}};
{{/is_identity_group_column}}
{{/columns}}
{{#has_audit_group}}
{{{audit_group_qualified}}} audit;
{{/has_audit_group}}
{{^has_audit_group}}
{{#has_audit_columns}}
/**
* @brief Username of the person who last modified this {{entity_singular_words}}.
*/
std::string modified_by;
/**
* @brief Username of the account that performed this action.
*/
std::string performed_by;
/**
* @brief Code identifying the reason for the change.
*
* References change_reasons table (soft FK).
*/
std::string change_reason_code;
/**
* @brief Free-text commentary explaining the change.
*/
std::string change_commentary;
{{/has_audit_columns}}
/**
* @brief Timestamp when this version of the record was recorded.
*/
std::chrono::system_clock::time_point recorded_at;
{{/has_audit_group}}
};
/**
* @brief Dispatch-key identifier for {{entity_singular}}, e.g. for the
* generic history-diff request and action registries. Single source
* of truth: every call site spells entity_type_of(value) regardless
* of which entity it holds.
*/
[[nodiscard]] constexpr std::string_view entity_type_of(const {{entity_singular}}&) {
return "ores.{{component}}.{{entity_singular}}";
}
}
#endif
{{/domain_entity}}
{{#junction}}
#ifndef ORES_{{component_upper}}_DOMAIN_{{name_singular_upper}}_HPP
#define ORES_{{component_upper}}_DOMAIN_{{name_singular_upper}}_HPP
{{#cpp.includes.domain}}
#include {{{.}}}
{{/cpp.includes.domain}}
#include <string_view>
namespace ores::{{component}}::domain {
/**
* @brief {{{brief}}}
*
{{#description_lines}}
*{{#.}} {{{.}}}{{/.}}
{{/description_lines}}
*/
struct {{name_singular}} final {
/**
* @brief Version number for optimistic locking and change tracking.
*/
int version = 0;
{{#has_tenant_id}}
/**
* @brief Tenant identifier for multi-tenancy isolation.
*/
std::string tenant_id;
{{/has_tenant_id}}
/**
* @brief {{{left.description}}}
{{#left.detail}}
*
* {{{left.detail}}}
{{/left.detail}}
*/
{{{left.cpp_type}}} {{left.column}};
/**
* @brief {{{right.description}}}
{{#right.detail}}
*
* {{{right.detail}}}
{{/right.detail}}
*/
{{{right.cpp_type}}} {{right.column}};
{{#columns}}
/**
* @brief {{{description}}}
{{#detail}}
*
* {{{detail}}}
{{/detail}}
*/
{{{cpp_type}}} {{name}}{{#default_value}} = {{{default_value}}}{{/default_value}};
{{/columns}}
/**
* @brief Username of the person who last modified this {{name_singular_words}}.
*/
std::string modified_by;
/**
* @brief Username of the account that performed this action.
*/
std::string performed_by;
/**
* @brief Code identifying the reason for the change.
*
* References change_reasons table (soft FK).
*/
std::string change_reason_code;
/**
* @brief Free-text commentary explaining the change.
*/
std::string change_commentary;
/**
* @brief Timestamp when this version of the record was recorded.
*/
std::chrono::system_clock::time_point recorded_at;
};
/**
* @brief Dispatch-key identifier for {{name_singular}}, e.g. for the
* generic history-diff request and action registries. Single source
* of truth: every call site spells entity_type_of(value) regardless
* of which entity it holds.
*/
[[nodiscard]] constexpr std::string_view entity_type_of(const {{name_singular}}&) {
return "ores.{{component}}.{{name_singular}}";
}
}
#endif
{{/junction}}
See also
- Parent facet: ores.cpp.domain
- Template variable reference