Skip to content

Commit c0e9a54

Browse files
author
Daniel Marjamäki
committed
Refactoring: Refactoring the Settings class
1 parent 3bab5f6 commit c0e9a54

13 files changed

Lines changed: 36 additions & 77 deletions

lib/settings.cpp

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <stdexcept>
2525

2626
Settings::Settings()
27-
: inconclusive(false)
2827
{
2928
_debug = false;
3029
_checkCodingStyle = false;
@@ -38,46 +37,7 @@ Settings::Settings()
3837
_showtime = 0; // TODO: use enum
3938
_append = "";
4039
_terminate = false;
41-
}
42-
43-
Settings::Settings(const Settings &s)
44-
: inconclusive(s.inconclusive)
45-
{
46-
*this = s;
47-
}
48-
49-
// Constructor used in unit testing..
50-
Settings::Settings(bool all)
51-
: inconclusive(all)
52-
{
53-
Settings s;
54-
*this = s; // This assigns all members except "inconclusive"
55-
}
56-
57-
const Settings &Settings::operator=(const Settings & s)
58-
{
59-
if (&s == this)
60-
return *this;
61-
62-
_debug = s._debug;
63-
_checkCodingStyle = s._checkCodingStyle;
64-
_errorsOnly = s._errorsOnly;
65-
_inlineSuppressions = s._inlineSuppressions;
66-
_verbose = s._verbose;
67-
_force = s._force;
68-
_xml = s._xml;
69-
_jobs = s._jobs;
70-
_exitCode = s._exitCode;
71-
_showtime = s._showtime;
72-
_append = s._append;
73-
_terminate = s._terminate;
74-
_outputFormat = s._outputFormat;
75-
return *this;
76-
}
77-
78-
Settings::~Settings()
79-
{
80-
40+
inconclusive = false;
8141
}
8242

8343

lib/settings.h

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
#ifndef SETTINGS_H
20-
#define SETTINGS_H
19+
#ifndef settingsH
20+
#define settingsH
2121

2222
#include <list>
2323
#include <string>
@@ -49,25 +49,14 @@ class Settings
4949
/** @brief terminate checking */
5050
bool _terminate;
5151

52-
Settings(bool all);
53-
5452
public:
5553
Settings();
56-
Settings(const Settings &s);
57-
const Settings &operator=(const Settings &s);
58-
virtual ~Settings();
59-
60-
/** @brief Return test settings where inconclusive is true */
61-
static Settings testSettings()
62-
{
63-
return Settings(true);
64-
}
6554

6655
/** @brief Is --debug given? */
6756
bool _debug;
6857

6958
/** @brief Inconclusive checks - for debugging of Cppcheck */
70-
const bool inconclusive;
59+
bool inconclusive;
7160

7261
/** @brief Is --style given? */
7362
bool _checkCodingStyle;

test/testbufferoverrun.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class TestBufferOverrun : public TestFixture
5353
errout.str("");
5454

5555
// Check for buffer overruns..
56-
Settings settings(showAll ? Settings::testSettings() : Settings());
56+
Settings settings;
57+
settings.inconclusive = showAll;
5758
settings._checkCodingStyle = true;
5859
CheckBufferOverrun checkBufferOverrun(&tokenizer, &settings, this);
5960
checkBufferOverrun.bufferOverrun();

test/testclass.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,8 @@ class TestClass : public TestFixture
417417
errout.str("");
418418

419419
// Check..
420-
Settings settings(Settings::testSettings());
420+
Settings settings;
421+
settings.inconclusive = true;
421422
settings._checkCodingStyle = true;
422423
CheckClass checkClass(&tokenizer, &settings, this);
423424
checkClass.operatorEqToSelf();
@@ -1391,7 +1392,8 @@ class TestClass : public TestFixture
13911392
errout.str("");
13921393

13931394
// Check..
1394-
Settings settings(Settings::testSettings());
1395+
Settings settings;
1396+
settings.inconclusive = true;
13951397
CheckClass checkClass(&tokenizer, &settings, this);
13961398
checkClass.constructors();
13971399
}
@@ -2106,7 +2108,7 @@ class TestClass : public TestFixture
21062108
errout.str("");
21072109

21082110
// Check..
2109-
Settings settings(Settings::testSettings());
2111+
Settings settings;
21102112
settings._checkCodingStyle = true;
21112113
CheckClass checkClass(&tokenizer, &settings, this);
21122114
checkClass.thisSubtraction();

test/testconstructors.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ class TestConstructors : public TestFixture
4646
errout.str("");
4747

4848
// Check class constructors..
49-
Settings settings(showAll ? Settings::testSettings() : Settings());
49+
Settings settings;
50+
settings.inconclusive = showAll;
5051
settings._checkCodingStyle = true;
5152
CheckClass checkClass(&tokenizer, &settings, this);
5253
checkClass.constructors();

test/testdangerousfunctions.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class TestDangerousFunctions : public TestFixture
5353
errout.str("");
5454

5555
// Check for dangerous functions..
56-
Settings settings(Settings::testSettings());
56+
Settings settings;
57+
settings.inconclusive = true;
5758
CheckDangerousFunctions checkDangerousFunctions(&tokenizer, &settings, this);
5859
checkDangerousFunctions.dangerousFunctions();
5960
}

test/testdivision.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ class TestDivision : public TestFixture
4646
// Clear the error buffer..
4747
errout.str("");
4848

49-
Settings settings(all ? Settings::testSettings() : Settings());
49+
Settings settings;
50+
settings.inconclusive = all;
5051
settings._checkCodingStyle = style;
5152

5253
// Check for unsigned divisions..

test/testincompletestatement.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ class TestIncompleteStatement : public TestFixture
4747
// Clear the error buffer..
4848
errout.str("");
4949

50-
Settings settings(Settings::testSettings());
51-
52-
// Check for unused variables..
50+
// Check for incomplete statements..
51+
Settings settings;
5352
CheckOther checkOther(&tokenizer, &settings, this);
5453
checkOther.checkIncompleteStatement();
5554
}

test/testmemleak.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ class TestMemleakInFunction : public TestFixture
212212
errout.str("");
213213

214214
// Check for memory leaks..
215-
Settings settings(showAll ? Settings::testSettings() : Settings());
216-
settings._debug = true;
215+
Settings settings;
216+
settings.inconclusive = showAll;
217217
tokenizer.fillFunctionList();
218218
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this);
219219
checkMemoryLeak.check();
@@ -600,7 +600,8 @@ class TestMemleakInFunction : public TestFixture
600600
}
601601
}
602602

603-
Settings settings(all ? Settings::testSettings() : Settings());
603+
Settings settings;
604+
settings.inconclusive = all;
604605
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, NULL);
605606
all = false;
606607
checkMemoryLeak.simplifycode(tokens, all);
@@ -2141,8 +2142,8 @@ class TestMemleakInFunction : public TestFixture
21412142
errout.str("");
21422143

21432144
// Check for memory leaks..
2144-
Settings settings(Settings::testSettings());
2145-
settings._debug = true;
2145+
Settings settings;
2146+
settings.inconclusive = true;
21462147

21472148
{
21482149
std::istringstream istr(_autoDealloc);
@@ -2712,8 +2713,8 @@ class TestMemleakInClass : public TestFixture
27122713
errout.str("");
27132714

27142715
// Check for memory leaks..
2715-
Settings settings(showAll ? Settings::testSettings() : Settings());
2716-
settings._debug = true;
2716+
Settings settings;
2717+
settings.inconclusive = true;
27172718
tokenizer.fillFunctionList();
27182719
CheckMemoryLeakInClass checkMemoryLeak(&tokenizer, &settings, this);
27192720
checkMemoryLeak.check();

test/testpreprocessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,8 +1060,8 @@ class TestPreprocessor : public TestFixture
10601060
std::istringstream istr(filedata);
10611061
std::map<std::string, std::string> actual;
10621062
Settings settings;
1063-
settings._verbose = true;
10641063
settings._debug = true;
1064+
settings._verbose = true;
10651065
Preprocessor preprocessor(&settings, this);
10661066
preprocessor.preprocess(istr, actual, "file.c");
10671067

0 commit comments

Comments
 (0)