Skip to content

Commit 9dfe8ba

Browse files
committed
fix warnings
1 parent 94b4659 commit 9dfe8ba

File tree

1 file changed

+56
-23
lines changed

1 file changed

+56
-23
lines changed

modules/mrpt_config/src/CConfigFileBase.cpp

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void CConfigFileBase::write(
5353
section, name,
5454
format(
5555
((std::abs(value) > 1e-4f && std::abs(value) < 1e4f) || value == .0f) ? "%f" : "%e",
56-
value),
56+
static_cast<double>(value)),
5757
name_padding_width, value_padding_width, comment);
5858
}
5959

@@ -68,23 +68,31 @@ void CConfigFileBase::writeString(
6868
const std::string& comment)
6969
{
7070
if (name_padding_width < 1 && value_padding_width < 1 && comment.empty())
71-
this->writeString(section, name, str); // Default (old) behavior.
71+
{
72+
this->writeString(section, name, str);
73+
}
7274

7375
std::string name_pad;
7476
if (name_padding_width >= 1)
75-
name_pad = mrpt::format(
76-
"%*s", -name_padding_width,
77-
name.c_str()); // negative width: printf right padding
77+
{
78+
// negative width: printf right padding
79+
name_pad = mrpt::format("%*s", -name_padding_width, name.c_str());
80+
}
7881
else
82+
{
7983
name_pad = name;
84+
}
8085

8186
std::string value_pad;
8287
if (value_padding_width >= 1)
83-
value_pad = mrpt::format(
84-
" %*s", -value_padding_width,
85-
str.c_str()); // negative width: printf right padding
88+
{
89+
// negative width: printf right padding
90+
value_pad = mrpt::format(" %*s", -value_padding_width, str.c_str());
91+
}
8692
else
93+
{
8794
value_pad = str;
95+
}
8896

8997
if (!comment.empty())
9098
{
@@ -116,8 +124,9 @@ float CConfigFileBase::read_float(
116124
float defaultValue,
117125
bool failIfNotFound) const
118126
{
119-
return (float)atof(
120-
readString(section, name, format("%.10e", defaultValue), failIfNotFound).c_str());
127+
return static_cast<float>(atof(
128+
readString(section, name, format("%.10e", static_cast<double>(defaultValue)), failIfNotFound)
129+
.c_str()));
121130
}
122131

123132
/*---------------------------------------------------------------
@@ -141,8 +150,8 @@ uint64_t CConfigFileBase::read_uint64_t(
141150
uint64_t defaultValue,
142151
bool failIfNotFound) const
143152
{
144-
string s =
145-
readString(section, name, format("%lu", (long unsigned int)defaultValue), failIfNotFound);
153+
string s = readString(
154+
section, name, format("%lu", static_cast<long unsigned int>(defaultValue)), failIfNotFound);
146155
return mrpt::system::os::_strtoull(s.c_str(), nullptr, 0);
147156
}
148157

@@ -157,10 +166,22 @@ bool CConfigFileBase::read_bool(
157166
{
158167
const string s = mrpt::system::lowerCase(
159168
trim(readString(section, name, string(defaultValue ? "1" : "0"), failIfNotFound)));
160-
if (s == "true") return true;
161-
if (s == "false") return false;
162-
if (s == "yes") return true;
163-
if (s == "no") return false;
169+
if (s == "true")
170+
{
171+
return true;
172+
}
173+
if (s == "false")
174+
{
175+
return false;
176+
}
177+
if (s == "yes")
178+
{
179+
return true;
180+
}
181+
if (s == "no")
182+
{
183+
return false;
184+
}
164185
return (0 != atoi(s.c_str()));
165186
}
166187

@@ -197,19 +218,23 @@ std::string CConfigFileBase::read_string_first_word(
197218
"all whitespaces??",
198219
name.c_str(), section.c_str()));
199220
}
200-
else
201-
return "";
221+
return "";
202222
}
203-
else
204-
return auxStrs[0];
223+
224+
return auxStrs[0];
205225
}
206226

207227
bool CConfigFileBase::sectionExists(const std::string& section_name) const
208228
{
209229
std::vector<std::string> sects;
210230
getAllSections(sects);
211231
for (auto& sect : sects)
212-
if (!mrpt::system::os::_strcmpi(section_name.c_str(), sect.c_str())) return true;
232+
{
233+
if (!mrpt::system::os::_strcmpi(section_name.c_str(), sect.c_str()))
234+
{
235+
return true;
236+
}
237+
}
213238
return false;
214239
}
215240

@@ -218,7 +243,10 @@ bool CConfigFileBase::keyExists(const std::string& section, const std::string& k
218243
std::vector<std::string> keys;
219244
getAllKeys(section, keys);
220245
for (auto& k : keys)
221-
if (!mrpt::system::os::_strcmpi(key.c_str(), k.c_str())) return true;
246+
if (!mrpt::system::os::_strcmpi(key.c_str(), k.c_str()))
247+
{
248+
return true;
249+
}
222250
return false;
223251
}
224252

@@ -261,10 +289,15 @@ void CConfigFileBase::setContentFromYAML(const std::string& yaml_block)
261289
}
262290

263291
// 1st: unscoped:
264-
for (const auto& kv : unscoped) this->write("", kv.first, kv.second);
292+
for (const auto& kv : unscoped)
293+
{
294+
this->write("", kv.first, kv.second);
295+
}
265296

266297
for (const auto& sect : sections)
298+
{
267299
for (const auto& kv : sect.second) this->write(sect.first, kv.first, kv.second);
300+
}
268301

269302
MRPT_END
270303
}

0 commit comments

Comments
 (0)