MVault 0.0.1
Loading...
Searching...
No Matches
Functions
ToStringFunctions

Functions for printing custom classes. More...

Functions

template<class T >
std::string mvlt::ToString (const T &data) noexcept
 A template method for providing an interface converting any type to a string.
 
template<>
std::string mvlt::ToString (const long long int &data) noexcept
 Specialization of the ToString method for the long long int type.
 
template<>
std::string mvlt::ToString (const unsigned long long int &data) noexcept
 Specialization of the ToString method for the unsigned long long int type.
 
template<>
std::string mvlt::ToString (const long int &data) noexcept
 Specialization of the ToString method for the int type.
 
template<>
std::string mvlt::ToString (const unsigned long int &data) noexcept
 Specialization of the ToString method for the int type.
 
template<>
std::string mvlt::ToString (const int &data) noexcept
 Specialization of the ToString method for the int type.
 
template<>
std::string mvlt::ToString (const unsigned int &data) noexcept
 Specialization of the ToString method for the unsigned int type.
 
template<>
std::string mvlt::ToString (const short int &data) noexcept
 Specialization of the ToString method for the short int type.
 
template<>
std::string mvlt::ToString (const unsigned short int &data) noexcept
 Specialization of the ToString method for the unsigned short int type.
 
template<>
std::string mvlt::ToString (const bool &data) noexcept
 Specialization of the ToString method for the bool type.
 
template<>
std::string mvlt::ToString (const std::string &data) noexcept
 Specialization of the ToString method for the std::string type.
 
template<>
std::string mvlt::ToString (const float &data) noexcept
 Specialization of the ToString method for the float type.
 
template<>
std::string mvlt::ToString (const double &data) noexcept
 Specialization of the ToString method for the double type.
 
template<>
std::string mvlt::ToString (const char &data) noexcept
 Specialization of the ToString method for the float type.
 

Detailed Description

Functions for printing custom classes.

Since the repository supports any type, including custom classes, these functions for converting objects of custom classes must be defined by users. This is implemented using the specialization of a partial function. The library defines a template function ToString, which accepts an object of any type and returns an empty string. This is necessary in order for the code to work with any types, even if conversion to a string is not defined for them. However, if you want to add to your type the ability to convert to a string, then you must define the ToString function for your type.

For example, like this

template <>
std::string mvlt::ToString(const std::vector<int>& data)
{
if (data.size() == 0) return "{}";
std::string res = "{}";
for (const int& dataIt : data)
{
res += std::to_string(dataIt) + ", ";
}
res.pop_back();
res.pop_back();
res += "}";
return res;
}
std::string ToString(const T &data) noexcept
A template method for providing an interface converting any type to a string.
Definition ToString.h:75

This code defines the ToString function for a vector of integers.

By calling this function:

std::vector<int> vec = {1, 2, 3, 4, 5};
std::cout << ToString(vec) << std::endl;

The output will be as follows:

{1, 2, 3, 4, 5}

By default, the function is defined for the following types:

Function Documentation

◆ ToString() [1/14]

template<>
std::string mvlt::ToString ( const bool data)
inlinenoexcept

Specialization of the ToString method for the bool type.

Template Parameters
<bool>boolean variable
Parameters
[in]datathe variable to be converted to a string
Returns
string with true if data true, otherwise retutn string with false

◆ ToString() [2/14]

template<>
std::string mvlt::ToString ( const char data)
inlinenoexcept

Specialization of the ToString method for the float type.

Template Parameters
<char>char variable
Parameters
[in]datathe variable to be converted to a string
Returns
string with one char

◆ ToString() [3/14]

template<>
std::string mvlt::ToString ( const double data)
inlinenoexcept

Specialization of the ToString method for the double type.

Template Parameters
<double>float variable
Parameters
[in]datathe variable to be converted to a string
Returns
result of std::to_string function

◆ ToString() [4/14]

template<>
std::string mvlt::ToString ( const float data)
inlinenoexcept

Specialization of the ToString method for the float type.

Template Parameters
<float>float variable
Parameters
[in]datathe variable to be converted to a string
Returns
result of std::to_string function

◆ ToString() [5/14]

template<>
std::string mvlt::ToString ( const int data)
inlinenoexcept

Specialization of the ToString method for the int type.

Template Parameters
<int>integer variable
Parameters
[in]datathe variable to be converted to a string
Returns
result of std::to_string function

◆ ToString() [6/14]

template<>
std::string mvlt::ToString ( const long int data)
inlinenoexcept

Specialization of the ToString method for the int type.

Template Parameters
<longint> integer variable
Parameters
[in]datathe variable to be converted to a string
Returns
result of std::to_string function

◆ ToString() [7/14]

template<>
std::string mvlt::ToString ( const long long int data)
inlinenoexcept

Specialization of the ToString method for the long long int type.

Template Parameters
<longlong int> integer variable
Parameters
[in]datathe variable to be converted to a string
Returns
result of std::to_string function

◆ ToString() [8/14]

template<>
std::string mvlt::ToString ( const short int data)
inlinenoexcept

Specialization of the ToString method for the short int type.

Template Parameters
<shortint> integer variable
Parameters
[in]datathe variable to be converted to a string
Returns
result of std::to_string function

◆ ToString() [9/14]

template<>
std::string mvlt::ToString ( const std::string &  data)
inlinenoexcept

Specialization of the ToString method for the std::string type.

Template Parameters
<std::string>string variable
Parameters
[in]datathe variable to be converted to a string
Returns
data

◆ ToString() [10/14]

template<class T >
std::string mvlt::ToString ( const T data)
noexcept

A template method for providing an interface converting any type to a string.

This function allows you to use the same interface inside the Vault for any class, since this function accepts any type. Therefore, if you do not plan to use the functionality of saving to files or printing data, then there will be no problems when using a custom type. At the same time, if you plan to work with files or printing data, you can specialize this function for each required type.

Template Parameters
<T>Any type of data
Parameters
[in]datathe variable to be converted to a string
Returns
This function returns an empty string. The specialization of this function for types will return strings with data from data.

◆ ToString() [11/14]

template<>
std::string mvlt::ToString ( const unsigned int data)
inlinenoexcept

Specialization of the ToString method for the unsigned int type.

Template Parameters
<unsignedint> integer variable
Parameters
[in]datathe variable to be converted to a string
Returns
result of std::to_string function

◆ ToString() [12/14]

template<>
std::string mvlt::ToString ( const unsigned long int data)
inlinenoexcept

Specialization of the ToString method for the int type.

Template Parameters
<unsignedlong int> integer variable
Parameters
[in]datathe variable to be converted to a string
Returns
result of std::to_string function

◆ ToString() [13/14]

template<>
std::string mvlt::ToString ( const unsigned long long int data)
inlinenoexcept

Specialization of the ToString method for the unsigned long long int type.

Template Parameters
<unsignedlong long int> integer variable
Parameters
[in]datathe variable to be converted to a string
Returns
result of std::to_string function

◆ ToString() [14/14]

template<>
std::string mvlt::ToString ( const unsigned short int data)
inlinenoexcept

Specialization of the ToString method for the unsigned short int type.

Template Parameters
<unsignedshort int> integer variable
Parameters
[in]datathe variable to be converted to a string
Returns
result of std::to_string function