Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=7caf30231720e36f7935eefa59c70175608f0587
commit 7caf30231720e36f7935eefa59c70175608f0587 Author: Michel Hermier <[email protected]> Date: Mon Aug 18 14:53:24 2014 +0200 libpacman: Try to reduce number of list implementations in C, introduction of partially implemented C++ list. diff --git a/lib/libpacman/CMakeLists.txt b/lib/libpacman/CMakeLists.txt index aaede5e..82cbf7d 100644 --- a/lib/libpacman/CMakeLists.txt +++ b/lib/libpacman/CMakeLists.txt @@ -26,7 +26,6 @@ set(FLIB_SOURCES util/fdispatchlogger.h util/flist.c util/flist.h - util/flist_p.h util/ffilelogger.c util/ffilelogger.h util/ffunctional.h @@ -36,7 +35,6 @@ set(FLIB_SOURCES util/flogger.h util/fptrlist.c util/fptrlist.h - util/fptrlist_p.h util/fsyslogger.c util/fsyslogger.h util/list.c diff --git a/lib/libpacman/util.h b/lib/libpacman/util.h index 869eaf8..c979ab3 100644 --- a/lib/libpacman/util.h +++ b/lib/libpacman/util.h @@ -59,7 +59,6 @@ #define _pacman_basename f_basename int _pacman_copyfile(char *src, char *dest); int _pacman_unpack(const char *archive, const char *prefix, const char *fn); -int _pacman_rmrf(char *path); int _pacman_ldconfig(char *root); #ifdef _PACMAN_TRANS_H int _pacman_chroot_system(const char *cmdline, pmtrans_t *trans); @@ -84,6 +83,7 @@ extern "C" { #endif int _pacman_makepath(const char *path); +int _pacman_rmrf(char *path); #ifdef __cplusplus } diff --git a/lib/libpacman/util/flist.c b/lib/libpacman/util/flist.c index c3417e6..60e1890 100644 --- a/lib/libpacman/util/flist.c +++ b/lib/libpacman/util/flist.c @@ -22,7 +22,7 @@ #include "config.h" -#include "util/flist_p.h" +#include "util/fptrlist.h" #include "fstdlib.h" diff --git a/lib/libpacman/util/flist.h b/lib/libpacman/util/flist.h index 59b9f3e..54ec9ea 100644 --- a/lib/libpacman/util/flist.h +++ b/lib/libpacman/util/flist.h @@ -27,9 +27,328 @@ #include "util/fcallback.h" #ifdef __cplusplus -extern "C" { + +#ifdef F_NOCOMPAT +class FListItemBase +{ +public: + ListItem() + : ListItem(NULL, NULL) + { } + + ListItem(FListItemBase *previous, FListItemBase *next) + : m_next(next), m_previous(previous) + { } + + virtual ~FListItemBase() = 0; + + ListItemBase *next() + { + return m_next; + } + + ListItemBase *next() const + { + return m_next; + } + + ListItemBase *previous() + { + return m_previous; + } + + const ListItemBase *previous() const + { + return m_previous; + } + +protected: + virtual void *c_data() const = 0; + + bool insert_after(FListItemBase *previous); + + ListItemBase *m_next; + ListItemBase *m_previous; +}; + +template <typename T> +class FListItem + : public FListItemBase +{ + ListItem() + { } + + explicit ListItem(T &data) + : m_data(data) + { } + + virtual ~ListItem() + { } + + virtual void *c_data() const override + { + return &m_data; + } + + T *c_data() const + { + return &m_data; + } + + T &data() + { + return m_data; + } + + const T &data() const + { + return m_data; + } + + ListItem<T> *next() + { + return FListItemBase::next(); + } + + ListItem<T> *next() const + { + return FListItemBase::next(); + } + + ListItem<T> *previous() + { + return FListItemBase::previous(); + } + + const ListItem<T> *previous() const + { + return FListItemBase::previous(); + } + +protected: + T m_data; + +private: + ListItem(const ListItem<T> &o); + + ListItem<T> &operator = (const ListItem<T> &o); +}; + +class FListBase + : private FListItemBase +{ +public: + /* std::list compatibility */ + typedef ListItem<T> *iterator; + typedef const List<T>::iterator const_iterator; + + FListBase() + : FListBase(this, this) + { } + + ~FListBase() + { + clear(); + } + + size_t count() const; + + FList::iterator begin() + { + return first(); + } + + FList::const_iterator begin() const + { + return first(); + } + + FList::const_iterator cbegin() const + { + return first(); + } + + List::iterator end() + { + return last(); + } + + List::const_iterator end() const + { + return last(); + } + + List::const_iterator cend() const + { + return last(); + } + + ListItemBase *first() + { + return FListItemBase::next(); + } + + const ListItemBase *first() const + { + return FListItemBase::next(); + } + + ListItemBase *last() + { + return FListItemBase::previous(); + } + + const ListItemBase *last() const + { + return FListItemBase::previous(); + } + +protected: + virtual bool add(FListItem *item); + +protected: + ListBase(const ListItem<T> &o); + + ListBase &operator = (const ListBase &o); + +}; + +template <typename T> +class List + : private FListBase +{ +public: + /* std::list compatibility */ + typedef ListItem<T> *iterator; + typedef const List<T>::iterator const_iterator; + + List() + { } + + ~List() + { + clear(); + } + + void clear(); + bool empty() const; + + FList::iterator begin() + { + return first(); + } + + FList::const_iterator begin() const + { + return first(); + } + + FList::const_iterator cbegin() const + { + return first(); + } + + List::iterator end() + { + return last(); + } + + List::const_iterator end() const + { + return last(); + } + + List::const_iterator cend() const + { + return last(); + } + +#if 0 + typedef ListItem *reverse_iterator; + typedef const List::iterator const_reverse_iterator; + + List::reverse_iterator rbegin(); + List::const_reverse_iterator rbegin() const; + List::const_reverse_iterator crbegin() const; + List::reverse_iterator rend(); + List::const_reverse_iterator rend() const; + List::const_reverse_iterator crend() const; #endif +public: + /* extensions */ + bool all_match(const FMatcher &matcher) const + { + const_iterator end = cend(); + + for(const_iterator it = beging(); it != end; it = it->next()) { + if(matcher.match(it.data()) == false) { + return false; + } + } + return true; + } + + bool any_match(const FList *list, const FMatcher &matcher) const + { + const_iterator end = cend(); + + for(const_iterator it = begin(); it != end; it = it->next()) { + if(matcher.match(it->data()) == true) { + return true; + } + } + return false; + } + + ListItem<T> *find(const FComparator &comparator) + { + iterator end = this->end(); + + for(iterator it = begin(); it != end; it = it->next()) { + if(comparator->compare(it->data()) == 0) { + return it; + } + } + return NULL; + } + + ListItem<T> *first() + { + return FListBase::first(); + } + + const ListItem<T> *first() const + { + return FListBase::first(); + } + + ListItem<T> *last() + { + return FListBase::last(); + } + + const ListItem<T> *last() const + { + return FListBase::last(); + } + +private: + List(const List &); + + List &operator = (const List &); + + virtual void *c_data() const override + { + RET_ERR(PM_ERR_WRONG_ARGS, NULL); + } +}; + +#endif /* F_NOCOMPAT */ + +extern "C" { +#endif /* __cplusplus */ + #ifndef F_NOCOMPAT typedef struct __pmlist_t FList; typedef struct __pmlist_t FListItem; @@ -72,8 +391,6 @@ const FListItem *f_list_last_const(const FList *self); FListItem *f_list_rend(FList *self); const FListItem *f_list_rend_const(const FList *self); -#include "util/flist_p.h" - #ifdef __cplusplus } #endif diff --git a/lib/libpacman/util/flist_p.h b/lib/libpacman/util/flist_p.h deleted file mode 100644 index 4961dbf..0000000 --- a/lib/libpacman/util/flist_p.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * flist_p.h - * - * Copyright (c) 2002-2006 by Judd Vinet <[email protected]> - * Copyright (c) 2013-2014 by Michel Hermier <[email protected]> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, - * USA. - */ -#ifndef F_LIST_P_H -#define F_LIST_P_H - -#include "util/flist.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef F_NOCOMPAT -/* Chained list struct */ -struct __pmlist_t { - struct __pmlist_t *prev; - struct __pmlist_t *next; - void *data; -}; -#else -struct FListItem { - FListItem *next; - FListItem *previous; -}; - -struct FList { - FListItem as_FListItem; -}; -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* F_LIST_P_H */ - -/* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libpacman/util/fptrlist.c b/lib/libpacman/util/fptrlist.c index d633e62..875d9ce 100644 --- a/lib/libpacman/util/fptrlist.c +++ b/lib/libpacman/util/fptrlist.c @@ -22,7 +22,7 @@ #include "config.h" -#include "util/fptrlist_p.h" +#include "util/fptrlist.h" #include "fstdlib.h" diff --git a/lib/libpacman/util/fptrlist.h b/lib/libpacman/util/fptrlist.h index 03981f1..df39f40 100644 --- a/lib/libpacman/util/fptrlist.h +++ b/lib/libpacman/util/fptrlist.h @@ -24,13 +24,18 @@ #include "pacman.h" -#include "util/flist.h" - #ifdef __cplusplus extern "C" { #endif #ifndef F_NOCOMPAT +/* Chained list struct */ +struct __pmlist_t { + struct __pmlist_t *prev; + struct __pmlist_t *next; + void *data; +}; + typedef struct __pmlist_t FPtrList; typedef struct __pmlist_t FPtrListItem; #else @@ -38,6 +43,9 @@ typedef struct FPtrList FPtrList; typedef struct FPtrListItem FPtrListItem; #endif +#include "util/flist.h" +#include "util/list.h" + FPtrListItem *f_ptrlistitem_new(void *data); int f_ptrlistitem_delete(FListItem *self, FVisitor *visitor); diff --git a/lib/libpacman/util/fptrlist_p.h b/lib/libpacman/util/fptrlist_p.h deleted file mode 100644 index 01cd17a..0000000 --- a/lib/libpacman/util/fptrlist_p.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * fptrlist_p.h - * - * Copyright (c) 2002-2006 by Judd Vinet <[email protected]> - * Copyright (c) 2013-2014 by Michel Hermier <[email protected]> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, - * USA. - */ -#ifndef F_PTRLIST_P_H -#define F_PTRLIST_P_H - -#include "util/fptrlist.h" - -#include "util/flist_p.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef F_NOCOMPAT -struct FPtrList { - FList as_FList; -}; - -struct FPtrListItem { - FListItem as_FListItem; - void *data; -}; -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* F_PTRLIST_P_H */ - -/* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libpacman/util/list.c b/lib/libpacman/util/list.c index ffd2b4c..368f6ea 100644 --- a/lib/libpacman/util/list.c +++ b/lib/libpacman/util/list.c @@ -26,7 +26,7 @@ /* pacman-g2 */ #include "list.h" -#include "fptrlist_p.h" +#include "fptrlist.h" #include "fstdlib.h" #include "util.h" diff --git a/lib/libpacman/util/stringlist.c b/lib/libpacman/util/stringlist.c index cdaa409..29d9ab0 100644 --- a/lib/libpacman/util/stringlist.c +++ b/lib/libpacman/util/stringlist.c @@ -28,7 +28,6 @@ /* pacman-g2 */ #include "stringlist.h" -#include "util/fptrlist_p.h" #include "util.h" /* Test for existence of a string in a FStringList diff --git a/lib/libpacman/util/stringlist.h b/lib/libpacman/util/stringlist.h index aeb2e3d..1a9a283 100644 --- a/lib/libpacman/util/stringlist.h +++ b/lib/libpacman/util/stringlist.h @@ -21,7 +21,7 @@ #ifndef _PACMAN_STRINGLIST_H #define _PACMAN_STRINGLIST_H -#include "util/list.h" +#include "util/fptrlist.h" #include "fstring.h" #ifdef __cplusplus _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
