FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Implemented template metod peel by JohanMabille · Pull Request #47 · QuantStack/git2cpp · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .hpp  (3) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 1 addition & 0 deletions src/wrapper/commit_wrapper.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ class commit_wrapper : public wrapper_base<git_commit>
commit_wrapper(git_commit* commit);

friend class repository_wrapper;
friend class reference_wrapper;
};
1 change: 1 addition & 0 deletions src/wrapper/object_wrapper.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ class object_wrapper : public wrapper_base<git_object>
object_wrapper(git_object* obj);

friend class repository_wrapper;
friend class reference_wrapper;
};
30 changes: 30 additions & 0 deletions src/wrapper/refs_wrapper.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <concepts>
#include <string>

#include <git2.h>
Expand All @@ -20,9 +21,38 @@ class reference_wrapper : public wrapper_base<git_reference>
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::resource_type;
git_object* resource = nullptr;
throw_if_error(git_reference_peel(&resource, this->p_resource, obj_type));
return W(reinterpret_cast<resource_type*>(resource));
}

Back | FazBrowse Home | New Git URL