Add some more templates for methods that return std::string.

This commit is contained in:
Jacob 2024-05-13 00:45:04 +02:00
parent 8caa3d92eb
commit 27ff72f2a5
2 changed files with 91 additions and 0 deletions

View file

@ -97,16 +97,31 @@ namespace docpp {
* @return std::string The key of the property
*/
std::string getKey() const;
/**
* @brief Get the key of the property in a specific type
* @return T The key of the property
*/
template <typename T> T getKey() const;
/**
* @brief Get the value of the property
* @return std::string The value of the property
*/
std::string getValue() const;
/**
* @brief Get the value of the property in a specific type
* @return T The value of the property
*/
template <typename T> T getValue() const;
/**
* @brief Get the property.
* @return std::pair<std::string, std::string> The value of the property
*/
std::pair<std::string, std::string> get() const;
/**
* @brief Get the property in a specific type.
* @return std::pair<T, T> The value of the property
*/
template <typename T> std::pair<T, T> get() const;
/**
* @brief Set the key of the property.
* @param key The key.
@ -332,12 +347,23 @@ namespace docpp {
* @return std::string The data of the element
*/
std::string getTag() const;
/**
* @brief Get the tag of the element in a specific type
* @return T The tag of the element
*/
template <typename T> T getTag() const;
/**
* @brief Get the data of the element
* @return std::string The data of the element
*/
std::string getData() const;
/**
* @brief Get the data of the element in a specific type
* @return T The data of the element
*/
template <typename T> T getData() const;
Element operator=(const Element& element);
void operator+=(const std::string& data);
};
@ -609,6 +635,11 @@ namespace docpp {
* @return std::string The doctype of the document
*/
std::string getDoctype() const;
/**
* @brief Get the doctype of the document in a specific type
* @return T The doctype of the document
*/
template <typename T> T getDoctype() const;
/**
* @brief Set the document
@ -677,16 +708,31 @@ namespace docpp {
* @return std::string The key of the property
*/
std::string getKey() const;
/**
* @brief Get the key of the property in a specific type
* @return T The key of the property
*/
template <typename T> T getKey() const;
/**
* @brief Get the value of the property
* @return std::string The value of the property
*/
std::string getValue() const;
/**
* @brief Get the value of the property in a specific type
* @return T The value of the property
*/
template <typename T> T getValue() const;
/**
* @brief Get the property.
* @return std::pair<std::string, std::string> The value of the property
*/
std::pair<std::string, std::string> get() const;
/**
* @brief Get the property in a specific type.
* @return std::pair<T, T> The value of the property
*/
template <typename T> std::pair<T, T> get() const;
/**
* @brief Set the key of the property.
* @param key The key.
@ -877,6 +923,11 @@ namespace docpp {
* @return std::string The tag of the element
*/
std::string getTag() const;
/**
* @brief Get the tag of the element in a specific type
* @return T The tag of the element
*/
template <typename T> T getTag() const;
/**
* @brief Get the properties of the element
* @return std::vector<Property> The properties of the element

View file

@ -22,14 +22,26 @@ std::string docpp::HTML::Property::getKey() const {
return this->property.first;
}
template <typename T> T docpp::HTML::Property::getKey() const {
return T(this->property.first);
}
std::string docpp::HTML::Property::getValue() const {
return this->property.second;
}
template <typename T> T docpp::HTML::Property::getValue() const {
return T(this->property.second);
}
std::pair<std::string, std::string> docpp::HTML::Property::get() const {
return this->property;
}
template <typename T> std::pair<T, T> docpp::HTML::Property::get() const {
return T(this->property);
}
void docpp::HTML::Property::setKey(const std::string& key) {
this->property.first = key;
}
@ -236,10 +248,18 @@ std::string docpp::HTML::Element::getTag() const {
return this->tag;
}
template <typename T> T docpp::HTML::Element::getTag() const {
return T(this->tag);
}
std::string docpp::HTML::Element::getData() const {
return this->data;
}
template <typename T> T docpp::HTML::Element::getData() const {
return T(this->data);
}
docpp::HTML::Section::Section(const std::string& tag, const Properties& properties) {
this->tag = tag;
this->properties = properties;
@ -615,6 +635,10 @@ std::string docpp::HTML::Document::getDoctype() const {
return this->doctype;
}
template <typename T> T docpp::HTML::Document::getDoctype() const {
return T(this->doctype);
}
docpp::CSS::Property::Property(const std::string& key, const std::string& value) {
this->set(key, value);
}
@ -627,14 +651,26 @@ std::string docpp::CSS::Property::getKey() const {
return this->property.first;
}
template <typename T> T docpp::CSS::Property::getKey() const {
return T(this->property.first);
}
std::string docpp::CSS::Property::getValue() const {
return this->property.second;
}
template <typename T> T docpp::CSS::Property::getValue() const {
return T(this->property.second);
}
std::pair<std::string, std::string> docpp::CSS::Property::get() const {
return this->property;
}
template <typename T> std::pair<T, T> docpp::CSS::Property::get() const {
return std::pair<T, T>(this->property.first, this->property.second);
}
void docpp::CSS::Property::setKey(const std::string& key) {
this->property.first = key;
}
@ -812,6 +848,10 @@ std::string docpp::CSS::Element::getTag() const {
return this->element.first;
}
template <typename T> T docpp::CSS::Element::getTag() const {
return T(this->element.first);
}
std::vector<docpp::CSS::Property> docpp::CSS::Element::getProperties() const {
return this->element.second;
}