SlHelpers
Patch.h
1 // SPDX-License-Identifier: GPL-2.0-only
2 
3 #pragma once
4 
5 #include <filesystem>
6 #include <istream>
7 #include <optional>
8 #include <set>
9 #include <string>
10 #include <vector>
11 
12 #include "../helpers/LastError.h"
13 
14 namespace SlKernCVS {
15 
19 class Patch {
20 public:
22  using Header = std::vector<std::string>;
24  using Paths = std::set<std::filesystem::path>;
25 
26  Patch() = delete;
27 
29  static std::optional<Patch> create(const std::filesystem::path &path);
31  static std::optional<Patch> create(std::istream &is);
32 
34  const auto &header() const noexcept { return m_header; }
36  const auto &paths() const noexcept { return m_paths; }
37 
39  static auto lastError() noexcept { return m_lastError.lastError(); }
40 private:
41  Patch(Header &&header, Paths &&paths) : m_header(std::move(header)),
42  m_paths(std::move(paths)) {}
43 
44  Header m_header;
45  Paths m_paths;
46 
47  using LastError = SlHelpers::LastErrorStream<>;
48  static thread_local LastError m_lastError;
49 };
50 
51 }
std::set< std::filesystem::path > Paths
Type for patched paths.
Definition: Patch.h:24
static auto lastError() noexcept
Return the last error string if any.
Definition: Patch.h:39
Stores a string (usually an error string) to be retrieved later.
Definition: LastError.h:87
const auto & header() const noexcept
Get header of this Patch.
Definition: Patch.h:34
Parses a patch into header and files patched.
Definition: Patch.h:19
const auto & paths() const noexcept
Get paths this Patch touches.
Definition: Patch.h:36
std::vector< std::string > Header
Type for a patch header.
Definition: Patch.h:22
Definition: Branches.h:15
static std::optional< Patch > create(const std::filesystem::path &path)
Create a new Patch from file at path.
std::string lastError() const noexcept
Obtain the stored string.
Definition: LastError.h:112