Skip to content

Commit d4263b7

Browse files
committed
Corrected push and pop
1 parent b0678dd commit d4263b7

File tree

12 files changed

+350
-97
lines changed

12 files changed

+350
-97
lines changed

include/buffer.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,12 @@ void Buffer<T,D>::pop(SPData<T,D> elt){
119119
==============================================================================*/
120120
template <class T, class D>
121121
std::string Buffer<T,D>::toString(){
122-
std::string str;
123-
str = "\t\tBuffer size is " + std::to_string(mSize);
124-
str += " and start at index " + std::to_string(mStart) + "\n";
125-
str += explicitPointerToString(mExplicit);
122+
std::string str = "";
123+
if (mSize > 0) {
124+
str = "\t\tBuffer size is " + std::to_string(mSize);
125+
str += " and start at index " + std::to_string(mStart) + "\n";
126+
str += "\t\t\t" + explicitPointerToString(mExplicit);
127+
}
126128
return str;
127129
}
128130

include/compare.hpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@ class CompareStacks: public Problem<T,D>{
2424
void runCompare(int buffer = 0);
2525

2626
private:
27-
28-
// Stack Functions: defined by user
27+
// Stack Functions: defined by user
2928
virtual D readInput(std::vector<std::string> line) = 0;
3029
virtual std::shared_ptr<T> initStack() = 0;
3130
virtual bool popCondition(D data) = 0;
3231
virtual void popAction(Data<T,D> elt) {};
3332
virtual bool pushCondition(D data) = 0;
3433
virtual void pushAction(Data<T,D> elt) {};
3534

35+
// pop
36+
Data<T,D> popCompare();
37+
3638
// Stack: Normal Stack for comparison
3739
std::shared_ptr<NormalStack<T,D>> mNormalStack;
3840
};
@@ -50,10 +52,18 @@ CompareStacks<T,D>::CompareStacks(std::string fileName, int size, int space, int
5052
/*==============================================================================
5153
Stack Functions: run, push, pop, top
5254
==============================================================================*/
55+
template <class T, class D>
56+
Data<T,D> CompareStacks<T,D>::popCompare(){
57+
std::cout << "Debug CompareStacks::pop 1" << std::endl;
58+
return Problem<T,D>::mStack->pop(*this);
59+
std::cout << "Debug CompareStacks::pop 2" << std::endl;
60+
}
61+
5362
template <class T, class D>
5463
void CompareStacks<T,D>::runCompare(int buffer){
5564
Problem<T,D>::initStackIntern();
5665
while ((Problem<T,D>::mInput.good())) {
66+
std::streampos position = Problem<T,D>::mInput.tellg();
5767
for (int i = 1; i <= buffer; i++) {
5868
bool bIndex = Problem<T,D>::top(i).mIndex == mNormalStack->top(i).mIndex;
5969
bool bData = Problem<T,D>::top(i).mData == mNormalStack->top(i).mData;
@@ -67,19 +77,28 @@ void CompareStacks<T,D>::runCompare(int buffer){
6777
}
6878
D data = readInput(line);
6979
Problem<T,D>::mIndex++; // Might have to move
80+
std::cout << "Debug runCompare 1" << std::endl;
7081
if (Problem<T,D>::emptystack() != mNormalStack->isempty()) {
7182
throw "One stack is empty and not the other";
7283
}
73-
while ( !(Problem<T,D>::emptystack()) && (popCondition(data)) ) {
74-
Data<T,D> elt = Problem<T,D>::pop();
84+
std::cout << "Debug runCompare 2" << std::endl;
85+
while ( (!(Problem<T,D>::emptystack())) && (popCondition(data)) ) {
86+
std::cout << "Debug runCompare 2.1" << std::endl;
87+
Data<T,D> elt = popCompare();
88+
std::cout << "Debug runCompare 2.2" << std::endl;
7589
Data<T,D> eltNormal = mNormalStack->pop();
90+
std::cout << "Debug runCompare 2.3" << std::endl;
7691
bool bIndex = elt.mIndex == eltNormal.mIndex;
7792
bool bData = elt.mData == eltNormal.mData;
78-
if (!bIndex || bData) {
93+
std::cout << "Debug runCompare 2.4" << std::endl;
94+
if (!bIndex || !bData) {
7995
throw "The two elements popped are different";
8096
}
97+
std::cout << "Debug runCompare 2.5" << std::endl;
8198
popAction(elt);
99+
std::cout << "Debug runCompare 2.6" << std::endl;
82100
}
101+
std::cout << "Debug runCompare 3" << std::endl;
83102
if (pushCondition(data)) {
84103
Data<T,D> elt (Problem<T,D>::mIndex,data);
85104
pushAction(elt);

include/component.hpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Component{
4141
bool isempty();
4242
bool isempty(int lvl);
4343
bool isExplicitEmpty();
44+
bool single(int lvl);
4445

4546
Levels<T,D> mPartial;
4647
ExplicitPointer<T,D> mExplicit;
@@ -73,8 +74,8 @@ std::string levelsToString(Levels<T,D> levels){
7374
for (typename Levels<T,D>::iterator it = levels.begin() ; it != levels.end(); ++it)
7475
{
7576
index++;
76-
str += "\t\t\tLevel" + std::to_string(index) + "->\n";
77-
str += "\t\t\t\t" + blockToString(*it) + "\n";
77+
str += "\t\t\tLevel " + std::to_string(index) + " ->";
78+
str += " " + blockToString(*it) + "\n";
7879
}
7980
return str;
8081
}
@@ -83,10 +84,10 @@ template <class T, class D>
8384
std::string Component<T,D>::toString(){
8485
std::string str;
8586
str = levelsToString(mPartial);
86-
str += "\t\t\tExplicit->\n";
87+
str += "\t\t\tExplicit -> ";
8788
str += explicitPointerToString(mExplicit);
88-
str += "\t\t\tSignature->\n";
89-
//str += (&mSign).toString() + "\n";
89+
str += "\n\t\t\tSignature -> ";
90+
str += mSign.toString() + "\n";
9091
return str;
9192
}
9293

@@ -142,6 +143,14 @@ int Component<T,D>::topIndex(int lvl){
142143
}
143144
}
144145

146+
template <class T, class D>
147+
bool Component<T,D>::single(int lvl){
148+
if (mPartial[lvl].empty()) {
149+
return false;
150+
}
151+
return (mPartial[lvl].back().single());
152+
}
153+
145154
/*==============================================================================
146155
Setters
147156
==============================================================================*/

0 commit comments

Comments
 (0)