Made nodes more performant & misc changes

This commit is contained in:
theskywinds 2025-06-13 12:17:07 +02:00
parent 370177599c
commit ca041c45d0
3 changed files with 30 additions and 9 deletions

View File

@ -10,17 +10,17 @@
namespace AtmAdmin { namespace AtmAdmin {
class XMLStorage { class XMLStorage {
public: public:
explicit XMLStorage (const std::string& search) : m_search(search) { explicit XMLStorage (std::string search) : m_search(std::move(search)) {
initXMLDoc(); initXMLDoc();
pugi::xml_node accountData {(getXMLUserData(search))}; this->m_data ={initAccountNode(m_search)};
this->name ={accountData.child_value("name") }; this->name ={m_data.child_value("name") };
this->pin ={std::stoi(accountData.child_value("pin")) }; this->pin ={std::stoi(m_data.child_value("pin")) };
} }
void initXMLDoc (); void initXMLDoc ();
pugi::xml_node getXMLUserData (const std::string& toSearch); pugi::xml_node initAccountNode (const std::string& toSearch);
std::string name{}; std::string name{};
int pin{}; int pin{};
@ -33,6 +33,7 @@ namespace AtmAdmin {
// void updateXMLData (const std::string& toSearch); // Is currently unused. // void updateXMLData (const std::string& toSearch); // Is currently unused.
pugi::xml_document m_doc; pugi::xml_document m_doc;
const std::string m_search; const std::string m_search;
pugi::xml_node m_data;
}; };
} }

View File

@ -33,7 +33,7 @@ namespace AtmAdmin {
// It also saves and applies the information if the user accepts it. // It also saves and applies the information if the user accepts it.
void confirmUserInformation (std::string& information, const std::string& tempInformation, const Choice choice) { void confirmUserInformation (std::string& information, const std::string& tempInformation, const Choice choice) {
char userCheck; char userCheck;
[[maybe_unused]] bool loopDone = true; bool loopDone = true;
do { do {
if (choice == PIN) if (choice == PIN)

View File

@ -2,7 +2,6 @@
#include <iostream> #include <iostream>
#include "../libs/XMLStorage.h" #include "../libs/XMLStorage.h"
#include "pugixml.hpp"
namespace AtmAdmin { namespace AtmAdmin {
void XMLStorage::initXMLDoc () { void XMLStorage::initXMLDoc () {
@ -15,7 +14,7 @@ namespace AtmAdmin {
} }
// getXMLData retrieves the data required by XMLStorage. // 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()); pugi::xml_node data = m_doc.first_child().child("accounts").find_child_by_attribute("account", "owner", toSearch.c_str());
if (data.empty()) { if (data.empty()) {
@ -28,7 +27,28 @@ namespace AtmAdmin {
} }
// void XMLStorage::updateXMLData (const std::string& toSearch) { // void XMLStorage::updateXMLData (const std::string& toSearch) {
// // TODO: FILL WITH CODE THAT UPDATES DATABASE // // I wish <format> 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") << '.';
// } // }
} }