Several changes

* Remove typedefs on struct and enums
* First working version of gmio_stla_stats_get()
This commit is contained in:
Hugues Delorme 2015-12-03 18:00:25 +01:00
parent 3850f0f278
commit fb81b25407
63 changed files with 918 additions and 734 deletions

View File

@ -14,23 +14,29 @@
****************************************************************************/
#include <gmio_core/error.h>
#include <gmio_core/rwargs.h>
#include <gmio_stl/stl_io.h>
#include <gmio_stl/stl_io_options.h>
#include <gmio_stl/stl_mesh.h>
#include <gmio_stl/stl_mesh_creator.h>
#include "../commons/benchmark_tools.h"
#include <string.h>
typedef struct my_igeom
struct gmio_stl_triangle;
struct my_igeom
{
uint32_t facet_count;
} my_igeom_t;
};
static void dummy_process_triangle(
void* cookie,
uint32_t triangle_id,
const gmio_stl_triangle_t* triangle)
const struct gmio_stl_triangle* triangle)
{
my_igeom_t* my_igeom = (my_igeom_t*)(cookie);
struct my_igeom* my_igeom = (struct my_igeom*)(cookie);
GMIO_UNUSED(triangle_id);
GMIO_UNUSED(triangle);
if (my_igeom != NULL)
@ -39,18 +45,18 @@ static void dummy_process_triangle(
static void bmk_gmio_stl_read(const char* filepath)
{
my_igeom_t cookie = {0};
gmio_stl_mesh_creator_t mesh_creator = {0};
struct my_igeom cookie = {0};
struct gmio_stl_mesh_creator mesh_creator = {0};
int error = GMIO_ERROR_OK;
mesh_creator.cookie = &cookie;
mesh_creator.func_add_triangle = dummy_process_triangle;
error = gmio_stl_read_file(filepath, &mesh_creator, NULL);
error = gmio_stl_read_file(filepath, NULL, &mesh_creator);
if (error != GMIO_ERROR_OK)
printf("gmio error: 0x%X\n", error);
}
static gmio_endianness_t to_byte_order(gmio_stl_format_t format)
static enum gmio_endianness to_byte_order(enum gmio_stl_format format)
{
switch (format) {
case GMIO_STL_FORMAT_BINARY_LE:
@ -65,22 +71,22 @@ static gmio_endianness_t to_byte_order(gmio_stl_format_t format)
}
enum { STL_TRIANGLE_ARRAY_SIZE = 512 };
typedef struct stl_readwrite_conv
struct stl_readwrite_conv
{
gmio_transfer_t trsf;
gmio_stream_pos_t out_stream_pos_begin;
gmio_stl_format_t in_format;
gmio_stl_format_t out_format;
gmio_stl_triangle_t triangle_array[STL_TRIANGLE_ARRAY_SIZE];
struct gmio_rwargs rwargs;
struct gmio_stream_pos out_stream_pos_begin;
enum gmio_stl_format in_format;
enum gmio_stl_format out_format;
struct gmio_stl_triangle triangle_array[STL_TRIANGLE_ARRAY_SIZE];
unsigned triangle_pos;
uint32_t total_triangle_count;
} stl_readwrite_conv_t;
};
static void readwrite_ascii_begin_solid(
void* cookie, gmio_streamsize_t stream_size, const char* solid_name)
{
stl_readwrite_conv_t* rw_conv = (stl_readwrite_conv_t*)cookie;
gmio_stream_t* stream = &rw_conv->trsf.stream;
struct stl_readwrite_conv* rw_conv = (struct stl_readwrite_conv*)cookie;
struct gmio_stream* stream = &rw_conv->rwargs.stream;
GMIO_UNUSED(stream_size);
if (rw_conv->out_format == GMIO_STL_FORMAT_ASCII) {
stream->func_write(stream->cookie, "solid ", 1, 6);
@ -92,50 +98,50 @@ static void readwrite_ascii_begin_solid(
* point. Header will be correctly rewritten at the end of the read
* procedure (in gmio_stl_mesh_creator::func_end_solid() callback)
*/
const gmio_endianness_t byte_order = to_byte_order(rw_conv->out_format);
const enum gmio_endianness byte_order = to_byte_order(rw_conv->out_format);
gmio_stlb_write_header(stream, byte_order, NULL, 0);
}
}
static void readwrite_binary_begin_solid(
void* cookie, uint32_t tri_count, const gmio_stlb_header_t* header)
void* cookie, uint32_t tri_count, const struct gmio_stlb_header* header)
{
stl_readwrite_conv_t* rw_conv = (stl_readwrite_conv_t*)cookie;
gmio_stream_t* stream = &rw_conv->trsf.stream;
struct stl_readwrite_conv* rw_conv = (struct stl_readwrite_conv*)cookie;
struct gmio_stream* stream = &rw_conv->rwargs.stream;
if (rw_conv->out_format == GMIO_STL_FORMAT_ASCII) {
stream->func_write(stream->cookie, "solid\n", 1, 6);
}
else {
const gmio_endianness_t byte_order = to_byte_order(rw_conv->out_format);
const enum gmio_endianness byte_order = to_byte_order(rw_conv->out_format);
gmio_stlb_write_header(stream, byte_order, header, tri_count);
}
}
static void readwrite_get_triangle(
const void* cookie, uint32_t tri_id, gmio_stl_triangle_t* triangle)
const void* cookie, uint32_t tri_id, struct gmio_stl_triangle* triangle)
{
const gmio_stl_triangle_t* tri_array = (const gmio_stl_triangle_t*)cookie;
const struct gmio_stl_triangle* tri_array = (const struct gmio_stl_triangle*)cookie;
*triangle = tri_array[tri_id];
}
static void stl_readwrite_flush_triangles(stl_readwrite_conv_t* rw_conv)
static void stl_readwrite_flush_triangles(struct stl_readwrite_conv* rw_conv)
{
gmio_stl_mesh_t mesh = {0};
gmio_stl_write_options_t options = {0};
struct gmio_stl_mesh mesh = {0};
struct gmio_stl_write_options options = {0};
mesh.cookie = &rw_conv->triangle_array[0];
mesh.triangle_count = rw_conv->triangle_pos;
mesh.func_get_triangle = &readwrite_get_triangle;
options.stl_write_triangles_only = GMIO_TRUE;
options.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SCIENTIFIC_LOWERCASE;
options.stla_float32_prec = 6;
gmio_stl_write(rw_conv->out_format, &rw_conv->trsf, &mesh, &options);
gmio_stl_write(&rw_conv->rwargs, &mesh, rw_conv->out_format, &options);
rw_conv->triangle_pos = 0;
}
static void readwrite_add_triangle(
void* cookie, uint32_t tri_id, const gmio_stl_triangle_t* triangle)
void* cookie, uint32_t tri_id, const struct gmio_stl_triangle* triangle)
{
stl_readwrite_conv_t* rw_conv = (stl_readwrite_conv_t*)cookie;
struct stl_readwrite_conv* rw_conv = (struct stl_readwrite_conv*)cookie;
if (rw_conv->triangle_pos >= STL_TRIANGLE_ARRAY_SIZE)
stl_readwrite_flush_triangles(rw_conv);
rw_conv->triangle_array[rw_conv->triangle_pos] = *triangle;
@ -145,15 +151,15 @@ static void readwrite_add_triangle(
static void readwrite_end_solid(void* cookie)
{
stl_readwrite_conv_t* rw_conv = (stl_readwrite_conv_t*)cookie;
gmio_stream_t* stream = &rw_conv->trsf.stream;
struct stl_readwrite_conv* rw_conv = (struct stl_readwrite_conv*)cookie;
struct gmio_stream* stream = &rw_conv->rwargs.stream;
if (rw_conv->triangle_pos != 0)
stl_readwrite_flush_triangles(rw_conv);
if (rw_conv->out_format == GMIO_STL_FORMAT_ASCII) {
stream->func_write(stream->cookie, "endsolid", 1, 8);
}
else if (rw_conv->in_format == GMIO_STL_FORMAT_ASCII) {
const gmio_endianness_t byte_order = to_byte_order(rw_conv->out_format);
const enum gmio_endianness byte_order = to_byte_order(rw_conv->out_format);
/* The total facet count has to be written because it wasn't known at
* the beginning of the read procedure */
stream->func_set_pos(stream->cookie, &rw_conv->out_stream_pos_begin);
@ -166,24 +172,24 @@ static void bmk_gmio_stl_readwrite_conv(const char* filepath)
{
FILE* infile = fopen(filepath, "rb");
FILE* outfile = fopen("_readwrite_conv.stl", "wb");
gmio_transfer_t in_trsf = {0};
stl_readwrite_conv_t rw_conv = {0};
gmio_stl_mesh_creator_t mesh_creator = {0};
struct gmio_rwargs in_rwargs = {0};
struct stl_readwrite_conv rw_conv = {0};
struct gmio_stl_mesh_creator mesh_creator = {0};
int error = GMIO_ERROR_OK;
/* rw_conv.out_format = GMIO_STL_FORMAT_BINARY_LE; */
rw_conv.out_format = GMIO_STL_FORMAT_ASCII;
if (infile != NULL) {
in_trsf.memblock = gmio_memblock_malloc(512 * 1024);
in_trsf.stream = gmio_stream_stdio(infile);
rw_conv.in_format = gmio_stl_get_format(&in_trsf.stream);
in_rwargs.memblock = gmio_memblock_malloc(512 * 1024);
in_rwargs.stream = gmio_stream_stdio(infile);
rw_conv.in_format = gmio_stl_get_format(&in_rwargs.stream);
}
if (outfile != NULL) {
rw_conv.trsf.memblock = gmio_memblock_malloc(512 * 1024);
rw_conv.trsf.stream = gmio_stream_stdio(outfile);
rw_conv.trsf.stream.func_get_pos(
rw_conv.trsf.stream.cookie,
rw_conv.rwargs.memblock = gmio_memblock_malloc(512 * 1024);
rw_conv.rwargs.stream = gmio_stream_stdio(outfile);
rw_conv.rwargs.stream.func_get_pos(
rw_conv.rwargs.stream.cookie,
&rw_conv.out_stream_pos_begin);
}
@ -193,10 +199,10 @@ static void bmk_gmio_stl_readwrite_conv(const char* filepath)
mesh_creator.func_add_triangle = &readwrite_add_triangle;
mesh_creator.func_end_solid = &readwrite_end_solid;
error = gmio_stl_read(&in_trsf, &mesh_creator);
error = gmio_stl_read(&in_rwargs, &mesh_creator);
gmio_memblock_deallocate(&in_trsf.memblock);
gmio_memblock_deallocate(&rw_conv.trsf.memblock);
gmio_memblock_deallocate(&in_rwargs.memblock);
gmio_memblock_deallocate(&rw_conv.rwargs.memblock);
if (error != GMIO_ERROR_OK)
printf("gmio error: 0x%X\n", error);
@ -208,7 +214,7 @@ int main(int argc, char** argv)
const char* filepath = argv[1];
/* Declare benchmarks */
benchmark_cmp_arg_t cmp_args[] = {
struct benchmark_cmp_arg cmp_args[] = {
{ "read_file()",
bmk_gmio_stl_read, NULL,
NULL, NULL },
@ -218,10 +224,10 @@ int main(int argc, char** argv)
{0}
};
const size_t cmp_count =
sizeof(cmp_args) / sizeof(benchmark_cmp_arg_t) - 1;
benchmark_cmp_result_t cmp_res[2] = {0};
benchmark_cmp_result_array_t res_array = {0};
const benchmark_cmp_result_header_t header = { "gmio", NULL };
sizeof(cmp_args) / sizeof(struct benchmark_cmp_arg) - 1;
struct benchmark_cmp_result cmp_res[2] = {0};
struct benchmark_cmp_result_array res_array = {0};
const struct benchmark_cmp_result_header header = { "gmio", NULL };
cmp_args[0].func1_filepath = filepath;
cmp_args[1].func1_filepath = filepath;

View File

@ -39,9 +39,8 @@ struct benchmark_timer
clock_t start_tick;
#endif
};
typedef struct benchmark_timer benchmark_timer_t;
static void benchmark_timer_start(benchmark_timer_t* timer)
static void benchmark_timer_start(struct benchmark_timer* timer)
{
#ifdef BENCHMARK_TIMER_WINDOWS
QueryPerformanceFrequency(&timer->frequency);
@ -51,7 +50,7 @@ static void benchmark_timer_start(benchmark_timer_t* timer)
#endif
}
static gmio_time_ms_t benchmark_timer_elapsed_ms(const benchmark_timer_t* timer)
static gmio_time_ms_t benchmark_timer_elapsed_ms(const struct benchmark_timer* timer)
{
#ifdef BENCHMARK_TIMER_WINDOWS
LARGE_INTEGER end_time = {0};
@ -194,7 +193,7 @@ static void printf_func_exec_time(
}
/*! Returns the strlen of the longest tag string */
static size_t find_maxlen_cmp_result_tag(benchmark_cmp_result_array_t res_array)
static size_t find_maxlen_cmp_result_tag(struct benchmark_cmp_result_array res_array)
{
size_t max_len = 0;
size_t i;
@ -207,7 +206,7 @@ static size_t find_maxlen_cmp_result_tag(benchmark_cmp_result_array_t res_array)
/*! Writes in output args the func1 execution informations */
static void select_cmp_result_func1_exec_infos(
const benchmark_cmp_result_t* cmp,
const struct benchmark_cmp_result* cmp,
gmio_time_ms_t* time,
gmio_bool_t* has_time)
{
@ -217,7 +216,7 @@ static void select_cmp_result_func1_exec_infos(
/*! Writes in output args the func2 execution informations */
static void select_cmp_result_func2_exec_infos(
const benchmark_cmp_result_t* cmp,
const struct benchmark_cmp_result* cmp,
gmio_time_ms_t* time,
gmio_bool_t* has_time)
{
@ -227,11 +226,11 @@ static void select_cmp_result_func2_exec_infos(
/*! Typedef on pointer to functions like select_cmp_result_funcX_exec_infos() */
typedef void (*func_select_cmp_result_func_exec_infos_t)(
const benchmark_cmp_result_t*, gmio_time_ms_t*, gmio_bool_t*);
const struct benchmark_cmp_result*, gmio_time_ms_t*, gmio_bool_t*);
/*! Returns the strlen of the longest execution time string */
static size_t find_maxlen_cmp_result_func_exec_time(
benchmark_cmp_result_array_t res_array,
struct benchmark_cmp_result_array res_array,
func_select_cmp_result_func_exec_infos_t func_select_exec_infos)
{
char strbuff[1024] = {0};
@ -249,7 +248,7 @@ static size_t find_maxlen_cmp_result_func_exec_time(
/*! Returns the strlen of the longest func2/func1 ratio string */
static size_t find_maxlen_cmp_result_ratio(
benchmark_cmp_result_array_t res_array)
struct benchmark_cmp_result_array res_array)
{
char strbuff[1024] = {0};
size_t max_len = 0;
@ -262,7 +261,7 @@ static size_t find_maxlen_cmp_result_ratio(
return max_len;
}
static void update_benchmark_cmp_result_ratio(benchmark_cmp_result_t* result)
static void update_benchmark_cmp_result_ratio(struct benchmark_cmp_result* result)
{
if (result->has_func1_exec_time && result->has_func2_exec_time) {
if (result->func2_exec_time_ms > 0) {
@ -281,20 +280,20 @@ static void update_benchmark_cmp_result_ratio(benchmark_cmp_result_t* result)
/* Implementation */
benchmark_cmp_result_t benchmark_cmp(benchmark_cmp_arg_t arg)
struct benchmark_cmp_result benchmark_cmp(struct benchmark_cmp_arg arg)
{
benchmark_cmp_result_t result = {0};
struct benchmark_cmp_result result = {0};
result.tag = arg.tag;
if (arg.func1 != NULL) {
benchmark_timer_t timer = {0};
struct benchmark_timer timer = {0};
benchmark_timer_start(&timer);
(*arg.func1)(arg.func1_filepath);
result.func1_exec_time_ms = benchmark_timer_elapsed_ms(&timer);
result.has_func1_exec_time = GMIO_TRUE;
}
if (arg.func2 != NULL) {
benchmark_timer_t timer = {0};
struct benchmark_timer timer = {0};
benchmark_timer_start(&timer);
(*arg.func2)(arg.func2_filepath);
result.func2_exec_time_ms = benchmark_timer_elapsed_ms(&timer);
@ -307,8 +306,8 @@ benchmark_cmp_result_t benchmark_cmp(benchmark_cmp_arg_t arg)
void benchmark_cmp_batch(
size_t run_count,
const benchmark_cmp_arg_t *arg_array,
benchmark_cmp_result_t *result_array,
const struct benchmark_cmp_arg *arg_array,
struct benchmark_cmp_result *result_array,
void (*func_init)(),
void (*func_cleanup)())
{
@ -324,8 +323,8 @@ void benchmark_cmp_batch(
(*func_init)();
for (i = 0; i < array_size; ++i) {
const benchmark_cmp_result_t ires = benchmark_cmp(arg_array[i]);
benchmark_cmp_result_t* fres = &result_array[i];
const struct benchmark_cmp_result ires = benchmark_cmp(arg_array[i]);
struct benchmark_cmp_result* fres = &result_array[i];
if (run != 0) {
if (fres->func1_exec_time_ms > ires.func1_exec_time_ms)
fres->func1_exec_time_ms = ires.func1_exec_time_ms;
@ -345,9 +344,9 @@ void benchmark_cmp_batch(
}
void benchmark_print_results(
benchmark_print_format_t format,
benchmark_cmp_result_header_t header,
benchmark_cmp_result_array_t result_array)
enum benchmark_print_format format,
struct benchmark_cmp_result_header header,
struct benchmark_cmp_result_array result_array)
{
if (format == BENCHMARK_PRINT_FORMAT_MARKDOWN) {
const char* header_comp1 =
@ -391,7 +390,7 @@ void benchmark_print_results(
/* Print benchmark result lines */
for (i = 0; i < result_array.count; ++i) {
const benchmark_cmp_result_t result = result_array.ptr[i];
const struct benchmark_cmp_result result = result_array.ptr[i];
printf("%-*s | ", (int)width_tag_col, result.tag);
printf_func_exec_time(
width_func1_col,

View File

@ -46,7 +46,6 @@ struct benchmark_cmp_arg
/*! Argument passed to the 2nd function on exec */
const char* func2_filepath;
};
typedef struct benchmark_cmp_arg benchmark_cmp_arg_t;
/*! Holds the result of the exec time comparison between two functions */
struct benchmark_cmp_result
@ -63,16 +62,15 @@ struct benchmark_cmp_result
gmio_bool_t has_func2_exec_time;
float func2_func1_ratio;
};
typedef struct benchmark_cmp_result benchmark_cmp_result_t;
/*! Runs func1 then func2 and measures the respective execution time */
benchmark_cmp_result_t benchmark_cmp(benchmark_cmp_arg_t arg);
struct benchmark_cmp_result benchmark_cmp(struct benchmark_cmp_arg arg);
/*! Runs a batch(array) of comparison benchmarks */
void benchmark_cmp_batch(
size_t run_count,
const benchmark_cmp_arg_t* arg_array,
benchmark_cmp_result_t* result_array,
const struct benchmark_cmp_arg* arg_array,
struct benchmark_cmp_result* result_array,
void (*func_init)(),
void (*func_cleanup)());
@ -83,15 +81,13 @@ enum benchmark_print_format
{
BENCHMARK_PRINT_FORMAT_MARKDOWN = 0
};
typedef enum benchmark_print_format benchmark_print_format_t;
/*! Array of benchmark_cmp_result */
struct benchmark_cmp_result_array
{
const benchmark_cmp_result_t* ptr;
const struct benchmark_cmp_result* ptr;
size_t count;
};
typedef struct benchmark_cmp_result_array benchmark_cmp_result_array_t;
/*! Horizontal header labels for benchmark results(by column) */
struct benchmark_cmp_result_header
@ -99,13 +95,12 @@ struct benchmark_cmp_result_header
const char* component_1;
const char* component_2;
};
typedef struct benchmark_cmp_result_header benchmark_cmp_result_header_t;
/*! Prints formatted benchmark results */
void benchmark_print_results(
benchmark_print_format_t format,
benchmark_cmp_result_header_t header,
benchmark_cmp_result_array_t result_array);
enum benchmark_print_format format,
struct benchmark_cmp_result_header header,
struct benchmark_cmp_result_array result_array);
GMIO_C_LINKAGE_END

View File

@ -19,15 +19,15 @@
#include <string.h>
typedef union
union gmio_int_bytes_32_convert
{
uint32_t integer;
uint8_t bytes[4];
} gmio_int_bytes_32_convert_t;
};
gmio_endianness_t gmio_host_endianness()
enum gmio_endianness gmio_host_endianness()
{
gmio_int_bytes_32_convert_t conv;
union gmio_int_bytes_32_convert conv;
conv.integer = 0x01020408;
if (conv.bytes[0] == 0x08 && conv.bytes[3] == 0x01)

View File

@ -52,12 +52,10 @@ enum gmio_endianness
#endif
};
typedef enum gmio_endianness gmio_endianness_t;
GMIO_C_LINKAGE_BEGIN
/*! Returns endianness (byte order) of the host's CPU architecture */
GMIO_LIB_EXPORT gmio_endianness_t gmio_host_endianness();
GMIO_LIB_EXPORT enum gmio_endianness gmio_host_endianness();
GMIO_C_LINKAGE_END

View File

@ -31,8 +31,8 @@ enum gmio_error
/*! No error occurred, success */
GMIO_ERROR_OK = 0,
/*! Pointer on argument gmio_transfer_t is NULL */
GMIO_ERROR_NULL_TRANSFER,
/*! Pointer on argument gmio_rwargs is NULL */
GMIO_ERROR_NULL_RWARGS,
/*! Pointer on argument memory block is NULL */
GMIO_ERROR_NULL_MEMBLOCK,
@ -57,8 +57,6 @@ enum gmio_error
GMIO_ERROR_UNKNOWN
};
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_ERROR_OK ? GMIO_TRUE : GMIO_FALSE; }

View File

@ -13,31 +13,31 @@
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
****************************************************************************/
#ifndef GMIO_INTERNAL_HELPER_TRANSFER_H
#define GMIO_INTERNAL_HELPER_TRANSFER_H
#ifndef GMIO_INTERNAL_HELPER_RWARGS_H
#define GMIO_INTERNAL_HELPER_RWARGS_H
#include "../transfer.h"
#include "../rwargs.h"
#include "helper_task_iface.h"
/*! Safe and convenient function for gmio_task_iface::func_is_stop_requested()
* through gmio_transfer::task_iface
*/
GMIO_INLINE gmio_bool_t gmio_transfer_is_stop_requested(
const gmio_transfer_t* trsf)
GMIO_INLINE gmio_bool_t gmio_rwargs_is_stop_requested(
const struct gmio_rwargs* args)
{
if (trsf != NULL)
return gmio_task_iface_is_stop_requested(&trsf->task_iface);
if (args != NULL)
return gmio_task_iface_is_stop_requested(&args->task_iface);
return GMIO_FALSE;
}
/*! Safe and convenient function for gmio_task_iface::func_handle_progress()
* through gmio_transfer::task_iface
*/
GMIO_INLINE void gmio_transfer_handle_progress(
const gmio_transfer_t* trsf, size_t value, size_t max_value)
GMIO_INLINE void gmio_rwargs_handle_progress(
const struct gmio_rwargs* args, size_t value, size_t max_value)
{
if (trsf != NULL)
gmio_task_iface_handle_progress(&trsf->task_iface, value, max_value);
if (args != NULL)
gmio_task_iface_handle_progress(&args->task_iface, value, max_value);
}
#endif /* GMIO_INTERNAL_HELPER_TRANSFER_H */
#endif /* GMIO_INTERNAL_HELPER_RWARGS_H */

View File

@ -19,7 +19,7 @@
#include "../stream.h"
/*! Safe and convenient function for gmio_stream::func_at_end() */
GMIO_INLINE gmio_bool_t gmio_stream_at_end(gmio_stream_t* stream)
GMIO_INLINE gmio_bool_t gmio_stream_at_end(struct gmio_stream* stream)
{
if (stream != NULL && stream->func_at_end != NULL)
return stream->func_at_end(stream->cookie);
@ -27,7 +27,7 @@ GMIO_INLINE gmio_bool_t gmio_stream_at_end(gmio_stream_t* stream)
}
/*! Safe and convenient function for gmio_stream::func_error() */
GMIO_INLINE int gmio_stream_error(gmio_stream_t* stream)
GMIO_INLINE int gmio_stream_error(struct gmio_stream* stream)
{
if (stream != NULL && stream->func_error != NULL)
return stream->func_error(stream->cookie);
@ -36,7 +36,7 @@ GMIO_INLINE int gmio_stream_error(gmio_stream_t* stream)
/*! Safe and convenient function for gmio_stream::func_read() */
GMIO_INLINE size_t gmio_stream_read(
gmio_stream_t* stream, void *ptr, size_t size, size_t count)
struct gmio_stream* stream, void *ptr, size_t size, size_t count)
{
if (stream != NULL && stream->func_read != NULL)
return stream->func_read(stream->cookie, ptr, size, count);
@ -45,7 +45,7 @@ GMIO_INLINE size_t gmio_stream_read(
/*! Safe and convenient function for gmio_stream::func_write() */
GMIO_INLINE size_t gmio_stream_write(
gmio_stream_t* stream, const void *ptr, size_t size, size_t count)
struct gmio_stream* stream, const void *ptr, size_t size, size_t count)
{
if (stream != NULL && stream->func_write != NULL)
return stream->func_write(stream->cookie, ptr, size, count);
@ -53,7 +53,7 @@ GMIO_INLINE size_t gmio_stream_write(
}
/*! Safe and convenient function for gmio_stream::func_size() */
GMIO_INLINE gmio_streamsize_t gmio_stream_size(gmio_stream_t* stream)
GMIO_INLINE gmio_streamsize_t gmio_stream_size(struct gmio_stream* stream)
{
if (stream != NULL && stream->func_size != NULL)
return stream->func_size(stream->cookie);
@ -62,7 +62,7 @@ GMIO_INLINE gmio_streamsize_t gmio_stream_size(gmio_stream_t* stream)
/*! Safe and convenient function for gmio_stream::func_get_pos() */
GMIO_INLINE int gmio_stream_get_pos(
gmio_stream_t* stream, gmio_stream_pos_t* pos)
struct gmio_stream* stream, struct gmio_stream_pos* pos)
{
if (stream != NULL && stream->func_get_pos != NULL)
return stream->func_get_pos(stream->cookie, pos);
@ -71,7 +71,7 @@ GMIO_INLINE int gmio_stream_get_pos(
/*! Safe and convenient function for gmio_stream::func_set_pos() */
GMIO_INLINE int gmio_stream_set_pos(
gmio_stream_t* stream, const gmio_stream_pos_t* pos)
struct gmio_stream* stream, const struct gmio_stream_pos* pos)
{
if (stream != NULL && stream->func_set_pos != NULL)
return stream->func_set_pos(stream->cookie, pos);

View File

@ -22,7 +22,7 @@
/*! Safe and convenient function for gmio_task_iface::func_is_stop_requested() */
GMIO_INLINE gmio_bool_t gmio_task_iface_is_stop_requested(
const gmio_task_iface_t* itask)
const struct gmio_task_iface* itask)
{
if (itask != NULL && itask->func_is_stop_requested != NULL)
return itask->func_is_stop_requested(itask->cookie);
@ -31,7 +31,7 @@ GMIO_INLINE gmio_bool_t gmio_task_iface_is_stop_requested(
/*! Safe and convenient function for gmio_task_iface::func_handle_progress() */
GMIO_INLINE void gmio_task_iface_handle_progress(
const gmio_task_iface_t* itask, size_t value, size_t max_value)
const struct gmio_task_iface* itask, size_t value, size_t max_value)
{
if (itask != NULL && itask->func_handle_progress != NULL)
itask->func_handle_progress(itask->cookie, value, max_value);

View File

@ -29,7 +29,6 @@ struct gmio_const_string
const char* ptr; /*!< Contents */
size_t len; /*!< Size(length) of current contents */
};
typedef struct gmio_const_string gmio_const_string_t;
/*! Stores a mutable string of 8-bit chars
*
@ -42,42 +41,60 @@ struct gmio_string
size_t len; /*!< Size(length) of current contents */
size_t max_len; /*!< Maximum contents size(capacity) */
};
typedef struct gmio_string gmio_string_t;
/*! Expands to bracket initialization of a gmio_const_string from const char[]
*
* Example:
* \code
* static const char token[] = "woops";
* gmio_const_string_t token_s = GMIO_CONST_STRING_FROM_ARRAY(token);
* struct gmio_const_string token_s = GMIO_CONST_STRING_FROM_ARRAY(token);
* \endcode
*/
#define GMIO_CONST_STRING_FROM_ARRAY(array) { &(array)[0], sizeof(array) - 1 }
/*! Returns an initialized gmio_const_string_t object */
GMIO_INLINE gmio_const_string_t gmio_const_string(const char* ptr, size_t len);
/*! Returns an initialized struct gmio_const_string object */
GMIO_INLINE struct gmio_const_string gmio_const_string(const char* ptr, size_t len);
/*! Returns an initialized struct gmio_string object */
GMIO_INLINE struct gmio_string gmio_string(char* ptr, size_t len, size_t max_len);
/*! Clears the contents of the string \p str and makes it null */
GMIO_INLINE void gmio_string_clear(gmio_string_t* str);
GMIO_INLINE void gmio_string_clear(struct gmio_string* str);
/*! Clears the contents of the string \p str and makes it null */
GMIO_INLINE const char* gmio_string_end(const struct gmio_string* str);
/*
* -- Implementation
*/
gmio_const_string_t gmio_const_string(const char* ptr, size_t len)
struct gmio_const_string gmio_const_string(const char* ptr, size_t len)
{
gmio_const_string_t cstr;
struct gmio_const_string cstr;
cstr.ptr = ptr;
cstr.len = len;
return cstr;
}
void gmio_string_clear(gmio_string_t* str)
struct gmio_string gmio_string(char* ptr, size_t len, size_t max_len)
{
struct gmio_string str;
str.ptr = ptr;
str.len = len;
str.max_len = max_len;
return str;
}
void gmio_string_clear(struct gmio_string* str)
{
str->ptr[0] = 0;
str->len = 0;
}
const char* gmio_string_end(const struct gmio_string* str)
{
return &str->ptr[str->len];
}
#endif /* GMIO_INTERNAL_STRING_H */

View File

@ -17,7 +17,7 @@
#include "helper_stream.h"
void gmio_stringstream_init(gmio_stringstream_t *it)
void gmio_stringstream_init(struct gmio_stringstream *it)
{
/* Trick: declaring the buffer exhausted will actually trigger the first
* call to gmio_stream_read() inside gmio_next_char()
@ -28,8 +28,8 @@ void gmio_stringstream_init(gmio_stringstream_t *it)
gmio_stringstream_next_char(it);
}
gmio_eat_word_error_t gmio_stringstream_eat_word(
gmio_stringstream_t *it, gmio_string_t *str)
enum gmio_eat_word_error gmio_stringstream_eat_word(
struct gmio_stringstream *it, struct gmio_string *str)
{
char* str_ptr_at = str->ptr + str->len;
const char* str_ptr_end = str->ptr + str->max_len;
@ -61,7 +61,7 @@ gmio_eat_word_error_t gmio_stringstream_eat_word(
#if 0
gmio_bool_t gmio_stringstream_checked_next_chars(
gmio_stringstream_t *it, const char *str)
struct gmio_stringstream *it, const char *str)
{
size_t pos = 0;
const char* curr_char = gmio_stringstream_current_char(it);

View File

@ -28,39 +28,39 @@
*/
struct gmio_stringstream
{
gmio_stream_t stream;
gmio_string_t strbuff;
struct gmio_stream stream;
struct gmio_string strbuff;
const char* strbuff_end; /*!< Position after last char in strbuff */
const char* strbuff_at; /*!< Position indicator in buffer */
void* cookie;
void (*func_stream_read_hook)(void* cookie, const gmio_string_t* strbuff);
void (*func_stream_read_hook)(
void* cookie, const struct gmio_string* strbuff);
};
typedef struct gmio_stringstream gmio_stringstream_t;
/*! Initializes iterator */
void gmio_stringstream_init(gmio_stringstream_t* it);
void gmio_stringstream_init(struct gmio_stringstream* it);
/*! Returns the char where the iterator is currently pointing at */
GMIO_INLINE const char* gmio_stringstream_current_char(
const gmio_stringstream_t* it);
const struct gmio_stringstream* it);
/*! Moves on next char in stream */
GMIO_INLINE const char* gmio_stringstream_next_char(
gmio_stringstream_t *it);
struct gmio_stringstream *it);
/*! Moves on next char in stream */
GMIO_INLINE gmio_stringstream_t* gmio_stringstream_move_next_char(
gmio_stringstream_t *it);
GMIO_INLINE struct gmio_stringstream* gmio_stringstream_move_next_char(
struct gmio_stringstream *it);
/*! Advances iterator until the first non-space char */
GMIO_INLINE const char* gmio_stringstream_skip_ascii_spaces(
gmio_stringstream_t* it);
struct gmio_stringstream* it);
/*! Advances iterator until the first non-space char and copies in \p str any
* space found */
GMIO_INLINE void gmio_stringstream_copy_ascii_spaces(
gmio_stringstream_t* it, gmio_string_t* str);
struct gmio_stringstream* it, struct gmio_string* str);
/*! Error codes returned by gmio_eat_word() */
enum gmio_eat_word_error
@ -69,11 +69,10 @@ enum gmio_eat_word_error
GMIO_EAT_WORD_ERROR_EMPTY,
GMIO_EAT_WORD_ERROR_CAPACITY_OVERFLOW
};
typedef enum gmio_eat_word_error gmio_eat_word_error_t;
/*! Advances iterator so that next word is extracted into \p str */
gmio_eat_word_error_t gmio_stringstream_eat_word(
gmio_stringstream_t* it, gmio_string_t* str);
enum gmio_eat_word_error gmio_stringstream_eat_word(
struct gmio_stringstream* it, struct gmio_string* str);
#if 0
/*! Iterate over stream while it matches input string \p str
@ -81,12 +80,12 @@ gmio_eat_word_error_t gmio_stringstream_eat_word(
* Returns GMIO_TRUE if \p str was fully matched
*/
gmio_bool_t gmio_stringstream_checked_next_chars(
gmio_stringstream_t* it, const char* str);
struct gmio_stringstream* it, const char* str);
#endif
/*! Parses float from string iterator \p it */
GMIO_INLINE gmio_float32_t gmio_stringstream_parse_float32(
gmio_stringstream_t* it);
struct gmio_stringstream* it);
/*! Converts C string \p str to float
*
@ -119,14 +118,14 @@ GMIO_INLINE gmio_float32_t gmio_to_float32(const char* str);
#include <errno.h>
#include <stdlib.h>
const char* gmio_stringstream_current_char(const gmio_stringstream_t* it)
const char* gmio_stringstream_current_char(const struct gmio_stringstream* it)
{
return it->strbuff_at < it->strbuff_end ?
it->strbuff_at :
NULL;
}
const char *gmio_stringstream_next_char(gmio_stringstream_t *it)
const char *gmio_stringstream_next_char(struct gmio_stringstream *it)
{
++(it->strbuff_at);
if (it->strbuff_at < it->strbuff_end)
@ -146,13 +145,13 @@ const char *gmio_stringstream_next_char(gmio_stringstream_t *it)
return NULL;
}
gmio_stringstream_t* gmio_stringstream_move_next_char(gmio_stringstream_t *it)
struct gmio_stringstream* gmio_stringstream_move_next_char(struct gmio_stringstream *it)
{
gmio_stringstream_next_char(it);
return it;
}
const char* gmio_stringstream_skip_ascii_spaces(gmio_stringstream_t* it)
const char* gmio_stringstream_skip_ascii_spaces(struct gmio_stringstream* it)
{
const char* curr_char = gmio_stringstream_current_char(it);
while (curr_char != NULL && gmio_ascii_isspace(*curr_char))
@ -161,7 +160,7 @@ const char* gmio_stringstream_skip_ascii_spaces(gmio_stringstream_t* it)
}
void gmio_stringstream_copy_ascii_spaces(
gmio_stringstream_t* it, gmio_string_t* str)
struct gmio_stringstream* it, struct gmio_string* str)
{
const char* curr_char = gmio_stringstream_current_char(it);
while (curr_char != NULL
@ -200,13 +199,13 @@ gmio_float32_t gmio_to_float32(const char* str)
#endif
}
gmio_float32_t gmio_stringstream_parse_float32(gmio_stringstream_t* it)
gmio_float32_t gmio_stringstream_parse_float32(struct gmio_stringstream* it)
{
#if defined(GMIO_STRINGSTREAM_USE_FAST_ATOF)
return gmio_stringstream_fast_atof(it);
#else
char strbuff_ptr[64];
gmio_string_t strbuff = { &strbuff_ptr[0], 0, sizeof(strbuff_ptr) };
struct gmio_string strbuff = { &strbuff_ptr[0], 0, sizeof(strbuff_ptr) };
gmio_stringstream_eat_word(it, &strbuff);
return (gmio_float32_t)atof(strbuff_ptr);
#endif

View File

@ -12,7 +12,7 @@
#include "fast_atof.h"
#include "stringstream.h"
GMIO_INLINE uint32_t gmio_stringstream_strtoul10(gmio_stringstream_t* it)
GMIO_INLINE uint32_t gmio_stringstream_strtoul10(struct gmio_stringstream* it)
{
unsigned int value = 0;
const char* in = gmio_stringstream_current_char(it);
@ -25,7 +25,7 @@ GMIO_INLINE uint32_t gmio_stringstream_strtoul10(gmio_stringstream_t* it)
return value;
}
GMIO_INLINE int32_t gmio_stringstream_strtol10(gmio_stringstream_t* it)
GMIO_INLINE int32_t gmio_stringstream_strtol10(struct gmio_stringstream* it)
{
const char* in = gmio_stringstream_current_char(it);
const gmio_bool_t inv = (*in == '-');
@ -39,21 +39,21 @@ GMIO_INLINE int32_t gmio_stringstream_strtol10(gmio_stringstream_t* it)
return value;
}
typedef struct
struct gmio_stringstream_strtof10_result
{
float val;
unsigned char_diff;
} gmio_stringstream_strtof10_result_t;
};
GMIO_INLINE gmio_stringstream_strtof10_result_t gmio_stringstream_strtof10(
gmio_stringstream_t* it)
GMIO_INLINE struct gmio_stringstream_strtof10_result
gmio_stringstream_strtof10(struct gmio_stringstream* it)
{
const char* in = gmio_stringstream_current_char(it);
const uint32_t MAX_SAFE_U32_VALUE = UINT_MAX / 10 - 10;
uint32_t int_val = 0;
float float_val = 0.f;
unsigned char_diff = 0;
gmio_stringstream_strtof10_result_t result;
struct gmio_stringstream_strtof10_result result;
/* Use integer arithmetic for as long as possible, for speed and
* precision */
@ -79,7 +79,7 @@ GMIO_INLINE gmio_stringstream_strtof10_result_t gmio_stringstream_strtof10(
return result;
}
GMIO_INLINE float gmio_stringstream_fast_atof(gmio_stringstream_t* it)
GMIO_INLINE float gmio_stringstream_fast_atof(struct gmio_stringstream* it)
{
const char* in = gmio_stringstream_current_char(it);
const gmio_bool_t negative = ('-' == *in);
@ -92,7 +92,7 @@ GMIO_INLINE float gmio_stringstream_fast_atof(gmio_stringstream_t* it)
value = gmio_stringstream_strtof10(it).val;
in = gmio_stringstream_current_char(it);
if (is_local_decimal_point(*in)) {
const gmio_stringstream_strtof10_result_t decimal =
const struct gmio_stringstream_strtof10_result decimal =
gmio_stringstream_strtof10(
gmio_stringstream_move_next_char(it));
value += decimal.val * fast_atof_table[decimal.char_diff];

View File

@ -17,44 +17,38 @@
#include <stdlib.h>
GMIO_INLINE gmio_memblock_t gmio_memblock_null()
{
gmio_memblock_t buff = {0};
return buff;
}
gmio_memblock_t gmio_memblock(
struct gmio_memblock gmio_memblock(
void* ptr, size_t size, void (*func_deallocate)(void*))
{
gmio_memblock_t buff;
struct gmio_memblock buff;
buff.ptr = ptr;
buff.size = ptr != NULL ? size : 0;
buff.func_deallocate = func_deallocate;
return buff;
}
gmio_memblock_t gmio_memblock_malloc(size_t size)
struct gmio_memblock gmio_memblock_malloc(size_t size)
{
return gmio_memblock(malloc(size), size, &free);
}
gmio_memblock_t gmio_memblock_calloc(size_t num, size_t size)
struct gmio_memblock gmio_memblock_calloc(size_t num, size_t size)
{
return gmio_memblock(calloc(num, size), num * size, &free);
}
gmio_memblock_t gmio_memblock_realloc(void* ptr, size_t size)
struct gmio_memblock gmio_memblock_realloc(void* ptr, size_t size)
{
return gmio_memblock(realloc(ptr, size), size, &free);
}
void gmio_memblock_deallocate(gmio_memblock_t *mblock)
void gmio_memblock_deallocate(struct gmio_memblock *mblock)
{
if (mblock != NULL && mblock->func_deallocate != NULL)
mblock->func_deallocate(mblock->ptr);
}
static gmio_memblock_t gmio_memblock_default_internal_ctor()
static struct gmio_memblock gmio_memblock_default_internal_ctor()
{
return gmio_memblock_malloc(128 * 1024); /* 128 KB */
}
@ -74,7 +68,7 @@ gmio_memblock_constructor_func_t gmio_memblock_default_constructor()
return gmio_global_mblock_ctor;
}
gmio_memblock_t gmio_memblock_default()
struct gmio_memblock gmio_memblock_default()
{
return gmio_global_mblock_ctor();
}

View File

@ -40,7 +40,6 @@ struct gmio_memblock
* beginning at \p ptr */
void (*func_deallocate)(void* ptr);
};
typedef struct gmio_memblock gmio_memblock_t;
GMIO_C_LINKAGE_BEGIN
@ -48,27 +47,27 @@ GMIO_C_LINKAGE_BEGIN
*
* If \p ptr is NULL then gmio_memblock::size is forced to \c 0
*/
GMIO_LIB_EXPORT gmio_memblock_t gmio_memblock(
GMIO_LIB_EXPORT struct gmio_memblock gmio_memblock(
void* ptr, size_t size, void (*func_deallocate)(void*));
/*! Returns a gmio_memblock object allocated with standard \c malloc() */
GMIO_LIB_EXPORT gmio_memblock_t gmio_memblock_malloc(size_t size);
GMIO_LIB_EXPORT struct gmio_memblock gmio_memblock_malloc(size_t size);
/*! Returns a gmio_memblock object allocated with standard \c calloc() */
GMIO_LIB_EXPORT gmio_memblock_t gmio_memblock_calloc(size_t num, size_t size);
GMIO_LIB_EXPORT struct gmio_memblock gmio_memblock_calloc(size_t num, size_t size);
/*! Returns a gmio_memblock object allocated with standard \c realloc() */
GMIO_LIB_EXPORT gmio_memblock_t gmio_memblock_realloc(void* ptr, size_t size);
GMIO_LIB_EXPORT struct gmio_memblock gmio_memblock_realloc(void* ptr, size_t size);
/*! Safe and convenient call to gmio_memblock::func_deallocate() */
GMIO_LIB_EXPORT void gmio_memblock_deallocate(gmio_memblock_t* mblock);
GMIO_LIB_EXPORT void gmio_memblock_deallocate(struct gmio_memblock* mblock);
/*! Typedef for a pointer to a function that creates an allocated mblock
*
* Signature:
* \code gmio_memblock_t mblock_ctor(); \endcode
* \code struct gmio_memblock mblock_ctor(); \endcode
*/
typedef gmio_memblock_t (*gmio_memblock_constructor_func_t)();
typedef struct gmio_memblock (*gmio_memblock_constructor_func_t)();
/*! Installs a global function to construct gmio_memblock objects
*
@ -88,7 +87,7 @@ GMIO_LIB_EXPORT gmio_memblock_constructor_func_t gmio_memblock_default_construct
/*! Returns a gmio_memblock object created using the function
* gmio_memblock_default_constructor() */
GMIO_LIB_EXPORT gmio_memblock_t gmio_memblock_default();
GMIO_LIB_EXPORT struct gmio_memblock gmio_memblock_default();
GMIO_C_LINKAGE_END

62
src/gmio_core/rwargs.h Normal file
View File

@ -0,0 +1,62 @@
/****************************************************************************
** gmio
** Copyright Fougue (2 Mar. 2015)
** contact@fougue.pro
**
** 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".
****************************************************************************/
/*! \file rwargs.h
* Declares structures for the common arguments of read/write operations
*
* \addtogroup gmio_core
* @{
*/
#ifndef GMIO_RWARGS_H
#define GMIO_RWARGS_H
#include "stream.h"
#include "memblock.h"
#include "task_iface.h"
/*! Common arguments for read or write functions */
struct gmio_rwargs
{
/*! The stream object to be used for I/O */
struct gmio_stream stream;
/*! Optional memory block used by the stream to bufferize I/O device
* operations
*
* If passed null to a read/write function, then a temporary memblock
* is created with the global default constructor function (see
* gmio_memblock_default())
*/
struct gmio_memblock memblock;
/*! Optional interface by which the I/O operation can be controlled */
struct gmio_task_iface task_iface;
};
GMIO_INLINE struct gmio_rwargs gmio_rwargs_null();
/*
* Implementation
*/
struct gmio_rwargs gmio_rwargs_null()
{
static const struct gmio_rwargs null = {0};
return null;
}
#endif /* GMIO_RWARGS_H */

View File

@ -45,9 +45,9 @@ GMIO_INLINE int gmio_fstat(int fd, gmio_stat_t* buf)
#endif /* GMIO_HAVE_SYS_TYPES_H && GMIO_HAVE_SYS_STAT_H */
gmio_stream_t gmio_stream_null()
struct gmio_stream gmio_stream_null()
{
gmio_stream_t null_stream = {0};
struct gmio_stream null_stream = {0};
return null_stream;
}
@ -129,7 +129,7 @@ static gmio_streamsize_t gmio_stream_stdio_size(void* cookie)
#endif
}
static int gmio_stream_stdio_get_pos(void* cookie, gmio_stream_pos_t* pos)
static int gmio_stream_stdio_get_pos(void* cookie, struct gmio_stream_pos* pos)
{
fpos_t fpos;
int res = fgetpos((FILE*)cookie, &fpos);
@ -137,16 +137,16 @@ static int gmio_stream_stdio_get_pos(void* cookie, gmio_stream_pos_t* pos)
return res;
}
static int gmio_stream_stdio_set_pos(void* cookie, const gmio_stream_pos_t* pos)
static int gmio_stream_stdio_set_pos(void* cookie, const struct gmio_stream_pos* pos)
{
fpos_t fpos;
memcpy(&fpos, &pos->cookie[0], sizeof(fpos_t));
return fsetpos((FILE*)cookie, &fpos);
}
gmio_stream_t gmio_stream_stdio(FILE* file)
struct gmio_stream gmio_stream_stdio(FILE* file)
{
gmio_stream_t stream = gmio_stream_null();
struct gmio_stream stream = gmio_stream_null();
stream.cookie = file;
stream.func_at_end = gmio_stream_stdio_at_end;
stream.func_error = gmio_stream_stdio_error;

View File

@ -108,7 +108,7 @@ struct gmio_stream
* \retval 0 on success
* \retval !=0 on error
*/
int (*func_get_pos)(void* cookie, gmio_stream_pos_t* pos);
int (*func_get_pos)(void* cookie, struct gmio_stream_pos* pos);
/*! Pointer on a function that restores the current position in the stream
* to \p pos
@ -116,21 +116,19 @@ struct gmio_stream
* \retval 0 on success
* \retval !=0 on error
*/
int (*func_set_pos)(void* cookie, const gmio_stream_pos_t* pos);
int (*func_set_pos)(void* cookie, const struct gmio_stream_pos* pos);
};
typedef struct gmio_stream gmio_stream_t;
GMIO_C_LINKAGE_BEGIN
/* Initialization */
/*! Returns a null stream */
GMIO_LIB_EXPORT gmio_stream_t gmio_stream_null();
GMIO_LIB_EXPORT struct gmio_stream 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);
GMIO_LIB_EXPORT struct gmio_stream gmio_stream_stdio(FILE* file);
GMIO_C_LINKAGE_END

View File

@ -18,8 +18,8 @@
#include <stdio.h>
#include <stdlib.h>
gmio_stream_pos_t gmio_stream_pos_null()
struct gmio_stream_pos gmio_stream_pos_null()
{
gmio_stream_pos_t pos = {0};
struct gmio_stream_pos pos = {0};
return pos;
}

View File

@ -42,12 +42,11 @@ struct gmio_stream_pos
/*! Stores the actual(concrete) stream position object */
uint8_t cookie[GMIO_STREAM_POS_COOKIE_SIZE];
};
typedef struct gmio_stream_pos gmio_stream_pos_t;
GMIO_C_LINKAGE_BEGIN
/*! Returns a null stream position */
GMIO_LIB_EXPORT gmio_stream_pos_t gmio_stream_pos_null();
GMIO_LIB_EXPORT struct gmio_stream_pos gmio_stream_pos_null();
GMIO_C_LINKAGE_END

View File

@ -50,7 +50,5 @@ struct gmio_task_iface
void (*func_handle_progress)(void* cookie, size_t value, size_t max_value);
};
typedef struct gmio_task_iface gmio_task_iface_t;
#endif /* GMIO_TASK_IFACE_H */
/*! @} */

View File

@ -41,7 +41,6 @@ enum gmio_float_text_format
/*! Use the shortest representation: decimal or scientific uppercase */
GMIO_FLOAT_TEXT_FORMAT_SHORTEST_UPPERCASE
};
typedef enum gmio_float_text_format gmio_float_text_format_t;
#endif /* GMIO_TEXT_FORMAT_H */
/*! @} */

View File

@ -21,7 +21,7 @@
/*! Safe and convenient function for
* gmio_stl_mesh_creator::func_ascii_begin_solid() */
GMIO_INLINE void gmio_stl_mesh_creator_ascii_begin_solid(
gmio_stl_mesh_creator_t* creator,
struct gmio_stl_mesh_creator* creator,
gmio_streamsize_t stream_size,
const char* solid_name)
{
@ -34,9 +34,9 @@ GMIO_INLINE void gmio_stl_mesh_creator_ascii_begin_solid(
/*! Safe and convenient function for
* gmio_stl_mesh_creator::func_binary_begin_solid() */
GMIO_INLINE void gmio_stl_mesh_creator_binary_begin_solid(
gmio_stl_mesh_creator_t* creator,
struct gmio_stl_mesh_creator* creator,
uint32_t tri_count,
const gmio_stlb_header_t* header)
const struct gmio_stlb_header* header)
{
if (creator != NULL && creator->func_binary_begin_solid != NULL)
creator->func_binary_begin_solid(creator->cookie, tri_count, header);
@ -45,9 +45,9 @@ GMIO_INLINE void gmio_stl_mesh_creator_binary_begin_solid(
/*! Safe and convenient function for
* gmio_stl_mesh_creator::func_add_triangle() */
GMIO_INLINE void gmio_stl_mesh_creator_add_triangle(
gmio_stl_mesh_creator_t* creator,
struct gmio_stl_mesh_creator* creator,
uint32_t tri_id,
const gmio_stl_triangle_t* triangle)
const struct gmio_stl_triangle* triangle)
{
if (creator != NULL && creator->func_add_triangle != NULL)
creator->func_add_triangle(creator->cookie, tri_id, triangle);
@ -56,7 +56,7 @@ GMIO_INLINE void gmio_stl_mesh_creator_add_triangle(
/*! Safe and convenient function for
* gmio_stl_mesh_creator::func_end_solid() */
GMIO_INLINE void gmio_stl_mesh_creator_end_solid(
gmio_stl_mesh_creator_t* creator)
struct gmio_stl_mesh_creator* creator)
{
if (creator != NULL && creator->func_end_solid != NULL)
creator->func_end_solid(creator->cookie);

View File

@ -22,19 +22,19 @@
#include "../stl_mesh_creator.h"
/* gmio_stl_triangle */
typedef void (*gmio_stl_triangle_func_fix_endian_t)(gmio_stl_triangle_t*);
typedef void (*gmio_stl_triangle_func_fix_endian_t)(struct gmio_stl_triangle*);
/* gmio_stl_mesh */
typedef void (*gmio_stl_mesh_func_get_triangle_t)(
const void*, uint32_t, gmio_stl_triangle_t*);
const void*, uint32_t, struct gmio_stl_triangle*);
/* gmio_stl_mesh_creator */
typedef void (*gmio_stl_mesh_creator_func_ascii_begin_solid_t)(
void*, gmio_streamsize_t, const char*);
typedef void (*gmio_stl_mesh_creator_func_binary_begin_solid_t)(
void*, uint32_t, const gmio_stlb_header_t*);
void*, uint32_t, const struct gmio_stlb_header*);
typedef void (*gmio_stl_mesh_creator_func_add_triangle_t)(
void*, uint32_t, const gmio_stl_triangle_t*);
void*, uint32_t, const struct gmio_stl_triangle*);
typedef void (*gmio_stl_mesh_creator_func_end_solid_t)(void*);
#endif /* GMIO_INTERNAL_STL_FUNPTR_TYPEDEFS_H */

View File

@ -16,30 +16,31 @@
#include "stl_rw_common.h"
#include "../../gmio_core/error.h"
#include "../../gmio_core/rwargs.h"
#include "../stl_error.h"
#include "../stl_io.h"
gmio_bool_t gmio_check_transfer(int *error, const gmio_transfer_t* trsf)
gmio_bool_t gmio_check_rwargs(int *error, const struct gmio_rwargs* args)
{
if (trsf == NULL) {
*error = GMIO_ERROR_NULL_TRANSFER;
if (args == NULL) {
*error = GMIO_ERROR_NULL_RWARGS;
}
else {
if (trsf->memblock.ptr == NULL)
if (args->memblock.ptr == NULL)
*error = GMIO_ERROR_NULL_MEMBLOCK;
else if (trsf->memblock.size == 0)
else if (args->memblock.size == 0)
*error = GMIO_ERROR_INVALID_MEMBLOCK_SIZE;
}
return gmio_no_error(*error);
}
gmio_bool_t gmio_stl_check_mesh(int *error, const gmio_stl_mesh_t* mesh)
gmio_bool_t gmio_stl_check_mesh(int *error, const struct gmio_stl_mesh* mesh)
{
if (mesh == NULL
|| (mesh->triangle_count > 0 && mesh->func_get_triangle == NULL))
{
*error = GMIO_STL_ERROR_NULL_GET_TRIANGLE_FUNC;
*error = GMIO_STL_ERROR_NULL_FUNC_GET_TRIANGLE;
}
return gmio_no_error(*error);
@ -47,13 +48,13 @@ gmio_bool_t gmio_stl_check_mesh(int *error, const gmio_stl_mesh_t* mesh)
gmio_bool_t gmio_stlb_check_params(
int *error,
const gmio_transfer_t *trsf,
gmio_endianness_t byte_order)
const struct gmio_rwargs* args,
enum gmio_endianness byte_order)
{
if (!gmio_check_transfer(error, trsf))
if (!gmio_check_rwargs(error, args))
return GMIO_FALSE;
if (trsf->memblock.size < GMIO_STLB_MIN_CONTENTS_SIZE)
if (args->memblock.size < GMIO_STLB_MIN_CONTENTS_SIZE)
*error = GMIO_ERROR_INVALID_MEMBLOCK_SIZE;
if (byte_order != GMIO_ENDIANNESS_LITTLE
&& byte_order != GMIO_ENDIANNESS_BIG)

View File

@ -22,9 +22,9 @@
#include "../../gmio_core/global.h"
#include "../../gmio_core/endian.h"
#include "../../gmio_core/transfer.h"
#include "../stl_mesh.h"
#include "../stl_triangle.h"
struct gmio_rwargs;
struct gmio_stl_mesh;
struct gmio_stlb_readwrite_helper
{
@ -32,15 +32,14 @@ struct gmio_stlb_readwrite_helper
uint32_t i_facet_offset;
gmio_stl_triangle_func_fix_endian_t func_fix_endian;
};
typedef struct gmio_stlb_readwrite_helper gmio_stlb_readwrite_helper_t;
gmio_bool_t gmio_check_transfer(int* error, const gmio_transfer_t* trsf);
gmio_bool_t gmio_check_rwargs(int* error, const struct gmio_rwargs* args);
gmio_bool_t gmio_stl_check_mesh(int* error, const gmio_stl_mesh_t *mesh);
gmio_bool_t gmio_stl_check_mesh(int* error, const struct gmio_stl_mesh* mesh);
gmio_bool_t gmio_stlb_check_params(
int* error,
const gmio_transfer_t* trsf,
gmio_endianness_t byte_order);
const struct gmio_rwargs* args,
enum gmio_endianness byte_order);
#endif /* GMIO_INTERNAL_STLB_RW_COMMON_H */

View File

@ -18,10 +18,14 @@
#include "stl_funptr_typedefs.h"
#include "stl_rw_common.h"
#include "../stl_error.h"
#include "../stl_io_options.h"
#include "../stl_mesh.h"
#include "../../gmio_core/error.h"
#include "../../gmio_core/rwargs.h"
#include "../../gmio_core/text_format.h"
#include "../../gmio_core/internal/helper_rwargs.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"
@ -85,7 +89,7 @@ GMIO_INLINE char* gmio_write_rawstr_eol(char* buffer, const char* str)
}
GMIO_INLINE char gmio_float_text_format_to_specifier(
gmio_float_text_format_t format)
enum gmio_float_text_format format)
{
switch (format) {
case GMIO_FLOAT_TEXT_FORMAT_DECIMAL_LOWERCASE: return 'f';
@ -114,36 +118,37 @@ GMIO_INLINE char* gmio_write_stdio_format(
GMIO_INLINE char* gmio_write_coords(
char* buffer,
const char* coords_format,
const gmio_stl_coords_t* coords)
const struct gmio_stl_coords* coords)
{
return buffer + sprintf(buffer,
coords_format, coords->x, coords->y, coords->z);
}
GMIO_INLINE gmio_bool_t gmio_transfer_flush_buffer(
gmio_transfer_t* trsf, size_t n)
GMIO_INLINE gmio_bool_t gmio_rwargs_flush_buffer(
struct gmio_rwargs* args, size_t n)
{
const size_t write_count =
gmio_stream_write(&trsf->stream, trsf->memblock.ptr, sizeof(char), n);
gmio_stream_write(
&args->stream, args->memblock.ptr, sizeof(char), n);
return write_count == n;
}
int gmio_stla_write(
gmio_transfer_t* trsf,
const gmio_stl_mesh_t* mesh,
const gmio_stl_write_options_t* options)
struct gmio_rwargs* args,
const struct gmio_stl_mesh* mesh,
const struct gmio_stl_write_options* options)
{
/* Constants */
const uint32_t total_facet_count = mesh != NULL ? mesh->triangle_count : 0;
const uint32_t buffer_facet_count =
trsf != NULL ?
gmio_size_to_uint32(trsf->memblock.size / GMIO_STLA_FACET_SIZE_P2)
args != NULL ?
gmio_size_to_uint32(args->memblock.size / GMIO_STLA_FACET_SIZE_P2)
: 0;
const char* opt_solid_name =
options != NULL ? options->stla_solid_name : NULL;
const char* solid_name =
opt_solid_name != NULL ? opt_solid_name : "";
const gmio_float_text_format_t float32_format =
const enum gmio_float_text_format float32_format =
options != NULL ?
options->stla_float32_format :
GMIO_FLOAT_TEXT_FORMAT_DECIMAL_LOWERCASE;
@ -153,19 +158,19 @@ int gmio_stla_write(
options != NULL ? options->stl_write_triangles_only : GMIO_FALSE;
/* Variables */
uint32_t ifacet = 0;
void* mblock_ptr = trsf != NULL ? trsf->memblock.ptr : NULL;
void* mblock_ptr = args != NULL ? args->memblock.ptr : NULL;
char* buffc = mblock_ptr;
char coords_format[64];
int error = GMIO_ERROR_OK;
/* Check validity of input parameters */
if (!gmio_check_transfer(&error, trsf))
if (!gmio_check_rwargs(&error, args))
return error;
if (!gmio_stl_check_mesh(&error, mesh))
return error;
if (float32_prec == 0 || float32_prec > 9)
return GMIO_STL_ERROR_INVALID_FLOAT32_PREC;
if (trsf->memblock.size < GMIO_STLA_FACET_SIZE_P2)
if (args->memblock.size < GMIO_STLA_FACET_SIZE_P2)
return GMIO_ERROR_INVALID_MEMBLOCK_SIZE;
{ /* Create XYZ coords format string (for normal and vertex coords) */
@ -185,7 +190,7 @@ int gmio_stla_write(
if (!write_triangles_only) {
buffc = gmio_write_rawstr(buffc, "solid ");
buffc = gmio_write_rawstr_eol(buffc, solid_name);
if (!gmio_transfer_flush_buffer(trsf, buffc - (char*)mblock_ptr))
if (!gmio_rwargs_flush_buffer(args, buffc - (char*)mblock_ptr))
return GMIO_ERROR_STREAM;
}
@ -199,10 +204,10 @@ int gmio_stla_write(
const void* mesh_cookie = mesh->cookie;
const uint32_t clamped_facet_count =
GMIO_MIN(ifacet + buffer_facet_count, total_facet_count);
gmio_stl_triangle_t tri;
struct gmio_stl_triangle tri;
uint32_t ibuffer_facet;
gmio_transfer_handle_progress(trsf, ifacet, total_facet_count);
gmio_rwargs_handle_progress(args, ifacet, total_facet_count);
/* Writing of facets is buffered */
buffc = mblock_ptr;
@ -226,19 +231,19 @@ int gmio_stla_write(
buffc = gmio_write_rawstr(buffc, "\nendfacet\n");
} /* end for (ibuffer_facet) */
if (!gmio_transfer_flush_buffer(trsf, buffc - (char*)mblock_ptr))
if (!gmio_rwargs_flush_buffer(args, buffc - (char*)mblock_ptr))
error = GMIO_ERROR_STREAM;
/* Task control */
if (gmio_no_error(error) && gmio_transfer_is_stop_requested(trsf))
if (gmio_no_error(error) && gmio_rwargs_is_stop_requested(args))
error = GMIO_ERROR_TRANSFER_STOPPED;
} /* end for (ifacet) */
/* Write end of solid */
if (gmio_no_error(error) && !write_triangles_only) {
buffc = gmio_write_rawstr(trsf->memblock.ptr, "endsolid ");
buffc = gmio_write_rawstr(args->memblock.ptr, "endsolid ");
buffc = gmio_write_rawstr_eol(buffc, solid_name);
if (!gmio_transfer_flush_buffer(trsf, buffc - (char*)mblock_ptr))
if (!gmio_rwargs_flush_buffer(args, buffc - (char*)mblock_ptr))
error = GMIO_ERROR_STREAM;
}

View File

@ -16,20 +16,19 @@
#ifndef GMIO_INTERNAL_STLA_WRITE_H
#define GMIO_INTERNAL_STLA_WRITE_H
#include "../stl_mesh.h"
#include "../stl_io_options.h"
#include "../../gmio_core/text_format.h"
#include "../../gmio_core/transfer.h"
struct gmio_rwargs;
struct gmio_stl_mesh;
struct gmio_stl_write_options;
/*! Writes geometry in the STL ascii format
*
* \return Error code (see error.h and stl_error.h)
* \retval GMIO_ERROR_INVALID_MEMBLOCK_SIZE
* if <tt>trsf->memblock.size < 512</tt>
* if <tt>args->memblock.size < 512</tt>
*/
int gmio_stla_write(
gmio_transfer_t* trsf,
const gmio_stl_mesh_t* mesh,
const gmio_stl_write_options_t* options);
struct gmio_rwargs* args,
const struct gmio_stl_mesh* mesh,
const struct gmio_stl_write_options* options);
#endif /* GMIO_INTERNAL_STLA_WRITE_H */

View File

@ -17,7 +17,7 @@
#include "../../gmio_core/internal/byte_swap.h"
void gmio_stl_triangle_bswap(gmio_stl_triangle_t* triangle)
void gmio_stl_triangle_bswap(struct gmio_stl_triangle* triangle)
{
int i;
uint32_t* uintcoord_ptr = (uint32_t*)&(triangle->normal.x);

View File

@ -24,6 +24,6 @@
* Each XYZ coord (float32) is individually reversed (byte-swap) as well as
* the "attribute byte count" member.
*/
void gmio_stl_triangle_bswap(gmio_stl_triangle_t* triangle);
void gmio_stl_triangle_bswap(struct gmio_stl_triangle* triangle);
#endif /* GMIO_INTERNAL_STLB_BYTE_SWAP_H */

View File

@ -20,26 +20,27 @@
#include "stlb_byte_swap.h"
#include "../stl_error.h"
#include "../stl_io.h"
#include "../stl_io_options.h"
#include "../../gmio_core/error.h"
#include "../../gmio_core/internal/byte_codec.h"
#include "../../gmio_core/internal/min_max.h"
#include "../../gmio_core/internal/helper_rwargs.h"
#include "../../gmio_core/internal/helper_stream.h"
#include "../../gmio_core/internal/helper_transfer.h"
#include "../../gmio_core/internal/safe_cast.h"
#include <string.h>
GMIO_INLINE void write_triangle_memcpy(
const gmio_stl_triangle_t* triangle, uint8_t* mblock)
const struct gmio_stl_triangle* triangle, uint8_t* mblock)
{
memcpy(mblock, triangle, GMIO_STLB_TRIANGLE_RAWSIZE);
}
static void gmio_stlb_write_facets(
const gmio_stl_mesh_t* mesh,
const struct gmio_stl_mesh* mesh,
uint8_t* mblock,
const gmio_stlb_readwrite_helper_t* wparams)
const struct gmio_stlb_readwrite_helper* wparams)
{
const uint32_t facet_count = wparams->facet_count;
const uint32_t i_facet_offset = wparams->i_facet_offset;
@ -48,7 +49,7 @@ static void gmio_stlb_write_facets(
const gmio_stl_mesh_func_get_triangle_t func_get_triangle =
mesh->func_get_triangle;
const void* cookie = mesh->cookie;
gmio_stl_triangle_t triangle;
struct gmio_stl_triangle triangle;
uint32_t mblock_offset = 0;
uint32_t i_facet = 0;
@ -65,10 +66,10 @@ static void gmio_stlb_write_facets(
}
int gmio_stlb_write(
gmio_transfer_t* trsf,
const gmio_stl_mesh_t* mesh,
const gmio_stl_write_options_t* options,
gmio_endianness_t byte_order)
struct gmio_rwargs* args,
const struct gmio_stl_mesh* mesh,
const struct gmio_stl_write_options* options,
enum gmio_endianness byte_order)
{
/* Constants */
const uint32_t facet_count =
@ -76,14 +77,14 @@ int gmio_stlb_write(
const gmio_bool_t write_triangles_only =
options != NULL ? options->stl_write_triangles_only : GMIO_FALSE;
/* Variables */
void* mblock_ptr = trsf != NULL ? trsf->memblock.ptr : NULL;
gmio_stlb_readwrite_helper_t wparams = {0};
void* mblock_ptr = args != NULL ? args->memblock.ptr : NULL;
struct gmio_stlb_readwrite_helper wparams = {0};
uint32_t i_facet = 0;
int error = GMIO_ERROR_OK;
/* Check validity of input parameters */
if (!gmio_stl_check_mesh(&error, mesh)
|| !gmio_stlb_check_params(&error, trsf, byte_order))
|| !gmio_stlb_check_params(&error, args, byte_order))
{
return error;
}
@ -94,11 +95,11 @@ int gmio_stlb_write(
/* Note: trsf != NULL certified by gmio_stlb_check_params() */
/* coverity[var_deref_op : FALSE] */
wparams.facet_count = gmio_size_to_uint32(
trsf->memblock.size / GMIO_STLB_TRIANGLE_RAWSIZE);
args->memblock.size / GMIO_STLB_TRIANGLE_RAWSIZE);
if (!write_triangles_only) {
error = gmio_stlb_write_header(
&trsf->stream,
&args->stream,
byte_order,
options != NULL ? options->stlb_header_data : NULL,
facet_count);
@ -111,7 +112,7 @@ int gmio_stlb_write(
i_facet < facet_count && gmio_no_error(error);
i_facet += wparams.facet_count)
{
gmio_transfer_handle_progress(trsf, i_facet, facet_count);
gmio_rwargs_handle_progress(args, i_facet, facet_count);
/* Write to memory block */
wparams.facet_count = GMIO_MIN(wparams.facet_count,
@ -122,7 +123,7 @@ int gmio_stlb_write(
/* Write memory block to stream */
if (gmio_stream_write(
&trsf->stream,
&args->stream,
mblock_ptr,
GMIO_STLB_TRIANGLE_RAWSIZE,
wparams.facet_count)
@ -132,7 +133,7 @@ int gmio_stlb_write(
}
/* Handle stop request */
if (gmio_no_error(error) && gmio_transfer_is_stop_requested(trsf))
if (gmio_no_error(error) && gmio_rwargs_is_stop_requested(args))
error = GMIO_ERROR_TRANSFER_STOPPED;
} /* end for */

View File

@ -16,10 +16,10 @@
#ifndef GMIO_INTERNAL_STLB_WRITE_H
#define GMIO_INTERNAL_STLB_WRITE_H
#include "../stl_mesh.h"
#include "../stl_io_options.h"
#include "../../gmio_core/endian.h"
#include "../../gmio_core/transfer.h"
struct gmio_rwargs;
struct gmio_stl_mesh;
struct gmio_stl_write_options;
enum gmio_endianness;
/*! Writes geometry in the STL binary format
*
@ -28,9 +28,9 @@
* if <tt>trsf->memblock.size < GMIO_STLB_MIN_CONTENTS_SIZE</tt>
*/
int gmio_stlb_write(
gmio_transfer_t* trsf,
const gmio_stl_mesh_t* mesh,
const gmio_stl_write_options_t* options,
gmio_endianness_t byte_order);
struct gmio_rwargs* args,
const struct gmio_stl_mesh* mesh,
const struct gmio_stl_write_options* options,
enum gmio_endianness byte_order);
#endif /* GMIO_INTERNAL_STLB_WRITE_H */

View File

@ -35,7 +35,7 @@ enum gmio_stl_error
/*! Common STL write error indicating gmio_stl_mesh::func_get_triangle()
* pointer is NULL */
GMIO_STL_ERROR_NULL_GET_TRIANGLE_FUNC = GMIO_STL_ERROR_TAG + 0x02,
GMIO_STL_ERROR_NULL_FUNC_GET_TRIANGLE = GMIO_STL_ERROR_TAG + 0x02,
/* Specific error codes returned by STL_ascii read function */
@ -58,7 +58,5 @@ enum gmio_stl_error
GMIO_STL_ERROR_FACET_COUNT = GMIO_STL_ERROR_TAG + 0x1002
};
typedef enum gmio_stl_error gmio_stl_error_t;
#endif /* GMIO_STL_ERROR_H */
/*! @} */

View File

@ -34,11 +34,11 @@ GMIO_INLINE gmio_streamsize_t gmio_stlb_streamsize(uint32_t facet_count)
return GMIO_STLB_HEADER_SIZE + 4 + facet_count*GMIO_STLB_TRIANGLE_RAWSIZE;
}
gmio_stl_format_t gmio_stl_get_format(gmio_stream_t *stream)
enum gmio_stl_format gmio_stl_get_format(struct gmio_stream *stream)
{
char fixed_buffer[GMIO_FIXED_BUFFER_SIZE] = {0};
size_t read_size = 0;
gmio_stream_pos_t stream_start_pos = gmio_stream_pos_null();
struct gmio_stream_pos stream_start_pos = gmio_stream_pos_null();
if (stream == NULL)
return GMIO_STL_FORMAT_UNKNOWN;
@ -89,13 +89,13 @@ gmio_stl_format_t gmio_stl_get_format(gmio_stream_t *stream)
return GMIO_STL_FORMAT_UNKNOWN;
}
gmio_stl_format_t gmio_stl_get_format_file(const char* filepath)
enum gmio_stl_format gmio_stl_get_format_file(const char* filepath)
{
gmio_stl_format_t format = GMIO_STL_FORMAT_UNKNOWN;
enum gmio_stl_format format = GMIO_STL_FORMAT_UNKNOWN;
FILE* file = fopen(filepath, "rb");
if (file != NULL) {
gmio_stream_t stream = gmio_stream_stdio(file);
struct gmio_stream stream = gmio_stream_stdio(file);
format = gmio_stl_get_format(&stream);
fclose(file);
}

View File

@ -35,8 +35,6 @@ enum gmio_stl_format
GMIO_STL_FORMAT_BINARY_BE /*!< STL binary (big-endian) */
};
typedef enum gmio_stl_format gmio_stl_format_t;
GMIO_C_LINKAGE_BEGIN
/*! Returns the format of the STL data in \p stream
@ -47,7 +45,7 @@ GMIO_C_LINKAGE_BEGIN
* \retval GMIO_STL_FORMAT_UNKNOWN in case of error.
*/
GMIO_LIBSTL_EXPORT
gmio_stl_format_t gmio_stl_get_format(gmio_stream_t* stream);
enum gmio_stl_format gmio_stl_get_format(struct gmio_stream* stream);
/*! Returns the format of the STL data in file at location \p filepath
*
@ -58,7 +56,7 @@ gmio_stl_format_t gmio_stl_get_format(gmio_stream_t* stream);
* environment
*/
GMIO_LIBSTL_EXPORT
gmio_stl_format_t gmio_stl_get_format_file(const char* filepath);
enum gmio_stl_format gmio_stl_get_format_file(const char* filepath);
GMIO_C_LINKAGE_END

View File

@ -17,33 +17,37 @@
#include "stl_error.h"
#include "stl_format.h"
#include "stlb_header.h"
#include "internal/stla_write.h"
#include "internal/stlb_write.h"
#include "../gmio_core/error.h"
#include "../gmio_core/rwargs.h"
#include "../gmio_core/stream.h"
#include "../gmio_core/transfer.h"
#include "../gmio_core/internal/byte_codec.h"
#include "../gmio_core/internal/helper_stream.h"
int gmio_stl_read_file(
const char* filepath,
gmio_stl_mesh_creator_t* creator,
gmio_task_iface_t* task_iface)
struct gmio_rwargs* args,
struct gmio_stl_mesh_creator* creator)
{
int error = GMIO_ERROR_OK;
FILE* file = NULL;
file = fopen(filepath, "rb");
if (file != NULL) {
gmio_transfer_t trsf = {0};
trsf.stream = gmio_stream_stdio(file);
trsf.memblock = gmio_memblock_default();
if (task_iface != NULL)
trsf.task_iface = *task_iface;
struct gmio_rwargs local_args =
args != NULL ? *args : gmio_rwargs_null();
const gmio_bool_t memblock_allocated =
local_args.memblock.ptr == NULL;
error = gmio_stl_read(&trsf, creator);
if (memblock_allocated)
local_args.memblock = gmio_memblock_default();
local_args.stream = gmio_stream_stdio(file);
error = gmio_stl_read(&local_args, creator);
fclose(file);
gmio_memblock_deallocate(&trsf.memblock);
if (memblock_allocated)
gmio_memblock_deallocate(&local_args.memblock);
}
else {
error = GMIO_ERROR_STDIO;
@ -52,24 +56,27 @@ int gmio_stl_read_file(
return error;
}
int gmio_stl_read(gmio_transfer_t *trsf, gmio_stl_mesh_creator_t *creator)
int gmio_stl_read(
struct gmio_rwargs* args,
struct gmio_stl_mesh_creator* creator)
{
int error = GMIO_ERROR_OK;
if (trsf != NULL) {
const gmio_stl_format_t stl_format = gmio_stl_get_format(&trsf->stream);
if (args != NULL) {
const enum gmio_stl_format stl_format =
gmio_stl_get_format(&args->stream);
switch (stl_format) {
case GMIO_STL_FORMAT_ASCII: {
error = gmio_stla_read(trsf, creator);
error = gmio_stla_read(args, creator);
break;
}
case GMIO_STL_FORMAT_BINARY_BE: {
error = gmio_stlb_read(trsf, creator, GMIO_ENDIANNESS_BIG);
error = gmio_stlb_read(args, creator, GMIO_ENDIANNESS_BIG);
break;
}
case GMIO_STL_FORMAT_BINARY_LE: {
error = gmio_stlb_read(trsf, creator, GMIO_ENDIANNESS_LITTLE);
error = gmio_stlb_read(args, creator, GMIO_ENDIANNESS_LITTLE);
break;
}
case GMIO_STL_FORMAT_UNKNOWN: {
@ -78,33 +85,36 @@ int gmio_stl_read(gmio_transfer_t *trsf, gmio_stl_mesh_creator_t *creator)
} /* end switch() */
}
else {
error = GMIO_ERROR_NULL_TRANSFER;
error = GMIO_ERROR_NULL_RWARGS;
}
return error;
}
int gmio_stl_write_file(
gmio_stl_format_t format,
const char *filepath,
const gmio_stl_mesh_t *mesh,
gmio_task_iface_t *task_iface,
const gmio_stl_write_options_t *options)
const char* filepath,
struct gmio_rwargs* args,
const struct gmio_stl_mesh* mesh,
enum gmio_stl_format format,
const struct gmio_stl_write_options* options)
{
int error = GMIO_ERROR_OK;
FILE* file = NULL;
file = fopen(filepath, "wb");
if (file != NULL) {
gmio_transfer_t trsf = {0};
trsf.stream = gmio_stream_stdio(file);
trsf.memblock = gmio_memblock_default();
if (task_iface != NULL)
trsf.task_iface = *task_iface;
struct gmio_rwargs local_args =
args != NULL ? *args : gmio_rwargs_null();
const gmio_bool_t memblock_allocated =
local_args.memblock.ptr == NULL;
error = gmio_stl_write(format, &trsf, mesh, options);
if (memblock_allocated)
local_args.memblock = gmio_memblock_default();
local_args.stream = gmio_stream_stdio(file);
error = gmio_stl_write(&local_args, mesh, format, options);
fclose(file);
gmio_memblock_deallocate(&trsf.memblock);
if (memblock_allocated)
gmio_memblock_deallocate(&local_args.memblock);
}
else {
error = GMIO_ERROR_STDIO;
@ -114,49 +124,56 @@ int gmio_stl_write_file(
}
int gmio_stl_write(
gmio_stl_format_t format,
gmio_transfer_t *trsf,
const gmio_stl_mesh_t *mesh,
const gmio_stl_write_options_t *options)
struct gmio_rwargs* args,
const struct gmio_stl_mesh* mesh,
enum gmio_stl_format format,
const struct gmio_stl_write_options* options)
{
int error = GMIO_ERROR_OK;
if (trsf != NULL) {
if (args != NULL) {
const gmio_bool_t memblock_allocated = args->memblock.ptr == NULL;
if (memblock_allocated)
args->memblock = gmio_memblock_default();
switch (format) {
case GMIO_STL_FORMAT_ASCII: {
error = gmio_stla_write(trsf, mesh, options);
error = gmio_stla_write(args, mesh, options);
break;
}
case GMIO_STL_FORMAT_BINARY_BE: {
error = gmio_stlb_write(trsf, mesh, options, GMIO_ENDIANNESS_BIG);
error = gmio_stlb_write(args, mesh, options, GMIO_ENDIANNESS_BIG);
break;
}
case GMIO_STL_FORMAT_BINARY_LE: {
error = gmio_stlb_write(trsf, mesh, options, GMIO_ENDIANNESS_LITTLE);
error = gmio_stlb_write(args, mesh, options, GMIO_ENDIANNESS_LITTLE);
break;
}
case GMIO_STL_FORMAT_UNKNOWN: {
error = GMIO_STL_ERROR_UNKNOWN_FORMAT;
}
} /* end switch() */
if (memblock_allocated)
gmio_memblock_deallocate(&args->memblock);
}
else {
error = GMIO_ERROR_NULL_TRANSFER;
error = GMIO_ERROR_NULL_RWARGS;
}
return error;
}
static const gmio_stlb_header_t internal_stlb_zero_header = {0};
static const struct gmio_stlb_header internal_stlb_zero_header = {0};
int gmio_stlb_write_header(
gmio_stream_t *stream,
gmio_endianness_t byte_order,
const gmio_stlb_header_t *header,
struct gmio_stream *stream,
enum gmio_endianness byte_order,
const struct gmio_stlb_header *header,
uint32_t facet_count)
{
uint8_t facet_count_bytes[sizeof(uint32_t)];
const gmio_stlb_header_t* non_null_header =
const struct gmio_stlb_header* non_null_header =
header != NULL ? header : &internal_stlb_zero_header;
/* Write 80-byte header */
@ -168,14 +185,11 @@ int gmio_stlb_write_header(
/* Write facet count */
if (byte_order == GMIO_ENDIANNESS_LITTLE)
gmio_encode_uint32_le(facet_count, &facet_count_bytes[0]);
gmio_encode_uint32_le(facet_count, facet_count_bytes);
else
gmio_encode_uint32_be(facet_count, &facet_count_bytes[0]);
if (gmio_stream_write(stream, &facet_count_bytes[0], sizeof(uint32_t), 1)
!= 1)
{
gmio_encode_uint32_be(facet_count, facet_count_bytes);
if (gmio_stream_write(stream, facet_count_bytes, sizeof(uint32_t), 1) != 1)
return GMIO_ERROR_STREAM;
}
return GMIO_ERROR_OK;
}

View File

@ -25,20 +25,21 @@
#include "stl_global.h"
#include "stl_format.h"
#include "stl_mesh.h"
#include "stl_mesh_creator.h"
#include "stl_io_options.h"
#include "../gmio_core/endian.h"
#include "../gmio_core/transfer.h"
struct gmio_rwargs;
struct gmio_stream;
struct gmio_stl_mesh;
struct gmio_stl_mesh_creator;
struct gmio_stl_write_options;
struct gmio_stlb_header;
enum gmio_endianness;
enum gmio_stl_format;
GMIO_C_LINKAGE_BEGIN
/*! Reads STL mesh from file, format is automatically guessed
*
* Internally, it uses:
* \li the builtin stream wrapper around FILE* (see gmio_stream_stdio())
* \li the global default function to construct a temporary gmio_memblock
* object (see gmio_memblock_default())
*
* \return Error code (see error.h and stl_error.h)
*/
@ -49,12 +50,13 @@ int gmio_stl_read_file(
* name specifications of the running environment */
const char* filepath,
/*! Defines the callbacks for the mesh creation */
gmio_stl_mesh_creator_t* creator,
/*! Common objects needed for the read operation
* gmio_read_args::stream is internally initialized with the
* builtin stream wrapper around \c FILE* (see gmio_stream_stdio()) */
struct gmio_rwargs* args,
/*! The interface object by which the read operation can be controlled.
* Optional, can be safely set to NULL */
gmio_task_iface_t* task_iface
/*! Defines the callbacks for the mesh creation */
struct gmio_stl_mesh_creator* creator
);
/*! Reads STL mesh from stream, format is automatically guessed
@ -63,11 +65,11 @@ int gmio_stl_read_file(
*/
GMIO_LIBSTL_EXPORT
int gmio_stl_read(
/*! Defines needed objects for the read operation */
gmio_transfer_t* trsf,
/*! Common objects needed for the read operation */
struct gmio_rwargs* args,
/*! Defines the callbacks for the mesh creation */
gmio_stl_mesh_creator_t* creator
struct gmio_stl_mesh_creator* creator
);
/*! Writes STL mesh to file
@ -81,24 +83,25 @@ int gmio_stl_read(
*/
GMIO_LIBSTL_EXPORT
int gmio_stl_write_file(
/*! STL format of the output file */
gmio_stl_format_t format,
/*! Path to the STL file. A stream is opened with fopen() so the string
* shall follow the file name specifications of the running
* environment */
const char* filepath,
/*! Defines the mesh to output */
const gmio_stl_mesh_t* mesh,
/*! Common objects needed for the write operation
* gmio_read_args::stream is internally initialized with the
* builtin stream wrapper around \c FILE* (see gmio_stream_stdio()) */
struct gmio_rwargs* args,
/*! The interface object by which the write operation can be controlled.
* Optional, can be safely set to NULL */
gmio_task_iface_t* task_iface,
/*! Defines the mesh to output */
const struct gmio_stl_mesh* mesh,
/*! STL format of the output file */
enum gmio_stl_format format,
/*! Options for the write operation, can be safely set to NULL to use
* default values */
const gmio_stl_write_options_t* options
const struct gmio_stl_write_options* options
);
/*! Writes STL mesh to stream
@ -107,18 +110,18 @@ int gmio_stl_write_file(
*/
GMIO_LIBSTL_EXPORT
int gmio_stl_write(
/*! STL format of the output */
gmio_stl_format_t format,
/*! Defines needed objects for the write operation */
gmio_transfer_t* trsf,
/*! Common objects needed for the write operation */
struct gmio_rwargs* args,
/*! Defines the mesh to output */
const gmio_stl_mesh_t* mesh,
const struct gmio_stl_mesh* mesh,
/*! STL format of the output */
enum gmio_stl_format format,
/*! Options for the write operation, can be safely set to NULL to use
* default values */
const gmio_stl_write_options_t* options
const struct gmio_stl_write_options* options
);
/*! Reads geometry from STL ascii stream
@ -134,11 +137,11 @@ int gmio_stl_write(
*/
GMIO_LIBSTL_EXPORT
int gmio_stla_read(
/*! Defines needed objects for the read operation */
gmio_transfer_t* trsf,
/*! Common objects needed for the read operation */
struct gmio_rwargs* args,
/*! Defines the callbacks for the mesh creation */
gmio_stl_mesh_creator_t* creator
struct gmio_stl_mesh_creator* creator
);
/*! Size(in bytes) of the minimum contents possible with the STL binary format */
@ -152,14 +155,14 @@ enum { GMIO_STLB_MIN_CONTENTS_SIZE = 284 };
*/
GMIO_LIBSTL_EXPORT
int gmio_stlb_read(
/*! Defines needed objects for the read operation */
gmio_transfer_t* trsf,
/*! Common objects needed for the read operation */
struct gmio_rwargs* args,
/*! Defines the callbacks for the mesh creation */
gmio_stl_mesh_creator_t* creator,
struct gmio_stl_mesh_creator* creator,
/*! Byte order of the input STL binary data */
gmio_endianness_t byte_order
enum gmio_endianness byte_order
);
/*! Writes STL binary header data to stream
@ -172,14 +175,14 @@ int gmio_stlb_read(
GMIO_LIBSTL_EXPORT
int gmio_stlb_write_header(
/*! Output stream where is written the header data */
gmio_stream_t* stream,
struct gmio_stream* stream,
/*! Byte order of the output STL data */
gmio_endianness_t byte_order,
enum gmio_endianness byte_order,
/*! 80-bytes array of header data, can be safely set to NULL to generate
* an array of zeroes */
const gmio_stlb_header_t* header,
const struct gmio_stlb_header* header,
/*! Total count of facets (triangles) in the mesh to be written */
uint32_t facet_count

View File

@ -59,7 +59,7 @@ struct gmio_stl_write_options
* Defaulted to \c GMIO_FLOAT_TEXT_FORMAT_DECIMAL_LOWERCASE when calling
* gmio_stl_write() with \c options==NULL
*/
gmio_float_text_format_t stla_float32_format;
enum gmio_float_text_format stla_float32_format;
/*! The maximum number of significant digits when writting float values
*
@ -78,9 +78,8 @@ struct gmio_stl_write_options
* \li calling gmio_stl_write() with <tt>options == NULL</tt>
* \li OR <tt>stlb_header_data == NULL</tt>
*/
const gmio_stlb_header_t* stlb_header_data;
const struct gmio_stlb_header* stlb_header_data;
};
typedef struct gmio_stl_write_options gmio_stl_write_options_t;
#endif /* GMIO_STL_IO_OPTIONS_H */
/*! @} */

View File

@ -39,10 +39,8 @@ struct gmio_stl_mesh
/*! Pointer on a function that stores the mesh triangle of index \p tri_id
* into \p triangle */
void (*func_get_triangle)(
const void* cookie, uint32_t tri_id, gmio_stl_triangle_t* triangle);
const void* cookie, uint32_t tri_id, struct gmio_stl_triangle* triangle);
};
typedef struct gmio_stl_mesh gmio_stl_mesh_t;
#endif /* GMIO_STL_MESH_H */
/*! @} */

View File

@ -59,17 +59,21 @@ struct gmio_stl_mesh_creator
* The argument \p header contains the header data(80 bytes)
*/
void (*func_binary_begin_solid)(
void* cookie, uint32_t tri_count, const gmio_stlb_header_t* header);
void* cookie,
uint32_t tri_count,
const struct gmio_stlb_header* header);
/*! Pointer on a function that adds a triangle to the user mesh
*
* The argument \p triangle is the triangle to be added, note that
* gmio_stl_triangle_t::attribute_byte_count is meaningless for STL ascii.
* struct gmio_stl_triangle::attribute_byte_count is meaningless for STL ascii.
*
* The argument \p tri_id is the index of the mesh triangle
*/
void (*func_add_triangle)(
void* cookie, uint32_t tri_id, const gmio_stl_triangle_t* triangle);
void* cookie,
uint32_t tri_id,
const struct gmio_stl_triangle* triangle);
/*! Pointer on a function that finalizes creation of the user mesh
*
@ -79,7 +83,5 @@ struct gmio_stl_mesh_creator
void (*func_end_solid)(void* cookie);
};
typedef struct gmio_stl_mesh_creator gmio_stl_mesh_creator_t;
#endif /* GMIO_STL_MESH_CREATOR_H */
/*! @} */

View File

@ -34,30 +34,26 @@ struct gmio_stl_coords
gmio_float32_t z;
};
typedef struct gmio_stl_coords gmio_stl_coords_t;
/*! STL mesh triangle defined three geometric vertices and an
* orientation(normal) */
struct gmio_stl_triangle
{
gmio_stl_coords_t normal; /*!< Normal vector */
gmio_stl_coords_t v1; /*!< Vertex 1 */
gmio_stl_coords_t v2; /*!< Vertex 2 */
gmio_stl_coords_t v3; /*!< Vertex 3 */
struct gmio_stl_coords normal; /*!< Normal vector */
struct gmio_stl_coords v1; /*!< Vertex 1 */
struct gmio_stl_coords v2; /*!< Vertex 2 */
struct gmio_stl_coords v3; /*!< Vertex 3 */
uint16_t attribute_byte_count; /*!< Useful only for STL binary format */
};
typedef struct gmio_stl_triangle gmio_stl_triangle_t;
/*! Constants for STL triangles */
enum {
/*! Compact size of a gmio_stl_coords_t object */
/*! Compact size of a struct gmio_stl_coords object */
GMIO_STL_COORDS_RAWSIZE = (3 * sizeof(gmio_float32_t)),
/*! Compact size of a gmio_stl_triangle_t object for STL ascii format */
/*! Compact size of a struct gmio_stl_triangle object for STL ascii format */
GMIO_STLA_TRIANGLE_RAWSIZE = (4 * GMIO_STL_COORDS_RAWSIZE),
/*! Compact size of a gmio_stl_triangle_t object for STL binary format */
/*! Compact size of a struct gmio_stl_triangle object for STL binary format */
GMIO_STLB_TRIANGLE_RAWSIZE = (GMIO_STLA_TRIANGLE_RAWSIZE + sizeof(uint16_t))
};

View File

@ -21,8 +21,9 @@
#include "internal/stl_rw_common.h"
#include "../gmio_core/error.h"
#include "../gmio_core/rwargs.h"
#include "../gmio_core/internal/helper_rwargs.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/stringstream.h"
#include "../gmio_core/internal/string_utils.h"
@ -80,7 +81,7 @@
*/
/* gmio_stla_token */
typedef enum
enum gmio_stla_token
{
null_token = 0,
ENDFACET_token,
@ -96,76 +97,79 @@ typedef enum
FLOAT_token = ID_token,
empty_token,
unknown_token
} gmio_stla_token_t;
};
/* gmio_stringstream_stla_cookie_t */
typedef struct
/* struct gmio_stringstream_stla_cookie */
struct gmio_stringstream_stla_cookie
{
/* Copy of gmio_stla_read() corresponding argument */
gmio_transfer_t* transfer;
struct gmio_rwargs* rwargs;
/* Cache for gmio_stream_size(&transfer->stream) */
gmio_streamsize_t stream_size;
/* Offset (in bytes) from beginning of stream : current position */
gmio_streamoffset_t stream_offset;
/* Cache for gmio_transfer::func_is_stop_requested() */
gmio_bool_t is_stop_requested;
} gmio_stringstream_stla_cookie_t;
};
/* gmio_stla_parse_data */
typedef struct
struct gmio_stla_parse_data
{
gmio_stla_token_t token;
enum gmio_stla_token token;
gmio_bool_t error;
gmio_stringstream_t stream_iterator;
gmio_stringstream_stla_cookie_t stream_iterator_cookie;
gmio_string_t string_buffer;
gmio_stl_mesh_creator_t* creator;
} gmio_stla_parse_data_t;
struct gmio_stringstream stream_iterator;
struct gmio_stringstream_stla_cookie stream_iterator_cookie;
struct gmio_string string_buffer;
struct gmio_stl_mesh_creator* creator;
};
/* Fixed maximum length of any gmio_string in this source file */
enum { GMIO_STLA_READ_STRING_MAX_LEN = 1024 };
/* Callback used for gmio_string_stream_fwd_iterator::func_stream_read_hook */
static void gmio_stringstream_stla_read_hook(
void* cookie, const gmio_string_t* strbuff)
void* cookie, const struct gmio_string* strbuff)
{
gmio_stringstream_stla_cookie_t* tcookie =
(gmio_stringstream_stla_cookie_t*)(cookie);
const gmio_transfer_t* trsf = tcookie != NULL ? tcookie->transfer : NULL;
struct gmio_stringstream_stla_cookie* tcookie =
(struct gmio_stringstream_stla_cookie*)(cookie);
const struct gmio_rwargs* rwargs =
tcookie != NULL ? tcookie->rwargs : NULL;
if (tcookie != NULL) {
tcookie->stream_offset += strbuff->len;
tcookie->is_stop_requested = gmio_transfer_is_stop_requested(trsf);
gmio_transfer_handle_progress(
trsf, tcookie->stream_offset, tcookie->stream_size);
tcookie->is_stop_requested = gmio_rwargs_is_stop_requested(rwargs);
gmio_rwargs_handle_progress(
rwargs, tcookie->stream_offset, tcookie->stream_size);
}
}
/* Root function, parses a whole solid */
static void parse_solid(gmio_stla_parse_data_t* data);
static void parse_solid(struct gmio_stla_parse_data* data);
int gmio_stla_read(gmio_transfer_t* trsf, gmio_stl_mesh_creator_t* creator)
int gmio_stla_read(
struct gmio_rwargs* args,
struct gmio_stl_mesh_creator* creator)
{
char fixed_buffer[GMIO_STLA_READ_STRING_MAX_LEN];
gmio_stla_parse_data_t parse_data;
struct gmio_stla_parse_data parse_data;
{ /* Check validity of input parameters */
int error = GMIO_ERROR_OK;
if (!gmio_check_transfer(&error, trsf))
if (!gmio_check_rwargs(&error, args))
return error;
}
parse_data.token = unknown_token;
parse_data.error = GMIO_FALSE;
parse_data.stream_iterator_cookie.transfer = trsf;
parse_data.stream_iterator_cookie.rwargs = args;
parse_data.stream_iterator_cookie.stream_offset = 0;
parse_data.stream_iterator_cookie.stream_size =
gmio_stream_size(&trsf->stream);
gmio_stream_size(&args->stream);
parse_data.stream_iterator_cookie.is_stop_requested = GMIO_FALSE;
parse_data.stream_iterator.stream = trsf->stream;
parse_data.stream_iterator.strbuff.ptr = trsf->memblock.ptr;
parse_data.stream_iterator.strbuff.max_len = trsf->memblock.size;
parse_data.stream_iterator.stream = args->stream;
parse_data.stream_iterator.strbuff.ptr = args->memblock.ptr;
parse_data.stream_iterator.strbuff.max_len = args->memblock.size;
parse_data.stream_iterator.cookie = &parse_data.stream_iterator_cookie;
parse_data.stream_iterator.func_stream_read_hook =
gmio_stringstream_stla_read_hook;
@ -207,7 +211,7 @@ static const char stla_tokstr_OUTER[] = "outer";
static const char stla_tokstr_SOLID[] = "solid";
static const char stla_tokstr_VERTEX[] = "vertex";
static const gmio_const_string_t stla_tokcstr[] = {
static const struct gmio_const_string stla_tokcstr[] = {
{0}, /* null_token */
GMIO_CONST_STRING_FROM_ARRAY(stla_tokstr_ENDFACET),
GMIO_CONST_STRING_FROM_ARRAY(stla_tokstr_ENDLOOP),
@ -224,20 +228,20 @@ static const gmio_const_string_t stla_tokcstr[] = {
};
/* Returns the string corresponding to token */
GMIO_INLINE const char* stla_token_to_string(gmio_stla_token_t token);
GMIO_INLINE const char* stla_token_to_string(enum gmio_stla_token token);
/* Qualifies input string as a token */
static gmio_stla_token_t stla_find_token(const char* word, size_t word_len);
static enum gmio_stla_token stla_find_token(const char* word, size_t word_len);
/* Same as parsing_find_token() but takes a gmio_string_t object as input */
GMIO_INLINE gmio_stla_token_t stla_find_token_from_string(const gmio_string_t* str);
/* Same as parsing_find_token() but takes a struct gmio_string object as input */
GMIO_INLINE enum gmio_stla_token stla_find_token_from_string(const struct gmio_string* str);
/* Returns true if \p token matches one of the candidate tokens
*
* Array \p candidates must end with a "null_token" item
*/
GMIO_INLINE gmio_bool_t stla_token_match_candidate(
gmio_stla_token_t token, const gmio_stla_token_t* candidates);
enum gmio_stla_token token, const enum gmio_stla_token* candidates);
/* --------------------------------------------------------------------------
* Error message functions
@ -245,11 +249,11 @@ GMIO_INLINE gmio_bool_t stla_token_match_candidate(
/* Makes the parsing fails and print error message */
static void stla_error_msg(
gmio_stla_parse_data_t* data, const char* msg);
struct gmio_stla_parse_data* data, const char* msg);
/* Makes the parsing fails with message showing token mismatch */
static void stla_error_token_expected(
gmio_stla_parse_data_t* data, gmio_stla_token_t token);
struct gmio_stla_parse_data* data, enum gmio_stla_token token);
/* --------------------------------------------------------------------------
* Parsing helper functions
@ -258,10 +262,10 @@ static void stla_error_token_expected(
/* Eats next token string and checks it against an expected token
*
* This procedure copies the token string into internal
* gmio_stla_parse_data_t::string_buffer
* struct gmio_stla_parse_data::string_buffer
*/
static int stla_eat_next_token(
gmio_stla_parse_data_t* data, gmio_stla_token_t expected_token);
struct gmio_stla_parse_data* data, enum gmio_stla_token expected_token);
/* Eats next token string and checks it against an expected token
*
@ -271,18 +275,18 @@ static int stla_eat_next_token(
* token string against expected
*/
static int stla_eat_next_token_inplace(
gmio_stla_parse_data_t* data, gmio_stla_token_t expected_token);
struct gmio_stla_parse_data* data, enum gmio_stla_token expected_token);
/* Eats contents until some expected "end" token is matched
*
* Array \p end_tokens must end with a "null_token" item
*/
static int stla_eat_until_token(
gmio_stla_parse_data_t* data, const gmio_stla_token_t* end_tokens);
struct gmio_stla_parse_data* data, const enum gmio_stla_token* end_tokens);
/* Returns true if parsing can continue */
GMIO_INLINE gmio_bool_t stla_parsing_can_continue(
const gmio_stla_parse_data_t* data);
const struct gmio_stla_parse_data* data);
/* --------------------------------------------------------------------------
* STLA parsing functions
@ -292,30 +296,30 @@ GMIO_INLINE gmio_bool_t stla_parsing_can_continue(
enum { GMIO_STLA_PARSE_ERROR = 1 };
/* Parses the (optional) solid name that appears after token "solid" */
static int parse_solidname_beg(gmio_stla_parse_data_t* data);
static int parse_solidname_beg(struct gmio_stla_parse_data* data);
/* Parses the (optional) solid name that appears after token "endsolid"
*
* It should be the same name as the one parsed with parse_solidname_beg()
*/
static int parse_solidname_end(gmio_stla_parse_data_t* data);
static int parse_solidname_end(struct gmio_stla_parse_data* data);
/* Parses "solid <name>" */
static int parse_beginsolid(gmio_stla_parse_data_t* data);
static int parse_beginsolid(struct gmio_stla_parse_data* data);
/* Parses "endsolid <name>" */
static gmio_bool_t parse_endsolid(gmio_stla_parse_data_t* data);
static gmio_bool_t parse_endsolid(struct gmio_stla_parse_data* data);
/* Parses STL (x,y,z) coords, each coord being separated by whitespaces */
GMIO_INLINE int parse_xyz_coords(
gmio_stla_parse_data_t* data, gmio_stl_coords_t* coords);
struct gmio_stla_parse_data* data, struct gmio_stl_coords* coords);
/* Parses a STL facet, ie. facet ... endfacet */
static int parse_facet(
gmio_stla_parse_data_t* data, gmio_stl_triangle_t* facet);
struct gmio_stla_parse_data* data, struct gmio_stl_triangle* facet);
/* Parses a list of facets */
static void parse_facets(gmio_stla_parse_data_t* data);
static void parse_facets(struct gmio_stla_parse_data* data);
/* __________________________________________________________________________
*
@ -326,12 +330,12 @@ static void parse_facets(gmio_stla_parse_data_t* data);
* STLA token utils
* -------------------------------------------------------------------------- */
const char* stla_token_to_string(gmio_stla_token_t token)
const char* stla_token_to_string(enum gmio_stla_token token)
{
return stla_tokcstr[token].ptr;
}
gmio_stla_token_t stla_find_token(const char* word, size_t word_len)
enum gmio_stla_token stla_find_token(const char* word, size_t word_len)
{
/* Get rid of ill-formed token */
if (word_len == 0)
@ -401,13 +405,13 @@ gmio_stla_token_t stla_find_token(const char* word, size_t word_len)
return ID_token;
}
gmio_stla_token_t stla_find_token_from_string(const gmio_string_t* str)
enum gmio_stla_token stla_find_token_from_string(const struct gmio_string* str)
{
return stla_find_token(str->ptr, str->len);
}
gmio_bool_t stla_token_match_candidate(
gmio_stla_token_t token, const gmio_stla_token_t* candidates)
enum gmio_stla_token token, const enum gmio_stla_token* candidates)
{
gmio_bool_t found = GMIO_FALSE;
size_t i;
@ -420,7 +424,7 @@ gmio_bool_t stla_token_match_candidate(
* Error message functions
* -------------------------------------------------------------------------- */
void stla_error_msg(gmio_stla_parse_data_t* data, const char* msg)
void stla_error_msg(struct gmio_stla_parse_data* data, const char* msg)
{
fprintf(stderr,
"\n"
@ -435,7 +439,7 @@ void stla_error_msg(gmio_stla_parse_data_t* data, const char* msg)
}
void stla_error_token_expected(
gmio_stla_parse_data_t* data, gmio_stla_token_t token)
struct gmio_stla_parse_data* data, enum gmio_stla_token token)
{
char msg[256] = {0};
sprintf(msg,
@ -450,11 +454,11 @@ void stla_error_token_expected(
* -------------------------------------------------------------------------- */
int stla_eat_next_token(
gmio_stla_parse_data_t* data,
gmio_stla_token_t expected_token)
struct gmio_stla_parse_data* data,
enum gmio_stla_token expected_token)
{
gmio_string_t* strbuff = &data->string_buffer;
gmio_eat_word_error_t eat_error;
struct gmio_string* strbuff = &data->string_buffer;
enum gmio_eat_word_error eat_error;
strbuff->len = 0;
eat_error = gmio_stringstream_eat_word(&data->stream_iterator, strbuff);
@ -477,10 +481,10 @@ int stla_eat_next_token(
}
int stla_eat_next_token_inplace(
gmio_stla_parse_data_t* data,
gmio_stla_token_t expected_token)
struct gmio_stla_parse_data* data,
enum gmio_stla_token expected_token)
{
gmio_stringstream_t* it = &data->stream_iterator;
struct gmio_stringstream* it = &data->stream_iterator;
const char* stream_char = NULL;
const char* expected_token_str = stla_token_to_string(expected_token);
gmio_bool_t error = GMIO_FALSE;
@ -512,16 +516,16 @@ int stla_eat_next_token_inplace(
}
int stla_eat_until_token(
gmio_stla_parse_data_t* data, const gmio_stla_token_t* end_tokens)
struct gmio_stla_parse_data* data, const enum gmio_stla_token* end_tokens)
{
if (!stla_token_match_candidate(data->token, end_tokens)) {
gmio_stringstream_t* stream_it = &data->stream_iterator;
gmio_string_t* strbuff = &data->string_buffer;
struct gmio_stringstream* stream_it = &data->stream_iterator;
struct gmio_string* strbuff = &data->string_buffer;
gmio_bool_t end_token_found = GMIO_FALSE;
do {
const size_t previous_buff_len = strbuff->len;
gmio_eat_word_error_t eat_word_err = 0;
enum gmio_eat_word_error eat_word_err = 0;
const char* next_word = NULL; /* Pointer on next word string */
size_t next_word_len = 0; /* Length of next word string */
@ -554,7 +558,7 @@ int stla_eat_until_token(
return 0;
}
gmio_bool_t stla_parsing_can_continue(const gmio_stla_parse_data_t* data)
gmio_bool_t stla_parsing_can_continue(const struct gmio_stla_parse_data* data)
{
return !data->error && !data->stream_iterator_cookie.is_stop_requested;
}
@ -563,7 +567,7 @@ gmio_bool_t stla_parsing_can_continue(const gmio_stla_parse_data_t* data)
* STLA parsing functions
* -------------------------------------------------------------------------- */
int parse_solidname_beg(gmio_stla_parse_data_t* data)
int parse_solidname_beg(struct gmio_stla_parse_data* data)
{
if (stla_eat_next_token(data, unknown_token) == 0) {
data->token = stla_find_token_from_string(&data->string_buffer);
@ -573,7 +577,7 @@ int parse_solidname_beg(gmio_stla_parse_data_t* data)
}
else {
/* Solid name can be made of multiple words */
const gmio_stla_token_t end_tokens[] = {
const enum gmio_stla_token end_tokens[] = {
FACET_token, ENDSOLID_token, null_token };
return stla_eat_until_token(data, end_tokens);
}
@ -581,14 +585,14 @@ int parse_solidname_beg(gmio_stla_parse_data_t* data)
return GMIO_STLA_PARSE_ERROR;
}
int parse_solidname_end(gmio_stla_parse_data_t* data)
int parse_solidname_end(struct gmio_stla_parse_data* data)
{
GMIO_UNUSED(data);
/* TODO: parse according to retrieved solid name */
return 0;
}
int parse_beginsolid(gmio_stla_parse_data_t* data)
int parse_beginsolid(struct gmio_stla_parse_data* data)
{
if (stla_eat_next_token(data, SOLID_token) == 0) {
if (parse_solidname_beg(data) == 0) {
@ -602,7 +606,7 @@ int parse_beginsolid(gmio_stla_parse_data_t* data)
return GMIO_STLA_PARSE_ERROR;
}
gmio_bool_t parse_endsolid(gmio_stla_parse_data_t* data)
gmio_bool_t parse_endsolid(struct gmio_stla_parse_data* data)
{
if (data->token == ENDSOLID_token
|| stla_eat_next_token(data, ENDSOLID_token) == 0)
@ -626,10 +630,10 @@ GMIO_INLINE int is_float_char(const char* str)
|| c == '+';
}
int parse_xyz_coords(gmio_stla_parse_data_t* data, gmio_stl_coords_t* coords)
int parse_xyz_coords(struct gmio_stla_parse_data* data, struct gmio_stl_coords* coords)
{
int errc = 0;
gmio_stringstream_t* it = &data->stream_iterator;
struct gmio_stringstream* it = &data->stream_iterator;
const char* strbuff = NULL;
strbuff = gmio_stringstream_skip_ascii_spaces(it);
@ -650,7 +654,7 @@ int parse_xyz_coords(gmio_stla_parse_data_t* data, gmio_stl_coords_t* coords)
return errc;
}
int parse_facet(gmio_stla_parse_data_t* data, gmio_stl_triangle_t* facet)
int parse_facet(struct gmio_stla_parse_data* data, struct gmio_stl_triangle* facet)
{
int errc = 0;
if (data->token != FACET_token)
@ -675,14 +679,14 @@ int parse_facet(gmio_stla_parse_data_t* data, gmio_stl_triangle_t* facet)
return errc;
}
void parse_facets(gmio_stla_parse_data_t* data)
void parse_facets(struct gmio_stla_parse_data* data)
{
const gmio_stl_mesh_creator_func_add_triangle_t func_add_triangle =
data->creator->func_add_triangle;
void* creator_cookie = data->creator->cookie;
gmio_string_t* strbuff = &data->string_buffer;
struct gmio_string* strbuff = &data->string_buffer;
uint32_t i_facet = 0;
gmio_stl_triangle_t facet;
struct gmio_stl_triangle facet;
facet.attribute_byte_count = 0;
while (data->token == FACET_token && stla_parsing_can_continue(data)) {
@ -702,7 +706,7 @@ void parse_facets(gmio_stla_parse_data_t* data)
}
}
void parse_solid(gmio_stla_parse_data_t* data)
void parse_solid(struct gmio_stla_parse_data* data)
{
parse_beginsolid(data);
parse_facets(data);

View File

@ -16,31 +16,142 @@
#include "stla_stats.h"
#include "../gmio_core/error.h"
#include "../gmio_core/internal/string.h"
#include "../gmio_core/internal/helper_rwargs.h"
#include "../gmio_core/internal/helper_stream.h"
#include "../gmio_core/internal/helper_transfer.h"
#include "../gmio_core/internal/min_max.h"
#include "../gmio_stl/internal/stl_rw_common.h"
gmio_stla_stats_t gmio_stla_stats_get(
gmio_transfer_t* trsf, unsigned stat_flags, size_t size_limit)
#include <string.h>
GMIO_INLINE const char* find_substr(
const struct gmio_string* str, size_t str_offset, const char* substr)
{
gmio_stla_stats_t stats = {0};
void* mblock_ptr = trsf != NULL ? trsf->memblock.ptr : NULL;
const size_t mblock_size = trsf != NULL ? trsf->memblock.size : 0;
return strstr(str->ptr + str_offset, substr);
}
static uint32_t stla_facet_count(
const struct gmio_string* strbuff, const char* end_ptr)
{
const char* substr_at = NULL;
size_t strbuff_pos = 0;
uint32_t facet_count = 0;
do {
substr_at = find_substr(strbuff, strbuff_pos, "endfacet");
if (substr_at != NULL && substr_at < end_ptr) {
++facet_count;
/* Note: strlen("endfacet") == 8 */
strbuff_pos = (substr_at - strbuff->ptr) + 8;
}
else {
substr_at = NULL;
}
} while (substr_at != NULL);
return facet_count;
}
enum {
BUFF_OVERLAP_SIZE = 14,
BUFF_OVERLAP_SIZE_DIV2 = BUFF_OVERLAP_SIZE / 2
};
struct gmio_stla_stats gmio_stla_stats_get(
struct gmio_rwargs* args, unsigned stat_flags)
{
struct gmio_stla_stats stats = {0};
struct gmio_stream* stream = args ? &args->stream : NULL;
void* mblock_ptr = args != NULL ? args->memblock.ptr : NULL;
/* Leave one byte to end the string buffer with 0 */
const size_t mblock_size = args != NULL ? args->memblock.size - 1: 0;
struct gmio_string strbuff = gmio_string(mblock_ptr, 0, mblock_size);
const gmio_bool_t flag_size =
(stat_flags & GMIO_STLA_STAT_FLAG_SIZE) != 0;
const gmio_bool_t flag_avg_facet_size =
(stat_flags & GMIO_STLA_STAT_FLAG_AVERAGE_FACET_SIZE) != 0;
const gmio_bool_t flag_facet_count =
(stat_flags & GMIO_STLA_STAT_FLAG_FACET_COUNT) != 0;
int err = GMIO_ERROR_OK;
/* Check validity of input transfer object */
if (!gmio_check_transfer(&err, trsf))
if (!gmio_check_rwargs(&err, args))
return stats;
/*if (stat_flags != 0) {
while (gmio_no_error(err)) {
if (stat_flags != 0) {
char overlap[14] = {0}; /* 14 == 2*(strlen("endfacet") - 1) */
gmio_bool_t endsolid_found = GMIO_FALSE;
while (!endsolid_found && gmio_no_error(err)) {
const char* substr_at = NULL;
const size_t read_size =
gmio_stream_read(stream, buffer_ptr, 1, buffer_size);
const int stream_err = gmio_stream_error(trsf->stream);
gmio_stream_read(stream, mblock_ptr, 1, mblock_size);
const int stream_err = gmio_stream_error(&args->stream);
const gmio_bool_t overlap_has_contents = overlap[0] != 0;
gmio_bool_t endsolid_in_overlap = GMIO_FALSE;
err = stream_err;
strbuff.len = read_size;
strbuff.ptr[strbuff.len] = 0;
/* Copy first half of overlap buffer */
if (overlap_has_contents) {
strncpy(&overlap[BUFF_OVERLAP_SIZE_DIV2],
mblock_ptr,
GMIO_MIN(BUFF_OVERLAP_SIZE_DIV2, read_size));
}
/* Find "endsolid" in overlap */
if (overlap_has_contents) {
substr_at = strstr(overlap, "endsolid");
endsolid_found = substr_at != NULL;
endsolid_in_overlap = endsolid_found;
}
/* Find "endsolid" in memblock */
if (!endsolid_found) {
substr_at = find_substr(&strbuff, 0, "endsolid");
endsolid_found = substr_at != NULL;
}
/* Update stream size */
if (flag_size) {
/* Note: strlen("endsolid") == 8 */
if (endsolid_found) {
if (!endsolid_in_overlap)
stats.size += (substr_at - strbuff.ptr) + 8;
/* TODO : gérer le cas où "endsolid" se trouve dans overlap */
}
else {
stats.size += read_size;
}
}
/* Find "endfacet" tokens */
if (flag_facet_count && !endsolid_in_overlap) {
const char* endsolid_ptr =
endsolid_found ? substr_at : gmio_string_end(&strbuff);
/* Check in overlap */
const gmio_bool_t endfacet_in_overlap =
overlap_has_contents
&& strstr(overlap, "endfacet") != NULL;
stats.facet_count += endfacet_in_overlap ? 1 : 0;
/* Check in memblock */
stats.facet_count += stla_facet_count(&strbuff, endsolid_ptr);
}
/* Copy second half of overlap buffer */
if (!endsolid_found && read_size >= BUFF_OVERLAP_SIZE_DIV2) {
memset(&overlap, 0, sizeof(overlap));
strncpy(overlap,
&strbuff.ptr[read_size - BUFF_OVERLAP_SIZE_DIV2],
GMIO_MIN(BUFF_OVERLAP_SIZE_DIV2, read_size));
}
}
}
}*/
return stats;
}

View File

@ -25,12 +25,12 @@
#include "stl_global.h"
#include "../gmio_core/transfer.h"
#include "../gmio_core/rwargs.h"
#include "../gmio_core/internal/helper_stream.h"
#include <stddef.h>
/*! Statistics of some STL ascii solid */
/*! Statistics of some STL ascii contents(eg. file) */
struct gmio_stla_stats
{
/*! Count of facets(triangles) */
@ -43,7 +43,6 @@ struct gmio_stla_stats
/*! Size of the STL ascii contents in bytes, including the "endsolid" tag */
size_t size;
};
typedef struct gmio_stla_stats gmio_stla_stats_t;
/*! Flags(OR-combinations) for each STL ascii statistic */
enum gmio_stla_stat_flag
@ -53,13 +52,12 @@ enum gmio_stla_stat_flag
GMIO_STLA_STAT_FLAG_SIZE = 0x04,
GMIO_STLA_STAT_FLAG_ALL = 0xFF
};
typedef enum gmio_stla_stat_flag gmio_stla_stat_flag_t;
GMIO_C_LINKAGE_BEGIN
GMIO_LIBSTL_EXPORT
gmio_stla_stats_t gmio_stla_stats_get(
gmio_transfer_t* trsf, unsigned stat_flags, size_t size_limit);
struct gmio_stla_stats gmio_stla_stats_get(
struct gmio_rwargs* args, unsigned stat_flags);
GMIO_C_LINKAGE_END

View File

@ -33,7 +33,6 @@ struct gmio_stlb_header
{
uint8_t data[GMIO_STLB_HEADER_SIZE];
};
typedef struct gmio_stlb_header gmio_stlb_header_t;
#endif /* GMIO_STLB_HEADER_H */
/*! @} */

View File

@ -25,23 +25,23 @@
#include "../gmio_core/error.h"
#include "../gmio_core/internal/byte_swap.h"
#include "../gmio_core/internal/convert.h"
#include "../gmio_core/internal/helper_rwargs.h"
#include "../gmio_core/internal/helper_stream.h"
#include "../gmio_core/internal/helper_transfer.h"
#include "../gmio_core/internal/safe_cast.h"
#include <string.h>
GMIO_INLINE void read_triangle_memcpy(
const uint8_t* buffer, gmio_stl_triangle_t* triangle)
const uint8_t* buffer, struct gmio_stl_triangle* triangle)
{
/* *triangle = *((gmio_stl_triangle_t*)(buffer)); */
/* *triangle = *((struct gmio_stl_triangle*)(buffer)); */
memcpy(triangle, buffer, GMIO_STLB_TRIANGLE_RAWSIZE);
}
static void gmio_stlb_read_facets(
gmio_stl_mesh_creator_t* creator,
struct gmio_stl_mesh_creator* creator,
const uint8_t* buffer,
const gmio_stlb_readwrite_helper_t* rparams)
const struct gmio_stlb_readwrite_helper* rparams)
{
const uint32_t facet_count = rparams->facet_count;
const uint32_t i_facet_offset = rparams->i_facet_offset;
@ -51,7 +51,7 @@ static void gmio_stlb_read_facets(
const gmio_stl_mesh_creator_func_add_triangle_t func_add_triangle =
creator != NULL ? creator->func_add_triangle : NULL;
void* cookie = creator->cookie;
gmio_stl_triangle_t triangle;
struct gmio_stl_triangle triangle;
uint32_t buffer_offset = 0;
uint32_t i_facet = 0;
@ -70,25 +70,25 @@ static void gmio_stlb_read_facets(
}
int gmio_stlb_read(
gmio_transfer_t* trsf,
gmio_stl_mesh_creator_t *creator,
gmio_endianness_t byte_order)
struct gmio_rwargs* args,
struct gmio_stl_mesh_creator *creator,
enum gmio_endianness byte_order)
{
/* Constants */
const uint32_t max_facet_count_per_read =
trsf != NULL ?
args != NULL ?
gmio_size_to_uint32(
trsf->memblock.size / GMIO_STLB_TRIANGLE_RAWSIZE)
args->memblock.size / GMIO_STLB_TRIANGLE_RAWSIZE)
: 0;
/* Variables */
void* mblock_ptr = trsf != NULL ? trsf->memblock.ptr : NULL;
gmio_stlb_readwrite_helper_t rparams = {0};
gmio_stlb_header_t header;
void* mblock_ptr = args != NULL ? args->memblock.ptr : NULL;
struct gmio_stlb_readwrite_helper rparams = {0};
struct gmio_stlb_header header;
uint32_t total_facet_count = 0; /* Facet count, as declared in the stream */
int error = GMIO_ERROR_OK; /* Helper to store function result error code */
/* Check validity of input parameters */
if (!gmio_stlb_check_params(&error, trsf, byte_order))
if (!gmio_stlb_check_params(&error, args, byte_order))
return error;
/* Initialize rparams */
@ -96,14 +96,14 @@ int gmio_stlb_read(
rparams.func_fix_endian = gmio_stl_triangle_bswap;
/* Read header */
if (gmio_stream_read(&trsf->stream, &header, GMIO_STLB_HEADER_SIZE, 1)
if (gmio_stream_read(&args->stream, &header, GMIO_STLB_HEADER_SIZE, 1)
!= 1)
{
return GMIO_STL_ERROR_HEADER_WRONG_SIZE;
}
/* Read facet count */
if (gmio_stream_read(&trsf->stream, mblock_ptr, sizeof(uint32_t), 1)
if (gmio_stream_read(&args->stream, mblock_ptr, sizeof(uint32_t), 1)
!= 1)
{
return GMIO_STL_ERROR_FACET_COUNT;
@ -121,17 +121,17 @@ int gmio_stlb_read(
while (gmio_no_error(error)
&& rparams.i_facet_offset < total_facet_count)
{
gmio_transfer_handle_progress(
trsf, rparams.i_facet_offset, total_facet_count);
gmio_rwargs_handle_progress(
args, rparams.i_facet_offset, total_facet_count);
rparams.facet_count =
gmio_size_to_uint32(
gmio_stream_read(
&trsf->stream,
&args->stream,
mblock_ptr,
GMIO_STLB_TRIANGLE_RAWSIZE,
max_facet_count_per_read));
if (gmio_stream_error(&trsf->stream) != 0)
if (gmio_stream_error(&args->stream) != 0)
error = GMIO_ERROR_STREAM;
else if (rparams.facet_count > 0)
error = GMIO_ERROR_OK;
@ -141,7 +141,7 @@ int gmio_stlb_read(
if (gmio_no_error(error)) {
gmio_stlb_read_facets(creator, mblock_ptr, &rparams);
rparams.i_facet_offset += rparams.facet_count;
if (gmio_transfer_is_stop_requested(trsf))
if (gmio_rwargs_is_stop_requested(args))
error = GMIO_ERROR_TRANSFER_STOPPED;
}
} /* end while */

View File

@ -31,7 +31,7 @@ static StlMesh_Mesh* occMeshPtr(const Handle_StlMesh_Mesh& mesh)
}
static void occmesh_add_triangle(
void* cookie, uint32_t tri_id, const gmio_stl_triangle_t* tri)
void* cookie, uint32_t tri_id, const struct gmio_stl_triangle* tri)
{
StlMesh_Mesh* mesh = static_cast<StlMesh_Mesh*>(cookie);
if (tri_id == 0)
@ -47,10 +47,10 @@ static void occmesh_add_triangle(
}
static void occmesh_get_triangle(
const void* cookie, uint32_t tri_id, gmio_stl_triangle_t* tri)
const void* cookie, uint32_t tri_id, struct gmio_stl_triangle* tri)
{
const gmio_occ_stl_mesh_domain_t* mesh_domain =
static_cast<const gmio_occ_stl_mesh_domain_t*>(cookie);
const struct gmio_occ_stl_mesh_domain* mesh_domain =
static_cast<const struct gmio_occ_stl_mesh_domain*>(cookie);
const Handle_StlMesh_MeshTriangle& occTri =
mesh_domain->triangles()->Value(tri_id + 1);
int idV1;
@ -87,9 +87,9 @@ static void occmesh_get_triangle(
} // namespace internal
gmio_stl_mesh_t gmio_stl_occmesh(const gmio_occ_stl_mesh_domain_t* mesh_domain)
struct gmio_stl_mesh gmio_stl_occmesh(const struct gmio_occ_stl_mesh_domain* mesh_domain)
{
gmio_stl_mesh_t mesh = {0};
struct gmio_stl_mesh mesh = {0};
mesh.cookie = mesh_domain;
if (mesh_domain != NULL && mesh_domain->mesh() != NULL) {
mesh.triangle_count =
@ -99,15 +99,15 @@ gmio_stl_mesh_t gmio_stl_occmesh(const gmio_occ_stl_mesh_domain_t* mesh_domain)
return mesh;
}
gmio_stl_mesh_creator_t gmio_stl_occmesh_creator(StlMesh_Mesh* mesh)
struct gmio_stl_mesh_creator gmio_stl_occmesh_creator(StlMesh_Mesh* mesh)
{
gmio_stl_mesh_creator_t creator = {0};
struct gmio_stl_mesh_creator creator = {0};
creator.cookie = mesh;
creator.func_add_triangle = internal::occmesh_add_triangle;
return creator;
}
gmio_stl_mesh_creator_t gmio_stl_hnd_occmesh_creator(const Handle_StlMesh_Mesh &hnd)
struct gmio_stl_mesh_creator gmio_stl_hnd_occmesh_creator(const Handle_StlMesh_Mesh &hnd)
{
return gmio_stl_occmesh_creator(internal::occMeshPtr(hnd));
}

View File

@ -57,14 +57,13 @@ private:
const StlMesh_SequenceOfMeshTriangle* m_triangles;
const TColgp_SequenceOfXYZ* m_vertices;
};
typedef struct gmio_occ_stl_mesh_domain gmio_occ_stl_mesh_domain_t;
/*! Returns a gmio_stl_mesh mapped to domain in StlMesh_Mesh
*
* The mesh's cookie will point to \p mesh_domain
*/
GMIO_LIBSUPPORT_EXPORT
gmio_stl_mesh_t gmio_stl_occmesh(const gmio_occ_stl_mesh_domain_t* mesh_domain);
struct gmio_stl_mesh gmio_stl_occmesh(const struct gmio_occ_stl_mesh_domain* mesh_domain);
/*! Returns a gmio_stl_mesh_creator that will build a new domain in a
* StlMesh_Mesh object
@ -72,7 +71,7 @@ gmio_stl_mesh_t gmio_stl_occmesh(const gmio_occ_stl_mesh_domain_t* mesh_domain);
* The creator's cookie will point \p mesh
*/
GMIO_LIBSUPPORT_EXPORT
gmio_stl_mesh_creator_t gmio_stl_occmesh_creator(StlMesh_Mesh* mesh);
struct gmio_stl_mesh_creator gmio_stl_occmesh_creator(StlMesh_Mesh* mesh);
/*! Same as gmio_stl_occmesh_creator(StlMesh_Mesh*) but takes a handle
*
@ -80,7 +79,7 @@ gmio_stl_mesh_creator_t gmio_stl_occmesh_creator(StlMesh_Mesh* mesh);
* handle \p hnd
*/
GMIO_LIBSUPPORT_EXPORT
gmio_stl_mesh_creator_t gmio_stl_hnd_occmesh_creator(const Handle_StlMesh_Mesh& hnd);
struct gmio_stl_mesh_creator gmio_stl_hnd_occmesh_creator(const Handle_StlMesh_Mesh& hnd);

View File

@ -35,11 +35,11 @@
/*! Returns a gmio_stream for C++ input stream (cookie will hold \p s ) */
template<typename CHAR, typename TRAITS>
gmio_stream_t gmio_istream_cpp(std::basic_istream<CHAR, TRAITS>* s);
gmio_stream gmio_istream_cpp(std::basic_istream<CHAR, TRAITS>* s);
/*! Returns a gmio_stream for C++ output stream (cookie will hold \p s ) */
template<typename CHAR, typename TRAITS>
gmio_stream_t gmio_ostream_cpp(std::basic_ostream<CHAR, TRAITS>* s);
gmio_stream gmio_ostream_cpp(std::basic_ostream<CHAR, TRAITS>* s);
@ -111,12 +111,12 @@ gmio_streamsize_t ostream_cpp_size(void* cookie)
return end_pos - begin_pos;
}
GMIO_INLINE void copy_cpp_streampos(gmio_stream_pos_t* pos, std::streampos spos)
GMIO_INLINE void copy_cpp_streampos(gmio_stream_pos* pos, std::streampos spos)
{
std::memcpy(&pos->cookie[0], &spos, sizeof(std::streampos));
}
GMIO_INLINE std::streampos to_cpp_streampos(const gmio_stream_pos_t* pos)
GMIO_INLINE std::streampos to_cpp_streampos(const gmio_stream_pos* pos)
{
std::streampos spos;
std::memcpy(&spos, &pos->cookie[0], sizeof(std::streampos));
@ -124,35 +124,35 @@ GMIO_INLINE std::streampos to_cpp_streampos(const gmio_stream_pos_t* pos)
}
template<typename STREAM>
int istream_cpp_get_pos(void* cookie, gmio_stream_pos_t* pos)
int istream_cpp_get_pos(void* cookie, gmio_stream_pos* pos)
{
copy_cpp_streampos(pos, static_cast<STREAM*>(cookie)->tellg());
return 0;
}
template<typename STREAM>
int istream_cpp_set_pos(void* cookie, const gmio_stream_pos_t* pos)
int istream_cpp_set_pos(void* cookie, const gmio_stream_pos* pos)
{
static_cast<STREAM*>(cookie)->seekg(to_cpp_streampos(pos));
return 0; // TODO: return error code
}
template<typename STREAM>
int ostream_cpp_get_pos(void* cookie, gmio_stream_pos_t* pos)
int ostream_cpp_get_pos(void* cookie, gmio_stream_pos* pos)
{
copy_cpp_streampos(pos, static_cast<STREAM*>(cookie)->tellp());
return 0;
}
template<typename STREAM>
static int ostream_cpp_set_pos(void* cookie, const gmio_stream_pos_t* pos)
static int ostream_cpp_set_pos(void* cookie, const gmio_stream_pos* pos)
{
static_cast<STREAM*>(cookie)->seekp(to_cpp_streampos(pos));
return 0; // TODO: return error code
}
template<typename STREAM>
void stream_cpp_init_common(STREAM* s, gmio_stream_t* stream)
void stream_cpp_init_common(STREAM* s, gmio_stream* stream)
{
*stream = gmio_stream_null();
stream->cookie = s;
@ -164,10 +164,10 @@ void stream_cpp_init_common(STREAM* s, gmio_stream_t* stream)
} // namespace gmio
template<typename CHAR, typename TRAITS>
gmio_stream_t gmio_istream_cpp(std::basic_istream<CHAR, TRAITS>* s)
gmio_stream gmio_istream_cpp(std::basic_istream<CHAR, TRAITS>* s)
{
typedef std::basic_istream<CHAR, TRAITS> CppStream;
gmio_stream_t stream;
gmio_stream stream;
gmio::internal::stream_cpp_init_common(s, &stream);
stream.func_size = gmio::internal::istream_cpp_size<CppStream>;
stream.func_read = gmio::internal::istream_cpp_read<CppStream>;
@ -177,10 +177,10 @@ gmio_stream_t gmio_istream_cpp(std::basic_istream<CHAR, TRAITS>* s)
}
template<typename CHAR, typename TRAITS>
gmio_stream_t gmio_ostream_cpp(std::basic_ostream<CHAR, TRAITS>* s)
gmio_stream gmio_ostream_cpp(std::basic_ostream<CHAR, TRAITS>* s)
{
typedef std::basic_ostream<CHAR, TRAITS> CppStream;
gmio_stream_t stream;
gmio_stream stream;
gmio::internal::stream_cpp_init_common(s, &stream);
stream.func_size = gmio::internal::ostream_cpp_size<CppStream>;
stream.func_write = gmio::internal::ostream_cpp_write<CppStream>;

View File

@ -64,7 +64,7 @@ static gmio_streamsize_t gmio_stream_qiodevice_size(void* cookie)
return device->size();
}
static int gmio_stream_qiodevice_get_pos(void* cookie, gmio_stream_pos_t* pos)
static int gmio_stream_qiodevice_get_pos(void* cookie, struct gmio_stream_pos* pos)
{
QIODevice* device = static_cast<QIODevice*>(cookie);
qint64 qpos = device->pos();
@ -73,7 +73,7 @@ static int gmio_stream_qiodevice_get_pos(void* cookie, gmio_stream_pos_t* pos)
}
static int gmio_stream_qiodevice_set_pos(
void* cookie, const gmio_stream_pos_t* pos)
void* cookie, const struct gmio_stream_pos* pos)
{
QIODevice* device = static_cast<QIODevice*>(cookie);
qint64 qpos;
@ -83,9 +83,9 @@ static int gmio_stream_qiodevice_set_pos(
return -1; /* TODO: return error code */
}
gmio_stream_t gmio_stream_qiodevice(QIODevice* device)
struct gmio_stream gmio_stream_qiodevice(QIODevice* device)
{
gmio_stream_t stream = {0};
struct gmio_stream stream = {0};
stream.cookie = device;
stream.func_at_end = gmio_stream_qiodevice_at_end;
stream.func_error = gmio_stream_qiodevice_error;

View File

@ -37,7 +37,7 @@ QT_END_NAMESPACE
/*! Returns a gmio_stream for \c QIODevice* (cookie will hold \p device) */
GMIO_LIBSUPPORT_EXPORT
gmio_stream_t gmio_stream_qiodevice(
struct gmio_stream gmio_stream_qiodevice(
#ifndef DOXYGEN
QT_PREPEND_NAMESPACE(QIODevice)* device
#else

View File

@ -50,8 +50,9 @@ file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/models
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
set(GMIO_TEST_STL_SRC
main_test_stl.c
test_stl_io.c
test_stl_internal.c
test_stl_io.c
test_stla_stats.c
core_utils.c
stl_utils.c)
if(GMIO_BUILD_SHARED_LIBS)

View File

@ -21,6 +21,7 @@ const char* test_stl_read();
const char* test_stlb_write_header();
const char* test_stlb_write();
const char* test_stla_write();
const char* test_stla_stats();
const char* all_tests()
{
@ -32,6 +33,7 @@ const char* all_tests()
UTEST_RUN(test_stlb_write_header);
UTEST_RUN(test_stlb_write);
UTEST_RUN(test_stla_write);
UTEST_RUN(test_stla_stats);
return NULL;
}

View File

@ -24,19 +24,19 @@
#include <ctype.h>
void gmio_stl_nop_add_triangle(
void *cookie, uint32_t tri_id, const gmio_stl_triangle_t *triangle)
void *cookie, uint32_t tri_id, const struct gmio_stl_triangle *triangle)
{
GMIO_UNUSED(cookie);
GMIO_UNUSED(tri_id);
GMIO_UNUSED(triangle);
}
gmio_stl_triangle_array_t gmio_stl_triangle_array_malloc(size_t tri_count)
struct gmio_stl_triangle_array gmio_stl_triangle_array_malloc(size_t tri_count)
{
gmio_stl_triangle_array_t array = {0};
struct gmio_stl_triangle_array array = {0};
if (tri_count > 0) {
array.ptr =
(gmio_stl_triangle_t*)calloc(tri_count, sizeof(gmio_stl_triangle_t));
(struct gmio_stl_triangle*)calloc(tri_count, sizeof(struct gmio_stl_triangle));
}
array.count = gmio_size_to_uint32(tri_count);
array.capacity = array.count;
@ -46,7 +46,7 @@ gmio_stl_triangle_array_t gmio_stl_triangle_array_malloc(size_t tri_count)
static void gmio_stl_data__ascii_begin_solid(
void* cookie, gmio_streamsize_t stream_size, const char* solid_name)
{
gmio_stl_data_t* data = (gmio_stl_data_t*)cookie;
struct gmio_stl_data* data = (struct gmio_stl_data*)cookie;
memset(&data->solid_name[0], 0, sizeof(data->solid_name));
if (solid_name != NULL) {
@ -66,22 +66,22 @@ static void gmio_stl_data__ascii_begin_solid(
}
static void gmio_stl_data__binary_begin_solid(
void* cookie, uint32_t tri_count, const gmio_stlb_header_t* header)
void* cookie, uint32_t tri_count, const struct gmio_stlb_header* header)
{
gmio_stl_data_t* data = (gmio_stl_data_t*)cookie;
struct gmio_stl_data* data = (struct gmio_stl_data*)cookie;
memcpy(&data->header, header, GMIO_STLB_HEADER_SIZE);
data->tri_array = gmio_stl_triangle_array_malloc(tri_count);
}
static void gmio_stl_data__add_triangle(
void* cookie, uint32_t tri_id, const gmio_stl_triangle_t* triangle)
void* cookie, uint32_t tri_id, const struct gmio_stl_triangle* triangle)
{
gmio_stl_data_t* data = (gmio_stl_data_t*)cookie;
struct gmio_stl_data* data = (struct gmio_stl_data*)cookie;
if (tri_id >= data->tri_array.capacity) {
uint32_t cap = data->tri_array.capacity;
cap += cap >> 3; /* Add 12.5% more capacity */
data->tri_array.ptr =
realloc(data->tri_array.ptr, cap * sizeof(gmio_stl_triangle_t));
realloc(data->tri_array.ptr, cap * sizeof(struct gmio_stl_triangle));
data->tri_array.capacity = cap;
}
memcpy(&data->tri_array.ptr[tri_id], triangle, GMIO_STLB_TRIANGLE_RAWSIZE);
@ -89,15 +89,15 @@ static void gmio_stl_data__add_triangle(
}
static void gmio_stl_data__get_triangle(
const void* cookie, uint32_t tri_id, gmio_stl_triangle_t* triangle)
const void* cookie, uint32_t tri_id, struct gmio_stl_triangle* triangle)
{
const gmio_stl_data_t* data = (const gmio_stl_data_t*)cookie;
const struct gmio_stl_data* data = (const struct gmio_stl_data*)cookie;
*triangle = data->tri_array.ptr[tri_id];
}
gmio_stl_mesh_creator_t gmio_stl_data_mesh_creator(gmio_stl_data_t *data)
struct gmio_stl_mesh_creator gmio_stl_data_mesh_creator(struct gmio_stl_data *data)
{
gmio_stl_mesh_creator_t creator = {0};
struct gmio_stl_mesh_creator creator = {0};
creator.cookie = data;
creator.func_ascii_begin_solid = &gmio_stl_data__ascii_begin_solid;
creator.func_binary_begin_solid = &gmio_stl_data__binary_begin_solid;
@ -105,9 +105,9 @@ gmio_stl_mesh_creator_t gmio_stl_data_mesh_creator(gmio_stl_data_t *data)
return creator;
}
gmio_stl_mesh_t gmio_stl_data_mesh(const gmio_stl_data_t *data)
struct gmio_stl_mesh gmio_stl_data_mesh(const struct gmio_stl_data *data)
{
gmio_stl_mesh_t mesh = {0};
struct gmio_stl_mesh mesh = {0};
mesh.cookie = data;
mesh.triangle_count = data->tri_array.count;
mesh.func_get_triangle = &gmio_stl_data__get_triangle;
@ -115,7 +115,7 @@ gmio_stl_mesh_t gmio_stl_data_mesh(const gmio_stl_data_t *data)
}
void gmio_stlb_header_to_printable_string(
const gmio_stlb_header_t *header, char *str, char replacement)
const struct gmio_stlb_header *header, char *str, char replacement)
{
size_t i = 0;
for (; i < GMIO_STLB_HEADER_SIZE; ++i) {
@ -127,8 +127,8 @@ void gmio_stlb_header_to_printable_string(
}
gmio_bool_t gmio_stl_coords_equal(
const gmio_stl_coords_t *lhs,
const gmio_stl_coords_t *rhs,
const struct gmio_stl_coords *lhs,
const struct gmio_stl_coords *rhs,
uint32_t max_ulp_diff)
{
return gmio_float32_equals_by_ulp(lhs->x, rhs->x, max_ulp_diff)
@ -137,8 +137,8 @@ gmio_bool_t gmio_stl_coords_equal(
}
gmio_bool_t gmio_stl_triangle_equal(
const gmio_stl_triangle_t *lhs,
const gmio_stl_triangle_t *rhs,
const struct gmio_stl_triangle *lhs,
const struct gmio_stl_triangle *rhs,
uint32_t max_ulp_diff)
{
return gmio_stl_coords_equal(&lhs->normal, &rhs->normal, max_ulp_diff)
@ -149,7 +149,7 @@ gmio_bool_t gmio_stl_triangle_equal(
}
void gmio_stl_nop_get_triangle(
const void *cookie, uint32_t tri_id, gmio_stl_triangle_t *triangle)
const void *cookie, uint32_t tri_id, struct gmio_stl_triangle *triangle)
{
GMIO_UNUSED(cookie);
GMIO_UNUSED(tri_id);

View File

@ -25,60 +25,58 @@
#include <string.h>
gmio_bool_t gmio_stl_coords_equal(
const gmio_stl_coords_t* lhs,
const gmio_stl_coords_t* rhs,
const struct gmio_stl_coords* lhs,
const struct gmio_stl_coords* rhs,
uint32_t max_ulp_diff);
gmio_bool_t gmio_stl_triangle_equal(
const gmio_stl_triangle_t* lhs,
const gmio_stl_triangle_t* rhs,
const struct gmio_stl_triangle* lhs,
const struct gmio_stl_triangle* rhs,
uint32_t max_ulp_diff);
/*! Does binary STL header \p lhs compare equal to \p rhs ? */
GMIO_INLINE gmio_bool_t gmio_stlb_header_equal(
const gmio_stlb_header_t* lhs, const gmio_stlb_header_t* rhs)
const struct gmio_stlb_header* lhs, const struct gmio_stlb_header* rhs)
{
return memcmp(lhs, rhs, GMIO_STLB_HEADER_SIZE) == 0;
}
void gmio_stlb_header_to_printable_string(
const gmio_stlb_header_t* header, char* str, char replacement);
const struct gmio_stlb_header* header, char* str, char replacement);
/*! Callback for gmio_stl_mesh_creator::func_add_triangle that does
* nothing(ie "no operation") */
void gmio_stl_nop_add_triangle(
void* cookie, uint32_t tri_id, const gmio_stl_triangle_t* triangle);
void* cookie, uint32_t tri_id, const struct gmio_stl_triangle* triangle);
/*! Callback for gmio_stl_mesh::func_get_triangle that does nothing */
void gmio_stl_nop_get_triangle(
const void* cookie, uint32_t tri_id, gmio_stl_triangle_t* triangle);
const void* cookie, uint32_t tri_id, struct gmio_stl_triangle* triangle);
/*! Holds an array of STL triangles */
struct gmio_stl_triangle_array
{
gmio_stl_triangle_t* ptr;
struct gmio_stl_triangle* ptr;
uint32_t count;
uint32_t capacity;
};
typedef struct gmio_stl_triangle_array gmio_stl_triangle_array_t;
/*! Returns an dynamically allocated array of gmio_stl_triangle_t
/*! Returns an dynamically allocated array of struct gmio_stl_triangle
*
* Contents of the memory block beginnning at gmio_stl_triangle_array::ptr
* is initialized with zeroes
*/
gmio_stl_triangle_array_t gmio_stl_triangle_array_malloc(size_t tri_count);
struct gmio_stl_triangle_array gmio_stl_triangle_array_malloc(size_t tri_count);
/*! Holds complete STL data (usable for both binary and ascii formats) */
struct gmio_stl_data
{
gmio_stlb_header_t header;
struct gmio_stlb_header header;
char solid_name[1024];
gmio_stl_triangle_array_t tri_array;
struct gmio_stl_triangle_array tri_array;
};
typedef struct gmio_stl_data gmio_stl_data_t;
gmio_stl_mesh_creator_t gmio_stl_data_mesh_creator(gmio_stl_data_t* data);
gmio_stl_mesh_t gmio_stl_data_mesh(const gmio_stl_data_t* data);
struct gmio_stl_mesh_creator gmio_stl_data_mesh_creator(struct gmio_stl_data* data);
struct gmio_stl_mesh gmio_stl_data_mesh(const struct gmio_stl_data* data);
#endif /* GMIO_TESTS_STL_UTILS_H */

View File

@ -58,7 +58,7 @@ static size_t gmio_stream_buffer_write(
void* cookie, const void* ptr, size_t item_size, size_t item_count)
{
if (item_size > 0 && item_count > 0) {
gmio_rw_buffer_t* buff = (gmio_rw_buffer_t*)cookie;
struct gmio_rw_buffer* buff = (struct gmio_rw_buffer*)cookie;
const size_t buff_remaining_size = buff->len - buff->pos;
const size_t wanted_write_size = item_size * item_count;
const size_t next_write_size =
@ -84,23 +84,23 @@ static gmio_streamsize_t gmio_stream_buffer_size(void* cookie)
return buff->len;
}
static int gmio_stream_buffer_get_pos(void* cookie, gmio_stream_pos_t* pos)
static int gmio_stream_buffer_get_pos(void* cookie, struct gmio_stream_pos* pos)
{
gmio_ro_buffer_t* buff = (gmio_ro_buffer_t*)cookie;
memcpy(&pos->cookie[0], &buff->pos, sizeof(size_t));
return 0;
}
static int gmio_stream_buffer_set_pos(void* cookie, const gmio_stream_pos_t* pos)
static int gmio_stream_buffer_set_pos(void* cookie, const struct gmio_stream_pos* pos)
{
gmio_ro_buffer_t* buff = (gmio_ro_buffer_t*)cookie;
memcpy(&buff->pos, &pos->cookie[0], sizeof(size_t));
return 0;
}
gmio_stream_t gmio_istream_buffer(gmio_ro_buffer_t* buff)
struct gmio_stream gmio_istream_buffer(gmio_ro_buffer_t* buff)
{
gmio_stream_t stream = {0};
struct gmio_stream stream = {0};
stream.cookie = buff;
stream.func_at_end = gmio_stream_buffer_at_end;
stream.func_error = gmio_stream_buffer_error;
@ -111,9 +111,9 @@ gmio_stream_t gmio_istream_buffer(gmio_ro_buffer_t* buff)
return stream;
}
gmio_stream_t gmio_stream_buffer(gmio_rw_buffer_t* buff)
struct gmio_stream gmio_stream_buffer(struct gmio_rw_buffer* buff)
{
gmio_stream_t stream = gmio_istream_buffer((gmio_ro_buffer_t*)buff);
struct gmio_stream stream = gmio_istream_buffer((gmio_ro_buffer_t*)buff);
stream.func_write = gmio_stream_buffer_write;
return stream;
}

View File

@ -34,9 +34,8 @@ struct gmio_rw_buffer
size_t len;
size_t pos;
};
typedef struct gmio_rw_buffer gmio_rw_buffer_t;
gmio_stream_t gmio_istream_buffer(gmio_ro_buffer_t* buff);
gmio_stream_t gmio_iostream_buffer(gmio_rw_buffer_t* buff);
struct gmio_stream gmio_istream_buffer(gmio_ro_buffer_t* buff);
struct gmio_stream gmio_iostream_buffer(struct gmio_rw_buffer* buff);
#endif /* GMIO_STREAM_BUFFER_H */

View File

@ -23,7 +23,7 @@
#include <stdlib.h>
#include <string.h>
static gmio_memblock_t buffer_ctor()
static struct gmio_memblock buffer_ctor()
{
return gmio_memblock_calloc(4, 256);
}
@ -36,7 +36,7 @@ const char* test_core__buffer()
const size_t obj_size = 256;
const size_t buff_size = obj_count * obj_size;
const uint8_t zero_buff[4 * 256] = {0};
gmio_memblock_t buff = gmio_memblock_calloc(obj_count, obj_size);
struct gmio_memblock buff = gmio_memblock_calloc(obj_count, obj_size);
UTEST_ASSERT(buff.ptr != NULL);
UTEST_ASSERT(buff.size == buff_size);
UTEST_ASSERT(memcmp(buff.ptr, &zero_buff[0], buff_size) == 0);
@ -49,7 +49,7 @@ const char* test_core__buffer()
/* gmio_memblock_malloc() */
{
const size_t buff_size = 2 * 1024; /* 2KB */
gmio_memblock_t buff = gmio_memblock_malloc(buff_size);
struct gmio_memblock buff = gmio_memblock_malloc(buff_size);
UTEST_ASSERT(buff.ptr != NULL);
UTEST_ASSERT(buff.size == buff_size);
UTEST_ASSERT(buff.func_deallocate == &free);
@ -58,7 +58,7 @@ const char* test_core__buffer()
/* gmio_memblock_realloc() */
{
const size_t buff_size = 1024; /* 1KB */
gmio_memblock_t buff = gmio_memblock_malloc(buff_size);
struct gmio_memblock buff = gmio_memblock_malloc(buff_size);
buff = gmio_memblock_realloc(buff.ptr, 2 * buff_size);
UTEST_ASSERT(buff.ptr != NULL);
UTEST_ASSERT(buff.size == (2 * buff_size));
@ -100,9 +100,9 @@ const char* test_core__error()
const char* test_core__stream()
{
{
const gmio_stream_t null_stream = gmio_stream_null();
const uint8_t null_bytes[sizeof(gmio_stream_t)] = {0};
UTEST_ASSERT(memcmp(&null_stream, &null_bytes, sizeof(gmio_stream_t))
const struct gmio_stream null_stream = gmio_stream_null();
const uint8_t null_bytes[sizeof(struct gmio_stream)] = {0};
UTEST_ASSERT(memcmp(&null_stream, &null_bytes, sizeof(struct gmio_stream))
== 0);
}

View File

@ -131,7 +131,7 @@ const char* test_internal__gmio_fast_atof()
{
char strbuff[2048] = {0};
gmio_stringstream_t it = {0};
struct gmio_stringstream it = {0};
gmio_ro_buffer_t streambuff = { fstr, sizeof(fstr) - 1, 0 };
float f2;
@ -182,10 +182,10 @@ const char* test_internal__stringstream()
char small_fwd_it_str[4];
char fwd_it_str[32];
gmio_stringstream_t fwd_it = {0};
struct gmio_stringstream fwd_it = {0};
char copy_str[128];
gmio_string_t copy_strbuff;
struct gmio_string copy_strbuff;
fwd_it.stream = gmio_istream_buffer(&buff);
fwd_it.strbuff.ptr = fwd_it_str;
@ -237,10 +237,10 @@ const char* test_internal__stringstream()
gmio_ro_buffer_t buff = { text, sizeof(text) - 1, 0 };
char fwd_it_str[32];
gmio_stringstream_t fwd_it = {0};
struct gmio_stringstream fwd_it = {0};
char copy_str[128];
gmio_string_t copy_strbuff;
struct gmio_string copy_strbuff;
fwd_it.stream = gmio_istream_buffer(&buff);
fwd_it.strbuff.ptr = fwd_it_str;

View File

@ -16,7 +16,7 @@
#include "utest_assert.h"
#include "../src/gmio_core/global.h"
#include "../src/gmio_core/transfer.h"
#include "../src/gmio_core/rwargs.h"
#include "../src/gmio_stl/stl_triangle.h"
#include <stddef.h>
@ -27,17 +27,17 @@ GMIO_PRAGMA_MSVC_WARNING_PUSH_AND_DISABLE(4127)
const char* test_platform__alignment()
{
UTEST_ASSERT(offsetof(gmio_stl_coords_t, x) == 0);
UTEST_ASSERT(offsetof(gmio_stl_coords_t, y) == 4);
UTEST_ASSERT(offsetof(gmio_stl_coords_t, z) == 8);
UTEST_ASSERT(sizeof(gmio_stl_coords_t) == GMIO_STL_COORDS_RAWSIZE);
UTEST_ASSERT(offsetof(struct gmio_stl_coords, x) == 0);
UTEST_ASSERT(offsetof(struct gmio_stl_coords, y) == 4);
UTEST_ASSERT(offsetof(struct gmio_stl_coords, z) == 8);
UTEST_ASSERT(sizeof(struct gmio_stl_coords) == GMIO_STL_COORDS_RAWSIZE);
UTEST_ASSERT(offsetof(gmio_stl_triangle_t, normal) == 0);
UTEST_ASSERT(offsetof(gmio_stl_triangle_t, v1) == GMIO_STL_COORDS_RAWSIZE);
UTEST_ASSERT(offsetof(gmio_stl_triangle_t, v2) == 2*GMIO_STL_COORDS_RAWSIZE);
UTEST_ASSERT(offsetof(gmio_stl_triangle_t, v3) == 3*GMIO_STL_COORDS_RAWSIZE);
UTEST_ASSERT(offsetof(gmio_stl_triangle_t, attribute_byte_count) == 4*GMIO_STL_COORDS_RAWSIZE);
UTEST_ASSERT(sizeof(gmio_stl_triangle_t) >= GMIO_STLB_TRIANGLE_RAWSIZE);
UTEST_ASSERT(offsetof(struct gmio_stl_triangle, normal) == 0);
UTEST_ASSERT(offsetof(struct gmio_stl_triangle, v1) == GMIO_STL_COORDS_RAWSIZE);
UTEST_ASSERT(offsetof(struct gmio_stl_triangle, v2) == 2*GMIO_STL_COORDS_RAWSIZE);
UTEST_ASSERT(offsetof(struct gmio_stl_triangle, v3) == 3*GMIO_STL_COORDS_RAWSIZE);
UTEST_ASSERT(offsetof(struct gmio_stl_triangle, attribute_byte_count) == 4*GMIO_STL_COORDS_RAWSIZE);
UTEST_ASSERT(sizeof(struct gmio_stl_triangle) >= GMIO_STLB_TRIANGLE_RAWSIZE);
return NULL;
}
@ -75,20 +75,21 @@ const char* test_platform__compiler()
* See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119
*/
{
const gmio_transfer_t trsf_null_bracket0 = {0};
gmio_transfer_t trsf_null_memset0;
const struct gmio_rwargs args_null_bracket0 = {0};
struct gmio_rwargs args_null_memset0;
memset(&trsf_null_memset0, 0, sizeof(gmio_transfer_t));
memset(&args_null_memset0, 0, sizeof(struct gmio_rwargs));
UTEST_ASSERT(memcmp(
&trsf_null_bracket0,
&trsf_null_memset0,
sizeof(gmio_transfer_t))
&args_null_bracket0,
&args_null_memset0,
sizeof(struct gmio_rwargs))
== 0);
UTEST_ASSERT(sizeof(gmio_transfer_t) >= (sizeof(gmio_stream_t)
+ sizeof(gmio_memblock_t)
+ sizeof(gmio_task_iface_t)));
UTEST_ASSERT(sizeof(struct gmio_rwargs)
>= (sizeof(struct gmio_stream)
+ sizeof(struct gmio_memblock)
+ sizeof(struct gmio_task_iface)));
}
/* Check sizeof() operator with fixed-size arrays */

View File

@ -18,6 +18,7 @@
#include "stl_utils.h"
#include "../src/gmio_core/error.h"
#include "../src/gmio_core/rwargs.h"
#include "../src/gmio_stl/internal/stl_rw_common.h"
#include "../src/gmio_stl/stl_error.h"
#include "../src/gmio_stl/stl_io.h"
@ -30,47 +31,47 @@ const char* test_stl_internal__rw_common()
{
int error = GMIO_ERROR_OK;
uint8_t buff[128] = {0};
gmio_transfer_t trsf = {0};
struct gmio_rwargs rwargs = {0};
UTEST_ASSERT(!gmio_check_transfer(&error, NULL));
UTEST_ASSERT(error == GMIO_ERROR_NULL_TRANSFER);
UTEST_ASSERT(!gmio_check_rwargs(&error, NULL));
UTEST_ASSERT(error == GMIO_ERROR_NULL_RWARGS);
UTEST_ASSERT(!gmio_check_transfer(&error, &trsf));
UTEST_ASSERT(!gmio_check_rwargs(&error, &rwargs));
UTEST_ASSERT(error == GMIO_ERROR_NULL_MEMBLOCK);
trsf.memblock = gmio_memblock(&buff[0], 0, NULL);
UTEST_ASSERT(!gmio_check_transfer(&error, &trsf));
rwargs.memblock = gmio_memblock(&buff[0], 0, NULL);
UTEST_ASSERT(!gmio_check_rwargs(&error, &rwargs));
UTEST_ASSERT(error == GMIO_ERROR_INVALID_MEMBLOCK_SIZE);
/* Verify that gmio_check_transfer() doesn't touch error when in case of
* success */
trsf.memblock = gmio_memblock(&buff[0], sizeof(buff), NULL);
UTEST_ASSERT(!gmio_check_transfer(&error, &trsf));
rwargs.memblock = gmio_memblock(&buff[0], sizeof(buff), NULL);
UTEST_ASSERT(!gmio_check_rwargs(&error, &rwargs));
UTEST_ASSERT(error == GMIO_ERROR_INVALID_MEMBLOCK_SIZE);
error = GMIO_ERROR_OK;
UTEST_ASSERT(gmio_check_transfer(&error, &trsf));
UTEST_ASSERT(gmio_check_rwargs(&error, &rwargs));
UTEST_ASSERT(error == GMIO_ERROR_OK);
}
/* gmio_stl_check_mesh() */
{
int error = GMIO_ERROR_OK;
gmio_stl_mesh_t mesh = {0};
struct gmio_stl_mesh mesh = {0};
UTEST_ASSERT(!gmio_stl_check_mesh(&error, NULL));
UTEST_ASSERT(error == GMIO_STL_ERROR_NULL_GET_TRIANGLE_FUNC);
UTEST_ASSERT(error == GMIO_STL_ERROR_NULL_FUNC_GET_TRIANGLE);
mesh.triangle_count = 100;
UTEST_ASSERT(!gmio_stl_check_mesh(&error, &mesh));
UTEST_ASSERT(error == GMIO_STL_ERROR_NULL_GET_TRIANGLE_FUNC);
UTEST_ASSERT(error == GMIO_STL_ERROR_NULL_FUNC_GET_TRIANGLE);
/* Verify that gmio_stl_check_mesh() doesn't touch error when in case of
* success */
mesh.triangle_count = 0;
mesh.func_get_triangle = &gmio_stl_nop_get_triangle;
UTEST_ASSERT(!gmio_stl_check_mesh(&error, &mesh));
UTEST_ASSERT(error == GMIO_STL_ERROR_NULL_GET_TRIANGLE_FUNC);
UTEST_ASSERT(error == GMIO_STL_ERROR_NULL_FUNC_GET_TRIANGLE);
error = GMIO_ERROR_OK;
UTEST_ASSERT(gmio_stl_check_mesh(&error, &mesh));
@ -80,23 +81,23 @@ const char* test_stl_internal__rw_common()
/* gmio_stlb_check_params() */
{
int error = GMIO_ERROR_OK;
gmio_transfer_t trsf = {0};
struct gmio_rwargs rwargs = {0};
uint8_t buff[1024] = {0};
UTEST_ASSERT(!gmio_stlb_check_params(&error, NULL, GMIO_ENDIANNESS_HOST));
UTEST_ASSERT(error == GMIO_ERROR_NULL_TRANSFER);
UTEST_ASSERT(error == GMIO_ERROR_NULL_RWARGS);
error = GMIO_ERROR_OK;
trsf.memblock = gmio_memblock(&buff[0], GMIO_STLB_MIN_CONTENTS_SIZE / 2, NULL);
UTEST_ASSERT(!gmio_stlb_check_params(&error, &trsf, GMIO_ENDIANNESS_HOST));
rwargs.memblock = gmio_memblock(&buff[0], GMIO_STLB_MIN_CONTENTS_SIZE / 2, NULL);
UTEST_ASSERT(!gmio_stlb_check_params(&error, &rwargs, GMIO_ENDIANNESS_HOST));
UTEST_ASSERT(error == GMIO_ERROR_INVALID_MEMBLOCK_SIZE);
error = GMIO_ERROR_OK;
trsf.memblock = gmio_memblock(&buff[0], sizeof(buff), NULL);
UTEST_ASSERT(gmio_stlb_check_params(&error, &trsf, GMIO_ENDIANNESS_HOST));
rwargs.memblock = gmio_memblock(&buff[0], sizeof(buff), NULL);
UTEST_ASSERT(gmio_stlb_check_params(&error, &rwargs, GMIO_ENDIANNESS_HOST));
UTEST_ASSERT(error == GMIO_ERROR_OK);
UTEST_ASSERT(!gmio_stlb_check_params(&error, &trsf, GMIO_ENDIANNESS_UNKNOWN));
UTEST_ASSERT(!gmio_stlb_check_params(&error, &rwargs, GMIO_ENDIANNESS_UNKNOWN));
UTEST_ASSERT(error == GMIO_STL_ERROR_UNSUPPORTED_BYTE_ORDER);
}

View File

@ -22,11 +22,12 @@
#include "../src/gmio_core/internal/min_max.h"
#include "../src/gmio_stl/stl_error.h"
#include "../src/gmio_stl/stl_io.h"
#include "../src/gmio_stl/stl_io_options.h"
#include <stddef.h>
#include <stdlib.h>
static const char* stl_grabcad_arm11_filepath =
static const char stl_grabcad_arm11_filepath[] =
"models/solid_grabcad_arm11_link0_hb.le_stlb";
struct stl_testcase_result
@ -51,7 +52,7 @@ struct stl_testcase
{
const char* filepath;
int errorcode;
gmio_stl_format_t format;
enum gmio_stl_format format;
const char* solid_name;
};
typedef struct stl_testcase stl_testcase;
@ -128,7 +129,7 @@ const char* test_stl_read()
const size_t expected_count =
sizeof(expected) / sizeof(stl_testcase);
size_t i; /* for loop counter */
gmio_stl_mesh_creator_t meshc = {0};
struct gmio_stl_mesh_creator meshc = {0};
stl_testcase_result_t result = {0};
meshc.cookie = &result;
@ -136,10 +137,10 @@ const char* test_stl_read()
meshc.func_add_triangle = &gmio_stl_nop_add_triangle;
for (i = 0; i < expected_count; ++i) {
const gmio_stl_format_t format =
const enum gmio_stl_format format =
gmio_stl_get_format_file(expected[i].filepath);
const int err =
gmio_stl_read_file(expected[i].filepath, &meshc, NULL);
gmio_stl_read_file(expected[i].filepath, NULL, &meshc);
/* Check format */
if (format != expected[i].format) {
@ -185,13 +186,13 @@ const char* test_stl_read()
const char* test_stlb_write_header()
{
const char* filepath = "temp/solid.stlb";
gmio_stlb_header_t header = {0};
struct gmio_stlb_header header = {0};
const char* header_str = "temp/solid.stlb generated with gmio library";
int error = GMIO_ERROR_OK;
{
FILE* outfile = fopen(filepath, "wb");
gmio_stream_t stream = gmio_stream_stdio(outfile);
struct gmio_stream stream = gmio_stream_stdio(outfile);
memcpy(&header,
header_str,
GMIO_MIN(GMIO_STLB_HEADER_SIZE, strlen(header_str)));
@ -202,9 +203,9 @@ const char* test_stlb_write_header()
}
{
gmio_stl_data_t data = {0};
gmio_stl_mesh_creator_t mesh_creator = gmio_stl_data_mesh_creator(&data);
error = gmio_stl_read_file(filepath, &mesh_creator, NULL);
struct gmio_stl_data data = {0};
struct gmio_stl_mesh_creator mesh_creator = gmio_stl_data_mesh_creator(&data);
error = gmio_stl_read_file(filepath, NULL, &mesh_creator);
UTEST_ASSERT(error == GMIO_ERROR_OK);
UTEST_ASSERT(gmio_stlb_header_equal(&header, &data.header));
UTEST_ASSERT(data.tri_array.count == 0);
@ -227,13 +228,13 @@ const char* test_stlb_write()
const char* model_filepath = stl_grabcad_arm11_filepath;
const char* model_filepath_out = "temp/solid.le_stlb";
const char* model_filepath_out_be = "temp/solid.be_stlb";
gmio_stl_data_t data = {0};
struct gmio_stl_data data = {0};
int error = GMIO_ERROR_OK;
/* Read input model file */
{
gmio_stl_mesh_creator_t creator = gmio_stl_data_mesh_creator(&data);
error = gmio_stl_read_file(model_filepath, &creator, NULL);
struct gmio_stl_mesh_creator creator = gmio_stl_data_mesh_creator(&data);
error = gmio_stl_read_file(model_filepath, NULL, &creator);
UTEST_ASSERT(error == GMIO_ERROR_OK);
}
@ -241,16 +242,16 @@ const char* test_stlb_write()
* Write also the model file in big-endian STL format
*/
{
gmio_stl_write_options_t options = {0};
const gmio_stl_mesh_t mesh = gmio_stl_data_mesh(&data);
struct gmio_stl_write_options options = {0};
const struct gmio_stl_mesh mesh = gmio_stl_data_mesh(&data);
options.stlb_header_data = &data.header;
error = gmio_stl_write_file(
GMIO_STL_FORMAT_BINARY_LE, model_filepath_out, &mesh, NULL, &options);
model_filepath_out, NULL, &mesh, GMIO_STL_FORMAT_BINARY_LE, &options);
UTEST_ASSERT(error == GMIO_ERROR_OK);
/* Big-endian version */
error = gmio_stl_write_file(
GMIO_STL_FORMAT_BINARY_BE, model_filepath_out_be, &mesh, NULL, &options);
model_filepath_out_be, NULL, &mesh, GMIO_STL_FORMAT_BINARY_BE, &options);
}
/* Check input and output models are equal */
@ -285,15 +286,15 @@ const char* test_stlb_write()
/* Check output LE/BE models are equal */
{
gmio_stl_data_t data_be = {0};
gmio_stl_mesh_creator_t creator = gmio_stl_data_mesh_creator(&data_be);
error = gmio_stl_read_file(model_filepath_out_be, &creator, NULL);
struct gmio_stl_data data_be = {0};
struct gmio_stl_mesh_creator creator = gmio_stl_data_mesh_creator(&data_be);
error = gmio_stl_read_file(model_filepath_out_be, NULL, &creator);
UTEST_ASSERT(error == GMIO_ERROR_OK);
UTEST_ASSERT(gmio_stlb_header_equal(&data.header, &data_be.header));
UTEST_ASSERT(data.tri_array.count == data_be.tri_array.count);
UTEST_ASSERT(memcmp(data.tri_array.ptr,
data_be.tri_array.ptr,
data.tri_array.count * sizeof(gmio_stl_triangle_t))
data.tri_array.count * sizeof(struct gmio_stl_triangle))
== 0);
free(data_be.tri_array.ptr);
}
@ -307,45 +308,45 @@ const char* test_stla_write()
{
const char* model_filepath = stl_grabcad_arm11_filepath;
const char* model_filepath_out = "temp/solid.stla";
gmio_stl_data_t data = {0};
struct gmio_stl_data data = {0};
char header_str[GMIO_STLB_HEADER_SIZE + 1] = {0};
int error = GMIO_ERROR_OK;
/* Read input model file */
{
gmio_stl_mesh_creator_t creator = gmio_stl_data_mesh_creator(&data);
error = gmio_stl_read_file(model_filepath, &creator, NULL);
struct gmio_stl_mesh_creator creator = gmio_stl_data_mesh_creator(&data);
error = gmio_stl_read_file(model_filepath, NULL, &creator);
UTEST_ASSERT(error == GMIO_ERROR_OK);
}
/* Write the model to STL ascii format */
{
gmio_stl_write_options_t options = {0};
const gmio_stl_mesh_t mesh = gmio_stl_data_mesh(&data);
struct gmio_stl_write_options options = {0};
const struct gmio_stl_mesh mesh = gmio_stl_data_mesh(&data);
gmio_stlb_header_to_printable_string(&data.header, &header_str[0], '_');
options.stla_solid_name = &header_str[0];
options.stla_float32_prec = 7;
options.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_LOWERCASE;
error = gmio_stl_write_file(
GMIO_STL_FORMAT_ASCII, model_filepath_out, &mesh, NULL, &options);
model_filepath_out, NULL, &mesh, GMIO_STL_FORMAT_ASCII, &options);
UTEST_ASSERT(error == GMIO_ERROR_OK);
}
/* Read the output STL ascii model */
{
char trim_header_str[sizeof(header_str)] = {0};
gmio_stl_data_t data_stla = {0};
gmio_stl_mesh_creator_t creator = gmio_stl_data_mesh_creator(&data_stla);
struct gmio_stl_data data_stla = {0};
struct gmio_stl_mesh_creator creator = gmio_stl_data_mesh_creator(&data_stla);
size_t i = 0;
strncpy(&trim_header_str[0], &header_str[0], sizeof(header_str));
gmio_string_trim_from_end(trim_header_str, sizeof(header_str));
error = gmio_stl_read_file(model_filepath_out, &creator, NULL);
error = gmio_stl_read_file(model_filepath_out, NULL, &creator);
UTEST_ASSERT(error == GMIO_ERROR_OK);
UTEST_ASSERT(data.tri_array.count == data_stla.tri_array.count);
UTEST_ASSERT(strcmp(&trim_header_str[0], &data_stla.solid_name[0]) == 0);
for (i = 0; i < data.tri_array.count; ++i) {
const gmio_stl_triangle_t* lhs = &data.tri_array.ptr[i];
const gmio_stl_triangle_t* rhs = &data_stla.tri_array.ptr[i];
const struct gmio_stl_triangle* lhs = &data.tri_array.ptr[i];
const struct gmio_stl_triangle* rhs = &data_stla.tri_array.ptr[i];
const gmio_bool_t tri_equal = gmio_stl_triangle_equal(lhs, rhs, 5);
UTEST_ASSERT(tri_equal);
}
@ -358,37 +359,37 @@ void generate_stlb_tests_models()
{
{
FILE* outfile = fopen("models/solid_empty.stlb", "wb");
gmio_stream_t stream = gmio_stream_stdio(outfile);
struct gmio_stream stream = gmio_stream_stdio(outfile);
gmio_stlb_write_header(&stream, GMIO_ENDIANNESS_LITTLE, NULL, 0);
fclose(outfile);
}
{
gmio_stl_mesh_t mesh = {0};
gmio_stl_triangle_t tri = {
struct gmio_stl_mesh mesh = {0};
struct gmio_stl_triangle tri = {
{ 0.f, 0.f, 1.f }, /* normal */
{ 0.f, 0.f, 0.f }, /* v1 */
{ 10.f, 0.f, 0.f }, /* v2 */
{ 5.f, 10.f, 0.f }, /* v3 */
0 /* attr */
};
gmio_stl_data_t data = {0};
struct gmio_stl_data data = {0};
data.tri_array.ptr = &tri;
data.tri_array.count = 1;
mesh = gmio_stl_data_mesh(&data);
gmio_stl_write_file(
GMIO_STL_FORMAT_BINARY_LE,
"models/solid_one_facet.le_stlb",
&mesh,
NULL,
&mesh,
GMIO_STL_FORMAT_BINARY_LE,
NULL);
gmio_stl_write_file(
GMIO_STL_FORMAT_BINARY_BE,
"models/solid_one_facet.be_stlb",
&mesh,
NULL,
&mesh,
GMIO_STL_FORMAT_BINARY_BE,
NULL);
}
}

View File

@ -13,35 +13,31 @@
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
****************************************************************************/
/*! \file transfer.h
* Declaration of gmio_transfer
*
* \addtogroup gmio_core
* @{
*/
#include "utest_assert.h"
#ifndef GMIO_TRANSFER_H
#define GMIO_TRANSFER_H
#include "../src/gmio_stl/stla_stats.h"
#include "global.h"
#include "memblock.h"
#include "stream.h"
#include "task_iface.h"
#include <stdio.h>
/*! Defines objects required for any transfer(read/write) operation */
struct gmio_transfer
static const char stl_jburkardt_sphere_filepath[] =
"models/solid_jburkardt_sphere.stla";
const char* test_stla_stats()
{
/*! The stream object to be used for I/O */
gmio_stream_t stream;
FILE* stla_file = fopen(stl_jburkardt_sphere_filepath, "rb");
struct gmio_rwargs rwargs = {0};
struct gmio_stla_stats stats = {0};
/*! The memory block used by the transfer for stream buffering */
gmio_memblock_t memblock;
rwargs.memblock = gmio_memblock_malloc(8 * 1024); /* 8Ko */
rwargs.stream = gmio_stream_stdio(stla_file);
/*! The interface object by which the transfer task can be controlled */
gmio_task_iface_t task_iface;
};
stats = gmio_stla_stats_get(&rwargs, GMIO_STLA_STAT_FLAG_ALL);
typedef struct gmio_transfer gmio_transfer_t;
gmio_memblock_deallocate(&rwargs.memblock);
fclose(stla_file);
#endif /* GMIO_TRANSFER_H */
/*! @} */
UTEST_ASSERT(stats.facet_count == 228);
/*UTEST_ASSERT(stats.size == 54297);*/
return NULL;
}