summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/rpmps.c44
-rw-r--r--lib/rpmps.h35
2 files changed, 79 insertions, 0 deletions
diff --git a/lib/rpmps.c b/lib/rpmps.c
index 8e991e6d0..d536c17d9 100644
--- a/lib/rpmps.c
+++ b/lib/rpmps.c
@@ -40,6 +40,50 @@ int rpmpsNumProblems(rpmps ps)
return numProblems;
}
+rpmpsi rpmpsInitIterator(rpmps ps)
+{
+ rpmpsi psi = NULL;
+ if (ps != NULL) {
+ psi = xcalloc(1, sizeof(*psi));
+ psi->ps = rpmpsLink(ps, "iter ref");
+ psi->ix = -1;
+ }
+ return psi;
+}
+
+rpmpsi rpmpsFreeIterator(rpmpsi psi)
+{
+ if (psi != NULL) {
+ rpmpsUnlink(psi->ps, "iter unref");
+ free(psi);
+ psi = NULL;
+ }
+ return psi;
+}
+
+int rpmpsNextIterator(rpmpsi psi)
+{
+ int i = -1;
+
+ if (psi != NULL && ++psi->ix >= 0) {
+ if (psi->ix < rpmpsNumProblems(psi->ps)) {
+ i = psi->ix;
+ } else {
+ psi->ix = -1;
+ }
+ }
+ return i;
+}
+
+rpmProblem rpmpsProblem(rpmpsi psi)
+{
+ rpmProblem p = NULL;
+ if (psi != NULL && psi->ix >= 0 && psi->ix < rpmpsNumProblems(psi->ps)) {
+ p = psi->ps->probs + psi->ix;
+ }
+ return p;
+}
+
rpmps rpmpsCreate(void)
{
rpmps ps = xcalloc(1, sizeof(*ps));
diff --git a/lib/rpmps.h b/lib/rpmps.h
index b0c591be4..35fc34e5e 100644
--- a/lib/rpmps.h
+++ b/lib/rpmps.h
@@ -24,6 +24,8 @@ typedef struct rpmProblem_s * rpmProblem;
*/
typedef struct rpmps_s * rpmps;
+typedef struct rpmpsi_s * rpmpsi;
+
/**
* Enumerate transaction set problem types.
*/
@@ -62,6 +64,11 @@ struct rpmps_s {
int nrefs; /*!< Reference count. */
};
+struct rpmpsi_s {
+ size_t ix;
+ rpmps ps;
+};
+
/**
* Return formatted string representation of a problem.
* @param prob rpm problem
@@ -104,6 +111,34 @@ rpmps XrpmpsLink (rpmps ps,
int rpmpsNumProblems(rpmps ps);
/**
+ * Initialize problem set iterator.
+ * @param ps problem set
+ * @return problem set iterator
+ */
+rpmpsi rpmpsInitIterator(rpmps ps);
+
+/**
+ * Destroy problem set iterator.
+ * @param psi problem set iterator
+ * @return problem set iterator (NULL)
+ */
+rpmpsi rpmpsFreeIterator(rpmpsi psi);
+
+/**
+ * Return next problem set iterator index
+ * @param psi problem set iterator
+ * @return iterator index, -1 on termination
+ */
+int rpmpsNextIterator(rpmpsi psi);
+
+/**
+ * Return current problem from problem set
+ * @param psi problem set iterator
+ * @return current rpmProblem
+ */
+rpmProblem rpmpsProblem(rpmpsi psi);
+
+/**
* Create a problem set.
* @return new problem set
*/