1.1.7. StringTemplate

class eprosima::is::core::StringTemplate

Allows to create a partially filled string with certain parameterizable fields that can be replaced during runtime. It is also possible to specify some details on how the template should be used.

More information about how to construct and properly use it is available on the StringTemplate constructor.

Public Functions

StringTemplate(const std::string &template_string, const std::string &usage_details)

Constructor.

Parameters
  • [in] template_string: A string that describes the desired template. Varying components of the string must be wrapped in curly braces {}. Currently only {message.<field>} variables are supported. The varying components of the string will be replaced by the value of the requested field when compute_string() is called.

  • [in] usage_details: A string that describes how this StringTemplate is being used.

StringTemplate(const StringTemplate &other)

Copy constructor.

Parameters
  • [in] other: const reference to a StringTemplate instance to be copied.

StringTemplate(StringTemplate &&other)

Move constructor.

Parameters

~StringTemplate()

Destructor.

const std::string compute_string(const eprosima::xtypes::DynamicData &message) const

Computes the desired output string, given the input message.

Return

The computed string with the required substitutions properly made.

Parameters
  • [in] message: The message used to compute the string template parameters.

std::string &usage_details()

Gets a mutable reference to the usage_details for this StringTemplate.

Return

The mutable reference to the usage_details string.

const std::string &usage_details() const

Gets a const reference to the usage_details for this StringTemplate.

Return

A const reference to the usage_details string.

class eprosima::is::core::InvalidTemplateFormat : public runtime_error

Runtime error that gets thrown when a certain runtime substitution string template is malformed in the YAML file.

Public Functions

InvalidTemplateFormat(const std::string &template_string, const std::string &details)

Constructor.

Parameters
  • [in] template_string: The source string containing the malformed template.

  • [in] details: Correct usage details of this template.

~InvalidTemplateFormat() = default

Destructor.

const std::string &template_string() const

Gets a const reference to the malformed StringTemplate.

Return

A const reference to the template.

class eprosima::is::core::UnavailableMessageField : public runtime_error

Runtime error that gets thrown when a certain field, required to perform the substitution in a StringTemplate, is unavailable within the provided Dynamic Data.

Public Functions

UnavailableMessageField(const std::string &field_name, const std::string &details)

Constructor.

Parameters
  • [in] field_name: The field which was not found during the substitution.

  • [in] details: Details on how to use this template.

const std::string &field_name() const

Gets a const reference to the field’s name.

Return

A const reference to the string representing the field’s name.