Skip to content

Commit 24697f8

Browse files
committed
Fix CIniTable's convert function for ISO C++
Notice that T_CONVERT_ITEM = T_ITEM
1 parent 4b4e63b commit 24697f8

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

src/xrGame/ini_table_loader.h

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,18 @@ class CIni_Table
4343
int table_width;
4444

4545
//перобразование из LPCSTR в T_ITEM
46-
47-
template <typename T_CONVERT_ITEM>
48-
T_ITEM convert(LPCSTR)
49-
{
50-
static_assert(!std::is_same_v<T_CONVERT_ITEM, T_CONVERT_ITEM>, "Specialization for convert in CIni_Table not found."); // Xottab_DUTY: Is this correct?
51-
NODEFAULT;
52-
}
53-
54-
template <>
55-
T_ITEM convert<int>(LPCSTR str)
46+
T_ITEM convert(LPCSTR str)
5647
{
57-
return atoi(str);
58-
}
59-
60-
template <>
61-
T_ITEM convert<float>(LPCSTR str)
62-
{
63-
return (float)atof(str);
48+
if constexpr(std::is_same<T_ITEM, int>::value)
49+
{
50+
return atoi(str);
51+
}
52+
else
53+
{
54+
static_assert(std::is_same_v<T_ITEM, float>,
55+
"Specialization for convert in CIni_Table not found.");
56+
return (float)atof(str);
57+
}
6458
}
6559
};
6660

@@ -108,15 +102,16 @@ typename CSIni_Table::ITEM_TABLE& CSIni_Table::table()
108102

109103
for (auto i = table_ini.Data.cbegin(); table_ini.Data.cend() != i; ++i)
110104
{
111-
typename T_INI_LOADER::index_type cur_index = T_INI_LOADER::IdToIndex((*i).first, type_max<T_INI_LOADER::index_type>);
105+
typename T_INI_LOADER::index_type cur_index =
106+
T_INI_LOADER::IdToIndex((*i).first, type_max<typename T_INI_LOADER::index_type>);
112107

113-
if (type_max<T_INI_LOADER::index_type> == cur_index)
108+
if (type_max<typename T_INI_LOADER::index_type> == cur_index)
114109
xrDebug::Fatal(DEBUG_INFO, "wrong community %s in section [%s]", (*i).first, table_sect);
115110

116111
(*m_pTable)[cur_index].resize(cur_table_width);
117112
for (std::size_t j = 0; j < cur_table_width; j++)
118113
{
119-
(*m_pTable)[cur_index][j] = convert<typename T_ITEM>(_GetItem(*(*i).second, (int)j, buffer));
114+
(*m_pTable)[cur_index][j] = convert(_GetItem(*(*i).second, (int)j, buffer));
120115
}
121116
}
122117

0 commit comments

Comments
 (0)