gitbase.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef GITBASE_H
  2. #define GITBASE_H
  3. #include <gitrepository.h>
  4. #include <QObject>
  5. #include <git2/types.h>
  6. #include <git2/errors.h>
  7. class GitRepository;
  8. template <typename T>
  9. class GitBase : public QObject
  10. {
  11. public:
  12. T *raw() const {
  13. return m_raw;
  14. }
  15. bool isValid() const {
  16. return m_raw != nullptr;
  17. }
  18. GitRepository *repository() const {
  19. return m_repository;
  20. }
  21. static QString lastError() {
  22. const git_error *e = giterr_last();
  23. if(e) {
  24. return QString("(%1): %2").arg(e->klass).arg(e->message);
  25. giterr_clear();
  26. }
  27. giterr_clear();
  28. return QString();
  29. }
  30. protected:
  31. GitBase(T *raw, GitRepository *parent) : QObject()
  32. ,m_raw(raw)
  33. ,m_repository(parent)
  34. {}
  35. GitBase(GitBase &&other) {
  36. //WARNING: m_raw should be moved in inherited class
  37. m_repository = other.m_repository;
  38. other.m_repository = nullptr;
  39. }
  40. GitBase &operator=(GitBase &&other) {
  41. if (&other != this) {
  42. //WARNING: m_raw should be moved in inherited class
  43. m_repository = other.m_repository;
  44. other.m_repository = nullptr;
  45. }
  46. return *this;
  47. }
  48. T *m_raw;
  49. GitRepository *m_repository;
  50. };
  51. #endif // GITBASE_H