From 86a05d38bbbaeaea680d821e0fc5f2da577b5c3a Mon Sep 17 00:00:00 2001 From: Hugues Delorme Date: Fri, 13 Mar 2015 11:04:14 +0100 Subject: [PATCH] gmio_core: move some helper functions into internal/ This applies to gmio_stream and gmio_transfer helper functions --- src/gmio_core/internal/helper_stream.h | 56 +++++++++++++++++++ .../helper_transfer.h} | 15 ++++- src/gmio_core/internal/string_parse.c | 2 + src/gmio_core/stream.c | 40 ++----------- src/gmio_core/stream.h | 36 +----------- src/gmio_core/transfer.h | 23 -------- src/gmio_stl/stl_format.c | 1 + src/gmio_stl/stla_read.c | 1 + src/gmio_stl/stla_write.c | 2 + src/gmio_stl/stlb_read.c | 2 + src/gmio_stl/stlb_write.c | 2 + 11 files changed, 84 insertions(+), 96 deletions(-) create mode 100644 src/gmio_core/internal/helper_stream.h rename src/gmio_core/{transfer.c => internal/helper_transfer.h} (65%) diff --git a/src/gmio_core/internal/helper_stream.h b/src/gmio_core/internal/helper_stream.h new file mode 100644 index 0000000..dd3543e --- /dev/null +++ b/src/gmio_core/internal/helper_stream.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** GeomIO Library +** Copyright FougSys (2 Mar. 2015) +** contact@fougsys.fr +** +** This software is a reusable library whose purpose is to provide complete +** I/O support for various CAD file formats (eg. STL) +** +** This software is governed by the CeCILL-B license under French law and +** abiding by the rules of distribution of free software. You can use, +** modify and/ or redistribute the software under the terms of the CeCILL-B +** license as circulated by CEA, CNRS and INRIA at the following URL +** "http://www.cecill.info". +****************************************************************************/ + +/* WARNING : + * this header has no multi-inclusion guard. It must be included only once + * in the translation unit of use. The reason is that all functions + * defined here are meant to be inlined for performance purpose + */ + +#include "../stream.h" + +/*! Safe and convenient function for gmio_stream::at_end_func() */ +GMIO_INLINE gmio_bool_t gmio_stream_at_end(gmio_stream_t* stream) +{ + if (stream != NULL && stream->at_end_func != NULL) + return stream->at_end_func(stream->cookie); + return GMIO_FALSE; +} + +/*! Safe and convenient function for gmio_stream::error_func() */ +GMIO_INLINE int gmio_stream_error(gmio_stream_t* stream) +{ + if (stream != NULL && stream->error_func != NULL) + return stream->error_func(stream->cookie); + return 0; +} + +/*! Safe and convenient function for gmio_stream::read_func() */ +GMIO_INLINE size_t gmio_stream_read( + gmio_stream_t* stream, void *ptr, size_t size, size_t count) +{ + if (stream != NULL && stream->read_func != NULL) + return stream->read_func(stream->cookie, ptr, size, count); + return 0; +} + +/*! Safe and convenient function for gmio_stream::write_func() */ +GMIO_INLINE size_t gmio_stream_write( + gmio_stream_t* stream, const void *ptr, size_t size, size_t count) +{ + if (stream != NULL && stream->write_func != NULL) + return stream->write_func(stream->cookie, ptr, size, count); + return 0; +} diff --git a/src/gmio_core/transfer.c b/src/gmio_core/internal/helper_transfer.h similarity index 65% rename from src/gmio_core/transfer.c rename to src/gmio_core/internal/helper_transfer.h index 405ddd5..6a086cb 100644 --- a/src/gmio_core/transfer.c +++ b/src/gmio_core/internal/helper_transfer.h @@ -13,18 +13,27 @@ ** "http://www.cecill.info". ****************************************************************************/ -#include "transfer.h" +/* WARNING : + * this header has no multi-inclusion guard. It must be included only once + * in the translation unit of use. The reason is that all functions + * defined here are meant to be inlined for performance purpose + */ + +#include "../transfer.h" #include -gmio_bool_t gmio_transfer_is_stop_requested(const gmio_transfer_t* trsf) +/*! Safe and convenient function for gmio_transfer::is_stop_requested_func() */ +GMIO_INLINE gmio_bool_t gmio_transfer_is_stop_requested( + const gmio_transfer_t* trsf) { if (trsf != NULL && trsf->is_stop_requested_func != NULL) return trsf->is_stop_requested_func(trsf->cookie); return GMIO_FALSE; } -gmio_bool_t gmio_transfer_handle_progress( +/*! Safe and convenient function for gmio_transfer::handle_progress_func() */ +GMIO_INLINE void gmio_transfer_handle_progress( const gmio_transfer_t* trsf, size_t value, size_t max_value) { if (trsf != NULL && trsf->handle_progress_func != NULL) diff --git a/src/gmio_core/internal/string_parse.c b/src/gmio_core/internal/string_parse.c index bc76b90..3b7f27e 100644 --- a/src/gmio_core/internal/string_parse.c +++ b/src/gmio_core/internal/string_parse.c @@ -15,6 +15,8 @@ #include "string_parse.h" +#include "helper_stream.h" + #include #include #include diff --git a/src/gmio_core/stream.c b/src/gmio_core/stream.c index 24922ff..9c40b13 100644 --- a/src/gmio_core/stream.c +++ b/src/gmio_core/stream.c @@ -34,18 +34,14 @@ static int gmio_stream_stdio_error(void* cookie) return ferror((FILE*) cookie); } -static size_t gmio_stream_stdio_read(void* cookie, - void* ptr, - size_t item_size, - size_t item_count) +static size_t gmio_stream_stdio_read( + void* cookie, void* ptr, size_t item_size, size_t item_count) { return fread(ptr, item_size, item_count, (FILE*) cookie); } -static size_t gmio_stream_stdio_write(void* cookie, - const void* ptr, - size_t item_size, - size_t item_count) +static size_t gmio_stream_stdio_write( + void* cookie, const void* ptr, size_t item_size, size_t item_count) { return fwrite(ptr, item_size, item_count, (FILE*) cookie); } @@ -58,31 +54,3 @@ void gmio_stream_set_stdio(gmio_stream_t* stream, FILE* file) stream->read_func = gmio_stream_stdio_read; stream->write_func = gmio_stream_stdio_write; } - -gmio_bool_t gmio_stream_at_end(gmio_stream_t* stream) -{ - if (stream != NULL && stream->at_end_func != NULL) - return stream->at_end_func(stream->cookie); - return GMIO_FALSE; -} - -int gmio_stream_error(gmio_stream_t* stream) -{ - if (stream != NULL && stream->error_func != NULL) - return stream->error_func(stream->cookie); - return 0; -} - -size_t gmio_stream_read(gmio_stream_t* stream, void *ptr, size_t size, size_t count) -{ - if (stream != NULL && stream->read_func != NULL) - return stream->read_func(stream->cookie, ptr, size, count); - return 0; -} - -size_t gmio_stream_write(gmio_stream_t* stream, const void *ptr, size_t size, size_t count) -{ - if (stream != NULL && stream->write_func != NULL) - return stream->write_func(stream->cookie, ptr, size, count); - return 0; -} diff --git a/src/gmio_core/stream.h b/src/gmio_core/stream.h index 4a535e9..d289eba 100644 --- a/src/gmio_core/stream.h +++ b/src/gmio_core/stream.h @@ -23,8 +23,6 @@ #include "global.h" #include -GMIO_C_LINKAGE_BEGIN - /*! Stream that can get input from an arbitrary data source or can write * output to an arbitrary data sink. * @@ -93,6 +91,8 @@ struct gmio_stream typedef struct gmio_stream gmio_stream_t; +GMIO_C_LINKAGE_BEGIN + /* Initialization */ /*! Installs a null stream */ @@ -101,38 +101,6 @@ GMIO_LIB_EXPORT void gmio_stream_set_null(gmio_stream_t* stream); /*! Configures \p stream for standard FILE* (cookie will hold \p file) */ GMIO_LIB_EXPORT void gmio_stream_set_stdio(gmio_stream_t* stream, FILE* file); -/* Services */ - -/*! Safe and convenient function for gmio_stream::at_end_func() - * - * Same as: \code stream->at_end_func(stream->cookie) \endcode - */ -GMIO_LIB_EXPORT gmio_bool_t gmio_stream_at_end(gmio_stream_t* stream); - -/*! Safe and convenient function for gmio_stream::error_func() - * - * Same as: \code stream->error_func(stream->cookie) \endcode - */ -GMIO_LIB_EXPORT int gmio_stream_error(gmio_stream_t* stream); - -/*! Safe and convenient function for gmio_stream::read_func() - * - * Same as: \code stream->read_func(stream->cookie) \endcode - */ -GMIO_LIB_EXPORT size_t gmio_stream_read(gmio_stream_t* stream, - void* ptr, - size_t size, - size_t count); - -/*! Safe and convenient function for gmio_stream::write_func() - * - * Same as: \code stream->write_func(stream->cookie) \endcode - */ -GMIO_LIB_EXPORT size_t gmio_stream_write(gmio_stream_t* stream, - const void* ptr, - size_t size, - size_t count); - GMIO_C_LINKAGE_END #endif /* GMIO_STREAM_H */ diff --git a/src/gmio_core/transfer.h b/src/gmio_core/transfer.h index 35bac92..e4df3b2 100644 --- a/src/gmio_core/transfer.h +++ b/src/gmio_core/transfer.h @@ -23,8 +23,6 @@ #include "global.h" #include "stream.h" -GMIO_C_LINKAGE_BEGIN - /*! Defines objects required for any transfer(read/write) operation */ struct gmio_transfer { @@ -62,25 +60,4 @@ struct gmio_transfer typedef struct gmio_transfer gmio_transfer_t; -/*! Safe and convenient function for gmio_transfer::is_stop_requested_func() - * - * Same as: \code trsf->is_stop_requested_func(trsf->cookie) \endcode - * - * TODO: don't export, move to gmio_core/internal - */ -GMIO_LIB_EXPORT -gmio_bool_t gmio_transfer_is_stop_requested(const gmio_transfer_t* trsf); - -/*! Safe and convenient function for gmio_transfer::handle_progress_func() - * - * Same as: \code trsf->handle_progress_func(trsf->cookie, v, maxv) \endcode - * - * TODO: don't export, move to gmio_core/internal - */ -GMIO_LIB_EXPORT -gmio_bool_t gmio_transfer_handle_progress( - const gmio_transfer_t* trsf, size_t value, size_t max_value); - -GMIO_C_LINKAGE_END - #endif /* GMIO_TRANSFER_H */ diff --git a/src/gmio_stl/stl_format.c b/src/gmio_stl/stl_format.c index 821a5aa..245ecd1 100644 --- a/src/gmio_stl/stl_format.c +++ b/src/gmio_stl/stl_format.c @@ -20,6 +20,7 @@ #include "../gmio_core/endian.h" #include "../gmio_core/internal/byte_codec.h" #include "../gmio_core/internal/byte_swap.h" +#include "../gmio_core/internal/helper_stream.h" #include "../gmio_core/internal/min_max.h" #include diff --git a/src/gmio_stl/stla_read.c b/src/gmio_stl/stla_read.c index 14c6413..c6d1e19 100644 --- a/src/gmio_stl/stla_read.c +++ b/src/gmio_stl/stla_read.c @@ -21,6 +21,7 @@ #include "internal/stl_rw_common.h" #include "../gmio_core/error.h" +#include "../gmio_core/internal/helper_transfer.h" #include "../gmio_core/internal/string_parse.h" #include diff --git a/src/gmio_stl/stla_write.c b/src/gmio_stl/stla_write.c index 81a95c5..50c4f43 100644 --- a/src/gmio_stl/stla_write.c +++ b/src/gmio_stl/stla_write.c @@ -21,6 +21,8 @@ #include "stl_error.h" #include "../gmio_core/error.h" +#include "../gmio_core/internal/helper_stream.h" +#include "../gmio_core/internal/helper_transfer.h" #include "../gmio_core/internal/min_max.h" #include "../gmio_core/internal/safe_cast.h" diff --git a/src/gmio_stl/stlb_read.c b/src/gmio_stl/stlb_read.c index f709e5e..a3ffddf 100644 --- a/src/gmio_stl/stlb_read.c +++ b/src/gmio_stl/stlb_read.c @@ -26,6 +26,8 @@ #include "../gmio_core/internal/byte_swap.h" #include "../gmio_core/internal/convert.h" #include "../gmio_core/internal/safe_cast.h" +#include "../gmio_core/internal/helper_stream.h" +#include "../gmio_core/internal/helper_transfer.h" #include diff --git a/src/gmio_stl/stlb_write.c b/src/gmio_stl/stlb_write.c index c03ac39..8ebe3c9 100644 --- a/src/gmio_stl/stlb_write.c +++ b/src/gmio_stl/stlb_write.c @@ -26,6 +26,8 @@ #include "../gmio_core/internal/byte_codec.h" #include "../gmio_core/internal/min_max.h" #include "../gmio_core/internal/safe_cast.h" +#include "../gmio_core/internal/helper_stream.h" +#include "../gmio_core/internal/helper_transfer.h" #include