diff --git a/.gitignore b/.gitignore index 7559f91..76e2d70 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,14 @@ # CLion IDE cmake-build-debug/ .idea/ -docs/output/ \ No newline at end of file +docs/output/ + +# Custom CMake to Makefile workflow +AED2324_PRJ1_G23 +cmake_install.cmake +CMakeCache.txt +CMakeDoxyfile.in +CMakeDoxygenDefaults.cmake +Doxyfile +Makefile +CMakeFiles/ diff --git a/1 b/1 new file mode 100644 index 0000000..65fb34e --- /dev/null +++ b/1 @@ -0,0 +1,36 @@ +cmake_minimum_required(VERSION 3.26) +project(AED2324_PRJ1_G23) + +set(CMAKE_CXX_STANDARD 20) + +# Doxygen Build +find_package(Doxygen) +if(DOXYGEN_FOUND) + set(BUILD_DOC_DIR "${CMAKE_SOURCE_DIR}/docs/output") + if(NOT EXISTS "${BUILD_DOC_DIR}") + file(MAKE_DIRECTORY "${BUILD_DOC_DIR}") + endif() + + set(DOXYGEN_IN "${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile") + set(DOXYGEN_OUT "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile") + configure_file("${DOXYGEN_IN}" "${DOXYGEN_OUT}" @ONLY) + + message("Doxygen build started") + add_custom_target(Doxygen ALL + COMMAND "${DOXYGEN_EXECUTABLE}" "${DOXYGEN_OUT}" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" + COMMENT "Generating API documentation with Doxygen" + VERBATIM) +else(DOXYGEN_FOUND) + message("Doxygen needs to be installed to generate the documentation.") +endif(DOXYGEN_FOUND) + +# Project build +add_executable(AED2324_PRJ1_G23 main.cpp + src/appClasses.cpp src/appClasses.hpp + src/appClassesPerUC.cpp src/appClassesPerUC.hpp + src/appStudentsClasses.cpp src/appStudentsClasses.hpp + src/classes.cpp src/classes.hpp + src/classesPerUC.cpp src/classesPerUC.hpp + src/studentsClasses.cpp src/studentsClasses.hpp + src/Utils.cpp src/Utils.hpp) diff --git a/CMakeLists.txt b/CMakeLists.txt index f22e34f..65fb34e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.26) project(AED2324_PRJ1_G23) -set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 20) # Doxygen Build find_package(Doxygen) @@ -32,4 +32,5 @@ add_executable(AED2324_PRJ1_G23 main.cpp src/appStudentsClasses.cpp src/appStudentsClasses.hpp src/classes.cpp src/classes.hpp src/classesPerUC.cpp src/classesPerUC.hpp - src/studentsClasses.cpp src/studentsClasses.hpp) \ No newline at end of file + src/studentsClasses.cpp src/studentsClasses.hpp + src/Utils.cpp src/Utils.hpp) diff --git a/main.cpp b/main.cpp index bc8f460..8149e25 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,23 @@ +#include "src/appClasses.hpp" +#include "src/appClassesPerUC.hpp" +#include "src/appStudentsClasses.hpp" +#include "src/classes.hpp" +#include "src/classesPerUC.hpp" +#include "src/studentsClasses.hpp" #include +#include +#include +#include int main() { - std::cout << "Hello, World!" << std::endl; - return 0; + std::ifstream file = std::ifstream("schedule/classes_per_uc.csv"); + std::string contents; + std::ostringstream sstr; + sstr << file.rdbuf(); + contents = sstr.str(); + AppCPU cpu = AppCPU(contents); + cpu.display(); + + //std::cout << "Hello, World!" << std::endl; + return 0; } diff --git a/schedule/classes_per_uc.csv b/schedule/classes_per_uc.csv index 829c4d9..7abb94c 100644 --- a/schedule/classes_per_uc.csv +++ b/schedule/classes_per_uc.csv @@ -1,229 +1,229 @@ -UcCode,ClassCode -L.EIC001,1LEIC01 -L.EIC001,1LEIC02 -L.EIC001,1LEIC03 -L.EIC001,1LEIC04 -L.EIC001,1LEIC05 -L.EIC001,1LEIC06 -L.EIC001,1LEIC07 -L.EIC001,1LEIC09 -L.EIC001,1LEIC10 -L.EIC001,1LEIC11 -L.EIC001,1LEIC12 -L.EIC001,1LEIC13 -L.EIC001,1LEIC15 -L.EIC002,1LEIC01 -L.EIC002,1LEIC02 -L.EIC002,1LEIC03 -L.EIC002,1LEIC04 -L.EIC002,1LEIC05 -L.EIC002,1LEIC06 -L.EIC002,1LEIC07 -L.EIC002,1LEIC08 -L.EIC002,1LEIC09 -L.EIC002,1LEIC10 -L.EIC002,1LEIC11 -L.EIC002,1LEIC12 -L.EIC002,1LEIC13 -L.EIC002,1LEIC14 -L.EIC002,1LEIC15 -L.EIC003,1LEIC01 -L.EIC003,1LEIC02 -L.EIC003,1LEIC03 -L.EIC003,1LEIC04 -L.EIC003,1LEIC05 -L.EIC003,1LEIC06 -L.EIC003,1LEIC07 -L.EIC003,1LEIC08 -L.EIC003,1LEIC09 -L.EIC003,1LEIC10 -L.EIC003,1LEIC11 -L.EIC003,1LEIC12 -L.EIC003,1LEIC13 -L.EIC003,1LEIC14 -L.EIC003,1LEIC15 -L.EIC003,1LEIC16 -L.EIC004,1LEIC01 -L.EIC004,1LEIC02 -L.EIC004,1LEIC03 -L.EIC004,1LEIC04 -L.EIC004,1LEIC05 -L.EIC004,1LEIC06 -L.EIC004,1LEIC07 -L.EIC004,1LEIC08 -L.EIC004,1LEIC09 -L.EIC004,1LEIC10 -L.EIC004,1LEIC11 -L.EIC004,1LEIC12 -L.EIC004,1LEIC13 -L.EIC004,1LEIC14 -L.EIC004,1LEIC15 -L.EIC004,1LEIC16 -L.EIC005,1LEIC01 -L.EIC005,1LEIC02 -L.EIC005,1LEIC03 -L.EIC005,1LEIC04 -L.EIC005,1LEIC05 -L.EIC005,1LEIC06 -L.EIC005,1LEIC07 -L.EIC005,1LEIC08 -L.EIC005,1LEIC09 -L.EIC005,1LEIC10 -L.EIC005,1LEIC11 -L.EIC005,1LEIC12 -L.EIC005,1LEIC13 -L.EIC005,1LEIC14 -L.EIC005,1LEIC15 -L.EIC011,2LEIC01 -L.EIC011,2LEIC02 -L.EIC011,2LEIC03 -L.EIC011,2LEIC04 -L.EIC011,2LEIC05 -L.EIC011,2LEIC06 -L.EIC011,2LEIC07 -L.EIC011,2LEIC08 -L.EIC011,2LEIC09 -L.EIC011,2LEIC10 -L.EIC011,2LEIC11 -L.EIC011,2LEIC12 -L.EIC011,2LEIC13 -L.EIC011,2LEIC14 -L.EIC011,2LEIC15 -L.EIC012,2LEIC01 -L.EIC012,2LEIC02 -L.EIC012,2LEIC03 -L.EIC012,2LEIC04 -L.EIC012,2LEIC05 -L.EIC012,2LEIC06 -L.EIC012,2LEIC07 -L.EIC012,2LEIC08 -L.EIC012,2LEIC09 -L.EIC012,2LEIC10 -L.EIC012,2LEIC11 -L.EIC012,2LEIC12 -L.EIC012,2LEIC13 -L.EIC012,2LEIC14 -L.EIC012,2LEIC15 -L.EIC013,2LEIC01 -L.EIC013,2LEIC02 -L.EIC013,2LEIC03 -L.EIC013,2LEIC04 -L.EIC013,2LEIC05 -L.EIC013,2LEIC06 -L.EIC013,2LEIC07 -L.EIC013,2LEIC08 -L.EIC013,2LEIC09 -L.EIC013,2LEIC10 -L.EIC013,2LEIC11 -L.EIC013,2LEIC12 -L.EIC013,2LEIC13 -L.EIC013,2LEIC14 -L.EIC013,2LEIC15 -L.EIC013,2LEIC16 -L.EIC014,2LEIC01 -L.EIC014,2LEIC02 -L.EIC014,2LEIC03 -L.EIC014,2LEIC04 -L.EIC014,2LEIC05 -L.EIC014,2LEIC06 -L.EIC014,2LEIC07 -L.EIC014,2LEIC08 -L.EIC014,2LEIC09 -L.EIC014,2LEIC10 -L.EIC014,2LEIC11 -L.EIC014,2LEIC12 -L.EIC014,2LEIC13 -L.EIC014,2LEIC14 -L.EIC014,2LEIC15 -L.EIC014,2LEIC16 -L.EIC015,2LEIC01 -L.EIC015,2LEIC02 -L.EIC015,2LEIC03 -L.EIC015,2LEIC04 -L.EIC015,2LEIC05 -L.EIC015,2LEIC06 -L.EIC015,2LEIC07 -L.EIC015,2LEIC08 -L.EIC015,2LEIC09 -L.EIC015,2LEIC10 -L.EIC015,2LEIC11 -L.EIC015,2LEIC12 -L.EIC015,2LEIC13 -L.EIC015,2LEIC14 -L.EIC015,2LEIC15 -L.EIC021,3LEIC01 -L.EIC021,3LEIC02 -L.EIC021,3LEIC03 -L.EIC021,3LEIC04 -L.EIC021,3LEIC05 -L.EIC021,3LEIC06 -L.EIC021,3LEIC08 -L.EIC021,3LEIC09 -L.EIC021,3LEIC10 -L.EIC021,3LEIC11 -L.EIC021,3LEIC12 -L.EIC021,3LEIC14 -L.EIC022,3LEIC01 -L.EIC022,3LEIC02 -L.EIC022,3LEIC03 -L.EIC022,3LEIC04 -L.EIC022,3LEIC05 -L.EIC022,3LEIC06 -L.EIC022,3LEIC07 -L.EIC022,3LEIC08 -L.EIC022,3LEIC09 -L.EIC022,3LEIC10 -L.EIC022,3LEIC12 -L.EIC022,3LEIC14 -L.EIC023,3LEIC01 -L.EIC023,3LEIC02 -L.EIC023,3LEIC03 -L.EIC023,3LEIC04 -L.EIC023,3LEIC05 -L.EIC023,3LEIC06 -L.EIC023,3LEIC07 -L.EIC023,3LEIC08 -L.EIC023,3LEIC09 -L.EIC023,3LEIC10 -L.EIC023,3LEIC11 -L.EIC023,3LEIC12 -L.EIC023,3LEIC13 -L.EIC023,3LEIC14 -L.EIC024,3LEIC01 -L.EIC024,3LEIC02 -L.EIC024,3LEIC03 -L.EIC024,3LEIC04 -L.EIC024,3LEIC05 -L.EIC024,3LEIC06 -L.EIC024,3LEIC08 -L.EIC024,3LEIC09 -L.EIC024,3LEIC10 -L.EIC024,3LEIC11 -L.EIC024,3LEIC12 -L.EIC025,3LEIC01 -L.EIC025,3LEIC02 -L.EIC025,3LEIC03 -L.EIC025,3LEIC04 -L.EIC025,3LEIC05 -L.EIC025,3LEIC06 -L.EIC025,3LEIC07 -L.EIC025,3LEIC08 -L.EIC025,3LEIC09 -L.EIC025,3LEIC10 -L.EIC025,3LEIC11 -L.EIC025,3LEIC12 -L.EIC025,3LEIC13 -L.EIC025,3LEIC14 -L.EIC025,3LEIC15 -UP001,1LEIC01 -UP001,1LEIC02 -UP001,1LEIC03 -UP001,1LEIC04 -UP001,1LEIC05 -UP001,1LEIC06 -UP001,1LEIC07 -UP001,1LEIC08 -UP001,1LEIC09 -UP001,1LEIC10 -UP001,1LEIC11 -UP001,1LEIC12 +UcCode,ClassCode +L.EIC001,1LEIC01 +L.EIC001,1LEIC02 +L.EIC001,1LEIC03 +L.EIC001,1LEIC04 +L.EIC001,1LEIC05 +L.EIC001,1LEIC06 +L.EIC001,1LEIC07 +L.EIC001,1LEIC09 +L.EIC001,1LEIC10 +L.EIC001,1LEIC11 +L.EIC001,1LEIC12 +L.EIC001,1LEIC13 +L.EIC001,1LEIC15 +L.EIC002,1LEIC01 +L.EIC002,1LEIC02 +L.EIC002,1LEIC03 +L.EIC002,1LEIC04 +L.EIC002,1LEIC05 +L.EIC002,1LEIC06 +L.EIC002,1LEIC07 +L.EIC002,1LEIC08 +L.EIC002,1LEIC09 +L.EIC002,1LEIC10 +L.EIC002,1LEIC11 +L.EIC002,1LEIC12 +L.EIC002,1LEIC13 +L.EIC002,1LEIC14 +L.EIC002,1LEIC15 +L.EIC003,1LEIC01 +L.EIC003,1LEIC02 +L.EIC003,1LEIC03 +L.EIC003,1LEIC04 +L.EIC003,1LEIC05 +L.EIC003,1LEIC06 +L.EIC003,1LEIC07 +L.EIC003,1LEIC08 +L.EIC003,1LEIC09 +L.EIC003,1LEIC10 +L.EIC003,1LEIC11 +L.EIC003,1LEIC12 +L.EIC003,1LEIC13 +L.EIC003,1LEIC14 +L.EIC003,1LEIC15 +L.EIC003,1LEIC16 +L.EIC004,1LEIC01 +L.EIC004,1LEIC02 +L.EIC004,1LEIC03 +L.EIC004,1LEIC04 +L.EIC004,1LEIC05 +L.EIC004,1LEIC06 +L.EIC004,1LEIC07 +L.EIC004,1LEIC08 +L.EIC004,1LEIC09 +L.EIC004,1LEIC10 +L.EIC004,1LEIC11 +L.EIC004,1LEIC12 +L.EIC004,1LEIC13 +L.EIC004,1LEIC14 +L.EIC004,1LEIC15 +L.EIC004,1LEIC16 +L.EIC005,1LEIC01 +L.EIC005,1LEIC02 +L.EIC005,1LEIC03 +L.EIC005,1LEIC04 +L.EIC005,1LEIC05 +L.EIC005,1LEIC06 +L.EIC005,1LEIC07 +L.EIC005,1LEIC08 +L.EIC005,1LEIC09 +L.EIC005,1LEIC10 +L.EIC005,1LEIC11 +L.EIC005,1LEIC12 +L.EIC005,1LEIC13 +L.EIC005,1LEIC14 +L.EIC005,1LEIC15 +L.EIC011,2LEIC01 +L.EIC011,2LEIC02 +L.EIC011,2LEIC03 +L.EIC011,2LEIC04 +L.EIC011,2LEIC05 +L.EIC011,2LEIC06 +L.EIC011,2LEIC07 +L.EIC011,2LEIC08 +L.EIC011,2LEIC09 +L.EIC011,2LEIC10 +L.EIC011,2LEIC11 +L.EIC011,2LEIC12 +L.EIC011,2LEIC13 +L.EIC011,2LEIC14 +L.EIC011,2LEIC15 +L.EIC012,2LEIC01 +L.EIC012,2LEIC02 +L.EIC012,2LEIC03 +L.EIC012,2LEIC04 +L.EIC012,2LEIC05 +L.EIC012,2LEIC06 +L.EIC012,2LEIC07 +L.EIC012,2LEIC08 +L.EIC012,2LEIC09 +L.EIC012,2LEIC10 +L.EIC012,2LEIC11 +L.EIC012,2LEIC12 +L.EIC012,2LEIC13 +L.EIC012,2LEIC14 +L.EIC012,2LEIC15 +L.EIC013,2LEIC01 +L.EIC013,2LEIC02 +L.EIC013,2LEIC03 +L.EIC013,2LEIC04 +L.EIC013,2LEIC05 +L.EIC013,2LEIC06 +L.EIC013,2LEIC07 +L.EIC013,2LEIC08 +L.EIC013,2LEIC09 +L.EIC013,2LEIC10 +L.EIC013,2LEIC11 +L.EIC013,2LEIC12 +L.EIC013,2LEIC13 +L.EIC013,2LEIC14 +L.EIC013,2LEIC15 +L.EIC013,2LEIC16 +L.EIC014,2LEIC01 +L.EIC014,2LEIC02 +L.EIC014,2LEIC03 +L.EIC014,2LEIC04 +L.EIC014,2LEIC05 +L.EIC014,2LEIC06 +L.EIC014,2LEIC07 +L.EIC014,2LEIC08 +L.EIC014,2LEIC09 +L.EIC014,2LEIC10 +L.EIC014,2LEIC11 +L.EIC014,2LEIC12 +L.EIC014,2LEIC13 +L.EIC014,2LEIC14 +L.EIC014,2LEIC15 +L.EIC014,2LEIC16 +L.EIC015,2LEIC01 +L.EIC015,2LEIC02 +L.EIC015,2LEIC03 +L.EIC015,2LEIC04 +L.EIC015,2LEIC05 +L.EIC015,2LEIC06 +L.EIC015,2LEIC07 +L.EIC015,2LEIC08 +L.EIC015,2LEIC09 +L.EIC015,2LEIC10 +L.EIC015,2LEIC11 +L.EIC015,2LEIC12 +L.EIC015,2LEIC13 +L.EIC015,2LEIC14 +L.EIC015,2LEIC15 +L.EIC021,3LEIC01 +L.EIC021,3LEIC02 +L.EIC021,3LEIC03 +L.EIC021,3LEIC04 +L.EIC021,3LEIC05 +L.EIC021,3LEIC06 +L.EIC021,3LEIC08 +L.EIC021,3LEIC09 +L.EIC021,3LEIC10 +L.EIC021,3LEIC11 +L.EIC021,3LEIC12 +L.EIC021,3LEIC14 +L.EIC022,3LEIC01 +L.EIC022,3LEIC02 +L.EIC022,3LEIC03 +L.EIC022,3LEIC04 +L.EIC022,3LEIC05 +L.EIC022,3LEIC06 +L.EIC022,3LEIC07 +L.EIC022,3LEIC08 +L.EIC022,3LEIC09 +L.EIC022,3LEIC10 +L.EIC022,3LEIC12 +L.EIC022,3LEIC14 +L.EIC023,3LEIC01 +L.EIC023,3LEIC02 +L.EIC023,3LEIC03 +L.EIC023,3LEIC04 +L.EIC023,3LEIC05 +L.EIC023,3LEIC06 +L.EIC023,3LEIC07 +L.EIC023,3LEIC08 +L.EIC023,3LEIC09 +L.EIC023,3LEIC10 +L.EIC023,3LEIC11 +L.EIC023,3LEIC12 +L.EIC023,3LEIC13 +L.EIC023,3LEIC14 +L.EIC024,3LEIC01 +L.EIC024,3LEIC02 +L.EIC024,3LEIC03 +L.EIC024,3LEIC04 +L.EIC024,3LEIC05 +L.EIC024,3LEIC06 +L.EIC024,3LEIC08 +L.EIC024,3LEIC09 +L.EIC024,3LEIC10 +L.EIC024,3LEIC11 +L.EIC024,3LEIC12 +L.EIC025,3LEIC01 +L.EIC025,3LEIC02 +L.EIC025,3LEIC03 +L.EIC025,3LEIC04 +L.EIC025,3LEIC05 +L.EIC025,3LEIC06 +L.EIC025,3LEIC07 +L.EIC025,3LEIC08 +L.EIC025,3LEIC09 +L.EIC025,3LEIC10 +L.EIC025,3LEIC11 +L.EIC025,3LEIC12 +L.EIC025,3LEIC13 +L.EIC025,3LEIC14 +L.EIC025,3LEIC15 +UP001,1LEIC01 +UP001,1LEIC02 +UP001,1LEIC03 +UP001,1LEIC04 +UP001,1LEIC05 +UP001,1LEIC06 +UP001,1LEIC07 +UP001,1LEIC08 +UP001,1LEIC09 +UP001,1LEIC10 +UP001,1LEIC11 +UP001,1LEIC12 diff --git a/src/Utils.cpp b/src/Utils.cpp new file mode 100644 index 0000000..ec9fec0 --- /dev/null +++ b/src/Utils.cpp @@ -0,0 +1,19 @@ +#include "Utils.hpp" +// djb2 hash : https://theartincode.stanis.me/008-djb2/ +uint8_t hash_str(std::string s) { + uint64_t hash = 5381; + for (char c : s) { + hash = (hash << 5) + hash + c; + } + return (uint8_t)(hash % 256); +} + +bool isnum(uint32_t c) { return (c >= '0' && c <= '9'); } + +void parse_csv_line(std::string s, std::vector &res) { + std::stringstream line(s); + std::string buf; + while (getline(line, buf, ',')) + res.push_back(buf); +} + diff --git a/src/Utils.hpp b/src/Utils.hpp new file mode 100644 index 0000000..b63db87 --- /dev/null +++ b/src/Utils.hpp @@ -0,0 +1,12 @@ +#ifndef UTILS_HPP +#define UTILS_HPP +#include +#include +#include +#include + +// djb2 hash : https://theartincode.stanis.me/008-djb2/ +uint8_t hash_str(std::string s); +bool isnum(uint32_t c); +void parse_csv_line(std::string s, std::vector &res); +#endif // !UTILS_HPP diff --git a/src/appClassesPerUC.cpp b/src/appClassesPerUC.cpp index e69de29..58ee5f7 100644 --- a/src/appClassesPerUC.cpp +++ b/src/appClassesPerUC.cpp @@ -0,0 +1,27 @@ +#include "appClassesPerUC.hpp" +#include +#include +#include "classesPerUC.hpp" + +AppCPU::AppCPU(std::string csv) { + std::stringstream s(csv); + std::string line; + this->entries = std::vector(); + getline(s,line,'\n'); + std::vector bufs; + parse_csv_line(line,bufs); + this->uc_cath_name = bufs[0]; + this->class_cath_name = bufs[1]; + line.clear(); + while (std::getline(s,line,'\n')) { + this->entries.push_back(ClassPerUC(line)); + } +} + + +void AppCPU::display() { + std::cout << this->uc_cath_name << ',' << this->class_cath_name << '\n'; + for (auto e : this->entries) { + e.display(); + } +} diff --git a/src/appClassesPerUC.hpp b/src/appClassesPerUC.hpp index e69de29..a1a92ce 100644 --- a/src/appClassesPerUC.hpp +++ b/src/appClassesPerUC.hpp @@ -0,0 +1,15 @@ +#include "classesPerUC.hpp" +#include +#include + + +class AppCPU { +private: + std::string uc_cath_name; + std::string class_cath_name; + std::vector entries; +public: + AppCPU(std::string csv); + void display(); + void sort_by(std::string category); +}; diff --git a/src/classesPerUC.cpp b/src/classesPerUC.cpp index e69de29..5af913d 100644 --- a/src/classesPerUC.cpp +++ b/src/classesPerUC.cpp @@ -0,0 +1,107 @@ +#include "classesPerUC.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "Utils.hpp" + + + + +ClassPerUC::ClassPerUC(std::string line) { + std::vector linebuf; + parse_csv_line(line, linebuf); + uc_codes_ = parse_uc(linebuf[0]); + class_codes_ = parse_class(linebuf[1]); +} + +uint16_t ClassPerUC::parse_uc(std::string uc_code) { + uint64_t hash = 5381; + std::string num_part; + for (char c : uc_code) { + if (!isnum(c)) { + hash = (hash << 5) + hash + c; + } + if (isnum(c)) { + num_part.push_back(c); + } + } + try { + uint8_t num = 0; + if (num_part != "") { + num = std::stoi(num_part); + } + return (uint16_t)((hash % 256) << 8) + (uint16_t)(num); + } catch (std::invalid_argument &e) { + std::cerr << e.what() << " uc: failed to parse" << '\n'; + std::exit(1); + } +} + +uint16_t ClassPerUC::parse_class(std::string class_code) { + uint8_t year = class_code[0] - '0'; + std::string classnum; + for (int i = 1; i < class_code.size(); ++i) { + if (isnum(class_code[i])) { + classnum.push_back(class_code[i]); + } + } + try { + uint8_t num = 0; + if (classnum != "") { + num = std::stoi(classnum); + } + return ((uint16_t)year << 8) + num; + } catch (std::invalid_argument &e) { + std::cerr << e.what() << " class: failed to parse" << '\n'; + std::exit(1); + } +} + +void ClassPerUC::display() { + // std::cout << "UcCode,ClassCode\n"; + std::string uc; + std::string cc; + uc_to_str(uc); + class_to_str(cc); + std::cout << uc << "," << cc << "\n"; +} + +void ClassPerUC::class_to_str(std::string &out) { + std::stringstream s; + // TODO: use exceptions to handle errors instead of closing. + if ((class_codes_ >> 8) == 19) { + out = "ClassCode"; + return; + } + s << (class_codes_ >> 8) << "LEIC" << std::setfill('0') << std::setw(2) + << (class_codes_ & 255); + out = s.str(); +} + +void ClassPerUC::uc_to_str(std::string &out) { + std::stringstream s; + std::string classname; + bool found = false; + uint16_t hash_of_class = uc_codes_ >> 8; + for (int i = 0; i <= sizeof(this->types_of_uc) / sizeof(char *); ++i) { + if (hash_of_class == hash_str(std::string(this->types_of_uc[i]))) { + classname = this->types_of_uc[i]; + found = true; + break; + } + } + if (!found) { + std::cerr << "There is no known uc type with hash " << hash_of_class + << "!\n"; + std::exit(1); + + } + s << classname << std::setfill('0') << std::setw(3) << (uc_codes_ & 255); + out = s.str(); +} diff --git a/src/classesPerUC.hpp b/src/classesPerUC.hpp index e69de29..b16538d 100644 --- a/src/classesPerUC.hpp +++ b/src/classesPerUC.hpp @@ -0,0 +1,24 @@ +#include +#include +#include +#include +#include + +#ifndef CLASSPERUC_H +#define CLASSPERUC_H +void parse_csv_line(std::string s, std::vector &res); +class ClassPerUC { +private: + uint16_t uc_codes_; + uint16_t class_codes_; + constexpr const static char* types_of_uc[] = {"L.EIC", "UP", "IAPD", "CSR", "IADE", "IR", "MPSAC", "DDS", "SEESTE"}; +public: + ClassPerUC(std::string line); + uint16_t parse_uc(std::string uc_code); + uint16_t parse_class(std::string class_code); + void class_to_str(std::string &out); + void uc_to_str(std::string &out); + void display(); +}; + +#endif // !CLASSPERUC_H