forked from p-ranav/cppgit2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrarray.hpp
More file actions
74 lines (53 loc) · 1.65 KB
/
Copy pathstrarray.hpp
File metadata and controls
74 lines (53 loc) · 1.65 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#pragma once
#include <git2.h>
#include <cppgit2/git_exception.hpp>
#include <cppgit2/libgit2_api.hpp>
#include <string>
#include <vector>
namespace cppgit2 {
class strarray : public libgit2_api {
public:
// Default construction
// Initializes libgit2
strarray();
// Construct from vector of strings
strarray(const std::vector<std::string>& strings);
// Construct from libgit2 C ptr
strarray(const git_strarray* c_ptr);
// Free the git_strarray struct
~strarray();
// Duplicate this array
strarray copy() const;
// Build vector of tag names from strarray
std::vector<std::string> to_vector() const;
// Iterator for use in range-based for loops
class iterator {
public:
explicit iterator(char** ptr) : ptr_(ptr) {}
iterator operator++() {
++ptr_;
return *this;
}
bool operator!=(const iterator& other) const { return ptr_ != other.ptr_; }
std::string operator*() { return std::string(*ptr_); }
private:
char** ptr_;
};
iterator begin() { return iterator(&c_struct_.strings[0]); }
iterator begin() const { return iterator(&c_struct_.strings[0]); }
iterator end() { return iterator(&c_struct_.strings[c_struct_.count]); }
iterator end() const { return iterator(&c_struct_.strings[c_struct_.count]); }
// Returns number of strings in strarray
size_t count() const { return c_struct_.count; }
// Get string at index
std::string operator[](size_t index) {
return std::string(c_struct_.strings[index]);
}
// Access libgit2 C ptr
const git_strarray* c_ptr() const;
private:
friend class remote;
friend class repository;
git_strarray c_struct_;
};
} // namespace cppgit2