diff --git a/include/libdivecomputer/Makefile.am b/include/libdivecomputer/Makefile.am index 006567f..e4ff00b 100644 --- a/include/libdivecomputer/Makefile.am +++ b/include/libdivecomputer/Makefile.am @@ -4,6 +4,7 @@ libdivecomputer_HEADERS = \ common.h \ utils.h \ buffer.h \ + iterator.h \ device.h \ parser.h \ datetime.h \ diff --git a/include/libdivecomputer/common.h b/include/libdivecomputer/common.h index 55ee67f..ab827b5 100644 --- a/include/libdivecomputer/common.h +++ b/include/libdivecomputer/common.h @@ -28,6 +28,7 @@ extern "C" { typedef enum dc_status_t { DC_STATUS_SUCCESS = 0, + DC_STATUS_DONE = 1, DC_STATUS_UNSUPPORTED = -1, DC_STATUS_INVALIDARGS = -2, DC_STATUS_NOMEMORY = -3, diff --git a/include/libdivecomputer/iterator.h b/include/libdivecomputer/iterator.h new file mode 100644 index 0000000..aabe1bf --- /dev/null +++ b/include/libdivecomputer/iterator.h @@ -0,0 +1,42 @@ +/* + * libdivecomputer + * + * Copyright (C) 2012 Jef Driesen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#ifndef DC_ITERATOR_H +#define DC_ITERATOR_H + +#include "common.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef struct dc_iterator_t dc_iterator_t; + +dc_status_t +dc_iterator_next (dc_iterator_t *iterator, void *item); + +dc_status_t +dc_iterator_free (dc_iterator_t *iterator); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* DC_ITERATOR_H */ diff --git a/src/Makefile.am b/src/Makefile.am index 949fb68..17a213b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,6 +11,7 @@ libdivecomputer_la_LDFLAGS = \ libdivecomputer_la_SOURCES = \ version.c \ + iterator-private.h iterator.c \ device-private.h device.c \ parser-private.h parser.c \ datetime.c \ diff --git a/src/iterator-private.h b/src/iterator-private.h new file mode 100644 index 0000000..105d40f --- /dev/null +++ b/src/iterator-private.h @@ -0,0 +1,45 @@ +/* + * libdivecomputer + * + * Copyright (C) 2012 Jef Driesen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#ifndef DC_ITERATOR_PRIVATE_H +#define DC_ITERATOR_PRIVATE_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef struct dc_iterator_vtable_t dc_iterator_vtable_t; + +struct dc_iterator_t { + const dc_iterator_vtable_t *vtable; +}; + +struct dc_iterator_vtable_t { + dc_status_t (*free) (dc_iterator_t *iterator); + dc_status_t (*next) (dc_iterator_t *iterator, void *item); +}; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* DC_ITERATOR_PRIVATE_H */ diff --git a/src/iterator.c b/src/iterator.c new file mode 100644 index 0000000..100f85a --- /dev/null +++ b/src/iterator.c @@ -0,0 +1,52 @@ +/* + * libdivecomputer + * + * Copyright (C) 2012 Jef Driesen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#include +#include + +#include "iterator-private.h" + +dc_status_t +dc_iterator_next (dc_iterator_t *iterator, void *item) +{ + if (iterator == NULL) + return DC_STATUS_UNSUPPORTED; + + if (iterator->vtable->next == NULL) + return DC_STATUS_UNSUPPORTED; + + if (item == NULL) + return DC_STATUS_INVALIDARGS; + + return iterator->vtable->next (iterator, item); +} + +dc_status_t +dc_iterator_free (dc_iterator_t *iterator) +{ + if (iterator == NULL) + return DC_STATUS_SUCCESS; + + if (iterator->vtable->free == NULL) + return DC_STATUS_UNSUPPORTED; + + return iterator->vtable->free (iterator); +} diff --git a/src/libdivecomputer.symbols b/src/libdivecomputer.symbols index ffe063a..6a07a74 100644 --- a/src/libdivecomputer.symbols +++ b/src/libdivecomputer.symbols @@ -17,6 +17,9 @@ dc_datetime_localtime dc_datetime_gmtime dc_datetime_mktime +dc_iterator_next +dc_iterator_free + dc_parser_get_type dc_parser_set_data dc_parser_get_datetime