Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=6002c583b6f82e84a616b07ea36515fb2830cb71
commit 6002c583b6f82e84a616b07ea36515fb2830cb71 Author: Michel Hermier <[email protected]> Date: Wed Sep 10 19:02:40 2014 +0200 libpacman: Drop FPtrList for FList<void *>. diff --git a/lib/libpacman/db/localdb.cpp b/lib/libpacman/db/localdb.cpp index 85b7c19..75c4028 100644 --- a/lib/libpacman/db/localdb.cpp +++ b/lib/libpacman/db/localdb.cpp @@ -142,7 +142,7 @@ int _pacman_localpackage_remove(Package *pkg, pmtrans_t *trans, int howmany, int _pacman_log(PM_LOG_FLOW1, _("removing files")); /* iterate through the list backwards, unlinking files */ - for(auto lp = pkg->files().rbegin(), end = pkg->files().rend(); lp != end; --lp /* FIXME: should be ++lp when operators are really working */) { + for(auto lp = pkg->files().rbegin(), end = pkg->files().rend(); lp != end; ++lp) { int nb = 0; double percent = 0; const char *file = *lp; diff --git a/lib/libpacman/util/flist.h b/lib/libpacman/util/flist.h index a41cff9..9bd335f 100644 --- a/lib/libpacman/util/flist.h +++ b/lib/libpacman/util/flist.h @@ -117,7 +117,7 @@ namespace flib typedef typename iterable_traits<Iterable>::pointer pointer; typedef typename iterable_traits<Iterable>::value_type value_type; - explicit const_iterator(iterable i) + explicit const_iterator(iterable i = iterable()) : m_iterable(i) { } @@ -128,6 +128,11 @@ namespace flib ~const_iterator() { } + operator iterable () + { + return m_iterable; + } + const_iterator &operator = (const const_iterator &o) { m_iterable = o.m_iterable; @@ -221,7 +226,7 @@ namespace flib typedef typename iterable_traits<Iterable>::reference reference; typedef typename iterable_traits<Iterable>::value_type value_type; - explicit iterator(iterable i) + explicit iterator(iterable i = iterable()) : m_iterable(i) { } @@ -232,6 +237,11 @@ namespace flib ~iterator() { } + operator iterable () + { + return m_iterable; + } + iterator &operator = (const iterator &o) { m_iterable = o.m_iterable; @@ -322,6 +332,7 @@ namespace flib return !Reverse ? iterable_traits<Iterable>::previous(m_iterable) : iterable_traits<Iterable>::next(m_iterable); } + public: /* FIXME: Make protected/private */ iterable m_iterable; }; } @@ -551,12 +562,12 @@ namespace flib { static iterable next(const iterable &i) { - return iterable_traits<FCListItem *>::next(i); + return static_cast<iterable>(iterable_traits<FCListItem *>::next(i)); } static iterable previous(const iterable &i) { - return iterable_traits<FCListItem *>::previous(i); + return static_cast<iterable>(iterable_traits<FCListItem *>::previous(i)); } static reference reference_of(iterable i) @@ -594,6 +605,18 @@ public: : FCListItem(this, this) { } + FList(FList &&o) + : FList() + { + swap(o); + } + + FList &operator = (FList &&o) + { + swap(o); + return *this; + } + virtual ~FList() override { clear(); @@ -602,7 +625,7 @@ public: /* Iterators */ iterator begin() { - return iterator(_next()); + return iterator(c_first()); } const_iterator begin() const @@ -612,12 +635,12 @@ public: const_iterator cbegin() const { - return const_iterator(_next()); + return const_iterator(c_first()); } reverse_iterator rbegin() { - return reverse_iterator(_previous()); + return reverse_iterator(c_last()); } const_reverse_iterator rbegin() const @@ -627,12 +650,12 @@ public: const_reverse_iterator crbegin() const { - return const_reverse_iterator(_previous()); + return const_reverse_iterator(c_last()); } iterator end() { - return iterator(_self()); + return iterator(c_end()); } const_iterator end() const @@ -642,12 +665,12 @@ public: const_iterator cend() const { - return const_iterator(_self()); + return const_iterator(c_end()); } reverse_iterator rend() { - return reverse_iterator(_self()); + return reverse_iterator(c_end()); } const_reverse_iterator rend() const @@ -657,13 +680,13 @@ public: const_reverse_iterator crend() const { - return const_reverse_iterator(_self()); + return const_reverse_iterator(c_end()); } /* Capacity */ bool empty() const { - return m_next == m_previous; + return begin() == end(); } size_type size() const @@ -688,22 +711,22 @@ public: /* extensions */ iterator first() { - return iterator(m_next); + return iterator(c_first()); } const_iterator first() const { - return const_iterator(m_next); + return const_iterator(c_first()); } iterator last() { - return iterator(m_previous); + return iterator(c_last()); } const_iterator last() const { - return iterator(m_previous); + return const_iterator(c_last()); } FList &add(const value_type &val) // Make default implementation to happend @@ -712,10 +735,15 @@ public: return *this; } + bool remove(void *ptr, _pacman_fn_cmp fn, void **data) + { + return remove(fn, ptr, data); + } + bool remove(_pacman_fn_cmp fn, void *ptr, value_type *data = nullptr) { - for(auto i = begin(), end = this->end(); i != end; i = i->next()) { - if(fn(ptr, *i) == 0) { + for(auto i = c_first(), end = c_end(); i != end; i = i->next()) { + if(fn(ptr, i->m_data) == 0) { /* we found a matching item */ i->remove(); if(data != nullptr) { @@ -732,19 +760,22 @@ public: FCListItem::swap(o); } -protected: - iterable _next() const +public: + iterable c_first() const { + ASSERT(this != NULL, RET_ERR(PM_ERR_WRONG_ARGS, NULL)); return static_cast<iterable>(m_next); } - iterable _previous() const + iterable c_last() const { + ASSERT(this != NULL, RET_ERR(PM_ERR_WRONG_ARGS, NULL)); return static_cast<iterable>(m_previous); } - iterable _self() const + iterable c_end() const { + ASSERT(this != NULL, RET_ERR(PM_ERR_WRONG_ARGS, NULL)); return static_cast<iterable>((FCListItem *)this); } diff --git a/lib/libpacman/util/fptrlist.cpp b/lib/libpacman/util/fptrlist.cpp index 2d5e9dc..39cb9d8 100644 --- a/lib/libpacman/util/fptrlist.cpp +++ b/lib/libpacman/util/fptrlist.cpp @@ -38,7 +38,7 @@ FPtrList *f_ptrlist_add_sorted(FPtrList *list, void *data, _pacman_fn_cmp fn) /* Find insertion point. */ FPtrListItem *previous, *end; - for(previous = end = list->_self(); previous->next() != end; previous = previous->next()) { + for(previous = end = list->c_end(); previous->next() != end; previous = previous->next()) { if(fn(data, previous->next()->m_data) <= 0) { break; } @@ -57,6 +57,10 @@ FPtrList *f_ptrlist_add_sorted(FPtrList *list, void *data, _pacman_fn_cmp fn) */ bool _pacman_list_remove(FPtrList *self, void *ptr, _pacman_fn_cmp fn, void **data) { + if(data != NULL) { + *data = NULL; + } + ASSERT(self != NULL, RET_ERR(PM_ERR_WRONG_ARGS, false)); return self->remove(ptr, fn, data); } @@ -72,7 +76,7 @@ FPtrList *_pacman_list_reverse(FPtrList *list) */ FPtrList *newlist = f_ptrlist_new(); - for(auto it = list->rbegin(), end = list->rend(); it != end; --it /* FIXME: should be ++it when operators are really working */) { + for(auto it = list->rbegin(), end = list->rend(); it != end; ++it) { newlist->add(*it); } @@ -117,32 +121,6 @@ int f_ptrlist_delete(FPtrList *self, FVisitor *visitor) #endif } -FPtrList &FPtrList::add(void *data) -{ - (new FPtrListItem(data))->insert_after(_previous()); - return *this; -} - -bool FPtrList::remove(void *ptr, _pacman_fn_cmp fn, void **data) -{ - if(data != NULL) { - *data = NULL; - } - - for(auto i = begin(), end = this->end(); i != end; ++i) { - if(fn(ptr, *i) == 0) { - /* we found a matching item */ - i.m_iterable->remove(); - if(data) { - *data = *i; - } - delete i.m_iterable; - return true; - } - } - return false; -} - FPtrList *f_ptrlist_add(FPtrList *list, void *data) { if (list == NULL) { diff --git a/lib/libpacman/util/fptrlist.h b/lib/libpacman/util/fptrlist.h index 082090c..791c3be 100644 --- a/lib/libpacman/util/fptrlist.h +++ b/lib/libpacman/util/fptrlist.h @@ -33,7 +33,7 @@ typedef struct FPtrList FPtrList; typedef struct FPtrListIterator FPtrListIterator; #else /* __cplusplus */ -typedef class FPtrList FPtrList; +typedef class FList<void *> FPtrList; typedef class FListItem<void *> FPtrListItem; typedef FPtrListItem FPtrListIterator; @@ -71,205 +71,6 @@ const FPtrListIterator *f_ptrlist_rend_const(const FPtrList *self); #ifdef __cplusplus } - -class FPtrList - : protected FCListItem -{ -public: - friend FPtrList *f_ptrlist_add_sorted(FPtrList *list, void *data, _pacman_fn_cmp fn); - - typedef FPtrListItem *iterable; - - class iterator - { - public: - iterator(iterable it = iterable()) - : m_iterable(it) - { } - - bool operator == (const iterator &o) - { - return m_iterable == o.m_iterable; - } - - bool operator != (const iterator &o) - { - return !operator == (o); - } - - void *operator * () const - { - return m_iterable->m_data; - } - - operator iterable () - { - return m_iterable; - } - - iterator &operator ++ () - { - m_iterable = m_iterable->next(); - return *this; - } - - iterator &operator -- () - { - m_iterable = m_iterable->previous(); - return *this; - } - - - iterator next() const - { - return m_iterable->next(); - } - - iterator previous() const - { - return m_iterable->previous(); - } - - iterable m_iterable; - }; - - typedef iterator const_iterator; - typedef iterator reverse_iterator; - typedef iterator const_reverse_iterator; - - FPtrList() - : FCListItem(this, this) - { } - - FPtrList(FPtrList &&o) - : FPtrList() - { - swap(o); - } - - FPtrList &operator = (FPtrList &&o) - { - swap(o); - return *this; - } - - iterator begin() - { - ASSERT(this != NULL, RET_ERR(PM_ERR_WRONG_ARGS, NULL)); - return iterator(_next()); - } - - const_iterator begin() const - { - return cbegin(); - } - - const_iterator cbegin() const - { - ASSERT(this != NULL, RET_ERR(PM_ERR_WRONG_ARGS, NULL)); - return const_iterator(_next()); - } - - iterator end() - { - return iterator(_self()); - } - - const_iterator end() const - { - return cend(); - } - - const_iterator cend() const - { - return const_iterator(_self()); - } - - iterator last() - { - return iterator(_previous()); - } - - const_iterator last() const - { - return clast(); - } - - const_iterator clast() const - { - return const_iterator(_previous()); - } - - reverse_iterator rbegin() - { - return reverse_iterator(_previous()); - } - - const_reverse_iterator rbegin() const - { - return crbegin(); - } - - const_reverse_iterator crbegin() const - { - return const_reverse_iterator(_previous()); - } - - reverse_iterator rend() - { - return reverse_iterator(_self()); - } - - const_reverse_iterator rend() const - { - return crend(); - } - - const_reverse_iterator crend() const - { - return const_reverse_iterator(_self()); - } - - bool empty() const - { - ASSERT(this != NULL, RET_ERR(PM_ERR_WRONG_ARGS, true)); - return begin() == end(); - } - - FPtrList &add(void *data); - bool remove(void *ptr, _pacman_fn_cmp fn, void **data); - - void clear() - { - // FIXME: lets leak for now - ASSERT(this != NULL, pm_errno = PM_ERR_WRONG_ARGS; return); - m_next = m_previous = this; - } - - void swap(FPtrList &o) { - FCListItem::swap(o); - } - -protected: - iterable _next() const - { - return static_cast<iterable>(m_next); - } - - iterable _previous() const - { - return static_cast<iterable>(m_previous); - } - - iterable _self() const - { - return static_cast<iterable>((FCListItem *)this); - } - -private: - FPtrList(const FPtrList &o); - FPtrList &operator = (const FPtrList &o); -}; #endif /* __cplusplus */ #endif /* F_PTRLIST_H */ diff --git a/lib/libpacman/util/fstringlist.cpp b/lib/libpacman/util/fstringlist.cpp index 815211d..340d573 100644 --- a/lib/libpacman/util/fstringlist.cpp +++ b/lib/libpacman/util/fstringlist.cpp @@ -34,6 +34,10 @@ */ int _pacman_list_is_strin(const char *needle, FStringList *haystack) { + if(haystack == NULL) { + return 0; + } + for(auto lp = haystack->begin(), end = haystack->end(); lp != end; ++lp) { const char *str = *lp; @@ -53,6 +57,11 @@ int _pacman_list_is_strin(const char *needle, FStringList *haystack) FStringList *_pacman_list_remove_dupes(FStringList *list) { FStringList *newlist = NULL; + + if(list == NULL) { + return NULL; + } + for(auto i = list->begin(), end = list->end(); i != end; ++i) { const char *str = *i; _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
