forked from QuantStack/git2cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefs_wrapper.hpp
More file actions
58 lines (43 loc) · 1.25 KB
/
refs_wrapper.hpp
File metadata and controls
58 lines (43 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include <concepts>
#include <string>
#include <git2.h>
#include "../wrapper/wrapper_base.hpp"
class reference_wrapper : public wrapper_base<git_reference>
{
public:
using base_type = wrapper_base<git_reference>;
~reference_wrapper();
reference_wrapper(reference_wrapper&&) noexcept = default;
reference_wrapper& operator=(reference_wrapper&&) noexcept = default;
std::string short_name() const;
bool is_remote() const;
template <class W>
W peel() const;
private:
reference_wrapper(git_reference* ref);
friend class repository_wrapper;
};
class commit_wrapper;
class object_wrapper;
// TODO: add constraints on W
// For now it accepts commit_wrapper and object_wrapper only
template <class W>
W reference_wrapper::peel() const
{
constexpr git_object_t obj_type = []
{
if constexpr (std::same_as<W, commit_wrapper>)
{
return GIT_OBJECT_COMMIT;
}
else // Default case
{
return GIT_OBJECT_ANY;
}
}();
using resource_type = typename W::resoure_type;
git_object* resource = nullptr;
throw_if_error(git_reference_peel(&resource, this->p_resource, obj_type));
return W(reinterpret_cast<resource_type*>(resource));
}