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 {
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;
};
}

View File

@ -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)

View File

@ -2,7 +2,6 @@
#include <iostream>
#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 <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") << '.';
// }
}