# StringTemplate.hpp
This File On Github
Ask A Question
API: latest
module: oatpp
#include "oatpp/core/data/share/StringTemplate.hpp"
# StringTemplate
String template.
namespace oatpp { namespace data { namespace share {
class StringTemplate {}
}}}
# Methods
Return Type | Name | Summary |
---|---|---|
[none] | StringTemplate | Constructor. |
void | format | Multiple implementations:
|
const std::vector<Variable>& | getTemplateVariables | Get all template variables. |
void | setExtraData | Set some extra data associated with the template. |
std::shared_ptr<void> | getExtraData | Get extra data associated with the template. |
# StringTemplate::StringTemplate
Constructor.
- @param text - original template text.
- @param variables - template variables.
StringTemplate(const oatpp::String& text, std::vector<Variable>&& variables)
# StringTemplate::format
- Format template.
- @param stream - stream to write result to.
- @param valueProvider - StringTemplate::ValueProvider.
void format(stream::ConsistentOutputStream* stream, ValueProvider* valueProvider) const
- Format template using StringTemplate::VectorValueProvider.
- @param stream - stream to write result to.
- @param params -
std::vector<oatpp::String>
.
void format(stream::ConsistentOutputStream* stream, const std::vector<oatpp::String>& params) const
- Format template using StringTemplate::MapValueProvider.
- @param stream - stream to write result to.
- @param params -
std::unordered_map<oatpp::String, oatpp::String>
.
void format(stream::ConsistentOutputStream* stream, const std::unordered_map<oatpp::String, oatpp::String>& params) const
- Format template using StringTemplate::SingleValueProvider.
- @param stream - stream to write result to.
- @param singleValue - value.
void format(stream::ConsistentOutputStream* stream, const oatpp::String& singleValue) const
- Format template.
- @param valueProvider - StringTemplate::ValueProvider.
- @return - oatpp::String.
oatpp::String format(ValueProvider* valueProvider) const
- Format template using StringTemplate::VectorValueProvider.
- @param params -
std::vector<oatpp::String>
. - @return - resultant string.
oatpp::String format(const std::vector<oatpp::String>& params) const
- @param params -
- Format template using StringTemplate::MapValueProvider.
- @param params -
std::unordered_map<oatpp::String, oatpp::String>
. - @return - resultant string.
oatpp::String format(const std::unordered_map<oatpp::String, oatpp::String>& params) const
- @param params -
- Format template using StringTemplate::SingleValueProvider.
- @param singleValue - value.
- @return - resultant string.
oatpp::String format(const oatpp::String& singleValue) const
# StringTemplate::getTemplateVariables
Get all template variables.
- @return -
std::vector
of StringTemplate::Variable.
const std::vector<Variable>& getTemplateVariables() const
# StringTemplate::setExtraData
Set some extra data associated with the template.
- @param data
void setExtraData(const std::shared_ptr<void>& data)
# StringTemplate::getExtraData
Get extra data associated with the template.
- @return
std::shared_ptr<void> getExtraData() const
# StringTemplate::Variable
Template variable.
namespace oatpp { namespace data { namespace share {
class StringTemplate {
struct Variable {}
};
}}}
# Fields
Type | Name | Summary |
---|---|---|
v_buff_size | posStart | Position of the first char in the original template string. |
v_buff_size | posEnd | Position of the last char in the original template string. |
oatpp::String | name | Name of the template variable. |
std::shared_ptr<void> | extra | Some auxiliary data. |
# StringTemplate::Variable::posStart
Position of the first char in the original template string.
v_buff_size posStart
# StringTemplate::Variable::posEnd
Position of the last char in the original template string.
v_buff_size posEnd
# StringTemplate::Variable::name
Name of the template variable.
oatpp::String name
# StringTemplate::Variable::extra
Some auxiliary data.
std::shared_ptr<void> extra
# StringTemplate::ValueProvider
Abstract template value provider.
namespace oatpp { namespace data { namespace share {
class StringTemplate {
class ValueProvider {}
};
}}}
# Methods
Return Type | Name | Summary |
---|---|---|
[none] | ~ValueProvider | Default virtual destructor. |
oatpp::String | getValue | Get value for variable. |
# StringTemplate::ValueProvider::~ValueProvider
Default virtual destructor.
virtual ~ValueProvider() = default
# StringTemplate::ValueProvider::getValue
Get value for variable.
- @param variable - StringTemplate::Variable.
- @param index - index of the variable in the template.
- @return - value for the given variable.
virtual oatpp::String getValue(const Variable& variable, v_uint32 index) = 0
# StringTemplate::VectorValueProvider
Provider of template variable-values based on the std::vector.
namespace oatpp { namespace data { namespace share {
class StringTemplate {
class VectorValueProvider : public ValueProvider {}
};
}}}
# StringTemplate::MapValueProvider
Provider of template variable-values based on the std::unordered_map.
namespace oatpp { namespace data { namespace share {
class StringTemplate {
class MapValueProvider : public ValueProvider {}
};
}}}
# StringTemplate::SingleValueProvider
Provider of template variable-values which returns the same value for all variables.
namespace oatpp { namespace data { namespace share {
class StringTemplate {
class SingleValueProvider : public ValueProvider {}
};
}}}