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

commit ed2f134709e78751b73c4d39a67befcd43346a62
Author: Michel Hermier <herm...@frugalware.org>
Date:   Fri Nov 7 10:42:39 2014 +0100

libpacman: Add keyed_value_traits, make flib::set privately inherit of 
flib::list.

diff --git a/lib/libpacman/database_cache.cpp b/lib/libpacman/database_cache.cpp
index 8f934ca..73d1ac2 100644
--- a/lib/libpacman/database_cache.cpp
+++ b/lib/libpacman/database_cache.cpp
@@ -130,7 +130,7 @@ int Database::remove_pkgfromcache(package_ptr pkg)
}

static
-Group *_pacman_db_get_grpfromlist(const list<Group *> &list, const char 
*target)
+Group *_pacman_db_get_grpfromlist(const group_set &list, const char *target)
{
if(_pacman_strempty(target)) {
return(NULL);
diff --git a/lib/libpacman/pacman_p.h b/lib/libpacman/pacman_p.h
index d8d57e0..a3db46a 100644
--- a/lib/libpacman/pacman_p.h
+++ b/lib/libpacman/pacman_p.h
@@ -61,6 +61,10 @@ template <typename T>
static inline __pmlist_t *c_cast(flib::list<T> *obj)
{ return (__pmlist_t *)obj; }

+template <class T, class Compare>
+static inline __pmlist_t *c_cast(flib::set<T, Compare> &obj)
+{ return (__pmlist_t *)&obj; }
+
static inline struct __pmpkg_t *c_cast(const libpacman::package_ptr &obj)
{ return (__pmpkg_t *)obj.get(); }

diff --git a/lib/libpacman/util/fset.h b/lib/libpacman/util/fset.h
index e8f8c22..9056ed1 100644
--- a/lib/libpacman/util/fset.h
+++ b/lib/libpacman/util/fset.h
@@ -28,13 +28,37 @@

namespace flib
{
-       template <class T, class Compare = std::less<T>>
+       template <class T>
+       struct keyed_value_traits
+       {
+               typedef T keyed_value_type;
+               typedef T key_type;
+               typedef T value_type;
+
+               static const key_type &key_of(const keyed_value_type &o)
+               {
+                       return o;
+               }
+
+               static value_type &value_of(keyed_value_type &o)
+               {
+                       return o;
+               }
+
+               static const value_type &value_of(const keyed_value_type &o)
+               {
+                       return o;
+               }
+       };
+
+       template <class T, class Compare = std::less<typename 
flib::keyed_value_traits<T>::key_type>>
class set
-               : public flib::list<T>
+               : private flib::list<T>
{
-       public:
+       private:
typedef flib::list<T> super_type;

+       public:
using typename super_type::iterator;
using typename super_type::value_type;

@@ -43,6 +67,28 @@ namespace flib

using super_type::list;

+               /* Iterators */
+               using super_type::begin;
+               using super_type::end;
+               using super_type::rbegin;
+               using super_type::rend;
+
+               /* Capacity */
+               using super_type::empty;
+               using super_type::size;
+
+               /* Element access */
+               using super_type::clear;
+               using super_type::contains;
+               using super_type::remove;
+
+               using super_type::any_match_if;
+
+               explicit operator const flib::list<T> &() const
+               {
+                       return *this;
+               }
+
virtual iterator add(const value_type &data) override
{
iterator end = this->end();
_______________________________________________
Frugalware-git mailing list
Frugalware-git@frugalware.org
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to