From a69b1d0c580bc779740ef79a7d16b69229896785 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 28 Jan 2023 20:31:24 +0100 Subject: Client to Server: send diffs instead of whole file --- diff.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'diff.cpp') diff --git a/diff.cpp b/diff.cpp index 99a2f14..b56fd51 100644 --- a/diff.cpp +++ b/diff.cpp @@ -1,6 +1,7 @@ #include "diff.h" #include +#include #include #include @@ -102,6 +103,22 @@ void Diff::create(const std::string& old_version, const std::string& new_version m_data = new_version.substr(old_pos0, new_pos1 - new_pos0); } +Diff::Diff(const boost::property_tree::ptree& ptree) +{ + create(ptree); +} + +void Diff::create(const boost::property_tree::ptree& ptree) +{ + m_pos0 = ptree.get("diff.start"); + m_pos1 = ptree.get("diff.end"); + + if (m_pos0 > m_pos1) + throw std::runtime_error("Bad range in diff"); + + m_data = ptree.get("diff.data"); +} + Diff::Diff(const std::string& xml) { create(xml); @@ -109,17 +126,11 @@ Diff::Diff(const std::string& xml) void Diff::create(const std::string& xml) { - pt::ptree tree; + pt::ptree ptree; std::istringstream ss{xml}; - pt::read_xml(ss, tree, pt::xml_parser::no_comments | pt::xml_parser::trim_whitespace); - - m_pos0 = tree.get("diff.start"); - m_pos1 = tree.get("diff.end"); - - if (m_pos0 > m_pos1) - throw std::runtime_error("Bad range in diff"); + pt::read_xml(ss, ptree, pt::xml_parser::no_comments | pt::xml_parser::trim_whitespace); - m_data = tree.get("diff.data"); + create(ptree); } boost::property_tree::ptree Diff::get_structure() const -- cgit v1.2.3