SlHelpers
Loading...
Searching...
No Matches
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
14namespace SlKernCVS {
15
19class Patch {
20public:
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(); }
40private:
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}
Parses a patch into header and files patched.
Definition Patch.h:19
static std::optional< Patch > create(std::istream &is)
Create a new Patch from stream is.
const auto & paths() const noexcept
Get paths this Patch touches.
Definition Patch.h:36
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
std::vector< std::string > Header
Type for a patch header.
Definition Patch.h:22
static std::optional< Patch > create(const std::filesystem::path &path)
Create a new Patch from file at path.
const auto & header() const noexcept
Get header of this Patch.
Definition Patch.h:34