gmio_core: move some helper functions into internal/
This applies to gmio_stream and gmio_transfer helper functions
This commit is contained in:
parent
9ecdd222ea
commit
86a05d38bb
56
src/gmio_core/internal/helper_stream.h
Normal file
56
src/gmio_core/internal/helper_stream.h
Normal file
@ -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;
|
||||
}
|
@ -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 <stddef.h>
|
||||
|
||||
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)
|
@ -15,6 +15,8 @@
|
||||
|
||||
#include "string_parse.h"
|
||||
|
||||
#include "helper_stream.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -23,8 +23,6 @@
|
||||
#include "global.h"
|
||||
#include <stdio.h>
|
||||
|
||||
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 */
|
||||
|
@ -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 */
|
||||
|
@ -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 <ctype.h>
|
||||
|
@ -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 <ctype.h>
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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 <string.h>
|
||||
|
||||
|
@ -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 <string.h>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user