summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt49
-rw-r--r--inc/gui.h26
-rw-r--r--inc/logger.h10
-rw-r--r--src/gui/gui.cc39
-rw-r--r--src/gui/gui.ui55
-rw-r--r--src/gui/resources.qrc6
-rw-r--r--src/gui/resources/input.txt1
-rw-r--r--src/logger/logger.cc20
-rw-r--r--src/main.cc88
9 files changed, 21 insertions, 273 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d4be3ee..9daac12 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,58 +1,45 @@
cmake_minimum_required(VERSION 3.5)
+set(CMAKE_CXX_COMPILER "g++")
project(risc_vector)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
-set(CMAKE_AUTOUIC ON) # automatically process .ui files into headers
-set(CMAKE_AUTOMOC ON)
-set(CMAKE_AUTORCC ON)
-add_compile_options(-Wall -lstdc++)
+add_compile_options(-Wall -lstdc++ -g -O0)
add_compile_options(-Wextra -Wpedantic)
# cpp standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
-set(CMAKE_CXX_COMPILER "g++")
-
# header files
include_directories(
${PROJECT_SOURCE_DIR}/inc
)
+# add gui
+add_subdirectory(gui)
+
# gather source files
file(GLOB_RECURSE SRCS "src/*.cc")
-list(REMOVE_ITEM SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/main.cc")
# find QT components
find_package(Qt6 COMPONENTS Widgets REQUIRED)
+qt_standard_project_setup()
# binary executable
-add_executable(${PROJECT_NAME} ${SRCS})
-qt_add_resources(GUI_RESOURCES "src/gui/resources.qrc")
-target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Widgets)
-
-# find_package(Catch2 REQUIRED)
-
-# #gather test files
-# file(GLOB_RECURSE TESTS "tests/*.cc")
-
-# # test executable
-# add_executable(tests ${SRCS} ${TESTS})
-# target_link_libraries(tests PRIVATE Catch2::Catch2WithMain PRIVATE Qt6::Widgets)
-
-# # test discovery
-# include(CTest)
-# include(Catch)
-# catch_discover_tests(tests)
+add_library(${PROJECT_NAME}_lib ${SRCS})
+target_link_libraries(${PROJECT_NAME}_lib)
+find_package(Catch2 REQUIRED)
-# # Gather GUI Source Files
-# file(GLOB_RECURSE GUI_SRCS "src/gui/*.cc")
+#gather test files
+file(GLOB_RECURSE TESTS "tests/*.cc")
-# # Gather GUI Resources
-# qt_add_resources(GUI_RESOURCES "src/gui/resources.qrc")
+# test executable
+add_executable(tests ${SRCS} ${TESTS})
+target_link_libraries(tests PRIVATE Catch2::Catch2WithMain PRIVATE)
-# # GUI executable
-# qt_add_executable("${PROJECT_NAME}_gui" ${GUI_SRCS} ${SRCS} ${GUI_RESOURCES})
-# target_link_libraries("${PROJECT_NAME}_gui" PRIVATE Qt6::Widgets)
+# test discovery
+include(CTest)
+include(Catch)
+catch_discover_tests(tests)
diff --git a/inc/gui.h b/inc/gui.h
deleted file mode 100644
index 668fafa..0000000
--- a/inc/gui.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#ifndef GUI_H
-#define GUI_H
-#include <QWidget>
-
-namespace Ui
-{
-class gui;
-}
-QT_END_NAMESPACE
-
-class Gui : public QWidget
-{
- Q_OBJECT
-
- public:
- Gui(QWidget *parent = nullptr);
- ~Gui();
-
- private slots:
- void on_pushButton_clicked();
-
- private:
- Ui::gui *ui;
- void loadTxtFile();
-};
-#endif // GUI_H
diff --git a/inc/logger.h b/inc/logger.h
index 38527c8..88f9e30 100644
--- a/inc/logger.h
+++ b/inc/logger.h
@@ -11,7 +11,7 @@ class Logger
public:
static Logger* getInstance();
- ~Logger();
+ ~Logger() = default;
/**
* Do not allow copies.
@@ -32,15 +32,9 @@ class Logger
void log(LogLevel, const string &);
private:
- /**
- * Constructor.
- * @param The file name to log to.
- * @return A new logger object.
- */
- Logger(const string &);
+ Logger() = default;
static Logger* logger_instance;
static LogLevel level;
- static ofstream logFile;
static string level_to_string(LogLevel);
static int level_to_int(LogLevel);
};
diff --git a/src/gui/gui.cc b/src/gui/gui.cc
deleted file mode 100644
index 9f2405d..0000000
--- a/src/gui/gui.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-#include "gui.h"
-#include "ui_gui.h"
-#include <QFile>
-#include <QTextStream>
-
-Gui::Gui(QWidget *parent)
- : QWidget(parent)
- , ui(new Ui::gui)
-{
- ui->setupUi(this);
- loadTxtFile();
-}
-
-Gui::~Gui()
-{
- delete ui;
-}
-
-void Gui::loadTxtFile(){
- QFile inputFile(":/resources/input.txt");
- inputFile.open(QIODevice::ReadOnly);
-
- QTextStream in(&inputFile);
- QString line = in.readAll();
- inputFile.close();
-
- ui->textEdit->setPlainText(line);
- QTextCursor cursor = ui->textEdit->textCursor();
- cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1);
-}
-
-void Gui::on_pushButton_clicked()
-{
- QString searchString = ui->lineEdit->text();
- ui->textEdit->find(searchString, QTextDocument::FindWholeWords);
-}
-
-
-
diff --git a/src/gui/gui.ui b/src/gui/gui.ui
deleted file mode 100644
index 5f71c91..0000000
--- a/src/gui/gui.ui
+++ /dev/null
@@ -1,55 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>gui</class>
- <widget class="QWidget" name="gui">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>800</width>
- <height>600</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>gui</string>
- </property>
- <widget class="QWidget" name="">
- <property name="geometry">
- <rect>
- <x>60</x>
- <y>30</y>
- <width>317</width>
- <height>232</height>
- </rect>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QLabel" name="label">
- <property name="text">
- <string>keyword</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLineEdit" name="lineEdit"/>
- </item>
- <item>
- <widget class="QPushButton" name="pushButton">
- <property name="text">
- <string>find</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <widget class="QTextEdit" name="textEdit"/>
- </item>
- </layout>
- </widget>
- </widget>
- <resources/>
- <connections/>
-</ui>
diff --git a/src/gui/resources.qrc b/src/gui/resources.qrc
deleted file mode 100644
index 8bfd4e7..0000000
--- a/src/gui/resources.qrc
+++ /dev/null
@@ -1,6 +0,0 @@
-<!DOCTYPE RCC>
-<RCC version="1.0">
- <qresource prefix="/resources">
- <file alias="input.txt">resources/input.txt</file>
- </qresource>
-</RCC>
diff --git a/src/gui/resources/input.txt b/src/gui/resources/input.txt
deleted file mode 100644
index fc1c3cf..0000000
--- a/src/gui/resources/input.txt
+++ /dev/null
@@ -1 +0,0 @@
-Lorem Ipsum \ No newline at end of file
diff --git a/src/logger/logger.cc b/src/logger/logger.cc
index 55d7a15..6dfaef1 100644
--- a/src/logger/logger.cc
+++ b/src/logger/logger.cc
@@ -6,21 +6,8 @@
using namespace std;
LogLevel Logger::level = INFO;
-ofstream Logger::logFile;
Logger *Logger::logger_instance;
-Logger::Logger(const string &filename)
-{
- if (!filename.empty()) {
- logFile.open(filename, ios::app);
- if (!logFile.is_open()) {
- cerr << "Error opening log file." << endl;
- }
- }
-}
-
-Logger::~Logger() { logFile.close(); }
-
void Logger::setLevel(LogLevel level) { level = level; }
void Logger::log(LogLevel level, const string &message)
@@ -39,17 +26,12 @@ void Logger::log(LogLevel level, const string &message)
<< message << endl;
cout << logEntry.str();
-
- if (logFile.is_open()) {
- logFile << logEntry.str();
- logFile.flush();
- }
}
Logger *Logger::getInstance()
{
if (logger_instance == nullptr) {
- logger_instance = new Logger("vector.log");
+ logger_instance = new Logger();
}
return logger_instance;
}
diff --git a/src/main.cc b/src/main.cc
deleted file mode 100644
index be0a6f0..0000000
--- a/src/main.cc
+++ /dev/null
@@ -1,88 +0,0 @@
-#include "cli.h"
-#include "definitions.h"
-#include "gui.h"
-#include "logger.h"
-#include <QApplication>
-#include <getopt.h>
-#include <iostream>
-
-static Logger *global_log = Logger::getInstance();
-
-static std::string version_number = "v0.1";
-static std::string banner =
- " _/_/_/ _/_/_/ _/_/_/ _/_/_/ \n"
- " _/ _/ _/ _/ _/ \n"
- " _/_/_/ _/ _/_/ _/ \n"
- " _/ _/ _/ _/ _/ \n"
- "_/ _/ _/_/_/ _/_/_/ _/_/_/ \n"
- " \n"
- " \n"
- " _/_/ _/_/ \n"
- " _/ _/ _/ _/_/_/_/ _/_/_/ _/_/_/_/_/ _/_/ _/_/_/ _/ \n"
- " _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ \n"
- "_/ _/ _/ _/_/_/ _/ _/ _/ _/ _/_/_/ _/ \n"
- " _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ \n"
- " _/ _/ _/_/_/_/ _/_/_/ _/ _/_/ _/ _/ _/ \n"
- " _/_/ _/_/ ";
-static void print_version_number()
-{
- std::cout << banner << version_number << '\n';
-}
-
-static void err()
-{
- std::cerr << "Usage:\n\trisc_vector [OPTIONS]\nOptions:\n\t--debug,\t-d: "
- "turn on verbose output\n\t--memory-only,\t-m: run the memory "
- "simulator only, without a GUI.\n\t--version,\t-v: print the "
- "version information and exit\n"
- << std::endl;
-}
-
-static void parseArguments(int argc, char **argv, bool &memory_only)
-{
- struct option long_options[] = {
- {"debug", no_argument, 0, 'd'},
- {"memory-only", no_argument, 0, 'm'},
- {0, 0, 0, 0}};
-
- int opt;
-
- while ((opt = getopt_long(argc, argv, "d:m", long_options, NULL)) != -1) {
- switch (opt) {
- case 'd':
- global_log->setLevel(DEBUG);
- global_log->log(DEBUG, "DEBUG output enabled.");
- break;
- case 'm':
- global_log->log(INFO, "Starting the storage CLI interface...");
- memory_only = true;
- break;
- default:
- err();
- exit(EXIT_FAILURE);
- }
- }
-}
-
-int main(int argc, char **argv)
-{
- print_version_number();
- global_log->log(INFO, "Initializing...");
-
- bool memory_only = false;
- parseArguments(argc, argv, memory_only);
-
- if (memory_only) {
- Cli cli;
- cli.run();
- } else {
- QApplication a(argc, argv);
- Gui w;
- w.show();
- return a.exec();
- }
-
- global_log->log(INFO, "Cleaning up...");
- global_log->log(INFO, "Goodbye!");
- return EXIT_SUCCESS;
-}