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

Add git_strarray wrapper by SandrineP · Pull Request #17 · 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 .cpp  (1) .hpp  (1) All 2 file types 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
48 changes: 48 additions & 0 deletions src/utils/common.cpp
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 @@ -23,3 +23,51 @@ std::string get_current_git_path()
// sub->add_option("directory", directory, "info about directory arg")
// ->check(CLI::ExistingDirectory | CLI::NonexistentPath)
// ->default_val(std::filesystem::current_path());

git_strarray_wrapper::git_strarray_wrapper(std::vector<std::string> patterns)
: m_patterns(std::move(patterns))
{
init_str_array();
}

git_strarray_wrapper::git_strarray_wrapper(git_strarray_wrapper&& rhs)
: m_patterns(std::move(rhs.m_patterns))
{
init_str_array();
Comment thread
JohanMabille marked this conversation as resolved.
rhs.reset_str_array();
}

git_strarray_wrapper& git_strarray_wrapper::operator=(git_strarray_wrapper&& rhs)
{
using std::swap;
swap(m_patterns, rhs.m_patterns);
swap(m_array.strings, rhs.m_array.strings);
swap(m_array.count, rhs.m_array.count);
return *this;
}

git_strarray_wrapper::~git_strarray_wrapper()
{
reset_str_array();
}

git_strarray_wrapper::operator git_strarray*()
{
return &m_array;
}

void git_strarray_wrapper::reset_str_array()
{
delete[] m_array.strings;
m_array={nullptr, 0};
}

void git_strarray_wrapper::init_str_array()
{
m_array.strings = new char*[m_patterns.size()];
m_array.count = m_patterns.size();
for (size_t i=0; i<m_patterns.size(); ++i)
{
m_array.strings[i] = const_cast<char*>(m_patterns[i].c_str());
}
Comment thread
JohanMabille marked this conversation as resolved.
}
30 changes: 30 additions & 0 deletions src/utils/common.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 @@ -2,6 +2,9 @@

#include <string>
#include <utility>
#include <vector>

#include <git2.h>

class noncopyable_nonmovable
{
Expand Down Expand Up @@ -57,3 +60,30 @@ class libgit2_object : private noncopyable_nonmovable
};

std::string get_current_git_path();

class git_strarray_wrapper
{
public:
git_strarray_wrapper()
: m_patterns{}
, m_array{nullptr, 0}
{}
git_strarray_wrapper(std::vector<std::string> patterns);

git_strarray_wrapper(const git_strarray_wrapper&) = delete;
git_strarray_wrapper& operator=(const git_strarray_wrapper&) = delete;

git_strarray_wrapper(git_strarray_wrapper&& rhs);
git_strarray_wrapper& operator=(git_strarray_wrapper&&);

~git_strarray_wrapper();

operator git_strarray*();

private:
std::vector<std::string> m_patterns;
git_strarray m_array;

void reset_str_array();
void init_str_array();
};

Back | FazBrowse Home | New Git URL