make pop_next_action() return a reference

This commit is contained in:
2024-07-27 20:17:22 -05:00
committed by Celtic Minstrel
parent 902fdb7a61
commit 3c3a105ae4
6 changed files with 23 additions and 20 deletions

View File

@@ -160,8 +160,8 @@ static bool load_prefs(fs::path fpath) {
// When replaying a BoE session, disregard the system settings and use the ones
// that were recorded
if (replaying) {
Element* prefs_action = pop_next_action("load_prefs");
std::istringstream in(prefs_action->GetText());
Element& prefs_action = pop_next_action("load_prefs");
std::istringstream in(prefs_action.GetText());
return load_prefs(in);
} else {
std::ifstream in(fpath.c_str());

View File

@@ -89,8 +89,11 @@ std::string next_action_type() {
return next_action->Value();
}
Element* pop_next_action(std::string expected_action_type) {
if (expected_action_type != "" && next_action->Value() != expected_action_type) {
Element& pop_next_action(std::string expected_action_type) {
if(next_action == nullptr){
throw "Replay error! No action left to pop";
}
if(expected_action_type != "" && next_action->Value() != expected_action_type){
std::ostringstream stream;
stream << "Replay error! Expected '" << expected_action_type << "' action next";
throw stream.str();
@@ -100,12 +103,12 @@ Element* pop_next_action(std::string expected_action_type) {
next_action = next_action->NextSiblingElement(false);
return to_return;
return *to_return;
}
std::map<std::string,std::string> info_from_action(Element* action) {
std::map<std::string,std::string> info_from_action(Element& action) {
std::map<std::string,std::string> info = {};
Element* next_child = action->FirstChildElement(false);
Element* next_child = action.FirstChildElement(false);
while(next_child){
info[next_child->Value()] = next_child->GetText();
next_child = next_child->NextSiblingElement(false);

View File

@@ -18,8 +18,8 @@ extern void record_action(std::string action_type, std::string inner_text);
extern void record_action(std::string action_type, std::map<std::string,std::string> info);
extern bool has_next_action();
extern std::string next_action_type();
extern Element* pop_next_action(std::string expected_action_type="");
extern std::map<std::string,std::string> info_from_action(Element* action);
extern Element& pop_next_action(std::string expected_action_type="");
extern std::map<std::string,std::string> info_from_action(Element& action);
extern std::string encode_file(fs::path file);
extern void decode_file(std::string data, fs::path file);