2015-03-03 00:38:33 +08:00
|
|
|
/****************************************************************************
|
2015-05-28 15:40:24 +08:00
|
|
|
** gmio
|
2015-05-01 00:19:45 +08:00
|
|
|
** Copyright Fougue (2 Mar. 2015)
|
2015-03-03 00:38:33 +08:00
|
|
|
** 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
|
2015-03-30 15:05:25 +08:00
|
|
|
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
2015-03-03 00:38:33 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
2015-03-05 01:25:51 +08:00
|
|
|
/*! \file stream.h
|
|
|
|
* Declaration of gmio_stream and utility functions
|
|
|
|
*/
|
|
|
|
|
2014-03-28 23:33:35 +08:00
|
|
|
#ifndef GMIO_STREAM_H
|
|
|
|
#define GMIO_STREAM_H
|
2013-01-11 01:48:46 +08:00
|
|
|
|
2013-01-16 00:56:24 +08:00
|
|
|
#include "global.h"
|
2013-03-03 04:51:08 +08:00
|
|
|
#include <stdio.h>
|
2013-01-11 01:48:46 +08:00
|
|
|
|
2015-03-03 18:35:15 +08:00
|
|
|
/*! Stream that can get input from an arbitrary data source or can write
|
|
|
|
* output to an arbitrary data sink.
|
2014-11-21 18:39:23 +08:00
|
|
|
*
|
|
|
|
* It can be seen as generalization of the standard \c FILE*, and is pretty
|
|
|
|
* much the same as [custom streams]
|
|
|
|
* (http://www.gnu.org/software/libc/manual/html_mono/libc.html#Custom-Streams)
|
|
|
|
* in the GNU C Library
|
|
|
|
*
|
2015-03-03 18:35:15 +08:00
|
|
|
* It uses a cookie being basically an opaque pointer on a hidden data type.
|
|
|
|
*
|
2014-11-21 18:39:23 +08:00
|
|
|
* The custom stream is implemented by defining hook functions that know how
|
|
|
|
* to read/write the data.
|
2014-01-21 17:51:23 +08:00
|
|
|
*/
|
2014-03-28 23:33:35 +08:00
|
|
|
struct gmio_stream
|
2013-01-11 01:48:46 +08:00
|
|
|
{
|
2015-03-03 18:35:15 +08:00
|
|
|
/*! Opaque pointer on the user stream, passed as first argument to
|
|
|
|
* hook functions */
|
2015-03-03 17:35:36 +08:00
|
|
|
void* cookie;
|
2014-01-21 17:51:23 +08:00
|
|
|
|
2015-03-03 18:35:15 +08:00
|
|
|
/*! Pointer on a function that checks end-of-stream indicator
|
|
|
|
*
|
|
|
|
* Checks whether the end-of-stream indicator associated with stream
|
|
|
|
* pointed by \p cookie is set, returning GMIO_TRUE if is.
|
|
|
|
*
|
|
|
|
* The function should behaves like C standard [feof()]
|
|
|
|
* (http://pubs.opengroup.org/onlinepubs/007904975/functions/feof.html)
|
|
|
|
*/
|
2015-07-10 17:33:05 +08:00
|
|
|
gmio_bool_t (*func_at_end)(void* cookie);
|
2014-02-13 18:18:46 +08:00
|
|
|
|
2015-03-03 18:35:15 +08:00
|
|
|
/*! Pointer on a function that checks error indicator
|
|
|
|
*
|
|
|
|
* Checks if the error indicator associated with stream pointed by
|
|
|
|
* \p cookie is set, returning a value different from zero if it is.
|
|
|
|
*
|
|
|
|
* The function should behaves like C standard [ferror()]
|
|
|
|
* (http://pubs.opengroup.org/onlinepubs/007904975/functions/ferror.html)
|
|
|
|
*/
|
2015-07-10 17:33:05 +08:00
|
|
|
int (*func_error)(void* cookie);
|
2014-11-21 18:39:23 +08:00
|
|
|
|
2015-03-03 18:35:15 +08:00
|
|
|
/*! Pointer on a function that reads block of data from stream
|
|
|
|
*
|
|
|
|
* Reads an array of \p count elements, each one with a size of
|
|
|
|
* \p size bytes, from the stream pointed by \p cookie and stores them in
|
|
|
|
* the block of memory specified by \p ptr
|
|
|
|
*
|
|
|
|
* The function should behaves like C standard [fread()]
|
|
|
|
* (http://pubs.opengroup.org/onlinepubs/007904975/functions/fread.html)
|
|
|
|
*
|
|
|
|
* \returns The total number of elements successfully read
|
|
|
|
*/
|
2015-07-10 17:33:05 +08:00
|
|
|
size_t (*func_read)(void* cookie, void* ptr, size_t size, size_t count);
|
2014-11-21 18:39:23 +08:00
|
|
|
|
2015-03-03 18:35:15 +08:00
|
|
|
/*! Pointer on a function that writes block of data to stream
|
|
|
|
*
|
|
|
|
* Writes an array of \p count elements, each one with a size of
|
|
|
|
* \p size bytes, from the block of memory pointed by \p ptr to the current
|
|
|
|
* position in the stream pointed by \p cookie
|
|
|
|
*
|
|
|
|
* The function should behaves like C standard [fwrite()]
|
|
|
|
* (http://pubs.opengroup.org/onlinepubs/007904975/functions/fwrite.html)
|
|
|
|
*
|
|
|
|
* \returns The total number of elements successfully written
|
|
|
|
*/
|
2015-07-10 17:33:05 +08:00
|
|
|
size_t (*func_write)(void* cookie, const void* ptr, size_t size, size_t count);
|
2015-03-24 01:15:31 +08:00
|
|
|
|
2015-03-30 23:26:11 +08:00
|
|
|
/*! Pointer on a function that returns the size(in bytes) of the stream */
|
2015-07-10 17:33:05 +08:00
|
|
|
size_t (*func_size)(void* cookie);
|
2015-03-24 01:15:31 +08:00
|
|
|
|
2015-03-30 23:26:11 +08:00
|
|
|
/*! Pointer on a function that moves the position indicator within the
|
2015-03-30 23:50:27 +08:00
|
|
|
* stream to the beginning
|
|
|
|
*
|
|
|
|
* The function should behaves like C standard [rewind()]
|
|
|
|
* (http://pubs.opengroup.org/onlinepubs/007904975/functions/rewind.html)
|
|
|
|
*/
|
2015-07-10 17:33:05 +08:00
|
|
|
void (*func_rewind)(void* cookie);
|
2014-02-13 18:18:46 +08:00
|
|
|
};
|
|
|
|
|
2014-03-28 23:33:35 +08:00
|
|
|
typedef struct gmio_stream gmio_stream_t;
|
2013-01-11 01:48:46 +08:00
|
|
|
|
2015-03-13 18:04:14 +08:00
|
|
|
GMIO_C_LINKAGE_BEGIN
|
|
|
|
|
2013-03-27 20:00:48 +08:00
|
|
|
/* Initialization */
|
|
|
|
|
2015-03-19 23:34:53 +08:00
|
|
|
/*! Returns a null stream */
|
|
|
|
GMIO_LIB_EXPORT gmio_stream_t gmio_stream_null();
|
|
|
|
|
|
|
|
/*! Returns a stream for standard FILE* (cookie will hold \p file) */
|
|
|
|
GMIO_LIB_EXPORT gmio_stream_t gmio_stream_stdio(FILE* file);
|
|
|
|
|
2014-03-28 23:33:35 +08:00
|
|
|
GMIO_C_LINKAGE_END
|
2014-03-13 22:57:04 +08:00
|
|
|
|
2014-03-28 23:33:35 +08:00
|
|
|
#endif /* GMIO_STREAM_H */
|