Archetype: cpp_service.hpp.mustache
Entity service declarations. service profile (per entity). Application-layer service wrapping repository calls with business-rule validation, NATS event emission, and structured error handling.
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_service.hpp.mustache.
{{! GENERATED FILE — tangled from projects/ores.codegen/library/templates/cpp_messaging.org. Edit the org source. }}
{{{cpp_license}}}
{{#domain_entity}}
#ifndef ORES_{{component_core_upper}}_SERVICE_{{entity_singular_upper}}_SERVICE_HPP
#define ORES_{{component_core_upper}}_SERVICE_{{entity_singular_upper}}_SERVICE_HPP
#include <cstdint>
#include <optional>
#include <string>
#include <vector>
#include "ores.logging/make_logger.hpp"
#include "ores.database/domain/context.hpp"
#include "ores.{{component_include}}/domain/{{entity_singular}}.hpp"
#include "ores.{{component_core}}/repository/{{entity_singular}}_repository.hpp"
#include "ores.{{component_core}}/export.hpp"
<<paste:C5F35C7E-6EED-48D8-99F8-793145586882>>
namespace ores::{{component}}::service {
/**
* @brief Service for managing {{entity_plural_words}}.
*/
class ORES_{{component_core_upper}}_EXPORT {{entity_singular}}_service {
private:
inline static std::string_view logger_name =
"ores.{{component}}.service.{{entity_singular}}_service";
[[nodiscard]] static auto& lg() {
using namespace ores::logging;
static auto instance = make_logger(logger_name);
return instance;
}
public:
using context = ores::database::context;
explicit {{entity_singular}}_service(context ctx);
std::vector<domain::{{entity_singular}}>
list_{{entity_plural_short}}(std::uint32_t offset, std::uint32_t limit);
std::uint32_t count_{{entity_plural_short}}();
std::optional<domain::{{entity_singular}}>
get_{{entity_singular_short}}(const std::string& {{primary_key.column}});
void save_{{entity_singular_short}}(const domain::{{entity_singular}}& {{entity_singular_short}});
void save_{{entity_plural_short}}(
const std::vector<domain::{{entity_singular}}>& {{entity_plural_short}});
void delete_{{entity_singular_short}}(const std::string& {{primary_key.column}});
void delete_{{entity_plural_short}}(
const std::vector<std::string>& {{primary_key.column}}s);
std::vector<domain::{{entity_singular}}>
get_{{entity_singular_short}}_history(const std::string& {{primary_key.column}});
<<paste:2D4EA0F9-6AF6-45A5-A959-F672BF866C6A>>
private:
context ctx_;
repository::{{entity_singular}}_repository repo_;
<<paste:047A96EF-1CC4-4661-B80B-C6C4532076AB>>
};
}
#endif
{{/domain_entity}}
{{#junction}}
#ifndef ORES_{{component_upper}}_SERVICE_{{name_singular_upper}}_SERVICE_HPP
#define ORES_{{component_upper}}_SERVICE_{{name_singular_upper}}_SERVICE_HPP
#include <string>
#include <vector>
{{#has_uuid_left_or_right}}
#include <boost/uuid/uuid.hpp>
{{/has_uuid_left_or_right}}
#include "ores.logging/make_logger.hpp"
#include "ores.database/domain/context.hpp"
#include "ores.{{component_include}}/domain/{{name_singular}}.hpp"
#include "ores.{{component_core}}/repository/{{name_singular}}_repository.hpp"
namespace ores::{{component}}::service {
/**
* @brief Service for managing {{name_words}}.
*
* This service provides functionality for:
* - Managing {{name_words}} (CRUD operations)
*/
class {{name_singular}}_service {
private:
inline static std::string_view logger_name =
"ores.{{component}}.service.{{name_singular}}_service";
[[nodiscard]] static auto& lg() {
using namespace ores::logging;
static auto instance = make_logger(logger_name);
return instance;
}
public:
using context = ores::database::context;
/**
* @brief Constructs a {{name_singular}}_service with required repositories.
*
* @param ctx The database context.
*/
explicit {{name_singular}}_service(context ctx);
/**
* @brief Lists all {{name_words}}.
*/
std::vector<domain::{{name_singular}}> list_{{name_short}}();
/**
* @brief Lists {{name_words}} for a specific {{left.column_title_lower}}.
*
* @param {{left.column}} The {{left.column_title_lower}} to filter by
*/
std::vector<domain::{{name_singular}}>
{{#left.is_uuid}}
list_{{name_short}}_by_{{left.column_short}}(const boost::uuids::uuid& {{left.column}});
{{/left.is_uuid}}
{{^left.is_uuid}}
list_{{name_short}}_by_{{left.column_short}}(const std::string& {{left.column}});
{{/left.is_uuid}}
/**
* @brief Saves a {{name_singular_words}} (creates or updates).
*
* @param {{name_singular_short}} The {{name_singular_words}} to save
*/
void save_{{name_singular_short}}(const domain::{{name_singular}}& {{name_singular_short}});
/**
* @brief Removes a {{name_singular_words}}.
*
* @param {{left.column}} The {{left.column_title_lower}}
* @param {{right.column}} The {{right.column_title_lower}}
*/
{{#left.is_uuid}}
void remove_{{name_singular_short}}(const boost::uuids::uuid& {{left.column}},
{{/left.is_uuid}}
{{^left.is_uuid}}
void remove_{{name_singular_short}}(const std::string& {{left.column}},
{{/left.is_uuid}}
{{#right.is_uuid}}
const boost::uuids::uuid& {{right.column}});
{{/right.is_uuid}}
{{^right.is_uuid}}
const std::string& {{right.column}});
{{/right.is_uuid}}
private:
repository::{{name_singular}}_repository repo_;
};
}
#endif
{{/junction}}
See also
- Parent facet: C++ messaging templates
- Template variable reference