move debug stuff out of calculator.cpp
This commit is contained in:
parent
1ad99f8129
commit
c1b63ea2de
2 changed files with 42 additions and 30 deletions
|
@ -1,5 +1,9 @@
|
||||||
#include <vector>
|
#ifndef __CALCULATOR_CPP
|
||||||
|
#define __CALCULATOR_CPP
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include "debug.cpp"
|
||||||
#include "stack.cpp"
|
#include "stack.cpp"
|
||||||
|
|
||||||
namespace Calculator
|
namespace Calculator
|
||||||
|
@ -22,34 +26,6 @@ struct Symbol {
|
||||||
double value = 0;
|
double value = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
void dbgPrint(const std::vector<Symbol>* _input) {
|
|
||||||
std::cout << "\033[31m";
|
|
||||||
|
|
||||||
for (auto it = _input->begin(); it != _input->end(); it++) {
|
|
||||||
auto type = it->type;
|
|
||||||
|
|
||||||
std::cout << "[";
|
|
||||||
if (type == SymbolType::add) std::cout << "+";
|
|
||||||
else if (type == SymbolType::subract) std::cout << "-";
|
|
||||||
else if (type == SymbolType::divide) std::cout << "/";
|
|
||||||
else if (type == SymbolType::multiply) std::cout << "*";
|
|
||||||
else if (type == SymbolType::number) std::cout << it->value;
|
|
||||||
else if (type == SymbolType::left_bracket) std::cout << "(";
|
|
||||||
else if (type == SymbolType::right_bracket) std::cout << ")";
|
|
||||||
|
|
||||||
std::cout << "]";
|
|
||||||
};
|
|
||||||
std::cout << "\033[0m";
|
|
||||||
}
|
|
||||||
|
|
||||||
void dbgPrint(const std::vector<unsigned int>* _input) {
|
|
||||||
std::cout << "\033[31m";
|
|
||||||
for (auto it = _input->begin(); it != _input->end(); it++) {
|
|
||||||
std::cout << "[" << *it << "]";
|
|
||||||
}
|
|
||||||
std::cout << "\033[31m";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief the result of parse function.
|
* @brief the result of parse function.
|
||||||
*/
|
*/
|
||||||
|
@ -412,4 +388,6 @@ parseAndCalculateResult parseAndCaluclate(const std::string& _input, bool debug
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
}; // namespace Calculator
|
}; // namespace Calculator
|
||||||
|
|
||||||
|
#endif
|
|
@ -2,6 +2,7 @@
|
||||||
#ifndef __DEBUG_CPP
|
#ifndef __DEBUG_CPP
|
||||||
#define __DEBUG_CPP
|
#define __DEBUG_CPP
|
||||||
|
|
||||||
|
#include "calculator.cpp"
|
||||||
#include "cursor.cpp"
|
#include "cursor.cpp"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,5 +26,38 @@ void debugKey(cursor::key _key) {
|
||||||
cursor::restorePosition();
|
cursor::restorePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Prints the content of _input.
|
||||||
|
*
|
||||||
|
* @param _input vector of symbols
|
||||||
|
*/
|
||||||
|
void dbgPrint(const std::vector<Calculator::Symbol>* _input) {
|
||||||
|
for (auto it = _input->begin(); it != _input->end(); it++) {
|
||||||
|
auto type = it->type;
|
||||||
|
|
||||||
|
std::cout << "[";
|
||||||
|
if (type == Calculator::SymbolType::add) std::cout << "+";
|
||||||
|
else if (type == Calculator::SymbolType::subract) std::cout << "-";
|
||||||
|
else if (type == Calculator::SymbolType::divide) std::cout << "/";
|
||||||
|
else if (type == Calculator::SymbolType::multiply) std::cout << "*";
|
||||||
|
else if (type == Calculator::SymbolType::number) std::cout << it->value;
|
||||||
|
else if (type == Calculator::SymbolType::left_bracket) std::cout << "(";
|
||||||
|
else if (type == Calculator::SymbolType::right_bracket) std::cout << ")";
|
||||||
|
|
||||||
|
std::cout << "]";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Prints the content of _input.
|
||||||
|
*
|
||||||
|
* @param _input vetcor of unsigned int
|
||||||
|
*/
|
||||||
|
void dbgPrint(const std::vector<unsigned int>* _input) {
|
||||||
|
for (auto it = _input->begin(); it != _input->end(); it++) {
|
||||||
|
std::cout << "[" << *it << "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
Reference in a new issue