tox-weechat/src/twc-list.h

89 lines
2.2 KiB
C
Raw Normal View History

2014-09-28 03:29:34 +02:00
/*
* Copyright (c) 2014 Håvard Pettersson <haavard.pettersson@gmail.com>
*
* This file is part of Tox-WeeChat.
*
* Tox-WeeChat 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 3 of the License, or
* (at your option) any later version.
*
* Tox-WeeChat 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 Tox-WeeChat. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TOX_WEECHAT_LIST_H
#define TOX_WEECHAT_LIST_H
#include <stdlib.h>
struct t_twc_list
{
size_t count;
struct t_twc_list_item *head;
struct t_twc_list_item *tail;
};
struct t_twc_list_item
{
struct t_twc_list *list;
// don't know if this is a good idea
// probably not
union
{
void *data;
struct t_twc_profile *profile;
struct t_twc_friend_request *friend_request;
2014-10-04 21:42:30 +02:00
struct t_twc_group_chat_invite *group_chat_invite;
2014-09-28 03:29:34 +02:00
struct t_twc_chat *chat;
struct t_twc_queued_message *queued_message;
};
struct t_twc_list_item *next_item;
struct t_twc_list_item *prev_item;
};
struct t_twc_list *
twc_list_new();
struct t_twc_list_item *
twc_list_item_new();
struct t_twc_list_item *
twc_list_item_new_data(const void *data);
struct t_twc_list_item *
twc_list_item_new_add(struct t_twc_list *list);
struct t_twc_list_item *
twc_list_item_new_data_add(struct t_twc_list *list, const void *data);
void
twc_list_add(struct t_twc_list *list, struct t_twc_list_item *item);
void *
twc_list_remove(struct t_twc_list_item *item);
void
twc_list_remove_with_data(struct t_twc_list *list, const void *data);
void *
twc_list_pop(struct t_twc_list *list);
struct t_twc_list_item *
twc_list_get(struct t_twc_list *list, size_t index);
#define twc_list_foreach(list, index, item) \
for (item = list->head, index = 0; \
item; \
item = item->next_item, ++index)
#endif // TOX_WEECHAT_LIST_H