Website Summary Files Commits Branches @commit @diff @stats
path: root / src
diff options
context:
space:
mode:
Commitdd8ff49d2bd29f08c5a6afa39d89dba3d715ee4a (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-05-30 20:33:26 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-05-30 20:33:26 +0300
Filesb012e52c5b2bd32ee55e3f59d341bfe4c493a873 /src
FMI-OOP-P2_Tables-dd8ff49d2bd29f08c5a6afa39d89dba3d715ee4a.tar
FMI-OOP-P2_Tables-dd8ff49d2bd29f08c5a6afa39d89dba3d715ee4a.tar.gz
FMI-OOP-P2_Tables-dd8ff49d2bd29f08c5a6afa39d89dba3d715ee4a.zip
Parent2929a4a6e811ddc2c2073158f50d2e20170c6c6a (diff)
Autocommit at 30.05.2022 @ 20:33
4 files changed, 17 insertions, 7 deletions
-rw-r--r--src/Generic/ConsoleInterface/Menu.cpp14
-rw-r--r--src/Models/Table.cpp6
-rw-r--r--src/UserInterface/UserInterface.cpp2
-rw-r--r--src/main.cpp2
diff --git a/src/Generic/ConsoleInterface/Menu.cpp b/src/Generic/ConsoleInterface/Menu.cpp
index d547990..9c2fca5 100644
--- a/src/Generic/ConsoleInterface/Menu.cpp
+++ b/src/Generic/ConsoleInterface/Menu.cpp
@@ -36,15 +36,13 @@ void Menu::navigate() const {
char buffer[MAX_LINE_WIDTH];
unsigned startIndex, commandEnd, paramsStart, index;
- while (1) {
+ bool hasThrown = false;
+ while (!hasThrown) {
startIndex = 0;
inputLineBox(buffer, MAX_LINE_WIDTH, false);
while (buffer[startIndex] == ' ') startIndex++;
- if (strncmp(buffer + startIndex, "quit", 4) == 0)
- break;
-
commandEnd = startIndex;
while (buffer[commandEnd] != ' ' && buffer[commandEnd] != '\n' && buffer[commandEnd] != '\0')
commandEnd++;
@@ -63,6 +61,12 @@ void Menu::navigate() const {
continue;
}
- menuOptions[index].run(buffer + paramsStart);
+ try {
+ menuOptions[index].run(buffer + paramsStart);
+ }
+ catch (std::logic_error err) {
+ hasThrown = true;
+ printLine(err.what());
+ }
}
}
diff --git a/src/Models/Table.cpp b/src/Models/Table.cpp
index a4103be..dd82b30 100644
--- a/src/Models/Table.cpp
+++ b/src/Models/Table.cpp
@@ -35,15 +35,18 @@ void Table::readFromFile(std::ifstream& inFile) {
while (!inFile.eof()) {
while (inFile.peek() == ' ') inFile.get();
+ // Entering a new cell on the current row
if (inFile.peek() == ',') {
colInd++;
inFile.get();
}
+ // Entering a new row
else if (inFile.peek() == '\n') {
cells.add(List<Cell*>(commaCount));
colInd = 0;
inFile.get();
}
+ // Parsing number
else if (inFile.peek() == '-' || inFile.peek() == '+' || isDigit(inFile.peek())) {
int whole = 0;
unsigned exponent = 1;
@@ -56,9 +59,11 @@ void Table::readFromFile(std::ifstream& inFile) {
if (isDigit(inFile.peek()))
throw std::logic_error(fileLocationExceptionMsg("Error: Expected digit but got something else at row ", cells.get_count(), inFile.tellg() % cells.get_count() + 1));
+ // Parsing digits of whole number/whole part of floating point number
while (isDigit(inFile.peek())) {
(whole *= 10) += inFile.get() - '0';
}
+ // Parsing digits of potential floating point number
if (inFile.peek() != '.') {
inFile.get();
while (isDigit(inFile.peek())) {
@@ -75,6 +80,7 @@ void Table::readFromFile(std::ifstream& inFile) {
else
cells[cells.get_count() - 1].add(new CellDouble((double)whole / exponent));
}
+ // Parsing string or formula
else if (inFile.peek() == '"') {
String res;
inFile.get();
diff --git a/src/UserInterface/UserInterface.cpp b/src/UserInterface/UserInterface.cpp
index 2edd22e..015e77f 100644
--- a/src/UserInterface/UserInterface.cpp
+++ b/src/UserInterface/UserInterface.cpp
@@ -69,7 +69,7 @@ void UserInterface::com_exit(const char* params) {
return;
}
- printLine("Exiting program...");
+ throw std::logic_error("Exiting program..."); // stupid way of making the program stop
}
void UserInterface::com_print(const char* params) {
diff --git a/src/main.cpp b/src/main.cpp
index 0f47890..64b09c2 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,6 +7,6 @@ int main() {
table.putCell(0, 2, "\"String");
table.putCell(0, 3, "\"= 3 * R0C1 + R0C0 ^ R0C1 * 27 / R0C1 - 2 * 2.5 * 2 * 2 + R0C2 ^ R0C2 + R9999C999999");
// table.putCell(0, 3, "= 1 + 2 * 3 + 4 + 5");
- UserInterface ui(&table);
+ UserInterface ui(nullptr);
ui.run();
}