atm-admin/src/XMLStorage.cpp

55 lines
1.8 KiB
C++
Raw Normal View History

2025-06-13 09:15:55 +00:00
#include <iomanip>
#include <iostream>
#include "../libs/XMLStorage.h"
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::initAccountNode (const std::string& toSearch) {
2025-06-13 09:15:55 +00:00
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) {
// // 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") << '.';
2025-06-13 09:15:55 +00:00
// }
}