Improve use of inlined functions
This commit is contained in:
parent
82f6386256
commit
0f3b8d1e59
@ -25,7 +25,7 @@
|
|||||||
# include <malloc.h>
|
# include <malloc.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
GMIO_INLINE static gmio_buffer_t gmio_buffer_null()
|
GMIO_INLINE gmio_buffer_t gmio_buffer_null()
|
||||||
{
|
{
|
||||||
gmio_buffer_t buff = { 0 };
|
gmio_buffer_t buff = { 0 };
|
||||||
return buff;
|
return buff;
|
||||||
|
@ -50,4 +50,12 @@ enum gmio_error
|
|||||||
|
|
||||||
typedef enum gmio_error gmio_error_t;
|
typedef enum gmio_error gmio_error_t;
|
||||||
|
|
||||||
|
/*! Returns true if <tt>code == GMIO_NO_ERROR</tt> */
|
||||||
|
GMIO_INLINE gmio_bool_t gmio_no_error(int code)
|
||||||
|
{ return code == GMIO_NO_ERROR; }
|
||||||
|
|
||||||
|
/*! Returns true if <tt>code != GMIO_NO_ERROR</tt> */
|
||||||
|
GMIO_INLINE gmio_bool_t gmio_error(int code)
|
||||||
|
{ return code != GMIO_NO_ERROR; }
|
||||||
|
|
||||||
#endif /* GMIO_ERROR_H */
|
#endif /* GMIO_ERROR_H */
|
||||||
|
@ -114,9 +114,11 @@ typedef double gmio_float64_t;
|
|||||||
|
|
||||||
#ifndef GMIO_INLINE
|
#ifndef GMIO_INLINE
|
||||||
# if defined(__GNUC__)
|
# if defined(__GNUC__)
|
||||||
# define GMIO_INLINE __inline__ /* Compatible with C90 */
|
# define GMIO_INLINE __inline__ static /* Compatible with C90 */
|
||||||
# elif defined(_MSC_VER)
|
# elif defined(_MSC_VER)
|
||||||
# define GMIO_INLINE __inline
|
# define GMIO_INLINE __inline static
|
||||||
|
# elif !defined(DOXYGEN)
|
||||||
|
# define GMIO_INLINE
|
||||||
# else
|
# else
|
||||||
/*! Expands to the C compiler specific inline keyword (if any) */
|
/*! Expands to the C compiler specific inline keyword (if any) */
|
||||||
# define GMIO_INLINE
|
# define GMIO_INLINE
|
||||||
|
@ -13,16 +13,13 @@
|
|||||||
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* WARNING :
|
#ifndef GMIO_INTERNAL_BYTE_CODEC_H
|
||||||
* this header has no multi-inclusion guard. It must be included only once
|
#define GMIO_INTERNAL_BYTE_CODEC_H
|
||||||
* in the translation unit of use. The reason is that all functions
|
|
||||||
* defined here are meant to be inlined for performance purpose
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "../global.h"
|
#include "../global.h"
|
||||||
|
|
||||||
/*! Reads a 16bit integer from memory-location \p bytes (little-endian) */
|
/*! Reads a 16bit integer from memory-location \p bytes (little-endian) */
|
||||||
GMIO_INLINE static uint16_t gmio_decode_uint16_le(const uint8_t* bytes)
|
GMIO_INLINE uint16_t gmio_decode_uint16_le(const uint8_t* bytes)
|
||||||
{
|
{
|
||||||
/* |0 |1 | */
|
/* |0 |1 | */
|
||||||
/* |BB|AA| -> 0xAABB */
|
/* |BB|AA| -> 0xAABB */
|
||||||
@ -30,7 +27,7 @@ GMIO_INLINE static uint16_t gmio_decode_uint16_le(const uint8_t* bytes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! Reads a 16bit integer from memory-location \p bytes (big-endian) */
|
/*! Reads a 16bit integer from memory-location \p bytes (big-endian) */
|
||||||
GMIO_INLINE static uint16_t gmio_decode_uint16_be(const uint8_t* bytes)
|
GMIO_INLINE uint16_t gmio_decode_uint16_be(const uint8_t* bytes)
|
||||||
{
|
{
|
||||||
/* |0 |1 | */
|
/* |0 |1 | */
|
||||||
/* |AA|BB| -> 0xAABB */
|
/* |AA|BB| -> 0xAABB */
|
||||||
@ -39,28 +36,28 @@ GMIO_INLINE static uint16_t gmio_decode_uint16_be(const uint8_t* bytes)
|
|||||||
|
|
||||||
/*! Writes 16bit integer \p val to the memory location at \p bytes in
|
/*! Writes 16bit integer \p val to the memory location at \p bytes in
|
||||||
* little-endian */
|
* little-endian */
|
||||||
GMIO_INLINE static void gmio_encode_uint16_le(uint16_t val, uint8_t* bytes)
|
GMIO_INLINE void gmio_encode_uint16_le(uint16_t val, uint8_t* bytes)
|
||||||
{
|
{
|
||||||
bytes[0] = val & 0xFF;
|
bytes[0] = val & 0xFF;
|
||||||
bytes[1] = (val >> 8) & 0xFF;
|
bytes[1] = (val >> 8) & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Reads a 32bit integer from memory-location \p bytes (little-endian) */
|
/*! Reads a 32bit integer from memory-location \p bytes (little-endian) */
|
||||||
GMIO_INLINE static uint32_t gmio_decode_uint32_le(const uint8_t* bytes)
|
GMIO_INLINE uint32_t gmio_decode_uint32_le(const uint8_t* bytes)
|
||||||
{
|
{
|
||||||
/* |DD|CC|BB|AA| -> 0xAABBCCDD */
|
/* |DD|CC|BB|AA| -> 0xAABBCCDD */
|
||||||
return bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24);
|
return bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Reads a 32bit integer from memory-location \p bytes (mixed-endian) */
|
/*! Reads a 32bit integer from memory-location \p bytes (mixed-endian) */
|
||||||
GMIO_INLINE static uint32_t gmio_decode_uint32_me(const uint8_t* bytes)
|
GMIO_INLINE uint32_t gmio_decode_uint32_me(const uint8_t* bytes)
|
||||||
{
|
{
|
||||||
/* |DD|CC|BB|AA| -> 0xCCDDAABB */
|
/* |DD|CC|BB|AA| -> 0xCCDDAABB */
|
||||||
return (bytes[0] << 16) | (bytes[1] << 24) | (bytes[3] << 8) | bytes[2];
|
return (bytes[0] << 16) | (bytes[1] << 24) | (bytes[3] << 8) | bytes[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Reads a 32bit integer from memory-location \p bytes (big-endian) */
|
/*! Reads a 32bit integer from memory-location \p bytes (big-endian) */
|
||||||
GMIO_INLINE static uint32_t gmio_decode_uint32_be(const uint8_t* bytes)
|
GMIO_INLINE uint32_t gmio_decode_uint32_be(const uint8_t* bytes)
|
||||||
{
|
{
|
||||||
/* |DD|CC|BB|AA| -> 0xDDCCBBAA */
|
/* |DD|CC|BB|AA| -> 0xDDCCBBAA */
|
||||||
return bytes[3] | (bytes[2] << 8) | (bytes[1] << 16) | (bytes[0] << 24);
|
return bytes[3] | (bytes[2] << 8) | (bytes[1] << 16) | (bytes[0] << 24);
|
||||||
@ -68,7 +65,7 @@ GMIO_INLINE static uint32_t gmio_decode_uint32_be(const uint8_t* bytes)
|
|||||||
|
|
||||||
/*! Writes 32bit integer \p val to the memory location at \p bytes in
|
/*! Writes 32bit integer \p val to the memory location at \p bytes in
|
||||||
* little-endian */
|
* little-endian */
|
||||||
GMIO_INLINE static void gmio_encode_uint32_le(uint32_t val, uint8_t* bytes)
|
GMIO_INLINE void gmio_encode_uint32_le(uint32_t val, uint8_t* bytes)
|
||||||
{
|
{
|
||||||
bytes[0] = val & 0xFF;
|
bytes[0] = val & 0xFF;
|
||||||
bytes[1] = (val >> 8) & 0xFF;
|
bytes[1] = (val >> 8) & 0xFF;
|
||||||
@ -78,10 +75,12 @@ GMIO_INLINE static void gmio_encode_uint32_le(uint32_t val, uint8_t* bytes)
|
|||||||
|
|
||||||
/*! Writes 32bit integer \p val to the memory location at \p bytes in
|
/*! Writes 32bit integer \p val to the memory location at \p bytes in
|
||||||
* big-endian */
|
* big-endian */
|
||||||
GMIO_INLINE static void gmio_encode_uint32_be(uint32_t val, uint8_t* bytes)
|
GMIO_INLINE void gmio_encode_uint32_be(uint32_t val, uint8_t* bytes)
|
||||||
{
|
{
|
||||||
bytes[0] = (val >> 24) & 0xFF;
|
bytes[0] = (val >> 24) & 0xFF;
|
||||||
bytes[1] = (val >> 16) & 0xFF;
|
bytes[1] = (val >> 16) & 0xFF;
|
||||||
bytes[2] = (val >> 8) & 0xFF;
|
bytes[2] = (val >> 8) & 0xFF;
|
||||||
bytes[3] = val & 0xFF;
|
bytes[3] = val & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* GMIO_INTERNAL_BYTE_CODEC_H */
|
||||||
|
@ -13,11 +13,8 @@
|
|||||||
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* WARNING :
|
#ifndef GMIO_INTERNAL_BYTE_SWAP_H
|
||||||
* this header has no multi-inclusion guard. It must be included only once
|
#define GMIO_INTERNAL_BYTE_SWAP_H
|
||||||
* in the translation unit of use. The reason is that all functions
|
|
||||||
* defined here are meant to be inlined for performance purpose
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "../global.h"
|
#include "../global.h"
|
||||||
|
|
||||||
@ -27,7 +24,7 @@
|
|||||||
|
|
||||||
/*! Returns \p val with the order of bytes reversed, uses compiler builtin
|
/*! Returns \p val with the order of bytes reversed, uses compiler builtin
|
||||||
* functions if available */
|
* functions if available */
|
||||||
GMIO_INLINE static uint16_t gmio_uint16_bswap(uint16_t val)
|
GMIO_INLINE uint16_t gmio_uint16_bswap(uint16_t val)
|
||||||
{
|
{
|
||||||
#ifdef GMIO_HAVE_GCC_BUILTIN_BSWAP16_FUNC
|
#ifdef GMIO_HAVE_GCC_BUILTIN_BSWAP16_FUNC
|
||||||
return __builtin_bswap16(val);
|
return __builtin_bswap16(val);
|
||||||
@ -40,7 +37,7 @@ GMIO_INLINE static uint16_t gmio_uint16_bswap(uint16_t val)
|
|||||||
|
|
||||||
/*! Returns \p val with the order of bytes reversed, uses compiler builtin
|
/*! Returns \p val with the order of bytes reversed, uses compiler builtin
|
||||||
* functions if available */
|
* functions if available */
|
||||||
GMIO_INLINE static uint32_t gmio_uint32_bswap(uint32_t val)
|
GMIO_INLINE uint32_t gmio_uint32_bswap(uint32_t val)
|
||||||
{
|
{
|
||||||
#ifdef GMIO_HAVE_GCC_BUILTIN_BSWAP32_FUNC
|
#ifdef GMIO_HAVE_GCC_BUILTIN_BSWAP32_FUNC
|
||||||
return __builtin_bswap32(val);
|
return __builtin_bswap32(val);
|
||||||
@ -54,3 +51,5 @@ GMIO_INLINE static uint32_t gmio_uint32_bswap(uint32_t val)
|
|||||||
| ((val >> 24) & 0x000000FF);
|
| ((val >> 24) & 0x000000FF);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* GMIO_INTERNAL_BYTE_SWAP_H */
|
||||||
|
@ -4,20 +4,17 @@
|
|||||||
* and irrXML.h
|
* and irrXML.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Adapted to ISO-C90.
|
/* Adapted to ISO-C90 */
|
||||||
*
|
|
||||||
* WARNING :
|
#ifndef GMIO_INTERNAL_FAST_ATOF_H
|
||||||
* this header has no multi-inclusion guard. It must be included only once
|
#define GMIO_INTERNAL_FAST_ATOF_H
|
||||||
* in the translation unit of use. The reason is that all functions
|
|
||||||
* defined here are meant to be inlined for performance purpose
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "../global.h"
|
#include "../global.h"
|
||||||
|
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
GMIO_INLINE static gmio_bool_t is_local_decimal_point(char in)
|
GMIO_INLINE gmio_bool_t is_local_decimal_point(char in)
|
||||||
{
|
{
|
||||||
/*! Selection of characters which count as decimal point in fast_atof
|
/*! Selection of characters which count as decimal point in fast_atof
|
||||||
* TODO: This should probably also be used in irr::core::string, but
|
* TODO: This should probably also be used in irr::core::string, but
|
||||||
@ -60,7 +57,7 @@ const float fast_atof_table[17] = {
|
|||||||
* \return The unsigned integer value of the digits. If the string specifies
|
* \return The unsigned integer value of the digits. If the string specifies
|
||||||
* too many digits to encode in an uint32_t then INT_MAX will be returned.
|
* too many digits to encode in an uint32_t then INT_MAX will be returned.
|
||||||
*/
|
*/
|
||||||
GMIO_INLINE static uint32_t strtoul10(const char* in, const char** out)
|
GMIO_INLINE uint32_t strtoul10(const char* in, const char** out)
|
||||||
{
|
{
|
||||||
gmio_bool_t overflow=GMIO_FALSE;
|
gmio_bool_t overflow=GMIO_FALSE;
|
||||||
uint32_t unsignedValue = 0;
|
uint32_t unsignedValue = 0;
|
||||||
@ -99,7 +96,7 @@ GMIO_INLINE static uint32_t strtoul10(const char* in, const char** out)
|
|||||||
* too many digits to encode in an int32_t then +INT_MAX or -INT_MAX will be
|
* too many digits to encode in an int32_t then +INT_MAX or -INT_MAX will be
|
||||||
* returned.
|
* returned.
|
||||||
*/
|
*/
|
||||||
GMIO_INLINE static int32_t strtol10(const char* in, const char** out)
|
GMIO_INLINE int32_t strtol10(const char* in, const char** out)
|
||||||
{
|
{
|
||||||
const gmio_bool_t negative = ('-' == *in);
|
const gmio_bool_t negative = ('-' == *in);
|
||||||
uint32_t unsignedValue = 0;
|
uint32_t unsignedValue = 0;
|
||||||
@ -136,7 +133,7 @@ GMIO_INLINE static int32_t strtol10(const char* in, const char** out)
|
|||||||
* \return The unsigned integer value of the digit. 0xffffffff if the input is
|
* \return The unsigned integer value of the digit. 0xffffffff if the input is
|
||||||
* not hex
|
* not hex
|
||||||
*/
|
*/
|
||||||
GMIO_INLINE static uint32_t ctoul16(char in)
|
GMIO_INLINE uint32_t ctoul16(char in)
|
||||||
{
|
{
|
||||||
if (in >= '0' && in <= '9')
|
if (in >= '0' && in <= '9')
|
||||||
return in - '0';
|
return in - '0';
|
||||||
@ -158,7 +155,7 @@ GMIO_INLINE static uint32_t ctoul16(char in)
|
|||||||
* \return The unsigned integer value of the digits. If the string specifies
|
* \return The unsigned integer value of the digits. If the string specifies
|
||||||
* too many digits to encode in an uint32_t then INT_MAX will be returned.
|
* too many digits to encode in an uint32_t then INT_MAX will be returned.
|
||||||
*/
|
*/
|
||||||
GMIO_INLINE static uint32_t strtoul16(const char* in, const char** out)
|
GMIO_INLINE uint32_t strtoul16(const char* in, const char** out)
|
||||||
{
|
{
|
||||||
gmio_bool_t overflow=GMIO_FALSE;
|
gmio_bool_t overflow=GMIO_FALSE;
|
||||||
uint32_t unsignedValue = 0;
|
uint32_t unsignedValue = 0;
|
||||||
@ -203,7 +200,7 @@ GMIO_INLINE static uint32_t strtoul16(const char* in, const char** out)
|
|||||||
* \return The unsigned integer value of the digits. If the string specifies
|
* \return The unsigned integer value of the digits. If the string specifies
|
||||||
* too many digits to encode in an uint32_t then INT_MAX will be returned.
|
* too many digits to encode in an uint32_t then INT_MAX will be returned.
|
||||||
*/
|
*/
|
||||||
GMIO_INLINE static uint32_t strtoul8(const char* in, const char** out)
|
GMIO_INLINE uint32_t strtoul8(const char* in, const char** out)
|
||||||
{
|
{
|
||||||
gmio_bool_t overflow=GMIO_FALSE;
|
gmio_bool_t overflow=GMIO_FALSE;
|
||||||
uint32_t unsignedValue = 0;
|
uint32_t unsignedValue = 0;
|
||||||
@ -245,7 +242,7 @@ GMIO_INLINE static uint32_t strtoul8(const char* in, const char** out)
|
|||||||
* \return The unsigned integer value of the digits. If the string specifies
|
* \return The unsigned integer value of the digits. If the string specifies
|
||||||
* too many digits to encode in an uint32_t then INT_MAX will be returned.
|
* too many digits to encode in an uint32_t then INT_MAX will be returned.
|
||||||
*/
|
*/
|
||||||
GMIO_INLINE static uint32_t strtoul_prefix(const char* in, const char** out)
|
GMIO_INLINE uint32_t strtoul_prefix(const char* in, const char** out)
|
||||||
{
|
{
|
||||||
if (!in)
|
if (!in)
|
||||||
{
|
{
|
||||||
@ -268,7 +265,7 @@ GMIO_INLINE static uint32_t strtoul_prefix(const char* in, const char** out)
|
|||||||
* \return The whole positive floating point representation of the digit
|
* \return The whole positive floating point representation of the digit
|
||||||
* sequence.
|
* sequence.
|
||||||
*/
|
*/
|
||||||
GMIO_INLINE static gmio_float32_t strtof10(const char* in, const char** out)
|
GMIO_INLINE gmio_float32_t strtof10(const char* in, const char** out)
|
||||||
{
|
{
|
||||||
const uint32_t MAX_SAFE_U32_VALUE = UINT_MAX / 10 - 10;
|
const uint32_t MAX_SAFE_U32_VALUE = UINT_MAX / 10 - 10;
|
||||||
uint32_t intValue = 0;
|
uint32_t intValue = 0;
|
||||||
@ -315,7 +312,7 @@ GMIO_INLINE static gmio_float32_t strtof10(const char* in, const char** out)
|
|||||||
* \return Pointer to the first character in the string that wasn't used
|
* \return Pointer to the first character in the string that wasn't used
|
||||||
* to create the float value.
|
* to create the float value.
|
||||||
*/
|
*/
|
||||||
GMIO_INLINE static const char* fast_atof_move(
|
GMIO_INLINE const char* fast_atof_move(
|
||||||
const char* in, gmio_float32_t* result)
|
const char* in, gmio_float32_t* result)
|
||||||
{
|
{
|
||||||
const gmio_bool_t negative = ('-' == *in);
|
const gmio_bool_t negative = ('-' == *in);
|
||||||
@ -360,7 +357,7 @@ GMIO_INLINE static const char* fast_atof_move(
|
|||||||
* wasn't used to create the float value.
|
* wasn't used to create the float value.
|
||||||
* \result Float value parsed from the input string
|
* \result Float value parsed from the input string
|
||||||
*/
|
*/
|
||||||
GMIO_INLINE static float fast_atof(const char* floatAsString, const char** out)
|
GMIO_INLINE float fast_atof(const char* floatAsString, const char** out)
|
||||||
{
|
{
|
||||||
float ret;
|
float ret;
|
||||||
if (out)
|
if (out)
|
||||||
@ -369,3 +366,5 @@ GMIO_INLINE static float fast_atof(const char* floatAsString, const char** out)
|
|||||||
fast_atof_move(floatAsString, &ret);
|
fast_atof_move(floatAsString, &ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* GMIO_INTERNAL_FAST_ATOF_H */
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
** 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/licences/Licence_CeCILL-B_V1-en.html".
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/* 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 "../error.h"
|
|
||||||
|
|
||||||
/*! Returns true if <tt>code == GMIO_NO_ERROR</tt> */
|
|
||||||
GMIO_INLINE static gmio_bool_t gmio_no_error(int code)
|
|
||||||
{
|
|
||||||
return code == GMIO_NO_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! Returns true if <tt>code != GMIO_NO_ERROR</tt> */
|
|
||||||
GMIO_INLINE static gmio_bool_t gmio_error(int code)
|
|
||||||
{
|
|
||||||
return code != GMIO_NO_ERROR;
|
|
||||||
}
|
|
@ -13,16 +13,13 @@
|
|||||||
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* WARNING :
|
#ifndef GMIO_INTERNAL_HELPER_STREAM_H
|
||||||
* this header has no multi-inclusion guard. It must be included only once
|
#define GMIO_INTERNAL_HELPER_STREAM_H
|
||||||
* 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"
|
#include "../stream.h"
|
||||||
|
|
||||||
/*! Safe and convenient function for gmio_stream::at_end_func() */
|
/*! Safe and convenient function for gmio_stream::at_end_func() */
|
||||||
GMIO_INLINE static gmio_bool_t gmio_stream_at_end(gmio_stream_t* stream)
|
GMIO_INLINE gmio_bool_t gmio_stream_at_end(gmio_stream_t* stream)
|
||||||
{
|
{
|
||||||
if (stream != NULL && stream->at_end_func != NULL)
|
if (stream != NULL && stream->at_end_func != NULL)
|
||||||
return stream->at_end_func(stream->cookie);
|
return stream->at_end_func(stream->cookie);
|
||||||
@ -30,7 +27,7 @@ GMIO_INLINE static gmio_bool_t gmio_stream_at_end(gmio_stream_t* stream)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! Safe and convenient function for gmio_stream::error_func() */
|
/*! Safe and convenient function for gmio_stream::error_func() */
|
||||||
GMIO_INLINE static int gmio_stream_error(gmio_stream_t* stream)
|
GMIO_INLINE int gmio_stream_error(gmio_stream_t* stream)
|
||||||
{
|
{
|
||||||
if (stream != NULL && stream->error_func != NULL)
|
if (stream != NULL && stream->error_func != NULL)
|
||||||
return stream->error_func(stream->cookie);
|
return stream->error_func(stream->cookie);
|
||||||
@ -38,7 +35,7 @@ GMIO_INLINE static int gmio_stream_error(gmio_stream_t* stream)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! Safe and convenient function for gmio_stream::read_func() */
|
/*! Safe and convenient function for gmio_stream::read_func() */
|
||||||
GMIO_INLINE static size_t gmio_stream_read(
|
GMIO_INLINE size_t gmio_stream_read(
|
||||||
gmio_stream_t* stream, void *ptr, size_t size, size_t count)
|
gmio_stream_t* stream, void *ptr, size_t size, size_t count)
|
||||||
{
|
{
|
||||||
if (stream != NULL && stream->read_func != NULL)
|
if (stream != NULL && stream->read_func != NULL)
|
||||||
@ -47,7 +44,7 @@ GMIO_INLINE static size_t gmio_stream_read(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! Safe and convenient function for gmio_stream::write_func() */
|
/*! Safe and convenient function for gmio_stream::write_func() */
|
||||||
GMIO_INLINE static size_t gmio_stream_write(
|
GMIO_INLINE size_t gmio_stream_write(
|
||||||
gmio_stream_t* stream, const void *ptr, size_t size, size_t count)
|
gmio_stream_t* stream, const void *ptr, size_t size, size_t count)
|
||||||
{
|
{
|
||||||
if (stream != NULL && stream->write_func != NULL)
|
if (stream != NULL && stream->write_func != NULL)
|
||||||
@ -56,7 +53,7 @@ GMIO_INLINE static size_t gmio_stream_write(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! Safe and convenient function for gmio_stream::size_func() */
|
/*! Safe and convenient function for gmio_stream::size_func() */
|
||||||
GMIO_INLINE static size_t gmio_stream_size(gmio_stream_t* stream)
|
GMIO_INLINE size_t gmio_stream_size(gmio_stream_t* stream)
|
||||||
{
|
{
|
||||||
if (stream != NULL && stream->size_func != NULL)
|
if (stream != NULL && stream->size_func != NULL)
|
||||||
return stream->size_func(stream->cookie);
|
return stream->size_func(stream->cookie);
|
||||||
@ -64,8 +61,10 @@ GMIO_INLINE static size_t gmio_stream_size(gmio_stream_t* stream)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! Safe and convenient function for gmio_stream::rewind_func() */
|
/*! Safe and convenient function for gmio_stream::rewind_func() */
|
||||||
GMIO_INLINE static void gmio_stream_rewind(gmio_stream_t* stream)
|
GMIO_INLINE void gmio_stream_rewind(gmio_stream_t* stream)
|
||||||
{
|
{
|
||||||
if (stream != NULL && stream->rewind_func != NULL)
|
if (stream != NULL && stream->rewind_func != NULL)
|
||||||
stream->rewind_func(stream->cookie);
|
stream->rewind_func(stream->cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* GMIO_INTERNAL_HELPER_STREAM_H */
|
||||||
|
@ -13,18 +13,15 @@
|
|||||||
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* WARNING :
|
#ifndef GMIO_INTERNAL_HELPER_TRANSFER_H
|
||||||
* this header has no multi-inclusion guard. It must be included only once
|
#define GMIO_INTERNAL_HELPER_TRANSFER_H
|
||||||
* 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 "../transfer.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
/*! Safe and convenient function for gmio_transfer::is_stop_requested_func() */
|
/*! Safe and convenient function for gmio_transfer::is_stop_requested_func() */
|
||||||
GMIO_INLINE static gmio_bool_t gmio_transfer_is_stop_requested(
|
GMIO_INLINE gmio_bool_t gmio_transfer_is_stop_requested(
|
||||||
const gmio_transfer_t* trsf)
|
const gmio_transfer_t* trsf)
|
||||||
{
|
{
|
||||||
if (trsf != NULL && trsf->is_stop_requested_func != NULL)
|
if (trsf != NULL && trsf->is_stop_requested_func != NULL)
|
||||||
@ -33,9 +30,11 @@ GMIO_INLINE static gmio_bool_t gmio_transfer_is_stop_requested(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! Safe and convenient function for gmio_transfer::handle_progress_func() */
|
/*! Safe and convenient function for gmio_transfer::handle_progress_func() */
|
||||||
GMIO_INLINE static void gmio_transfer_handle_progress(
|
GMIO_INLINE void gmio_transfer_handle_progress(
|
||||||
const gmio_transfer_t* trsf, size_t value, size_t max_value)
|
const gmio_transfer_t* trsf, size_t value, size_t max_value)
|
||||||
{
|
{
|
||||||
if (trsf != NULL && trsf->handle_progress_func != NULL)
|
if (trsf != NULL && trsf->handle_progress_func != NULL)
|
||||||
trsf->handle_progress_func(trsf->cookie, value, max_value);
|
trsf->handle_progress_func(trsf->cookie, value, max_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* GMIO_INTERNAL_HELPER_TRANSFER_H */
|
||||||
|
@ -13,18 +13,15 @@
|
|||||||
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* WARNING :
|
#ifndef GMIO_INTERNAL_SAFE_CAST_H
|
||||||
* this header has no multi-inclusion guard. It must be included only once
|
#define GMIO_INTERNAL_SAFE_CAST_H
|
||||||
* in the translation unit of use. The reason is that all functions
|
|
||||||
* defined here are meant to be inlined for performance purpose
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "../global.h"
|
#include "../global.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
/*! Returns \p val safely casted to unsigned 32b integer */
|
/*! Returns \p val safely casted to unsigned 32b integer */
|
||||||
GMIO_INLINE static uint32_t gmio_size_to_uint32(size_t val)
|
GMIO_INLINE uint32_t gmio_size_to_uint32(size_t val)
|
||||||
{
|
{
|
||||||
#if GMIO_TARGET_ARCH_BIT_SIZE > 32
|
#if GMIO_TARGET_ARCH_BIT_SIZE > 32
|
||||||
return val > 0xFFFFFFFF ? 0xFFFFFFFF : (uint32_t)val;
|
return val > 0xFFFFFFFF ? 0xFFFFFFFF : (uint32_t)val;
|
||||||
@ -32,3 +29,5 @@ GMIO_INLINE static uint32_t gmio_size_to_uint32(size_t val)
|
|||||||
return val;
|
return val;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* GMIO_INTERNAL_SAFE_CAST_H */
|
||||||
|
@ -16,6 +16,10 @@
|
|||||||
#include "string_parse.h"
|
#include "string_parse.h"
|
||||||
|
|
||||||
#include "helper_stream.h"
|
#include "helper_stream.h"
|
||||||
|
/*#define GMIO_USE_FAST_ATOF*/
|
||||||
|
#ifdef GMIO_USE_FAST_ATOF
|
||||||
|
# include "fast_atof.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -116,8 +120,10 @@ int gmio_get_float32(const char *str, gmio_float32_t *value_ptr)
|
|||||||
{
|
{
|
||||||
char* end_ptr; /* for strtod() */
|
char* end_ptr; /* for strtod() */
|
||||||
|
|
||||||
#ifdef GMIO_HAVE_STRTOF_FUNC
|
#if defined(GMIO_USE_FAST_ATOF)
|
||||||
*value_ptr = strtof(str, &end_ptr); /* Requires C99 */
|
*value_ptr = fast_atof(str, &end_ptr);
|
||||||
|
#elif defined(GMIO_HAVE_STRTOF_FUNC) /* Requires C99 */
|
||||||
|
*value_ptr = strtof(str, &end_ptr);
|
||||||
#else
|
#else
|
||||||
*value_ptr = (gmio_float32_t)strtod(str, &end_ptr);
|
*value_ptr = (gmio_float32_t)strtod(str, &end_ptr);
|
||||||
#endif
|
#endif
|
||||||
|
@ -13,17 +13,14 @@
|
|||||||
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* WARNING :
|
#ifndef GMIO_INTERNAL_HELPER_STL_MESH_CREATOR_H
|
||||||
* this header has no multi-inclusion guard. It must be included only once
|
#define GMIO_INTERNAL_HELPER_STL_MESH_CREATOR_H
|
||||||
* in the translation unit of use. The reason is that all functions
|
|
||||||
* defined here are meant to be inlined for performance purpose
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "../stl_mesh_creator.h"
|
#include "../stl_mesh_creator.h"
|
||||||
|
|
||||||
/*! Safe and convenient function for
|
/*! Safe and convenient function for
|
||||||
* gmio_stl_mesh_creator::ascii_begin_solid_func() */
|
* gmio_stl_mesh_creator::ascii_begin_solid_func() */
|
||||||
GMIO_INLINE static void gmio_stl_mesh_creator_ascii_begin_solid(
|
GMIO_INLINE void gmio_stl_mesh_creator_ascii_begin_solid(
|
||||||
gmio_stl_mesh_creator_t* creator,
|
gmio_stl_mesh_creator_t* creator,
|
||||||
size_t stream_size,
|
size_t stream_size,
|
||||||
const char* solid_name)
|
const char* solid_name)
|
||||||
@ -36,7 +33,7 @@ GMIO_INLINE static void gmio_stl_mesh_creator_ascii_begin_solid(
|
|||||||
|
|
||||||
/*! Safe and convenient function for
|
/*! Safe and convenient function for
|
||||||
* gmio_stl_mesh_creator::binary_begin_solid_func() */
|
* gmio_stl_mesh_creator::binary_begin_solid_func() */
|
||||||
GMIO_INLINE static void gmio_stl_mesh_creator_binary_begin_solid(
|
GMIO_INLINE void gmio_stl_mesh_creator_binary_begin_solid(
|
||||||
gmio_stl_mesh_creator_t* creator,
|
gmio_stl_mesh_creator_t* creator,
|
||||||
uint32_t tri_count,
|
uint32_t tri_count,
|
||||||
const uint8_t* header)
|
const uint8_t* header)
|
||||||
@ -47,7 +44,7 @@ GMIO_INLINE static void gmio_stl_mesh_creator_binary_begin_solid(
|
|||||||
|
|
||||||
/*! Safe and convenient function for
|
/*! Safe and convenient function for
|
||||||
* gmio_stl_mesh_creator::add_triangle_func() */
|
* gmio_stl_mesh_creator::add_triangle_func() */
|
||||||
GMIO_INLINE static void gmio_stl_mesh_creator_add_triangle(
|
GMIO_INLINE void gmio_stl_mesh_creator_add_triangle(
|
||||||
gmio_stl_mesh_creator_t* creator,
|
gmio_stl_mesh_creator_t* creator,
|
||||||
uint32_t tri_id,
|
uint32_t tri_id,
|
||||||
const gmio_stl_triangle_t* triangle)
|
const gmio_stl_triangle_t* triangle)
|
||||||
@ -58,9 +55,11 @@ GMIO_INLINE static void gmio_stl_mesh_creator_add_triangle(
|
|||||||
|
|
||||||
/*! Safe and convenient function for
|
/*! Safe and convenient function for
|
||||||
* gmio_stl_mesh_creator::end_solid_func() */
|
* gmio_stl_mesh_creator::end_solid_func() */
|
||||||
GMIO_INLINE static void gmio_stl_mesh_creator_end_solid(
|
GMIO_INLINE void gmio_stl_mesh_creator_end_solid(
|
||||||
gmio_stl_mesh_creator_t* creator)
|
gmio_stl_mesh_creator_t* creator)
|
||||||
{
|
{
|
||||||
if (creator != NULL && creator->end_solid_func != NULL)
|
if (creator != NULL && creator->end_solid_func != NULL)
|
||||||
creator->end_solid_func(creator->cookie);
|
creator->end_solid_func(creator->cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* GMIO_INTERNAL_HELPER_STL_MESH_CREATOR_H */
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
#include "stl_rw_common.h"
|
#include "stl_rw_common.h"
|
||||||
|
|
||||||
#include "../../gmio_core/error.h"
|
#include "../../gmio_core/error.h"
|
||||||
#include "../../gmio_core/internal/helper_error.h"
|
|
||||||
#include "../stl_error.h"
|
#include "../stl_error.h"
|
||||||
|
|
||||||
gmio_bool_t gmio_check_transfer(int *error, const gmio_transfer_t* trsf)
|
gmio_bool_t gmio_check_transfer(int *error, const gmio_transfer_t* trsf)
|
||||||
|
@ -134,7 +134,7 @@ static void gmio_stream_fwd_iterator_stla_read_hook(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GMIO_INLINE static gmio_bool_t parsing_can_continue(
|
GMIO_INLINE gmio_bool_t parsing_can_continue(
|
||||||
const gmio_stla_parse_data_t* data)
|
const gmio_stla_parse_data_t* data)
|
||||||
{
|
{
|
||||||
if (!data->error && !data->stream_iterator_cookie.is_stop_requested)
|
if (!data->error && !data->stream_iterator_cookie.is_stop_requested)
|
||||||
@ -142,13 +142,13 @@ GMIO_INLINE static gmio_bool_t parsing_can_continue(
|
|||||||
return GMIO_FALSE;
|
return GMIO_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
GMIO_INLINE static const char* current_token_as_identifier(
|
GMIO_INLINE const char* current_token_as_identifier(
|
||||||
const gmio_stla_parse_data_t* data)
|
const gmio_stla_parse_data_t* data)
|
||||||
{
|
{
|
||||||
return data->token == ID_token ? data->string_buffer.ptr : "";
|
return data->token == ID_token ? data->string_buffer.ptr : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
GMIO_INLINE static int get_current_token_as_float32(
|
GMIO_INLINE int get_current_token_as_float32(
|
||||||
const gmio_stla_parse_data_t* data, gmio_float32_t* value_ptr)
|
const gmio_stla_parse_data_t* data, gmio_float32_t* value_ptr)
|
||||||
{
|
{
|
||||||
if (data->token == FLOAT_token)
|
if (data->token == FLOAT_token)
|
||||||
@ -156,7 +156,7 @@ GMIO_INLINE static int get_current_token_as_float32(
|
|||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
GMIO_INLINE static void parsing_error(gmio_stla_parse_data_t* data)
|
GMIO_INLINE void parsing_error(gmio_stla_parse_data_t* data)
|
||||||
{
|
{
|
||||||
data->error = GMIO_TRUE;
|
data->error = GMIO_TRUE;
|
||||||
data->token = unknown_token;
|
data->token = unknown_token;
|
||||||
@ -239,7 +239,7 @@ static gmio_stla_token_t parsing_find_token(
|
|||||||
return ID_token;
|
return ID_token;
|
||||||
}
|
}
|
||||||
|
|
||||||
GMIO_INLINE static void parsing_advance(gmio_stla_parse_data_t* data)
|
GMIO_INLINE void parsing_advance(gmio_stla_parse_data_t* data)
|
||||||
{
|
{
|
||||||
if (!parsing_can_continue(data))
|
if (!parsing_can_continue(data))
|
||||||
return;
|
return;
|
||||||
@ -253,7 +253,7 @@ GMIO_INLINE static void parsing_advance(gmio_stla_parse_data_t* data)
|
|||||||
parsing_error(data);
|
parsing_error(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
GMIO_INLINE static void parsing_eat_token(
|
GMIO_INLINE void parsing_eat_token(
|
||||||
gmio_stla_token_t token, gmio_stla_parse_data_t* data)
|
gmio_stla_token_t token, gmio_stla_parse_data_t* data)
|
||||||
{
|
{
|
||||||
if (!parsing_can_continue(data))
|
if (!parsing_can_continue(data))
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
#include "stl_error.h"
|
#include "stl_error.h"
|
||||||
|
|
||||||
#include "../gmio_core/error.h"
|
#include "../gmio_core/error.h"
|
||||||
#include "../gmio_core/internal/helper_error.h"
|
|
||||||
#include "../gmio_core/internal/helper_stream.h"
|
#include "../gmio_core/internal/helper_stream.h"
|
||||||
#include "../gmio_core/internal/helper_transfer.h"
|
#include "../gmio_core/internal/helper_transfer.h"
|
||||||
#include "../gmio_core/internal/min_max.h"
|
#include "../gmio_core/internal/min_max.h"
|
||||||
|
@ -26,14 +26,13 @@
|
|||||||
#include "../gmio_core/error.h"
|
#include "../gmio_core/error.h"
|
||||||
#include "../gmio_core/internal/byte_swap.h"
|
#include "../gmio_core/internal/byte_swap.h"
|
||||||
#include "../gmio_core/internal/convert.h"
|
#include "../gmio_core/internal/convert.h"
|
||||||
#include "../gmio_core/internal/helper_error.h"
|
|
||||||
#include "../gmio_core/internal/helper_stream.h"
|
#include "../gmio_core/internal/helper_stream.h"
|
||||||
#include "../gmio_core/internal/helper_transfer.h"
|
#include "../gmio_core/internal/helper_transfer.h"
|
||||||
#include "../gmio_core/internal/safe_cast.h"
|
#include "../gmio_core/internal/safe_cast.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
GMIO_INLINE static void read_triangle_memcpy(
|
GMIO_INLINE void read_triangle_memcpy(
|
||||||
const uint8_t* buffer, gmio_stl_triangle_t* triangle)
|
const uint8_t* buffer, gmio_stl_triangle_t* triangle)
|
||||||
{
|
{
|
||||||
/* *triangle = *((gmio_stl_triangle_t*)(buffer)); */
|
/* *triangle = *((gmio_stl_triangle_t*)(buffer)); */
|
||||||
|
@ -25,14 +25,13 @@
|
|||||||
#include "../gmio_core/error.h"
|
#include "../gmio_core/error.h"
|
||||||
#include "../gmio_core/internal/byte_codec.h"
|
#include "../gmio_core/internal/byte_codec.h"
|
||||||
#include "../gmio_core/internal/min_max.h"
|
#include "../gmio_core/internal/min_max.h"
|
||||||
#include "../gmio_core/internal/helper_error.h"
|
|
||||||
#include "../gmio_core/internal/helper_stream.h"
|
#include "../gmio_core/internal/helper_stream.h"
|
||||||
#include "../gmio_core/internal/helper_transfer.h"
|
#include "../gmio_core/internal/helper_transfer.h"
|
||||||
#include "../gmio_core/internal/safe_cast.h"
|
#include "../gmio_core/internal/safe_cast.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
GMIO_INLINE static void write_triangle_memcpy(
|
GMIO_INLINE void write_triangle_memcpy(
|
||||||
const gmio_stl_triangle_t* triangle, uint8_t* buffer)
|
const gmio_stl_triangle_t* triangle, uint8_t* buffer)
|
||||||
{
|
{
|
||||||
memcpy(buffer, triangle, GMIO_STLB_TRIANGLE_RAWSIZE);
|
memcpy(buffer, triangle, GMIO_STLB_TRIANGLE_RAWSIZE);
|
||||||
|
Loading…
Reference in New Issue
Block a user