From 4081d418415ba6ea26076ca0a4905c7b3da49a27 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 15 Sep 2014 18:04:54 +0000 Subject: [PATCH] [1D] Change 'save' behavior to avoid endlessly appending solutions Instead of changing the solution 'id' provided by the user to avoid duplicates, replace the solution with the same id. --- src/oneD/OneDim.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/oneD/OneDim.cpp b/src/oneD/OneDim.cpp index 4c633f7d2..ea0c410b3 100644 --- a/src/oneD/OneDim.cpp +++ b/src/oneD/OneDim.cpp @@ -385,21 +385,17 @@ void OneDim::save(const std::string& fname, std::string id, XML_Node* ct; if (fin) { root.build(fin); - const XML_Node* same_ID = root.findID(id); - int jid = 1; - string idnew = id; - while (same_ID != 0) { - idnew = id + "_" + int2str(jid); - jid++; - same_ID = root.findID(idnew); + // Remove existing solution with the same id + XML_Node* same_ID = root.findID(id); + if (same_ID) { + same_ID->parent()->removeChild(same_ID); } - id = idnew; fin.close(); ct = &root.child("ctml"); } else { ct = &root.addChild("ctml"); } - XML_Node& sim = (XML_Node&)ct->addChild("simulation"); + XML_Node& sim = ct->addChild("simulation"); sim.addAttribute("id",id); addString(sim,"timestamp",asctime(newtime)); if (desc != "") {