|
Packit |
f228a3 |
/*
|
|
Packit |
f228a3 |
* collection.h
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* Copyright (C) 2009 Hector Martin <hector@marcansoft.com>
|
|
Packit |
f228a3 |
* Copyright (C) 2009 Nikias Bassen <nikias@gmx.li>
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
f228a3 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
f228a3 |
* License as published by the Free Software Foundation; either
|
|
Packit |
f228a3 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
f228a3 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
f228a3 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
f228a3 |
* Lesser General Public License for more details.
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
f228a3 |
* License along with this library; if not, write to the Free Software
|
|
Packit |
f228a3 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit |
f228a3 |
*/
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
#ifndef COLLECTION_H
|
|
Packit |
f228a3 |
#define COLLECTION_H
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
struct collection {
|
|
Packit |
f228a3 |
void **list;
|
|
Packit |
f228a3 |
int capacity;
|
|
Packit |
f228a3 |
};
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
void collection_init(struct collection *col);
|
|
Packit |
f228a3 |
void collection_add(struct collection *col, void *element);
|
|
Packit |
f228a3 |
void collection_remove(struct collection *col, void *element);
|
|
Packit |
f228a3 |
int collection_count(struct collection *col);
|
|
Packit |
f228a3 |
void collection_free(struct collection *col);
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
#define FOREACH(var, col) \
|
|
Packit |
f228a3 |
do { \
|
|
Packit |
f228a3 |
int _iter; \
|
|
Packit |
f228a3 |
for(_iter=0; _iter<(col)->capacity; _iter++) { \
|
|
Packit |
f228a3 |
if(!(col)->list[_iter]) continue; \
|
|
Packit |
f228a3 |
var = (col)->list[_iter];
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
#define ENDFOREACH \
|
|
Packit |
f228a3 |
} \
|
|
Packit |
f228a3 |
} while(0);
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
#endif
|