Skip to content

Commit 2dd3438

Browse files
committed
Removed pointers
1 parent e75c3d7 commit 2dd3438

File tree

5 files changed

+52
-48
lines changed

5 files changed

+52
-48
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
.wsjcpp/*
22
tmp/*
33
wsjcpp-diff-text
4-
.vscode/
4+
.vscode/*
5+
.logs/*
56

67
# Prerequisites
78
*.d

src/main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ int main(int argc, const char* argv[]) {
3737
WsjcppCore::readTextFile(sFileName1, sFileContent1);
3838
WsjcppCore::readTextFile(sFileName2, sFileContent2);
3939

40-
std::vector<WsjcppDiffTextRow *> vResult;
40+
std::vector<WsjcppDiffTextRow> vResult;
4141
WsjcppDiffText::compare(sFileContent1, sFileContent2, vResult);
4242
for (int i = 0; i < vResult.size(); i++) {
4343
std::cout <<
44-
vResult[i]->getKey() << " => line (" << vResult[i]->getNumberOfLine() << "): "
45-
<< vResult[i]->getLine() << std::endl;
44+
vResult[i].getKey() << " => line (" << vResult[i].getNumberOfLine() << "): "
45+
<< vResult[i].getLine() << std::endl;
4646
}
47+
vResult.clear();
4748
return 0;
4849
}
4950

src/wsjcpp_diff_text.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ std::string WsjcppDiffTextRow::getLine() {
3939
void WsjcppDiffText::compare(
4040
const std::string &sText1,
4141
const std::string &sText2,
42-
std::vector<WsjcppDiffTextRow *> &vOutput
42+
std::vector<WsjcppDiffTextRow> &vOutput
4343
) {
4444
std::vector<std::string> list1;
4545
std::istringstream isTxt1(sText1);
@@ -61,42 +61,42 @@ void WsjcppDiffText::compare(
6161

6262
int len1 = list1.size();
6363
int len2 = list2.size();
64-
int i=0, j=0;
64+
int i = 0, j = 0;
6565
//main comparisons
6666
while ((i<len1) && (j<len2)) {
6767
if (list1[i] != list2[j]) {
68-
//checkout for added rows
68+
// checkout for added rows
6969
for (int k = j + 1; k < len2; ++k) {
7070
if (list1[i] == list2[k]) {
7171
while (j<k) {
72-
vOutput.push_back(new WsjcppDiffTextRow(j, sWord.at(0), list2.at(j)));
72+
vOutput.push_back(WsjcppDiffTextRow(j, sWord.at(0), list2.at(j)));
7373
j++;
7474
}
7575
goto exit;
7676
}
7777
}
78-
//checkout for deleted rows
78+
// checkout for deleted rows
7979
for (int k=i+1;k<len1;++k) {
8080
if (list1[k]==list2[j]) {
8181
while (i<k) {
82-
vOutput.push_back(new WsjcppDiffTextRow(i, sWord.at(1), list1.at(i)));
82+
vOutput.push_back(WsjcppDiffTextRow(i, sWord.at(1), list1.at(i)));
8383
i++;
8484
}
8585
goto exit;
8686
}
8787
}
88-
vOutput.push_back(new WsjcppDiffTextRow(i, list1.at(i), list2.at(j)));
88+
vOutput.push_back(WsjcppDiffTextRow(i, list1.at(i), list2.at(j)));
8989
exit:;
9090
}
9191
i++, j++;
9292
}
9393
//work with the end of the texts
94-
while (j<len2) {
95-
vOutput.push_back(new WsjcppDiffTextRow(j, sWord.at(0), list2.at(j)));
94+
while (j < len2) {
95+
vOutput.push_back(WsjcppDiffTextRow(j, sWord.at(0), list2.at(j)));
9696
j++;
9797
}
98-
while (i<len1) {
99-
vOutput.push_back(new WsjcppDiffTextRow(i, sWord.at(1), list1.at(i)));
98+
while (i < len1) {
99+
vOutput.push_back(WsjcppDiffTextRow(i, sWord.at(1), list1.at(i)));
100100
i++;
101101
}
102102
}
@@ -107,18 +107,18 @@ void WsjcppDiffText::merge(
107107
std::string &curtxt,
108108
std::string &txt1,
109109
std::string &txt2,
110-
std::vector<WsjcppDiffTextRow *> &arr1,
111-
std::vector<WsjcppDiffTextRow *> &arr2
110+
std::vector<WsjcppDiffTextRow> &arr1,
111+
std::vector<WsjcppDiffTextRow> &arr2
112112
) {
113113
WsjcppDiffText::compare(txt1, txt2, arr1);
114114
WsjcppDiffText::compare(txt1, curtxt, arr2);
115115
for (unsigned int i=0;i<arr2.size();++i) {
116116
for (unsigned int j=0;j<arr1.size();++j) {
117117
//delete of matches and 'del'/'add' overlays from the first vector
118-
bool bLinesEqual = arr2.at(i)->getLine() == arr1.at(j)->getLine();
119-
bool bKeysEqual = arr2.at(i)->getKey() == arr1.at(j)->getLine(); // TODO why comparing key and line ???
120-
std::string sKey1 = arr1.at(j)->getKey();
121-
std::string sKey2 = arr2.at(i)->getKey();
118+
bool bLinesEqual = arr2[i].getLine() == arr1[j].getLine();
119+
bool bKeysEqual = arr2[i].getKey() == arr1[j].getLine(); // TODO why comparing key and line ???
120+
std::string sKey1 = arr1[j].getKey();
121+
std::string sKey2 = arr2[i].getKey();
122122
if ((bLinesEqual && (sKey1 == sKey2 || sKey1 == "!add"))
123123
|| (bKeysEqual && (sKey1 == "!del")))
124124
{
@@ -130,9 +130,9 @@ void WsjcppDiffText::merge(
130130
for (unsigned int i = 0; i < arr1.size(); ++i) {
131131
for (unsigned int j = 0; j < arr2.size(); ++j) {
132132
//delete of del overlays from the second vector and update of priority
133-
bool bLinesEqual = arr1.at(i)->getKey() == arr2.at(j)->getLine(); // TODO check why comparing key and line here ?
134-
bool bKeysEqual = arr1.at(i)->getKey() == arr2.at(j)->getKey();
135-
std::string sKey = arr2.at(j)->getKey();
133+
bool bLinesEqual = arr1[i].getKey() == arr2.at(j).getLine(); // TODO check why comparing key and line here ?
134+
bool bKeysEqual = arr1.at(i).getKey() == arr2.at(j).getKey();
135+
std::string sKey = arr2.at(j).getKey();
136136
if ((bLinesEqual && (sKey == "!del"))
137137
|| (bKeysEqual && (sKey != "!add") && (sKey != "!del")))
138138
{
@@ -146,7 +146,7 @@ void WsjcppDiffText::merge(
146146
arr1.insert(arr1.end(),arr2.begin(),arr2.end());
147147
for (unsigned int i=0; i < arr1.size(); ++i) {
148148
for (unsigned int j = arr1.size()-1; j > i; --j) {
149-
if (arr1.at(j-1)->getNumberOfLine() > arr1.at(j)->getNumberOfLine()) {
149+
if (arr1.at(j-1).getNumberOfLine() > arr1.at(j).getNumberOfLine()) {
150150
// TODO redesign
151151
std::swap(arr1.at(j-1), arr1.at(j));
152152
}

src/wsjcpp_diff_text.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ class WsjcppDiffText {
2727
static void compare(
2828
const std::string &sText1,
2929
const std::string &sText2,
30-
std::vector<WsjcppDiffTextRow *> &vOutput
30+
std::vector<WsjcppDiffTextRow> &vOutput
3131
);
3232
static void merge(
3333
std::string &curtxt,
3434
std::string &txt1,
3535
std::string &txt2,
36-
std::vector<WsjcppDiffTextRow *> &arr1,
37-
std::vector<WsjcppDiffTextRow *> &arr2
36+
std::vector<WsjcppDiffTextRow> &arr1,
37+
std::vector<WsjcppDiffTextRow> &arr2
3838
);
3939
};
4040

unit-tests.wsjcpp/src/unit_test_basic.cpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@ bool UnitTestBasic::run() {
2424
std::string txt1,
2525
std::string txt2,
2626
std::string txt3,
27-
std::vector<WsjcppDiffTextRow *> arr1,
28-
std::vector<WsjcppDiffTextRow *> arr2,
27+
std::vector<WsjcppDiffTextRow> arr1,
28+
std::vector<WsjcppDiffTextRow> arr2,
2929
unsigned int n
3030
) : txt1(txt1), txt2(txt2), txt3(txt3), arr1(arr1), arr2(arr2), n(n) {
3131
//
3232
}
3333
std::string txt1;
3434
std::string txt2;
3535
std::string txt3;
36-
std::vector<WsjcppDiffTextRow *> arr1;
37-
std::vector<WsjcppDiffTextRow *> arr2;
36+
std::vector<WsjcppDiffTextRow> arr1;
37+
std::vector<WsjcppDiffTextRow> arr2;
3838
unsigned int n;
3939
};
4040

4141
std::vector<LTest *> tests1;
42-
std::vector<WsjcppDiffTextRow *> arr1, arr2;
42+
std::vector<WsjcppDiffTextRow> arr1, arr2;
4343

4444
std::string text1 = text001();
4545
std::string text2 = text002();
@@ -113,23 +113,23 @@ bool UnitTestBasic::run() {
113113
std::string txt1,
114114
std::string txt2,
115115
std::string txt3,
116-
std::vector<WsjcppDiffTextRow *> arr1,
117-
std::vector<WsjcppDiffTextRow *> arr2,
118-
std::vector<WsjcppDiffTextRow *> arr3
116+
std::vector<WsjcppDiffTextRow> arr1,
117+
std::vector<WsjcppDiffTextRow> arr2,
118+
std::vector<WsjcppDiffTextRow> arr3
119119
) : txt1(txt1), txt2(txt2), txt3(txt3), arr1(arr1), arr2(arr2), arr3(arr3) {
120120
//
121121
}
122122

123123
std::string txt1;
124124
std::string txt2;
125125
std::string txt3;
126-
std::vector<WsjcppDiffTextRow *> arr1;
127-
std::vector<WsjcppDiffTextRow *> arr2;
128-
std::vector<WsjcppDiffTextRow *> arr3;
126+
std::vector<WsjcppDiffTextRow> arr1;
127+
std::vector<WsjcppDiffTextRow> arr2;
128+
std::vector<WsjcppDiffTextRow> arr3;
129129
};
130130

131131
std::vector<LTest2 *> tests2;
132-
std::vector<WsjcppDiffTextRow *> arr3;
132+
std::vector<WsjcppDiffTextRow> arr3;
133133
int id[8] = {0,1,1,2,3,4,5,6};
134134
std::vector<std::string> skey;
135135
skey.push_back("I");
@@ -151,7 +151,9 @@ bool UnitTestBasic::run() {
151151
sline.push_back("good");
152152
sline.push_back("boy");
153153

154-
for (int i=0;i<skey.size();++i) arr3.push_back(new WsjcppDiffTextRow(id[i], skey.at(i), sline.at(i)));
154+
for (int i = 0; i < skey.size(); ++i) {
155+
arr3.push_back(WsjcppDiffTextRow(id[i], skey.at(i), sline.at(i)));
156+
}
155157

156158
tests2.push_back(new LTest2(
157159
"You\nare\ngot\nand\ngood",
@@ -166,13 +168,13 @@ bool UnitTestBasic::run() {
166168

167169
unsigned int Success = 0;
168170
for (int i = 0; i < 8; ++i) {
169-
int id1 = arr1.at(i)->getNumberOfLine();
170-
int id2 = arr3.at(i)->getNumberOfLine();
171-
std::string key1 = arr1.at(i)->getKey();
172-
std::string key2 = arr3.at(i)->getKey();
173-
std::string line1 = arr1.at(i)->getLine();
174-
std::string line2 = arr3.at(i)->getLine();
175-
if (id1==id2 && key1==key2 && line1==line2) {
171+
int id1 = arr1[i].getNumberOfLine();
172+
int id2 = arr3[i].getNumberOfLine();
173+
std::string key1 = arr1[i].getKey();
174+
std::string key2 = arr3[i].getKey();
175+
std::string line1 = arr1[i].getLine();
176+
std::string line2 = arr3[i].getLine();
177+
if (id1 == id2 && key1 == key2 && line1 == line2) {
176178
Success+=1;
177179
} else {
178180
WsjcppLog::info(TAG, "In the sort test in the element №" + std::to_string(i+1) + ":");

0 commit comments

Comments
 (0)