diff --git a/libs/XMLStorage.h b/libs/XMLStorage.h index 13df534..ec0e46f 100644 --- a/libs/XMLStorage.h +++ b/libs/XMLStorage.h @@ -10,17 +10,17 @@ namespace AtmAdmin { class XMLStorage { public: - explicit XMLStorage (const std::string& search) : m_search(search) { + explicit XMLStorage (std::string search) : m_search(std::move(search)) { initXMLDoc(); - pugi::xml_node accountData {(getXMLUserData(search))}; + this->m_data ={initAccountNode(m_search)}; - this->name ={accountData.child_value("name") }; - this->pin ={std::stoi(accountData.child_value("pin")) }; + this->name ={m_data.child_value("name") }; + this->pin ={std::stoi(m_data.child_value("pin")) }; } void initXMLDoc (); - pugi::xml_node getXMLUserData (const std::string& toSearch); + pugi::xml_node initAccountNode (const std::string& toSearch); std::string name{}; int pin{}; @@ -33,6 +33,7 @@ namespace AtmAdmin { // void updateXMLData (const std::string& toSearch); // Is currently unused. pugi::xml_document m_doc; const std::string m_search; + pugi::xml_node m_data; }; } diff --git a/src/AtmAdmin.cpp b/src/AtmAdmin.cpp index 0e107e1..b8b7a86 100644 --- a/src/AtmAdmin.cpp +++ b/src/AtmAdmin.cpp @@ -33,7 +33,7 @@ namespace AtmAdmin { // It also saves and applies the information if the user accepts it. void confirmUserInformation (std::string& information, const std::string& tempInformation, const Choice choice) { char userCheck; - [[maybe_unused]] bool loopDone = true; + bool loopDone = true; do { if (choice == PIN) diff --git a/src/XMLStorage.cpp b/src/XMLStorage.cpp index f26bdf5..65145d3 100644 --- a/src/XMLStorage.cpp +++ b/src/XMLStorage.cpp @@ -2,7 +2,6 @@ #include #include "../libs/XMLStorage.h" -#include "pugixml.hpp" namespace AtmAdmin { void XMLStorage::initXMLDoc () { @@ -15,7 +14,7 @@ namespace AtmAdmin { } // getXMLData retrieves the data required by XMLStorage. - pugi::xml_node XMLStorage::getXMLUserData (const std::string& toSearch) { + pugi::xml_node XMLStorage::initAccountNode (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()) { @@ -28,7 +27,28 @@ namespace AtmAdmin { } // void XMLStorage::updateXMLData (const std::string& toSearch) { - // // TODO: FILL WITH CODE THAT UPDATES DATABASE + // // I wish existed, but this will have to do. + // auto doubleToFinal = [] (double input) + // { + // std::ostringstream stream; + // stream << std::fixed << std::setprecision(2) << input; + // return stream.str(); + // }; + // + // pugi::xml_node data {getXMLUserData(toSearch)}; + // data.child("money").text().set(doubleToFinal(this->money)); + // + // // DEBUG OUTPUT + // // std::cout << data.name() << ' ' << data.child("money").text().get() << '\n'; + // + // data = getXMLAdminData(); + // data.child("money").text().set(doubleToFinal(this->bank)); + // + // // DEBUG OUTPUT + // // std::cout << data.name() << ' ' << data.child("money").text().get(); + // + // std::cout.flags (std::ios::boolalpha); + // std::cout << "Bank saved: " << m_doc.save_file("./data/users.xml") << '.'; // } }