Skip to content

Commit 7e1cffe

Browse files
alxbilgerfredroy
authored andcommitted
[Sofa.Helper] Fix a few warnings
1 parent 924df2d commit 7e1cffe

13 files changed

Lines changed: 219 additions & 209 deletions

Sofa/framework/Helper/src/sofa/helper/AdvancedTimer.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ template class SOFA_HELPER_API AdvancedTimer::Id<AdvancedTimer::Val>;
5656
class TimerData
5757
{
5858
public:
59-
AdvancedTimer::IdTimer id;
59+
AdvancedTimer::IdTimer m_id;
6060
type::vector<Record> records;
6161
int nbIter;
6262
int interval;
@@ -89,7 +89,7 @@ class TimerData
8989

9090
void init(AdvancedTimer::IdTimer id)
9191
{
92-
this->id = id;
92+
this->m_id = id;
9393
const std::string envvar = std::string("SOFA_TIMER_") + (std::string)id;
9494
const char* val = getenv(envvar.c_str());
9595
if (!val || !*val)
@@ -174,7 +174,7 @@ void AdvancedTimer::clear()
174174
bool AdvancedTimer::isEnabled(IdTimer id)
175175
{
176176
TimerData& data = timers[id];
177-
if (!data.id)
177+
if (!data.m_id)
178178
{
179179
data.init(id);
180180
}
@@ -184,7 +184,7 @@ bool AdvancedTimer::isEnabled(IdTimer id)
184184
void AdvancedTimer::setEnabled(IdTimer id, bool val)
185185
{
186186
TimerData& data = timers[id];
187-
if (!data.id)
187+
if (!data.m_id)
188188
{
189189
data.init(id);
190190
}
@@ -197,7 +197,7 @@ void AdvancedTimer::setEnabled(IdTimer id, bool val)
197197
int AdvancedTimer::getInterval(IdTimer id)
198198
{
199199
TimerData& data = timers[id];
200-
if (!data.id)
200+
if (!data.m_id)
201201
{
202202
data.init(id);
203203
}
@@ -207,7 +207,7 @@ int AdvancedTimer::getInterval(IdTimer id)
207207
void AdvancedTimer::setInterval(IdTimer id, int val)
208208
{
209209
TimerData& data = timers[id];
210-
if (!data.id)
210+
if (!data.m_id)
211211
{
212212
data.init(id);
213213
}
@@ -220,7 +220,7 @@ void AdvancedTimer::begin(IdTimer id)
220220
std::stack<AdvancedTimer::IdTimer>& curTimer = getCurTimer();
221221
curTimer.push(id);
222222
TimerData& data = timers[curTimer.top()];
223-
if (!data.id)
223+
if (!data.m_id)
224224
{
225225
data.init(id);
226226
}
@@ -339,7 +339,7 @@ void AdvancedTimer::end(IdTimer id)
339339
std::string AdvancedTimer::end(IdTimer id, double time, double dt)
340340
{
341341
const TimerData& data = timers[id];
342-
if(!data.id)
342+
if(!data.m_id)
343343
{
344344
return std::string("");
345345
}
@@ -801,7 +801,7 @@ void TimerData::print()
801801
{
802802
static ctime_t tmargin = CTime::getTicksPerSec() / 100000;
803803
std::ostream& out = std::cout;
804-
out << "==== " << id << " ====\n\n";
804+
out << "==== " << m_id << " ====\n\n";
805805
if (!records.empty())
806806
{
807807
out << "Trace of last iteration :\n";
@@ -955,7 +955,7 @@ void AdvancedTimer::setOutputType(IdTimer id, const std::string& type)
955955
{
956956
// Seek for the timer
957957
TimerData& data = timers[id];
958-
if (!data.id)
958+
if (!data.m_id)
959959
{
960960
data.init(id);
961961
}
@@ -1101,7 +1101,7 @@ void TimerData::print(std::ostream& result)
11011101
{
11021102
//static ctime_t tmargin = CTime::getTicksPerSec() / 100000;
11031103
std::ostream& out = result;
1104-
out << "Timer: " << id << "\n";
1104+
out << "Timer: " << m_id << "\n";
11051105
if (!steps.empty())
11061106
{
11071107
//out << "\nSteps Duration Statistics (in ms) :\n";

Sofa/framework/Helper/src/sofa/helper/BackTrace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
namespace sofa::helper
4646
{
4747

48-
BackTrace::StackTrace BackTrace::getTrace(size_t maxEntries)
48+
BackTrace::StackTrace BackTrace::getTrace([[maybe_unused]] size_t maxEntries)
4949
{
5050
BackTrace::StackTrace result;
5151

Sofa/framework/Helper/src/sofa/helper/DiffLib.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
* *
2020
* Contact information: contact@sofa-framework.org *
2121
******************************************************************************/
22-
#include <cstring>
23-
#include <queue>
2422
#include <difflib.h>
2523
#include <sofa/helper/DiffLib.h>
2624

25+
#include <cstring>
26+
#include <queue>
27+
#include <utility>
28+
2729
namespace sofa::helper
2830
{
2931

@@ -35,27 +37,25 @@ std::vector<std::tuple<std::string, SReal>> SOFA_HELPER_API getClosestMatch(cons
3537
{
3638
public:
3739
Tuple(float ratio_, std::string value_)
38-
{
39-
ratio = ratio_;
40-
value = value_;
41-
}
40+
: ratio(ratio_), value(std::move(value_)) {}
41+
4242
float ratio;
4343
std::string value;
4444
};
45-
auto cmp = [](Tuple& left, Tuple& right) { return left.ratio < right.ratio; };
45+
auto cmp = [](const Tuple& left, Tuple& right) { return left.ratio < right.ratio; };
4646
std::priority_queue<Tuple, std::vector<Tuple>, decltype(cmp)> q3(cmp);
4747

4848
for(auto& s : haystack)
4949
{
5050
auto foo = difflib::MakeSequenceMatcher(needle,s);
51-
q3.push(Tuple(foo.ratio(), s));
51+
q3.emplace(foo.ratio(), s);
5252
}
5353
std::vector<std::tuple<std::string, SReal>> result;
54-
while(!q3.empty() && result.size()<=numEntries)
54+
while (!q3.empty() && result.size() <= numEntries)
5555
{
5656
if(q3.top().ratio < threshold)
5757
break;
58-
result.push_back(std::make_tuple(q3.top().value, q3.top().ratio));
58+
result.emplace_back(q3.top().value, q3.top().ratio);
5959
q3.pop();
6060
}
6161
return result;

Sofa/framework/Helper/src/sofa/helper/LCPcalc.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,8 +1386,8 @@ int nlcp_multiGrid(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal to
13861386
free(d_coarse);
13871387

13881388
free(d);
1389-
for (int i = 0; i < numContacts; i++)
1390-
delete W33[i];
1389+
for (int c = 0; c < numContacts; c++)
1390+
delete W33[c];
13911391
free(W33);
13921392

13931393
return 0;
@@ -1525,10 +1525,10 @@ int nlcp_multiGrid(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal to
15251525

15261526
if(verbose)
15271527
{
1528-
std::stringstream tmp;
1529-
tmp << "Result at the COARSE LEVEL: " << msgendl;
1530-
resultToString(tmp, F_coarse,num_group*3);
1531-
dmsg_info("LCPcalc") << tmp.str() ;
1528+
std::stringstream ss;
1529+
ss << "Result at the COARSE LEVEL: " << msgendl;
1530+
resultToString(ss, F_coarse,num_group*3);
1531+
dmsg_info("LCPcalc") << ss.str() ;
15321532
}
15331533

15341534

@@ -1551,10 +1551,10 @@ int nlcp_multiGrid(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal to
15511551

15521552
if(verbose)
15531553
{
1554-
std::stringstream tmp;
1555-
tmp << "projection at the finer LEVEL: " << msgendl ;
1556-
resultToString(tmp, f,dim);
1557-
dmsg_info("LCPcalc") << tmp.str() ;
1554+
std::stringstream ss;
1555+
ss << "projection at the finer LEVEL: " << msgendl ;
1556+
resultToString(ss, f,dim);
1557+
dmsg_info("LCPcalc") << ss.str() ;
15581558
}
15591559

15601560

@@ -1564,10 +1564,10 @@ int nlcp_multiGrid(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal to
15641564

15651565
if(verbose)
15661566
{
1567-
std::stringstream tmp;
1568-
tmp << "after 10 iteration at the finer LEVEL: " << msgendl ;
1569-
resultToString(tmp, f,dim);
1570-
dmsg_info("LCPcalc") << tmp.str();
1567+
std::stringstream ss;
1568+
ss << "after 10 iteration at the finer LEVEL: " << msgendl ;
1569+
resultToString(ss, f,dim);
1570+
dmsg_info("LCPcalc") << ss.str();
15711571
}
15721572

15731573
free(d_free_coarse);
@@ -1576,8 +1576,8 @@ int nlcp_multiGrid(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal to
15761576
free(d_coarse);
15771577

15781578
free(d);
1579-
for (int i = 0; i < numContacts; i++)
1580-
delete W33[i];
1579+
for (int c = 0; c < numContacts; c++)
1580+
delete W33[c];
15811581
free(W33);
15821582

15831583
return result;
@@ -1679,9 +1679,9 @@ int nlcp_gaussseidel(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal
16791679
for (int c=0; c<numContacts ; c++)
16801680
{
16811681
dn = dfree[3*c];
1682-
for (int i=0; i<dim; i++)
1682+
for (int k = 0; k < dim; k++)
16831683
{
1684-
dn += W[3*c ][i]*f[i];
1684+
dn += W[3 * c][k] * f[k];
16851685
}
16861686
if (dn < 0)
16871687
sum_d += -dn;
@@ -1711,8 +1711,8 @@ int nlcp_gaussseidel(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal
17111711
}
17121712

17131713
free(d);
1714-
for (int i = 0; i < numContacts; i++)
1715-
delete W33[i];
1714+
for (int c = 0; c < numContacts; c++)
1715+
delete W33[c];
17161716
free(W33);
17171717

17181718
if (verbose){
@@ -1725,8 +1725,8 @@ int nlcp_gaussseidel(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal
17251725
sofa::helper::AdvancedTimer::valSet("GS iterations", it);
17261726

17271727
free(d);
1728-
for (int i = 0; i < numContacts; i++)
1729-
delete W33[i];
1728+
for (int c = 0; c < numContacts; c++)
1729+
delete W33[c];
17301730
free(W33);
17311731

17321732
if (verbose)
@@ -1820,8 +1820,8 @@ int nlcp_gaussseidelTimed(int dim, SReal *dfree, SReal**W, SReal*f, SReal mu, SR
18201820
if((t1-t0) > tdiff)
18211821
{
18221822
free(d);
1823-
for (int i = 0; i < numContacts; i++)
1824-
delete W33[i];
1823+
for (int c = 0; c < numContacts; c++)
1824+
delete W33[c];
18251825
free(W33);
18261826
return 1;
18271827
}
@@ -1830,17 +1830,17 @@ int nlcp_gaussseidelTimed(int dim, SReal *dfree, SReal**W, SReal*f, SReal mu, SR
18301830
if (error < tol)
18311831
{
18321832
free(d);
1833-
for (int i = 0; i < numContacts; i++)
1834-
delete W33[i];
1833+
for (int c = 0; c < numContacts; c++)
1834+
delete W33[c];
18351835
free(W33);
18361836
sofa::helper::AdvancedTimer::valSet("GS iterations", it+1);
18371837
return 1;
18381838
}
18391839
}
18401840
sofa::helper::AdvancedTimer::valSet("GS iterations", it);
18411841
free(d);
1842-
for (int i = 0; i < numContacts; i++)
1843-
delete W33[i];
1842+
for (int c = 0; c < numContacts; c++)
1843+
delete W33[c];
18441844
free(W33);
18451845

18461846
if (verbose)

0 commit comments

Comments
 (0)