libdc/src/parser-private.h
Jef Driesen ff29d218bb Use helper functions to allocate and free objects.
Both the allocation and initialization of the object data structure is
now moved to a single function. The corresponding deallocation function
is intended to free objects that have been allocated, but are not fully
initialized yet. The public cleanup function shouldn't be used in such
case, because it may try to release resources that haven't been
initialized yet.
2016-01-05 20:40:21 +01:00

83 lines
2.2 KiB
C

/*
* libdivecomputer
*
* Copyright (C) 2008 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 PARSER_PRIVATE_H
#define PARSER_PRIVATE_H
#include <libdivecomputer/context.h>
#include <libdivecomputer/parser.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
struct dc_parser_t;
struct dc_parser_vtable_t;
typedef struct dc_parser_vtable_t dc_parser_vtable_t;
struct dc_parser_t {
const dc_parser_vtable_t *vtable;
dc_context_t *context;
const unsigned char *data;
unsigned int size;
};
struct dc_parser_vtable_t {
size_t size;
dc_family_t type;
dc_status_t (*set_data) (dc_parser_t *parser, const unsigned char *data, unsigned int size);
dc_status_t (*datetime) (dc_parser_t *parser, dc_datetime_t *datetime);
dc_status_t (*field) (dc_parser_t *parser, dc_field_type_t type, unsigned int flags, void *value);
dc_status_t (*samples_foreach) (dc_parser_t *parser, dc_sample_callback_t callback, void *userdata);
dc_status_t (*destroy) (dc_parser_t *parser);
};
dc_parser_t *
dc_parser_allocate (dc_context_t *context, const dc_parser_vtable_t *vtable);
void
dc_parser_deallocate (dc_parser_t *parser);
int
dc_parser_isinstance (dc_parser_t *parser, const dc_parser_vtable_t *vtable);
typedef struct sample_statistics_t {
unsigned int divetime;
double maxdepth;
} sample_statistics_t;
#define SAMPLE_STATISTICS_INITIALIZER {0, 0.0}
void
sample_statistics_cb (dc_sample_type_t type, dc_sample_value_t value, void *userdata);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* PARSER_PRIVATE_H */