* Simplify syntax used to call function with pointers
* Some documentation for foug_stream functions
This commit is contained in:
parent
f71c061328
commit
7daa164a8b
@ -1,7 +1,6 @@
|
||||
#include "stlb_read.h"
|
||||
|
||||
#include "../endian.h"
|
||||
#include "stlb_triangle.h"
|
||||
|
||||
struct _internal_foug_stlb_geom_input
|
||||
{
|
||||
@ -59,7 +58,7 @@ static void foug_stlb_read_facets(foug_stlb_geom_input_t* geom_input,
|
||||
buffer_offset += FOUG_STLB_TRIANGLE_SIZE;
|
||||
|
||||
/* Declare triangle */
|
||||
(*(geom_input->manip.process_next_triangle_func))(geom_input, &triangle);
|
||||
geom_input->manip.process_next_triangle_func(geom_input, &triangle);
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,7 +85,7 @@ int foug_stlb_read(foug_stlb_read_args_t args)
|
||||
return FOUG_STLB_READ_HEADER_WRONG_SIZE_ERROR;
|
||||
|
||||
if (args.geom_input->manip.process_header_func != NULL)
|
||||
(*(args.geom_input->manip.process_header_func))(args.geom_input, header_data);
|
||||
args.geom_input->manip.process_header_func(args.geom_input, header_data);
|
||||
|
||||
/* Read facet count */
|
||||
if (foug_stream_read(args.stream, args.buffer, sizeof(uint32_t), 1) != 1)
|
||||
@ -94,10 +93,10 @@ int foug_stlb_read(foug_stlb_read_args_t args)
|
||||
|
||||
total_facet_count = foug_decode_uint32_le(args.buffer);
|
||||
if (args.geom_input->manip.begin_triangles_func != NULL)
|
||||
(*(args.geom_input->manip.begin_triangles_func))(args.geom_input, total_facet_count);
|
||||
args.geom_input->manip.begin_triangles_func(args.geom_input, total_facet_count);
|
||||
|
||||
foug_task_control_reset(args.task_control);
|
||||
foug_task_control_set_range(args.task_control, 0., (foug_real32_t)total_facet_count);
|
||||
foug_task_control_set_range(args.task_control, 0.f, (foug_real32_t)total_facet_count);
|
||||
|
||||
/* Read triangles */
|
||||
buffer_facet_count = args.buffer_size / FOUG_STLB_TRIANGLE_SIZE;
|
||||
@ -127,7 +126,7 @@ int foug_stlb_read(foug_stlb_read_args_t args)
|
||||
} /* end while */
|
||||
|
||||
if (foug_stlb_no_error(error) && args.geom_input->manip.end_triangles_func != NULL)
|
||||
(*(args.geom_input->manip.end_triangles_func))(args.geom_input);
|
||||
args.geom_input->manip.end_triangles_func(args.geom_input);
|
||||
|
||||
if (foug_stlb_no_error(error) && accum_facet_count_read != total_facet_count)
|
||||
error = FOUG_STLB_READ_FACET_COUNT_ERROR;
|
||||
|
@ -56,7 +56,7 @@ static void foug_stlb_write_facets(const foug_stlb_geom_output_t* geom_output,
|
||||
|
||||
buffer_offset = 0;
|
||||
for (i_facet = ifacet_start; i_facet < (ifacet_start + facet_count); ++i_facet) {
|
||||
(*(geom_output->manip.get_triangle_func))(geom_output, i_facet, &triangle);
|
||||
geom_output->manip.get_triangle_func(geom_output, i_facet, &triangle);
|
||||
|
||||
memcpy(buffer + buffer_offset, &triangle, FOUG_STLB_TRIANGLE_SIZE);
|
||||
buffer_offset += FOUG_STLB_TRIANGLE_SIZE;
|
||||
@ -87,7 +87,7 @@ int foug_stlb_write(foug_stlb_write_args_t args)
|
||||
|
||||
/* Write header */
|
||||
if (args.geom_output->manip.get_header_func != NULL)
|
||||
(*(args.geom_output->manip.get_header_func))(args.geom_output, header_data);
|
||||
args.geom_output->manip.get_header_func(args.geom_output, header_data);
|
||||
else
|
||||
memset(header_data, 0, FOUG_STLB_HEADER_SIZE);
|
||||
|
||||
@ -95,7 +95,7 @@ int foug_stlb_write(foug_stlb_write_args_t args)
|
||||
return FOUG_STLB_WRITE_STREAM_ERROR;
|
||||
|
||||
/* Write facet count */
|
||||
facet_count = (*(args.geom_output->manip.get_triangle_count_func))(args.geom_output);
|
||||
facet_count = args.geom_output->manip.get_triangle_count_func(args.geom_output);
|
||||
foug_encode_uint32_le(facet_count, args.buffer);
|
||||
if (foug_stream_write(args.stream, args.buffer, sizeof(uint32_t), 1) != 1)
|
||||
return FOUG_STLB_WRITE_STREAM_ERROR;
|
||||
|
@ -24,6 +24,9 @@ foug_stream_t* foug_stream_create(foug_malloc_func_t func, void* data, foug_stre
|
||||
return stream;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Create a null stream manipulator
|
||||
*/
|
||||
foug_stream_manip_t foug_stream_manip_null()
|
||||
{
|
||||
foug_stream_manip_t manip;
|
||||
@ -57,6 +60,9 @@ static size_t foug_stream_stdio_write(foug_stream_t* stream,
|
||||
return fwrite(ptr, item_size, item_count, (FILE*) stream->cookie);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Create a stream manipulator for standard FILE*
|
||||
*/
|
||||
foug_stream_manip_t foug_stream_manip_stdio()
|
||||
{
|
||||
foug_stream_manip_t manip;
|
||||
@ -70,28 +76,59 @@ foug_stream_manip_t foug_stream_manip_stdio()
|
||||
foug_bool_t foug_stream_at_end(foug_stream_t* stream)
|
||||
{
|
||||
if (stream != NULL && stream->manip.at_end_func != NULL)
|
||||
return (*(stream->manip.at_end_func))(stream);
|
||||
return stream->manip.at_end_func(stream);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Check error indicator
|
||||
*
|
||||
* Checks if the error indicator associated with \p stream is set, returning a value different from
|
||||
* zero if it is.
|
||||
*
|
||||
* This indicator is generally set by a previous operation on the \p stream that failed.
|
||||
*/
|
||||
int foug_stream_error(foug_stream_t* stream)
|
||||
{
|
||||
if (stream != NULL && stream->manip.error_func != NULL)
|
||||
return (*(stream->manip.error_func))(stream);
|
||||
return stream->manip.error_func(stream);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Read block of data from stream
|
||||
*
|
||||
* Reads an array of \p item_count elements, each one with a \p item_size of size bytes, from the
|
||||
* \p stream and stores them in the block of memory specified by \p ptr.
|
||||
*
|
||||
* The total amount of bytes read if successful is (item_size * item_count).
|
||||
*
|
||||
* \return The total number of elements successfully read is returned.
|
||||
* If this number differs from the \p item_count argument, either a reading error occurred
|
||||
* or the end-of-file was reached while reading. In both cases, the proper indicator is set,
|
||||
* which can be checked with foug_stream_error() and foug_stream_at_end(), respectively.
|
||||
* If either \p item_size or \p item_count is zero, the function returns zero and both the
|
||||
* stream state and the content pointed by \p ptr remain unchanged.
|
||||
*/
|
||||
size_t foug_stream_read(foug_stream_t* stream, void *ptr, size_t item_size, size_t item_count)
|
||||
{
|
||||
if (stream != NULL && stream->manip.read_func != NULL)
|
||||
return (*(stream->manip.read_func))(stream, ptr, item_size, item_count);
|
||||
return stream->manip.read_func(stream, ptr, item_size, item_count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Write block of data to stream
|
||||
*
|
||||
* Writes an array of \p item_count elements, each one with a \p item_size of size bytes, from the
|
||||
* block of memory pointed by \p ptr to the current position in the \p stream.
|
||||
*
|
||||
* The total amount of bytes written is (item_size * item_count).
|
||||
*/
|
||||
size_t foug_stream_write(foug_stream_t* stream, const void *ptr, size_t item_size, size_t item_count)
|
||||
{
|
||||
if (stream != NULL && stream->manip.write_func != NULL)
|
||||
return (*(stream->manip.write_func))(stream, ptr, item_size, item_count);
|
||||
return stream->manip.write_func(stream, ptr, item_size, item_count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user