Skip to content

Commit c8be3ac

Browse files
committed
Remove template string parameter from Converter
And rename it from BasicStringConverter to Converter.
1 parent ec21bd0 commit c8be3ac

File tree

7 files changed

+28
-38
lines changed

7 files changed

+28
-38
lines changed

build/win/libfly/libfly.vcxproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,12 @@
229229
<ClInclude Include="..\..\..\fly\types\numeric\endian.hpp" />
230230
<ClInclude Include="..\..\..\fly\types\numeric\literals.hpp" />
231231
<ClInclude Include="..\..\..\fly\types\string\detail\classifier.hpp" />
232+
<ClInclude Include="..\..\..\fly\types\string\detail\converter.hpp" />
232233
<ClInclude Include="..\..\..\fly\types\string\detail\format_context.hpp" />
233234
<ClInclude Include="..\..\..\fly\types\string\detail\format_parameters.hpp" />
234235
<ClInclude Include="..\..\..\fly\types\string\detail\format_specifier.hpp" />
235236
<ClInclude Include="..\..\..\fly\types\string\detail\format_string.hpp" />
236237
<ClInclude Include="..\..\..\fly\types\string\detail\stream_util.hpp" />
237-
<ClInclude Include="..\..\..\fly\types\string\detail\string_converter.hpp" />
238238
<ClInclude Include="..\..\..\fly\types\string\detail\string_traits.hpp" />
239239
<ClInclude Include="..\..\..\fly\types\string\detail\string_unicode.hpp" />
240240
<ClInclude Include="..\..\..\fly\types\string\lexer.hpp" />

build/win/libfly/libfly.vcxproj.filters

+3-3
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@
292292
<ClInclude Include="..\..\..\fly\types\string\detail\classifier.hpp">
293293
<Filter>types\string\detail</Filter>
294294
</ClInclude>
295+
<ClInclude Include="..\..\..\fly\types\string\detail\converter.hpp">
296+
<Filter>types\string\detail</Filter>
297+
</ClInclude>
295298
<ClInclude Include="..\..\..\fly\types\string\detail\format_context.hpp">
296299
<Filter>types\string\detail</Filter>
297300
</ClInclude>
@@ -307,9 +310,6 @@
307310
<ClInclude Include="..\..\..\fly\types\string\detail\stream_util.hpp">
308311
<Filter>types\string\detail</Filter>
309312
</ClInclude>
310-
<ClInclude Include="..\..\..\fly\types\string\detail\string_converter.hpp">
311-
<Filter>types\string\detail</Filter>
312-
</ClInclude>
313313
<ClInclude Include="..\..\..\fly\types\string\detail\string_traits.hpp">
314314
<Filter>types\string\detail</Filter>
315315
</ClInclude>

build/win/libfly_unit_tests/libfly_unit_tests.vcxproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,11 @@
256256
<ClCompile Include="..\..\..\test\types\numeric\endian.cpp" />
257257
<ClCompile Include="..\..\..\test\types\numeric\literals.cpp" />
258258
<ClCompile Include="..\..\..\test\types\string\classifier.cpp" />
259+
<ClCompile Include="..\..\..\test\types\string\converter.cpp" />
259260
<ClCompile Include="..\..\..\test\types\string\format_parameters.cpp" />
260261
<ClCompile Include="..\..\..\test\types\string\format_string.cpp" />
261262
<ClCompile Include="..\..\..\test\types\string\lexer.cpp" />
262263
<ClCompile Include="..\..\..\test\types\string\string.cpp" />
263-
<ClCompile Include="..\..\..\test\types\string\string_converter.cpp" />
264264
<ClCompile Include="..\..\..\test\types\string\string_format.cpp" />
265265
<ClCompile Include="..\..\..\test\types\string\string_traits.cpp" />
266266
<ClCompile Include="..\..\..\test\types\string\string_unicode.cpp" />

build/win/libfly_unit_tests/libfly_unit_tests.vcxproj.filters

+3-3
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@
161161
<ClCompile Include="..\..\..\test\types\string\classifier.cpp">
162162
<Filter>types\string</Filter>
163163
</ClCompile>
164+
<ClCompile Include="..\..\..\test\types\string\converter.cpp">
165+
<Filter>types\string</Filter>
166+
</ClCompile>
164167
<ClCompile Include="..\..\..\test\types\string\format_parameters.cpp">
165168
<Filter>types\string</Filter>
166169
</ClCompile>
@@ -173,9 +176,6 @@
173176
<ClCompile Include="..\..\..\test\types\string\string.cpp">
174177
<Filter>types\string</Filter>
175178
</ClCompile>
176-
<ClCompile Include="..\..\..\test\types\string\string_converter.cpp">
177-
<Filter>types\string</Filter>
178-
</ClCompile>
179179
<ClCompile Include="..\..\..\test\types\string\string_format.cpp">
180180
<Filter>types\string</Filter>
181181
</ClCompile>

fly/types/string/detail/string_converter.hpp fly/types/string/detail/converter.hpp

+16-26
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace fly::detail {
99

1010
/**
11-
* Helper struct to convert a std::basic_string type to a plain-old-data type, e.g. int or float.
11+
* Helper struct to convert a std::string to a plain-old-data type, e.g. int or float.
1212
*
1313
* Ideally, this entire helper can be removed when the STL supports floating point types with
1414
* std::from_chars. However, only integral types are currently supported. Thus, integral types will
@@ -19,14 +19,10 @@ namespace fly::detail {
1919
* @author Timothy Flynn ([email protected])
2020
* @version March 21, 2019
2121
*/
22-
template <typename StringType, typename T>
23-
struct BasicStringConverter;
24-
25-
//==================================================================================================
26-
template <typename StringType, typename T>
27-
struct BasicStringConverter
22+
template <typename T>
23+
struct Converter
2824
{
29-
static std::optional<T> convert(const StringType &value)
25+
static std::optional<T> convert(const std::string &value)
3026
{
3127
const auto *begin = value.data();
3228
const auto *end = begin + value.size();
@@ -44,15 +40,13 @@ struct BasicStringConverter
4440
};
4541

4642
//==================================================================================================
47-
template <typename StringType>
48-
struct BasicStringConverter<StringType, float>
43+
template <>
44+
struct Converter<float>
4945
{
50-
using value_type = float;
51-
52-
static std::optional<value_type> convert(const StringType &value)
46+
static std::optional<float> convert(const std::string &value)
5347
{
5448
std::size_t index = 0;
55-
value_type result {};
49+
float result {};
5650

5751
try
5852
{
@@ -73,15 +67,13 @@ struct BasicStringConverter<StringType, float>
7367
};
7468

7569
//==================================================================================================
76-
template <typename StringType>
77-
struct BasicStringConverter<StringType, double>
70+
template <>
71+
struct Converter<double>
7872
{
79-
using value_type = double;
80-
81-
static std::optional<value_type> convert(const StringType &value)
73+
static std::optional<double> convert(const std::string &value)
8274
{
8375
std::size_t index = 0;
84-
value_type result {};
76+
double result {};
8577

8678
try
8779
{
@@ -102,15 +94,13 @@ struct BasicStringConverter<StringType, double>
10294
};
10395

10496
//==================================================================================================
105-
template <typename StringType>
106-
struct BasicStringConverter<StringType, long double>
97+
template <>
98+
struct Converter<long double>
10799
{
108-
using value_type = long double;
109-
110-
static std::optional<value_type> convert(const StringType &value)
100+
static std::optional<long double> convert(const std::string &value)
111101
{
112102
std::size_t index = 0;
113-
value_type result {};
103+
long double result {};
114104

115105
try
116106
{

fly/types/string/string.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#pragma once
22

33
#include "fly/types/string/detail/classifier.hpp"
4+
#include "fly/types/string/detail/converter.hpp"
45
#include "fly/types/string/detail/format_context.hpp"
56
#include "fly/types/string/detail/format_parameters.hpp"
67
#include "fly/types/string/detail/format_specifier.hpp"
78
#include "fly/types/string/detail/format_string.hpp"
8-
#include "fly/types/string/detail/string_converter.hpp"
99
#include "fly/types/string/detail/string_traits.hpp"
1010
#include "fly/types/string/detail/string_unicode.hpp"
1111
#include "fly/types/string/literals.hpp"
@@ -949,13 +949,13 @@ std::optional<T> BasicString<StringType>::convert(const StringType &value)
949949
}
950950
else if constexpr (std::is_same_v<char_type, char>)
951951
{
952-
return detail::BasicStringConverter<StringType, T>::convert(value);
952+
return detail::Converter<T>::convert(value);
953953
}
954954
else
955955
{
956956
if (auto result = unicode::template convert_encoding<std::string>(value); result)
957957
{
958-
return detail::BasicStringConverter<std::string, T>::convert(*result);
958+
return detail::Converter<T>::convert(*result);
959959
}
960960

961961
return std::nullopt;

test/types/string/string_converter.cpp test/types/string/converter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ StringType maxstr()
4646
} // namespace
4747

4848
CATCH_TEMPLATE_TEST_CASE(
49-
"BasicStringConverter",
49+
"Converter",
5050
"[string]",
5151
std::string,
5252
std::wstring,

0 commit comments

Comments
 (0)