Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=aca7b2d306e990121692c7f267c0999a896b3624

commit aca7b2d306e990121692c7f267c0999a896b3624
Author: Michel Hermier <[email protected]>
Date:   Thu Sep 25 10:43:00 2014 +0200

libpacman: Move flib::remove* to FList::remove.

* Returning number of remove is only possible in class, since removing from 
range require turning the new first element of the range.
* Converting pmhandle_t::dbs_sync to FList<Database *> since now we provide a 
simplier remove interface.

diff --git a/lib/libpacman/handle.h b/lib/libpacman/handle.h
index 397a75f..3e12e61 100644
--- a/lib/libpacman/handle.h
+++ b/lib/libpacman/handle.h
@@ -63,7 +63,7 @@ public:
pmaccess_t access;
uid_t uid;
libpacman::Database *db_local;
-       FPtrList dbs_sync; /* List of (libpacman::Database *) */
+       FList<libpacman::Database *> dbs_sync;
FILE *logfd;
FFileLock *filelock;
pmtrans_t *trans;
diff --git a/lib/libpacman/pacman.cpp b/lib/libpacman/pacman.cpp
index 1300ac1..ddc3b34 100644
--- a/lib/libpacman/pacman.cpp
+++ b/lib/libpacman/pacman.cpp
@@ -118,7 +118,7 @@ int pacman_release(void)
/* and also sync ones */
while(!handle->dbs_sync.empty()) {
/* db_unregister() will also update the handle->dbs_sync list */
-               pacman_db_unregister(*handle->dbs_sync.begin());
+               pacman_db_unregister(c_cast(*handle->dbs_sync.begin()));
}

if(handle->unlock() != 0) {
@@ -430,7 +430,7 @@ int pacman_db_unregister(pmdb_t *_db)
handle->db_local = NULL;
found = 1;
} else {
-               if(_pacman_list_remove(&handle->dbs_sync, db, f_ptrcmp, NULL)) {
+               if(handle->dbs_sync.remove(db)) {
found = 1;
}
}
diff --git a/lib/libpacman/util/falgorithm.h b/lib/libpacman/util/falgorithm.h
index 9428ad5..997c9bd 100644
--- a/lib/libpacman/util/falgorithm.h
+++ b/lib/libpacman/util/falgorithm.h
@@ -126,29 +126,6 @@ namespace flib
return false;
}

-       template <class InputOutputIterator, class T, class Function = 
detail::null_visitor>
-       typename InputOutputIterator::size_type
-                       remove(InputOutputIterator first, InputOutputIterator 
last, const T &val, Function fn = Function())
-       {
-               return remove_if(first, last,
-                               [&] (const typename 
InputOutputIterator::reference o) -> typename InputOutputIterator::size_type
-                               { return match(o, val); }, fn);
-       }
-
-       template <class InputOutputIterator, class UnaryPredicate, class 
Function = detail::null_visitor>
-       typename InputOutputIterator::size_type
-                       remove_if(InputOutputIterator first, 
InputOutputIterator last, UnaryPredicate pred, Function fn = Function())
-       {
-               typename InputOutputIterator::size_type size = 0;
-
-               while((first = std::find_if(first, last, pred)) != last) {
-                       fn(*first);
-                       first = first.remove();
-                       ++size;
-               }
-               return size;
-       }
-
template <class InputOutputIterator, class T, class Function>
typename InputOutputIterator::size_type
replace(InputOutputIterator first, InputOutputIterator last, const T &val, 
const T &new_val, Function fn = detail::null_visitor())
diff --git a/lib/libpacman/util/flist.h b/lib/libpacman/util/flist.h
index 5a6563c..77e4a75 100644
--- a/lib/libpacman/util/flist.h
+++ b/lib/libpacman/util/flist.h
@@ -736,6 +736,28 @@ public:
return it;
}

+       template <class Function = ::flib::detail::null_visitor>
+       size_type remove(const value_type &val, Function fn = Function())
+       {
+               return remove_if(
+                               [&] (const value_type &o) -> bool
+                               { return o == val; }, fn );
+       }
+
+       template <class UnaryPredicate, class Function = 
::flib::detail::null_visitor>
+       size_type remove_if(UnaryPredicate pred, Function fn = Function())
+       {
+               size_type size = 0;
+               iterator it = begin(), end = this->end();
+
+               while((it = flib::find_if(it, end, pred)) != end) {
+                       fn(*it);
+                       it = erase(it);
+                       ++size;
+               }
+               return size;
+       }
+
/* Operations */
void reverse() {
FCListItem *it = this;
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to