Skip to content

Commit 4e126aa

Browse files
committed
Short explanation on the cmake in build/cmakereadme.txt. Print functions in the Problem class
1 parent f7675d6 commit 4e126aa

File tree

10 files changed

+846
-745
lines changed

10 files changed

+846
-745
lines changed

build/cmakereadme.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Commands to use with cmake in the current folder
2+
3+
# For linking new files (or unlink removed files)
4+
cmake ..
5+
6+
# To create debugger executable
7+
cmake -DCMAKE_BUILD_TYPE=Debug ..
8+
9+
# For compilation (normal and debug)
10+
make
11+
12+
# To clean
13+
make clean
14+
15+
# To run gdb
16+
gdb
17+
file ./smartstack
18+
run

build/smartstack

-170 KB
Binary file not shown.

include/compressedStack.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ std::string CompressedStack<T,D>::toString()
6868
str += "\t\tSecond Component\n";
6969
str += mSecond.toString();
7070
str += "\t\tFully Compressed\n";
71-
str += toString();
71+
str += blockToString(mCompressed);
7272
return str;
7373
}
7474

include/data.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ std::string explicitToString(Explicit<D> xplicit)
7979
str = "{";
8080
for (typename Explicit<D>::iterator it = xplicit.begin() ; it != xplicit.end(); ++it)
8181
str += (*it).toString() + ",";
82-
str.back() = ')';
82+
str.back() = '}';
8383
return str;
8484
}
8585

include/normalStack.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class NormalStack: public Stack<D>
1717
Data<D> top(int k);
1818

1919
// IO
20+
std::string toString();
2021
void print();
2122
void println();
2223

@@ -57,9 +58,16 @@ template <class D>
5758

5859
/** IO **/
5960
template <class D>
61+
std::string NormalStack<D>::toString()
62+
{
63+
std::string str;
64+
str = "\tNormal Stack (Explicit Datas)\n\t\t";
65+
return str;
66+
}
67+
template <class D>
6068
void NormalStack<D>::print()
6169
{
62-
std::cout << "\tNormal Stack (Explicit Datas)\n\t\t";
70+
std::cout << this->toString();
6371
printExplicit(mDatas);
6472
}
6573
template <class D>

include/problem.hpp

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,28 @@ class Problem
2121
void run();
2222

2323
// Setters
24-
void setInitStack(void (*functionPointer)());
2524
void setReadInput(D (*functionPointer)());
25+
void setInitStack(void (*functionPointer)());
2626
void setPopCondition(bool (*functionPointer)());
2727
void setPopAction(void (*functionPointer)());
2828
void setPushCondition(bool (*functionPointer)());
2929
void setPushAction(void (*functionPointer)());
3030

31+
void setOutput(std::string fileName);
32+
33+
// IO
34+
std::string toString();
35+
void print();
36+
void println();
37+
3138
private:
3239
// Input/Ouput
3340
std::ifstream* mInput;
3441
std::ofstream* mOutput; // output file is optional
3542

3643
// Stack Functions: defined by user
37-
void (*mInitStack)();
3844
D (*mReadInput)();
45+
void (*mInitStack)();
3946
bool (*mPopCondition)();
4047
void (*mPopAction)();
4148
bool (*mPushCondition)();
@@ -68,6 +75,7 @@ Problem<T,D>::Problem(std::string fileName, int size)
6875
mContext = nullptr;
6976
mIndex = 0;
7077

78+
7179
mStack = new NormalStack<T> (size);
7280
}
7381

@@ -76,7 +84,7 @@ Problem<T,D>::Problem(std::string fileName, int size, int space)
7684
{
7785
std::ifstream ifstr;
7886
ifstr.open(fileName, std::ifstream::in);
79-
mInput = ifstr;
87+
mInput = &ifstr;
8088
mOutput = nullptr;
8189

8290
mInitStack = nullptr;
@@ -92,6 +100,29 @@ Problem<T,D>::Problem(std::string fileName, int size, int space)
92100
mStack = new CompressedStack<T,D> (size, space);
93101
}
94102

103+
/** IO **/
104+
template <class T, class D>
105+
std::string Problem<T,D>::toString(){
106+
std::string str;
107+
str = "Problem with an actual index of " + std::to_string(mIndex);
108+
str += ", with a stack of type\n";
109+
str += (*mStack).toString();
110+
return str;
111+
}
112+
113+
template <class T, class D>
114+
void Problem<T,D>::print()
115+
{
116+
std::cout << this->toString();
117+
}
118+
119+
template <class T, class D>
120+
void Problem<T,D>::println()
121+
{
122+
this->print();
123+
std::cout << std::endl;
124+
}
125+
95126
/** Running the stack **/
96127
template <class T, class D>
97128
void Problem<T,D>::run() {
@@ -106,4 +137,37 @@ void Problem<T,D>::run() {
106137
}
107138
}
108139

140+
/** Setters **/
141+
template <class T, class D>
142+
void Problem<T,D>::setReadInput(D (*functionPointer)()){
143+
mReadInput = functionPointer;
144+
}
145+
template <class T, class D>
146+
void Problem<T,D>::setInitStack(void (*functionPointer)()){
147+
mInitStack = functionPointer;
148+
}
149+
template <class T, class D>
150+
void Problem<T,D>::setPopAction(void (*functionPointer)()){
151+
mPopAction = functionPointer;
152+
}
153+
template <class T, class D>
154+
void Problem<T,D>::setPopCondition(bool (*functionPointer)()){
155+
mPopConditon = functionPointer;
156+
}
157+
template <class T, class D>
158+
void Problem<T,D>::setPushAction(void (*functionPointer)()){
159+
mPushAction = functionPointer;
160+
}
161+
template <class T, class D>
162+
void Problem<T,D>::setPushCondition(bool (*functionPointer)()){
163+
mPushConditon = functionPointer;
164+
}
165+
166+
template <class T, class D>
167+
void Problem<T,D>::setOutput(std::string fileName){
168+
std::ofstream ofstr;
169+
ofstr.open(fileName, std::ofstream::out);
170+
mOutput = &ofstr;
171+
}
172+
109173
#endif /* PROBLEM */

include/stack.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Stack
1414
virtual Data<D> top(int k) = 0;
1515

1616
// IO
17+
virtual std::string toString() = 0;
1718
virtual void print() = 0;
1819
virtual void println() = 0;
1920
};

0 commit comments

Comments
 (0)