#ifndef PACKAGEMANAGEMENT_ALPMPACKAGE_H #define PACKAGEMANAGEMENT_ALPMPACKAGE_H #include "./package.h" namespace RepoIndex { class AlpmDatabase; class AlpmPackage : public Package { public: AlpmPackage(AlpmDatabase *repository); AlpmPackage(alpm_pkg_t *package, AlpmDatabase *alpmDatabase); AlpmPackage(alpm_pkg_t *package); // ALPM specific meta data const alpm_pkg_t *ptr() const; alpm_pkg_t *ptr(); const char *base64Signature() const; void *openChangelog() const; size_t readChangelog(void *changelog, void *buffer, size_t bufferSize); bool closeChangelog(void *changelog); protected: alpm_pkg_t *m_ptr; }; /*! * \brief Constructs a new instance for the specified ALPM \a package. * \remarks This method is only meant to be used for packages which do * not belong to a database. */ inline AlpmPackage::AlpmPackage(alpm_pkg_t *package) : AlpmPackage(package, nullptr) {} inline uint qHash(const AlpmPackage &key) { return qHash(key.ptr()); } /*! * \brief Returns a pointer to the underlying alpm_pkg_t. */ inline const alpm_pkg_t *AlpmPackage::ptr() const { return m_ptr; } /*! * \brief Returns a pointer to the underlying alpm_pkg_t. */ inline alpm_pkg_t *AlpmPackage::ptr() { return m_ptr; } inline const char *AlpmPackage::base64Signature() const { return alpm_pkg_get_base64_sig(m_ptr); } inline void *AlpmPackage::openChangelog() const { return alpm_pkg_changelog_open(m_ptr); } inline size_t AlpmPackage::readChangelog(void *changelog, void *buffer, size_t bufferSize) { return alpm_pkg_changelog_read(buffer, bufferSize, m_ptr, changelog); } inline bool AlpmPackage::closeChangelog(void *changelog) { return alpm_pkg_changelog_close(m_ptr, changelog); } class AlpmOwnershipPackage : public AlpmPackage { public: // constructor, destructor AlpmOwnershipPackage(alpm_pkg_t *package); AlpmOwnershipPackage(const AlpmOwnershipPackage &other) = delete; AlpmOwnershipPackage(AlpmOwnershipPackage &&other); ~AlpmOwnershipPackage(); // assignment operator AlpmOwnershipPackage &operator =(const AlpmOwnershipPackage &other) = delete; AlpmOwnershipPackage &operator =(AlpmOwnershipPackage &&other); }; inline AlpmOwnershipPackage::AlpmOwnershipPackage(alpm_pkg_t *package) : AlpmPackage(package) {} inline AlpmOwnershipPackage::AlpmOwnershipPackage(AlpmOwnershipPackage &&other) : AlpmPackage(other.m_ptr) { other.m_ptr = nullptr; } inline AlpmOwnershipPackage &AlpmOwnershipPackage::operator =(AlpmOwnershipPackage &&other) { if(this != &other) { m_ptr = other.m_ptr; other.m_ptr = nullptr; } return *this; } inline AlpmOwnershipPackage::~AlpmOwnershipPackage() { alpm_pkg_free(ptr()); } } // namespace PackageManagement #endif // PACKAGEMANAGEMENT_ALPMPACKAGE_H