Babel
1
The voip software that only works on your local network
Loading...
Searching...
No Matches
ToString.hpp
Go to the documentation of this file.
1
/*
2
** EPITECH PROJECT, 2024
3
** rtype (Workspace)
4
** File description:
5
** toString.hpp
6
*/
7
17
#pragma once
18
#include <map>
19
#include <set>
20
#include <vector>
21
#include <string>
22
#include <utility>
23
#include <unordered_set>
24
#include <unordered_map>
25
26
namespace
Recoded
27
{
28
41
const
std::string
myToString
(
bool
value);
42
58
template
<
typename
T>
59
const
std::string
myToString
(
const
T &value)
60
{
61
return
std::to_string(value);
62
};
63
86
template
<
typename
T1,
typename
T2>
87
const
std::string
myToString
(
const
std::pair<T1, T2> &value)
88
{
89
return
"( x: "
+
myToString
(value.first) +
", y: "
+
myToString
(value.second) +
")"
;
90
};
91
92
108
template
<
typename
Key,
typename
Value>
109
std::string
myToString
(
const
std::map<Key, Value> &map)
110
{
111
std::string result =
"{ "
;
112
typename
std::map<Key, Value>::const_iterator it = map.begin();
113
for
(; it != map.end(); ++it) {
114
result +=
"'"
+
Recoded::myToString
(it->first) +
"' : '"
+
Recoded::myToString
(it->second) +
"'"
;
115
if
(std::next(it) != map.end())
116
result +=
", "
;
117
}
118
result +=
" }"
;
119
return
result;
120
}
121
136
template
<
typename
T>
137
std::string
myToString
(
const
std::set<T> &set)
138
{
139
std::string result =
"{ "
;
140
for
(
typename
std::set<T>::const_iterator it = set.begin(); it != set.end();) {
141
result +=
"'"
+
Recoded::myToString
(*it) +
"'"
;
142
if
(++it != set.end())
143
result +=
", "
;
144
}
145
result +=
" }"
;
146
return
result;
147
}
148
163
template
<
typename
T>
164
const
std::string
myToString
(
const
std::vector<T> &set)
165
{
166
std::string result =
"[ "
;
167
typename
std::vector<T>::const_iterator it = set.begin();
168
for
(; it != set.end(); ++it) {
169
result +=
"'"
+
Recoded::myToString
(*it) +
"'"
;
170
if
(std::next(it) != set.end())
171
result +=
", "
;
172
}
173
result +=
" ]"
;
174
return
result;
175
}
176
192
template
<
typename
Key,
typename
Value>
193
std::string
myToString
(
const
std::unordered_map<Key, Value> &map)
194
{
195
std::string result =
"{ "
;
196
typename
std::unordered_map<Key, Value>::const_iterator it = map.begin();
// Correct variable name
197
for
(; it != map.end(); ++it) {
198
result +=
"'"
+
Recoded::myToString
(it->first) +
"' : '"
+
Recoded::myToString
(it->second) +
"'"
;
199
if
(std::next(it) != map.end())
// Avoid trailing comma
200
result +=
", "
;
201
}
202
result +=
" }"
;
203
return
result;
204
}
205
220
template
<
typename
T>
221
const
std::string
myToString
(
const
std::unordered_set<T> &set)
222
{
223
std::string result =
"{ "
;
224
typename
std::unordered_set<T>::const_iterator it = set.begin();
225
for
(; it != set.end(); ++it) {
226
result +=
"'"
+
Recoded::myToString
(*it) +
"'"
;
227
if
(std::next(it) != set.end())
228
result +=
", "
;
229
}
230
result +=
" }"
;
231
return
result;
232
}
233
}
Recoded
Definition
ToString.hpp:27
Recoded::myToString
const std::string myToString(bool value)
Converts a boolean value to its string representation.
Definition
ToString.cpp:22
include
Recoded
ToString.hpp
Generated on Sun Feb 16 2025 23:01:55 for Babel by
1.12.0