1 /* messages.c - Iterator for a set of messages
3 * Copyright © 2009 Carl Worth
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see http://www.gnu.org/licenses/ .
18 * Author: Carl Worth <cworth@cworth.org>
21 #include "notmuch-private.h"
23 #include <glib.h> /* GList */
25 typedef struct _message_list {
26 notmuch_message_t *message;
27 struct _message_list *next;
30 struct _notmuch_messages {
32 message_list_t **tail;
35 /* Create a new notmuch_messages_t object, with 'ctx' as its talloc owner.
37 * This function can return NULL in case of out-of-memory.
40 _notmuch_messages_create (void *ctx)
42 notmuch_messages_t *messages;
44 messages = talloc (ctx, notmuch_messages_t);
45 if (unlikely (messages == NULL))
48 messages->head = NULL;
49 messages->tail = &messages->head;
54 /* Add a new message to 'messages'.
57 _notmuch_messages_add_message (notmuch_messages_t *messages,
58 notmuch_message_t *message)
60 message_list_t *new = talloc (messages, message_list_t);
62 new->message = message;
65 *(messages->tail) = new;
66 messages->tail = &new->next;
70 notmuch_messages_has_more (notmuch_messages_t *messages)
72 return messages->head != NULL;
76 notmuch_messages_get (notmuch_messages_t *messages)
78 if (messages->head == NULL)
81 return messages->head->message;
85 notmuch_messages_advance (notmuch_messages_t *messages)
87 if (messages->head == NULL)
90 messages->head = messages->head->next;
94 notmuch_messages_destroy (notmuch_messages_t *messages)
96 talloc_free (messages);