#ifndef ALPM_LIST_H #define ALPM_LIST_H #include #include namespace RepoIndex { /*! * \brief The ListIterator class is used to iterate Alpm::List instances. */ template class AlpmListIterator : public std::iterator { public: /*! * \brief Constructs a new iterator for the specified ALPM list node. */ AlpmListIterator(alpm_list_t *i) : m_ptr(i) {} /*! * \brief Returns the data for the current list node. */ const T operator *() const { return static_cast(m_ptr->data); } /*! * \brief Returns the data for the current list node. */ T operator*() { return static_cast(m_ptr->data); } /*! * \brief Returns whether the iterator is valid. */ operator bool() const { return m_ptr != nullptr; } /*! * \brief Moves to the next list node. */ AlpmListIterator &operator++() { m_ptr = m_ptr->next; return *this; } /*! * \brief Moves to the previous list node. */ AlpmListIterator &operator--() { m_ptr = m_ptr->prev; return *this; } /*! * \brief Returns the pointer to the current ALPM list node. */ alpm_list_t *ptr() { return m_ptr; } private: mutable alpm_list_t *m_ptr; }; /*! * \brief The List class is a simple C++ wrapper around the ALPM list implementation. */ template class AlpmList { public: /*! * \brief Constructs a list with the specified ALPM list node as the begin. */ AlpmList(alpm_list_t *begin) : m_begin(begin) {} /*! * \brief Returns an iterator for the first list node. */ AlpmListIterator begin() const { return m_begin; } /*! * \brief Returns an invalid iterator indicating the end of the list. */ AlpmListIterator end() const { return AlpmListIterator(nullptr); } private: AlpmListIterator m_begin; }; typedef AlpmList StringList; typedef AlpmList DependencyList; typedef AlpmList PackageList; typedef AlpmList GroupList; typedef AlpmList BackupList; } // namespace Alpm #endif // ALPM_LIST_H