@@ -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+
3138private:
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 **/
96127template <class T , class D >
97128void 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 */
0 commit comments