diff --git a/CMakeLists.txt b/CMakeLists.txt index 09865b2..9bf666e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,8 +6,12 @@ set(CMAKE_CXX_STANDARD 20) add_executable(${CMAKE_PROJECT_NAME} src/main.cpp src/AtmAdmin.cpp - src/XmlHandling.cpp - libs/XmlHandling.h) + src/XMLStorage.cpp +) + +file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/data + DESTINATION ${CMAKE_CURRENT_BINARY_DIR} +) find_package(pugixml CONFIG REQUIRED) target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE libs) diff --git a/libs/AtmAdmin.h b/libs/AtmAdmin.h index 5eb909d..64042d3 100644 --- a/libs/AtmAdmin.h +++ b/libs/AtmAdmin.h @@ -6,6 +6,7 @@ namespace AtmAdmin { // startup() is inline because of how small it is. char startup(); + void handleInvalidArguments(int argc); bool handleUserInformation(char choice, std::string& information); std::string changeAccountPin(); std::string changeAccountName(); diff --git a/libs/XMLStorage.h b/libs/XMLStorage.h new file mode 100644 index 0000000..13df534 --- /dev/null +++ b/libs/XMLStorage.h @@ -0,0 +1,39 @@ +// +// Created by skygrow on 5/14/25. +// + +#ifndef XMLSTORAGE_H +#define XMLSTORAGE_H + +#include "pugixml.hpp" + +namespace AtmAdmin { + class XMLStorage { + public: + explicit XMLStorage (const std::string& search) : m_search(search) { + initXMLDoc(); + + pugi::xml_node accountData {(getXMLUserData(search))}; + + this->name ={accountData.child_value("name") }; + this->pin ={std::stoi(accountData.child_value("pin")) }; + } + + void initXMLDoc (); + pugi::xml_node getXMLUserData (const std::string& toSearch); + + std::string name{}; + int pin{}; + + // ~XMLStorage() { + // updateXMLData(m_search); + // } + + private: + // void updateXMLData (const std::string& toSearch); // Is currently unused. + pugi::xml_document m_doc; + const std::string m_search; + }; +} + +#endif //XMLSTORAGE_H diff --git a/libs/XmlHandling.h b/libs/XmlHandling.h deleted file mode 100644 index f4a893d..0000000 --- a/libs/XmlHandling.h +++ /dev/null @@ -1,8 +0,0 @@ -// -// Created by theskywinds on 11-06-25. -// - -#ifndef XMLHANDLING_H -#define XMLHANDLING_H - -#endif //XMLHANDLING_H diff --git a/src/AtmAdmin.cpp b/src/AtmAdmin.cpp index 664fc19..0e107e1 100644 --- a/src/AtmAdmin.cpp +++ b/src/AtmAdmin.cpp @@ -14,6 +14,21 @@ namespace AtmAdmin { MONEY, }; + void handleInvalidArguments(int argc) { + if (argc != 2) { + std::cerr << "Invalid number of arguments: " << argc - 1 << '\n'; + + if (argc < 2) { + std::cerr << "The ability to make new accounts is not implemented." << '\n'; + std::cerr << "Please put in a pre-existing name." << std::endl; + } + else + std::cerr << "Too many arguments." << std::endl; + + exit (EXIT_FAILURE); + } + } + // Allows the user to double-check their inputted information. // It also saves and applies the information if the user accepts it. void confirmUserInformation (std::string& information, const std::string& tempInformation, const Choice choice) { diff --git a/src/XMLStorage.cpp b/src/XMLStorage.cpp new file mode 100644 index 0000000..f26bdf5 --- /dev/null +++ b/src/XMLStorage.cpp @@ -0,0 +1,34 @@ +#include +#include + +#include "../libs/XMLStorage.h" +#include "pugixml.hpp" + +namespace AtmAdmin { + void XMLStorage::initXMLDoc () { + pugi::xml_parse_result res = m_doc.load_file("./data/users.xml"); + + if (!res) { + std::cerr << "Error occurred: " << res.description(); + exit(EXIT_FAILURE); + } + } + + // getXMLData retrieves the data required by XMLStorage. + pugi::xml_node XMLStorage::getXMLUserData (const std::string& toSearch) { + pugi::xml_node data = m_doc.first_child().child("accounts").find_child_by_attribute("account", "owner", toSearch.c_str()); + + if (data.empty()) { + std::cerr << "Account not found, exiting."; + std::cout << data.name(); + exit(EXIT_FAILURE); + } + + return data; + } + + // void XMLStorage::updateXMLData (const std::string& toSearch) { + // // TODO: FILL WITH CODE THAT UPDATES DATABASE + // } +} + diff --git a/src/XmlHandling.cpp b/src/XmlHandling.cpp deleted file mode 100644 index b846b15..0000000 --- a/src/XmlHandling.cpp +++ /dev/null @@ -1,7 +0,0 @@ -// -// Created by theskywinds on 11-06-25. -// - -#include "../libs/XmlHandling.h" - - diff --git a/src/main.cpp b/src/main.cpp index bc7206b..108aa60 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ #include #include #include "AtmAdmin.h" +#include "XMLStorage.h" char startup() { char choice{}; @@ -12,7 +13,10 @@ char startup() { return choice; } -int main() { +int main(int argc, [[maybe_unused]] char** argv) { + AtmAdmin::handleInvalidArguments(argc); + + AtmAdmin::XMLStorage mainStorage{argv[1]}; bool continueLoop{true}; while (continueLoop) {