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

commit 528bbc5f2d0b799afa9f1e046d2fb6a8e43b52b7
Author: Michel Hermier <herm...@frugalware.org>
Date:   Sun May 11 09:20:01 2014 +0200

libpacman: Introduce new libpacman list API, should be more independant to 
implementation than previous one.

diff --git a/doc/libpacman-changes.txt b/doc/libpacman-changes.txt
index a8153e3..192d890 100644
--- a/doc/libpacman-changes.txt
+++ b/doc/libpacman-changes.txt
@@ -64,6 +64,16 @@ pacman_download_tell: Access to current download size.

pacman_download_xfered: Access to a xfered download size.

+pacman_list_begin: Access to iterator at bigging of list.
+
+pacman_list_end: Access to iterator at end of list.
+
+pacman_list_iterator_free: Free a list iterator.
+
+pacman_list_iterator_getdata: Access to iterator data.
+
+pacman_list_iterator_next: Make iterator goes next.
+
pmdepmissing_t: is now public and deprecate PM_DEPMISS.

pmgrp_t: is now public and deprecate PM_GRP.
@@ -82,6 +92,8 @@ PM_TRANS_SYNCPKGS: Access to transaction syncpkgs list.

==== Symbols removed:

+pacman_list_begin, pacman_list_iterator_next, pacman_list_iterator_getdata: 
Removed in favor of the new lit iterator API.
+
PM_NETBUF, PM_OPT_DLETA_H, PM_OPT_DLETA_M, PM_OPT_DLETA_H, PM_OPT_DLOFFSET, 
PM_OPT_DLRATE, PM_OPT_DLT, PM_OPT_DLT0, PM_OPT_DLXFERED1: Removed due to code 
refactor so public API does not try to hide that it use libftp internal 
callback. See pacman_trans_cb_download changes.

PM_TRANS: Unused in the public API.
diff --git a/lib/libpacman/pacman.cpp b/lib/libpacman/pacman.cpp
index 6577a46..609a73c 100644
--- a/lib/libpacman/pacman.cpp
+++ b/lib/libpacman/pacman.cpp
@@ -1328,46 +1328,33 @@ int pacman_logaction(const char *format, ...)
* @{
*/

-/** Get the first element of a list.
+/** Get the iterator to biginning of a list.
* @param list the list
* @return the first element
*/
-pmlist_t *pacman_list_first(pmlist_t *list)
+pmlist_iterator_t *pacman_list_begin(pmlist_t *list)
{
-       return(list);
+       return c_cast(list);
}

-/** Get the next element of a list.
- * @param entry the list entry
- * @return the next element on success, NULL on error
- */
-pmlist_t *pacman_list_next(pmlist_t *entry)
-{
-       ASSERT(entry != NULL, return(NULL));
-
-       return(entry->next);
-}
-
-/** Get the data of a list entry.
- * @param entry the list entry
- * @return the data on success, NULL on error
+/** Get the iterator to end of a list.
+ * @param list the list
+ * @return the first element
*/
-void *pacman_list_getdata(pmlist_t *entry)
+pmlist_iterator_t *pacman_list_end(pmlist_t *list)
{
-       ASSERT(entry != NULL, return(NULL));
-
-       return(entry->data);
+       return NULL;
}

/** Free a list.
* @param entry list to free
* @return 0 on success, -1 on error
*/
-int pacman_list_free(pmlist_t *entry)
+int pacman_list_free(pmlist_t *list)
{
-       ASSERT(entry != NULL, return(-1));
+       ASSERT(list != NULL, return(-1));

-       FREELIST(entry);
+       FREELIST(list);

return(0);
}
@@ -1382,6 +1369,39 @@ int pacman_list_count(pmlist_t *list)

return(_pacman_list_count(list));
}
+
+/** Free a list iterator.
+ * @param iterator the iterator
+ * @return 0 on success, -1 on error
+ */
+int pacman_list_iterator_free(pmlist_iterator_t *iterator)
+{
+       ASSERT(iterator != NULL, return -1);
+
+       return 0;
+}
+
+/** Get the next element of a list.
+ * @param entry the list entry
+ * @return the next element on success, NULL on error
+ */
+pmlist_iterator_t *pacman_list_iterator_next(pmlist_iterator_t *iterator)
+{
+       ASSERT(iterator != NULL, return NULL);
+
+       return c_cast(cxx_cast(iterator)->next);
+}
+
+/** Get the data of a list iterator.
+ * @param entry the list entry
+ * @return the data on success, NULL on error
+ */
+void *pacman_list_iterator_getdata(pmlist_iterator_t *iterator)
+{
+       ASSERT(iterator != NULL, return NULL);
+
+       return cxx_cast(iterator)->data;
+}
/** @} */

/** @defgroup pacman_misc Miscellaneous Functions
diff --git a/lib/libpacman/pacman.h b/lib/libpacman/pacman.h
index 09a1fe9..1e5f027 100644
--- a/lib/libpacman/pacman.h
+++ b/lib/libpacman/pacman.h
@@ -54,6 +54,7 @@ typedef struct __pmdepmissing_t pmdepmissing_t;
typedef struct __pmdownload_t pmdownload_t;
typedef struct __pmgrp_t pmgrp_t;
typedef struct __pmlist_t pmlist_t;
+typedef struct __pmlist_iterator_t pmlist_iterator_t;
typedef struct __pmpkg_t pmpkg_t;
typedef struct __pmsyncpkg_t pmsyncpkg_t;

@@ -66,6 +67,10 @@ typedef struct __pmsyncpkg_t PM_SYNCPKG;
typedef struct __pmdepmissing_t PM_DEPMISS;
typedef struct __pmconflict_t PM_CONFLICT;

+#define pacman_list_first pacman_list_begin
+#define pacman_list_next pacman_list_iterator_next
+#define pacman_list_getdata pacman_list_iterator_getdata
+
/*
* Library
*/
@@ -436,12 +441,16 @@ void *pacman_conflict_getinfo(pmconflict_t*conflict, 
unsigned char parm);
*/

/* pmlist_t */
-pmlist_t *pacman_list_first(pmlist_t *list);
-pmlist_t *pacman_list_next(pmlist_t *entry);
-void *pacman_list_getdata(pmlist_t *entry);
+pmlist_iterator_t *pacman_list_begin(pmlist_t *list);
+pmlist_iterator_t *pacman_list_end(pmlist_t *list);
int pacman_list_free(pmlist_t *entry);
int pacman_list_count(pmlist_t *list);

+/* pmlist_iterator_t */
+int pacman_list_iterator_free(pmlist_iterator_t *iterator);
+pmlist_iterator_t *pacman_list_iterator_next(pmlist_iterator_t *iterator);
+void *pacman_list_iterator_getdata(pmlist_iterator_t *iterator);
+
/* md5sums */
char *pacman_get_md5sum(char *name);
char *pacman_get_sha1sum(char *name);
diff --git a/lib/libpacman/pacman_p.h b/lib/libpacman/pacman_p.h
index 2a177a4..3f85e76 100644
--- a/lib/libpacman/pacman_p.h
+++ b/lib/libpacman/pacman_p.h
@@ -24,7 +24,7 @@
#include "pacman.h"

#define DEFINE_CAST(c_type, cxx_type)  \
-       static c_type *c_cast(cxx_type *obj)   \
+static c_type *c_cast(cxx_type *obj)   \
{ return (c_type *)obj; }              \
\
static cxx_type *cxx_cast(c_type *obj) \
@@ -40,6 +40,7 @@ class Package;
}

DEFINE_CAST(struct __pmdb_t, libpacman::Database)
+DEFINE_CAST(struct __pmlist_iterator_t, struct __pmlist_t)
DEFINE_CAST(struct __pmgrp_t, libpacman::Group)
DEFINE_CAST(struct __pmhandle_t, libpacman::Handle)
DEFINE_CAST(struct __pmpkg_t, libpacman::Package)
_______________________________________________
Frugalware-git mailing list
Frugalware-git@frugalware.org
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to