Improve indentation
This commit is contained in:
parent
e78c398026
commit
6b7ead1f24
@ -22,7 +22,6 @@
|
||||
|
||||
#include "global.h"
|
||||
|
||||
|
||||
/*! This enum defines common errors */
|
||||
enum gmio_error
|
||||
{
|
||||
|
@ -48,8 +48,11 @@ const char *gmio_next_char(gmio_string_stream_fwd_iterator_t *it)
|
||||
return it->buffer.ptr + it->buffer_pos;
|
||||
}
|
||||
else {
|
||||
if (gmio_stream_error(it->stream) != 0 || gmio_stream_at_end(it->stream))
|
||||
if (gmio_stream_error(it->stream) != 0
|
||||
|| gmio_stream_at_end(it->stream))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Read next chunk of data */
|
||||
it->buffer_pos = 0;
|
||||
@ -73,7 +76,8 @@ void gmio_skip_spaces(gmio_string_stream_fwd_iterator_t *it)
|
||||
curr_char = gmio_next_char(it);
|
||||
}
|
||||
|
||||
int gmio_eat_word(gmio_string_stream_fwd_iterator_t *it, gmio_string_buffer_t *buffer)
|
||||
int gmio_eat_word(
|
||||
gmio_string_stream_fwd_iterator_t *it, gmio_string_buffer_t *buffer)
|
||||
{
|
||||
const char* stream_curr_char = NULL;
|
||||
int isspace_res = 0;
|
||||
@ -86,7 +90,10 @@ int gmio_eat_word(gmio_string_stream_fwd_iterator_t *it, gmio_string_buffer_t *b
|
||||
gmio_skip_spaces(it);
|
||||
stream_curr_char = gmio_current_char(it);
|
||||
|
||||
while (i < buffer->max_len && stream_curr_char != NULL && isspace_res == 0) {
|
||||
while (i < buffer->max_len
|
||||
&& stream_curr_char != NULL
|
||||
&& isspace_res == 0)
|
||||
{
|
||||
isspace_res = isspace(*stream_curr_char);
|
||||
if (isspace_res == 0) {
|
||||
buffer->ptr[i] = *stream_curr_char;
|
||||
@ -121,7 +128,8 @@ int gmio_get_float32(const char *str, gmio_float32_t *value_ptr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
gmio_bool_t gmio_checked_next_chars(gmio_string_stream_fwd_iterator_t *it, const char *str)
|
||||
gmio_bool_t gmio_checked_next_chars(
|
||||
gmio_string_stream_fwd_iterator_t *it, const char *str)
|
||||
{
|
||||
size_t pos = 0;
|
||||
const char* curr_char = gmio_current_char(it);
|
||||
|
@ -26,8 +26,8 @@
|
||||
*/
|
||||
struct gmio_string_buffer
|
||||
{
|
||||
char* ptr; /*!< Buffer contents */
|
||||
size_t len; /*!< Size(length) of current contents */
|
||||
char* ptr; /*!< Buffer contents */
|
||||
size_t len; /*!< Size(length) of current contents */
|
||||
size_t max_len; /*!< Maximum contents size(length) */
|
||||
};
|
||||
|
||||
@ -41,20 +41,29 @@ typedef struct gmio_string_buffer gmio_string_buffer_t;
|
||||
*/
|
||||
struct gmio_string_stream_fwd_iterator
|
||||
{
|
||||
gmio_stream_t* stream;
|
||||
gmio_stream_t* stream;
|
||||
gmio_string_buffer_t buffer;
|
||||
size_t buffer_pos; /*!< Position indicator in buffer */
|
||||
size_t buffer_pos; /*!< Position indicator in buffer */
|
||||
|
||||
void* cookie;
|
||||
void (*stream_read_hook)(void* cookie, const gmio_string_buffer_t* str_buffer);
|
||||
void (*stream_read_hook)(void* cookie,
|
||||
const gmio_string_buffer_t* str_buffer);
|
||||
};
|
||||
|
||||
typedef struct gmio_string_stream_fwd_iterator gmio_string_stream_fwd_iterator_t;
|
||||
typedef struct gmio_string_stream_fwd_iterator
|
||||
gmio_string_stream_fwd_iterator_t;
|
||||
|
||||
void gmio_string_stream_fwd_iterator_init(gmio_string_stream_fwd_iterator_t* it);
|
||||
const char* gmio_current_char(const gmio_string_stream_fwd_iterator_t* it);
|
||||
void gmio_skip_spaces(gmio_string_stream_fwd_iterator_t* it);
|
||||
int gmio_eat_word(gmio_string_stream_fwd_iterator_t* it, gmio_string_buffer_t* buffer);
|
||||
void gmio_string_stream_fwd_iterator_init(
|
||||
gmio_string_stream_fwd_iterator_t* it);
|
||||
|
||||
const char* gmio_current_char(
|
||||
const gmio_string_stream_fwd_iterator_t* it);
|
||||
|
||||
void gmio_skip_spaces(
|
||||
gmio_string_stream_fwd_iterator_t* it);
|
||||
|
||||
int gmio_eat_word(
|
||||
gmio_string_stream_fwd_iterator_t* it, gmio_string_buffer_t* buffer);
|
||||
|
||||
/*! Move on next char in stream */
|
||||
const char* gmio_next_char(gmio_string_stream_fwd_iterator_t* it);
|
||||
@ -63,7 +72,8 @@ const char* gmio_next_char(gmio_string_stream_fwd_iterator_t* it);
|
||||
*
|
||||
* Returns GMIO_TRUE if \p str was fully matched
|
||||
*/
|
||||
gmio_bool_t gmio_checked_next_chars(gmio_string_stream_fwd_iterator_t* it, const char* str);
|
||||
gmio_bool_t gmio_checked_next_chars(
|
||||
gmio_string_stream_fwd_iterator_t* it, const char* str);
|
||||
|
||||
/*! Converts the string pointed to by \p str to gmio_float32_t representation
|
||||
*
|
||||
|
@ -44,15 +44,22 @@ gmio_stl_format_t gmio_stl_get_format(gmio_stream_t *stream, size_t data_size)
|
||||
/* Binary STL ? */
|
||||
if (read_size >= (GMIO_STLB_HEADER_SIZE + 4)) {
|
||||
/* Try with little-endian format */
|
||||
uint32_t facet_count = gmio_decode_uint32_le((const uint8_t*)fixed_buffer + 80);
|
||||
uint32_t facet_count =
|
||||
gmio_decode_uint32_le((const uint8_t*)fixed_buffer + 80);
|
||||
|
||||
if ((GMIO_STLB_HEADER_SIZE + 4 + facet_count*GMIO_STLB_TRIANGLE_RAWSIZE) == data_size)
|
||||
if ((GMIO_STLB_HEADER_SIZE + 4 + facet_count*GMIO_STLB_TRIANGLE_RAWSIZE)
|
||||
== data_size)
|
||||
{
|
||||
return GMIO_STL_BINARY_LE_FORMAT;
|
||||
}
|
||||
|
||||
/* Try with byte-reverted facet count */
|
||||
facet_count = gmio_uint32_bswap(facet_count);
|
||||
if ((GMIO_STLB_HEADER_SIZE + 4 + facet_count*GMIO_STLB_TRIANGLE_RAWSIZE) == data_size)
|
||||
if ((GMIO_STLB_HEADER_SIZE + 4 + facet_count*GMIO_STLB_TRIANGLE_RAWSIZE)
|
||||
== data_size)
|
||||
{
|
||||
return GMIO_STL_BINARY_BE_FORMAT;
|
||||
}
|
||||
}
|
||||
|
||||
/* ASCII STL ? */
|
||||
|
@ -31,13 +31,12 @@ struct gmio_stl_mesh
|
||||
const void* cookie;
|
||||
|
||||
/*! Number of triangles in the mesh */
|
||||
uint32_t triangle_count;
|
||||
uint32_t triangle_count;
|
||||
|
||||
/*! Pointer on a function that stores the mesh triangle of index \p tri_id
|
||||
* into \p triangle */
|
||||
void (*get_triangle_func)(const void* cookie,
|
||||
uint32_t tri_id,
|
||||
gmio_stl_triangle_t* triangle);
|
||||
void (*get_triangle_func)(
|
||||
const void* cookie, uint32_t tri_id, gmio_stl_triangle_t* triangle);
|
||||
};
|
||||
|
||||
typedef struct gmio_stl_mesh gmio_stl_mesh_t;
|
||||
|
@ -47,9 +47,8 @@ struct gmio_stl_mesh_creator
|
||||
*
|
||||
* The argument \p header contains the header data(80 bytes)
|
||||
*/
|
||||
void (*binary_begin_solid_func)(void* cookie,
|
||||
uint32_t tri_count,
|
||||
const uint8_t* header);
|
||||
void (*binary_begin_solid_func)(
|
||||
void* cookie, uint32_t tri_count, const uint8_t* header);
|
||||
|
||||
/*! Pointer on a function that adds a triangle to the user mesh
|
||||
*
|
||||
@ -58,9 +57,8 @@ struct gmio_stl_mesh_creator
|
||||
*
|
||||
* The argument \p tri_id is the index of the mesh triangle
|
||||
*/
|
||||
void (*add_triangle_func)(void* cookie,
|
||||
uint32_t tri_id,
|
||||
const gmio_stl_triangle_t* triangle);
|
||||
void (*add_triangle_func)(
|
||||
void* cookie, uint32_t tri_id, const gmio_stl_triangle_t* triangle);
|
||||
|
||||
/*! Pointer on a function that finalizes creation of the user mesh
|
||||
*
|
||||
|
@ -82,11 +82,11 @@ typedef struct
|
||||
/* Copy of gmio_stla_read() corresponding argument */
|
||||
gmio_transfer_t* transfer;
|
||||
/* Copy of gmio_stla_read_options::stream_size */
|
||||
size_t stream_size;
|
||||
size_t stream_size;
|
||||
/* Offset (in bytes) from beginning of stream : current position */
|
||||
size_t stream_offset;
|
||||
size_t stream_offset;
|
||||
/* Cache for gmio_transfer::is_stop_requested_func */
|
||||
gmio_bool_t is_stop_requested;
|
||||
gmio_bool_t is_stop_requested;
|
||||
} gmio_string_stream_fwd_iterator_cookie_t;
|
||||
|
||||
/* gmio_stla_token */
|
||||
@ -111,15 +111,15 @@ typedef enum
|
||||
typedef struct
|
||||
{
|
||||
gmio_stla_token_t token;
|
||||
gmio_bool_t error;
|
||||
gmio_string_stream_fwd_iterator_t stream_iterator;
|
||||
gmio_bool_t error;
|
||||
gmio_string_stream_fwd_iterator_t stream_iterator;
|
||||
gmio_string_stream_fwd_iterator_cookie_t stream_iterator_cookie;
|
||||
gmio_string_buffer_t string_buffer;
|
||||
gmio_string_buffer_t string_buffer;
|
||||
gmio_stl_mesh_creator_t* creator;
|
||||
} gmio_stla_parse_data_t;
|
||||
|
||||
static void gmio_stream_fwd_iterator_stla_read_hook(void* cookie,
|
||||
const gmio_string_buffer_t* buffer)
|
||||
static void gmio_stream_fwd_iterator_stla_read_hook(
|
||||
void* cookie, const gmio_string_buffer_t* buffer)
|
||||
{
|
||||
gmio_string_stream_fwd_iterator_cookie_t* tcookie =
|
||||
(gmio_string_stream_fwd_iterator_cookie_t*)(cookie);
|
||||
@ -132,20 +132,22 @@ static void gmio_stream_fwd_iterator_stla_read_hook(void* cookie,
|
||||
}
|
||||
}
|
||||
|
||||
GMIO_INLINE static gmio_bool_t parsing_can_continue(const gmio_stla_parse_data_t* data)
|
||||
GMIO_INLINE static gmio_bool_t parsing_can_continue(
|
||||
const gmio_stla_parse_data_t* data)
|
||||
{
|
||||
if (!data->error && !data->stream_iterator_cookie.is_stop_requested)
|
||||
return GMIO_TRUE;
|
||||
return GMIO_FALSE;
|
||||
}
|
||||
|
||||
GMIO_INLINE static const char* current_token_as_identifier(const gmio_stla_parse_data_t* data)
|
||||
GMIO_INLINE static const char* current_token_as_identifier(
|
||||
const gmio_stla_parse_data_t* data)
|
||||
{
|
||||
return data->token == ID_token ? data->string_buffer.ptr : "";
|
||||
}
|
||||
|
||||
GMIO_INLINE static int get_current_token_as_float32(const gmio_stla_parse_data_t* data,
|
||||
gmio_float32_t* value_ptr)
|
||||
GMIO_INLINE static int get_current_token_as_float32(
|
||||
const gmio_stla_parse_data_t* data, gmio_float32_t* value_ptr)
|
||||
{
|
||||
if (data->token == FLOAT_token)
|
||||
return gmio_get_float32(data->string_buffer.ptr, value_ptr);
|
||||
@ -161,7 +163,8 @@ GMIO_INLINE static void parsing_error(gmio_stla_parse_data_t* data)
|
||||
data->string_buffer.ptr);
|
||||
}
|
||||
|
||||
static gmio_stla_token_t parsing_find_token(const gmio_string_buffer_t* str_buffer)
|
||||
static gmio_stla_token_t parsing_find_token(
|
||||
const gmio_string_buffer_t* str_buffer)
|
||||
{
|
||||
const char* word = str_buffer->ptr;
|
||||
const size_t word_len = str_buffer->len;
|
||||
@ -248,7 +251,8 @@ static void parsing_advance(gmio_stla_parse_data_t* data)
|
||||
parsing_error(data);
|
||||
}
|
||||
|
||||
static void parsing_eat_token(gmio_stla_token_t token, gmio_stla_parse_data_t* data)
|
||||
static void parsing_eat_token(
|
||||
gmio_stla_token_t token, gmio_stla_parse_data_t* data)
|
||||
{
|
||||
if (!parsing_can_continue(data))
|
||||
return;
|
||||
@ -339,7 +343,8 @@ static void parse_endsolid(gmio_stla_parse_data_t* data)
|
||||
} /* end switch */
|
||||
}
|
||||
|
||||
static void parse_xyz_coords(gmio_stla_parse_data_t* data, gmio_stl_coords_t* coords)
|
||||
static void parse_xyz_coords(
|
||||
gmio_stla_parse_data_t* data, gmio_stl_coords_t* coords)
|
||||
{
|
||||
if (!parsing_can_continue(data))
|
||||
return;
|
||||
@ -362,7 +367,8 @@ static void parse_xyz_coords(gmio_stla_parse_data_t* data, gmio_stl_coords_t* co
|
||||
} /* end switch */
|
||||
}
|
||||
|
||||
static void parse_facet(gmio_stla_parse_data_t* data, gmio_stl_triangle_t* facet)
|
||||
static void parse_facet(
|
||||
gmio_stla_parse_data_t* data, gmio_stl_triangle_t* facet)
|
||||
{
|
||||
parsing_eat_token(FACET_token, data);
|
||||
parsing_eat_token(NORMAL_token, data);
|
||||
@ -391,8 +397,10 @@ static void parse_facets(gmio_stla_parse_data_t* data)
|
||||
|
||||
while (data->token == FACET_token && parsing_can_continue(data)) {
|
||||
parse_facet(data, &facet);
|
||||
if (is_add_triangle_available)
|
||||
data->creator->add_triangle_func(data->creator->cookie, i_facet_offset, &facet);
|
||||
if (is_add_triangle_available) {
|
||||
data->creator->add_triangle_func(
|
||||
data->creator->cookie, i_facet_offset, &facet);
|
||||
}
|
||||
++i_facet_offset;
|
||||
}
|
||||
}
|
||||
@ -414,9 +422,10 @@ static void parse_solid(gmio_stla_parse_data_t* data)
|
||||
|
||||
enum { GMIO_STLA_READ_STRING_BUFFER_LEN = 512 };
|
||||
|
||||
int gmio_stla_read(gmio_stl_mesh_creator_t* creator,
|
||||
gmio_transfer_t* trsf,
|
||||
const gmio_stla_read_options_t* options)
|
||||
int gmio_stla_read(
|
||||
gmio_stl_mesh_creator_t* creator,
|
||||
gmio_transfer_t* trsf,
|
||||
const gmio_stla_read_options_t* options)
|
||||
{
|
||||
char fixed_buffer[GMIO_STLA_READ_STRING_BUFFER_LEN];
|
||||
gmio_stla_parse_data_t parse_data;
|
||||
@ -439,7 +448,8 @@ int gmio_stla_read(gmio_stl_mesh_creator_t* creator,
|
||||
parse_data.stream_iterator.buffer.ptr = trsf->buffer;
|
||||
parse_data.stream_iterator.buffer.max_len = trsf->buffer_size;
|
||||
parse_data.stream_iterator.cookie = &parse_data.stream_iterator_cookie;
|
||||
parse_data.stream_iterator.stream_read_hook = gmio_stream_fwd_iterator_stla_read_hook;
|
||||
parse_data.stream_iterator.stream_read_hook =
|
||||
gmio_stream_fwd_iterator_stla_read_hook;
|
||||
gmio_string_stream_fwd_iterator_init(&parse_data.stream_iterator);
|
||||
|
||||
parse_data.string_buffer.ptr = &fixed_buffer[0];
|
||||
|
@ -98,16 +98,13 @@ static char* gmio_write_stdio_format(char* buffer, uint8_t prec)
|
||||
return buffer + 3 + prec_len;
|
||||
}
|
||||
|
||||
/*static char* gmio_write_float32_string(char* buffer, const char* format, gmio_float32_t val)
|
||||
static char* gmio_write_coords(
|
||||
char* buffer,
|
||||
const char* coords_format,
|
||||
const gmio_stl_coords_t* coords)
|
||||
{
|
||||
return buffer + sprintf(buffer, format, val);
|
||||
}*/
|
||||
|
||||
static char* gmio_write_coords(char* buffer,
|
||||
const char* coords_format,
|
||||
const gmio_stl_coords_t* coords)
|
||||
{
|
||||
return buffer + sprintf(buffer, coords_format, coords->x, coords->y, coords->z);
|
||||
return buffer + sprintf(buffer,
|
||||
coords_format, coords->x, coords->y, coords->z);
|
||||
}
|
||||
|
||||
static gmio_bool_t gmio_transfer_flush_buffer(gmio_transfer_t* trsf, size_t n)
|
||||
@ -115,18 +112,22 @@ static gmio_bool_t gmio_transfer_flush_buffer(gmio_transfer_t* trsf, size_t n)
|
||||
return gmio_stream_write(&trsf->stream, trsf->buffer, sizeof(char), n) == n;
|
||||
}
|
||||
|
||||
int gmio_stla_write(const gmio_stl_mesh_t* mesh,
|
||||
gmio_transfer_t* trsf,
|
||||
const gmio_stla_write_options_t* options)
|
||||
int gmio_stla_write(
|
||||
const gmio_stl_mesh_t* mesh,
|
||||
gmio_transfer_t* trsf,
|
||||
const gmio_stla_write_options_t* options)
|
||||
{
|
||||
/* Constants */
|
||||
const char* solid_name = options != NULL ? options->solid_name : NULL;
|
||||
const uint8_t float32_prec = options != NULL ? options->float32_prec : 9;
|
||||
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->buffer_size / GMIO_STLA_FACET_SIZE_P2) : 0;
|
||||
gmio_size_to_uint32(trsf->buffer_size / GMIO_STLA_FACET_SIZE_P2)
|
||||
: 0;
|
||||
/* Variables */
|
||||
uint32_t ifacet = 0;
|
||||
char* buffer_iterator = trsf != NULL ? trsf->buffer : NULL;
|
||||
char* buff_it = trsf != NULL ? trsf->buffer : NULL;
|
||||
char coords_format[64];
|
||||
int error = GMIO_NO_ERROR;
|
||||
|
||||
@ -141,21 +142,21 @@ int gmio_stla_write(const gmio_stl_mesh_t* mesh,
|
||||
return GMIO_INVALID_BUFFER_SIZE_ERROR;
|
||||
|
||||
{ /* Create XYZ coords format string (for normal and vertex coords) */
|
||||
char* coords_format_iterator = coords_format;
|
||||
coords_format_iterator = gmio_write_stdio_format(coords_format_iterator, float32_prec);
|
||||
coords_format_iterator = gmio_write_nspaces(coords_format_iterator, 2);
|
||||
coords_format_iterator = gmio_write_stdio_format(coords_format_iterator, float32_prec);
|
||||
coords_format_iterator = gmio_write_nspaces(coords_format_iterator, 2);
|
||||
coords_format_iterator = gmio_write_stdio_format(coords_format_iterator, float32_prec);
|
||||
*coords_format_iterator = 0; /* Write terminating null byte */
|
||||
char* it = coords_format;
|
||||
it = gmio_write_stdio_format(it, float32_prec);
|
||||
it = gmio_write_nspaces(it, 2);
|
||||
it = gmio_write_stdio_format(it, float32_prec);
|
||||
it = gmio_write_nspaces(it, 2);
|
||||
it = gmio_write_stdio_format(it, float32_prec);
|
||||
*it = 0; /* Write terminating null byte */
|
||||
/* TODO: check the "format" string can contain the given precision */
|
||||
}
|
||||
|
||||
/* Write solid declaration */
|
||||
{
|
||||
buffer_iterator = gmio_write_string(buffer_iterator, "solid ");
|
||||
buffer_iterator = gmio_write_string_eol(buffer_iterator, solid_name);
|
||||
if (!gmio_transfer_flush_buffer(trsf, buffer_iterator - (char*)trsf->buffer))
|
||||
buff_it = gmio_write_string(buff_it, "solid ");
|
||||
buff_it = gmio_write_string_eol(buff_it, solid_name);
|
||||
if (!gmio_transfer_flush_buffer(trsf, buff_it - (char*)trsf->buffer))
|
||||
return GMIO_STREAM_ERROR;
|
||||
}
|
||||
|
||||
@ -164,37 +165,40 @@ int gmio_stla_write(const gmio_stl_mesh_t* mesh,
|
||||
ifacet < total_facet_count && gmio_no_error(error);
|
||||
ifacet += buffer_facet_count)
|
||||
{
|
||||
const uint32_t clamped_facet_count = GMIO_MIN(ifacet + buffer_facet_count,
|
||||
total_facet_count);
|
||||
const uint32_t clamped_facet_count =
|
||||
GMIO_MIN(ifacet + buffer_facet_count, total_facet_count);
|
||||
gmio_stl_triangle_t tri;
|
||||
uint32_t ibuffer_facet;
|
||||
|
||||
gmio_transfer_handle_progress(trsf, ifacet, total_facet_count);
|
||||
|
||||
/* Writing of facets is buffered */
|
||||
buffer_iterator = trsf->buffer;
|
||||
for (ibuffer_facet = ifacet; ibuffer_facet < clamped_facet_count; ++ibuffer_facet) {
|
||||
buff_it = trsf->buffer;
|
||||
for (ibuffer_facet = ifacet;
|
||||
ibuffer_facet < clamped_facet_count;
|
||||
++ibuffer_facet)
|
||||
{
|
||||
mesh->get_triangle_func(mesh->cookie, ibuffer_facet, &tri);
|
||||
buffer_iterator = gmio_write_string(buffer_iterator, "facet normal ");
|
||||
buffer_iterator = gmio_write_coords(buffer_iterator, coords_format, &tri.normal);
|
||||
buffer_iterator = gmio_write_eol(buffer_iterator);
|
||||
buff_it = gmio_write_string(buff_it, "facet normal ");
|
||||
buff_it = gmio_write_coords(buff_it, coords_format, &tri.normal);
|
||||
buff_it = gmio_write_eol(buff_it);
|
||||
|
||||
buffer_iterator = gmio_write_string_eol(buffer_iterator, " outer loop");
|
||||
buffer_iterator = gmio_write_string(buffer_iterator, " vertex ");
|
||||
buffer_iterator = gmio_write_coords(buffer_iterator, coords_format, &tri.v1);
|
||||
buffer_iterator = gmio_write_eol(buffer_iterator);
|
||||
buffer_iterator = gmio_write_string(buffer_iterator, " vertex ");
|
||||
buffer_iterator = gmio_write_coords(buffer_iterator, coords_format, &tri.v2);
|
||||
buffer_iterator = gmio_write_eol(buffer_iterator);
|
||||
buffer_iterator = gmio_write_string(buffer_iterator, " vertex ");
|
||||
buffer_iterator = gmio_write_coords(buffer_iterator, coords_format, &tri.v3);
|
||||
buffer_iterator = gmio_write_eol(buffer_iterator);
|
||||
buffer_iterator = gmio_write_string_eol(buffer_iterator, " endloop");
|
||||
buff_it = gmio_write_string_eol(buff_it, " outer loop");
|
||||
buff_it = gmio_write_string(buff_it, " vertex ");
|
||||
buff_it = gmio_write_coords(buff_it, coords_format, &tri.v1);
|
||||
buff_it = gmio_write_eol(buff_it);
|
||||
buff_it = gmio_write_string(buff_it, " vertex ");
|
||||
buff_it = gmio_write_coords(buff_it, coords_format, &tri.v2);
|
||||
buff_it = gmio_write_eol(buff_it);
|
||||
buff_it = gmio_write_string(buff_it, " vertex ");
|
||||
buff_it = gmio_write_coords(buff_it, coords_format, &tri.v3);
|
||||
buff_it = gmio_write_eol(buff_it);
|
||||
buff_it = gmio_write_string_eol(buff_it, " endloop");
|
||||
|
||||
buffer_iterator = gmio_write_string_eol(buffer_iterator, "endfacet");
|
||||
buff_it = gmio_write_string_eol(buff_it, "endfacet");
|
||||
} /* end for (ibuffer_facet) */
|
||||
|
||||
if (!gmio_transfer_flush_buffer(trsf, buffer_iterator - (char*)trsf->buffer))
|
||||
if (!gmio_transfer_flush_buffer(trsf, buff_it - (char*)trsf->buffer))
|
||||
error = GMIO_STREAM_ERROR;
|
||||
|
||||
/* Task control */
|
||||
@ -204,9 +208,9 @@ int gmio_stla_write(const gmio_stl_mesh_t* mesh,
|
||||
|
||||
/* Write end of solid */
|
||||
if (gmio_no_error(error)) {
|
||||
buffer_iterator = gmio_write_string(trsf->buffer, "endsolid ");
|
||||
buffer_iterator = gmio_write_string_eol(buffer_iterator, solid_name);
|
||||
if (!gmio_transfer_flush_buffer(trsf, buffer_iterator - (char*)trsf->buffer))
|
||||
buff_it = gmio_write_string(trsf->buffer, "endsolid ");
|
||||
buff_it = gmio_write_string_eol(buff_it, solid_name);
|
||||
if (!gmio_transfer_flush_buffer(trsf, buff_it - (char*)trsf->buffer))
|
||||
error = GMIO_STREAM_ERROR;
|
||||
}
|
||||
|
||||
|
@ -31,16 +31,17 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
GMIO_INLINE static void read_triangle_memcpy(const uint8_t* buffer,
|
||||
gmio_stl_triangle_t* triangle)
|
||||
GMIO_INLINE static void read_triangle_memcpy(
|
||||
const uint8_t* buffer, gmio_stl_triangle_t* triangle)
|
||||
{
|
||||
/* *triangle = *((gmio_stl_triangle_t*)(buffer)); */
|
||||
memcpy(triangle, buffer, GMIO_STLB_TRIANGLE_RAWSIZE);
|
||||
}
|
||||
|
||||
static void gmio_stlb_read_facets(gmio_stl_mesh_creator_t* creator,
|
||||
const uint8_t* buffer,
|
||||
const gmio_stlb_readwrite_helper_t* rparams)
|
||||
static void gmio_stlb_read_facets(
|
||||
gmio_stl_mesh_creator_t* creator,
|
||||
const uint8_t* buffer,
|
||||
const gmio_stlb_readwrite_helper_t* rparams)
|
||||
{
|
||||
const uint32_t facet_count = rparams->facet_count;
|
||||
const uint32_t i_facet_offset = rparams->i_facet_offset;
|
||||
@ -60,15 +61,19 @@ static void gmio_stlb_read_facets(gmio_stl_mesh_creator_t* creator,
|
||||
rparams->fix_endian_func(&triangle);
|
||||
|
||||
/* Declare triangle */
|
||||
creator->add_triangle_func(creator->cookie, i_facet_offset + i_facet, &triangle);
|
||||
creator->add_triangle_func(
|
||||
creator->cookie, i_facet_offset + i_facet, &triangle);
|
||||
}
|
||||
}
|
||||
|
||||
int gmio_stlb_read(gmio_stl_mesh_creator_t *creator,
|
||||
gmio_transfer_t* trsf,
|
||||
const gmio_stlb_read_options_t* options)
|
||||
int gmio_stlb_read(
|
||||
gmio_stl_mesh_creator_t *creator,
|
||||
gmio_transfer_t* trsf,
|
||||
const gmio_stlb_read_options_t* options)
|
||||
{
|
||||
const gmio_endianness_t host_byte_order = gmio_host_endianness();
|
||||
/* Constants */
|
||||
const gmio_endianness_t host_byte_order =
|
||||
gmio_host_endianness();
|
||||
const gmio_endianness_t byte_order =
|
||||
options != NULL ? options->byte_order : host_byte_order;
|
||||
const uint32_t max_facet_count_per_read =
|
||||
@ -76,10 +81,11 @@ int gmio_stlb_read(gmio_stl_mesh_creator_t *creator,
|
||||
gmio_size_to_uint32(
|
||||
trsf->buffer_size / GMIO_STLB_TRIANGLE_RAWSIZE)
|
||||
: 0;
|
||||
/* Variables */
|
||||
gmio_stlb_readwrite_helper_t rparams = {0};
|
||||
uint8_t header_data[GMIO_STLB_HEADER_SIZE];
|
||||
uint32_t total_facet_count = 0; /* Count of facets as declared in the stream */
|
||||
int error = GMIO_NO_ERROR; /* Helper variable to store function result error code */
|
||||
uint8_t header_data[GMIO_STLB_HEADER_SIZE];
|
||||
uint32_t total_facet_count = 0; /* Facet count, as declared in the stream */
|
||||
int error = GMIO_NO_ERROR; /* Helper to store function result error code */
|
||||
|
||||
/* Check validity of input parameters */
|
||||
if (!gmio_stlb_check_params(&error, trsf, byte_order))
|
||||
@ -105,8 +111,10 @@ int gmio_stlb_read(gmio_stl_mesh_creator_t *creator,
|
||||
total_facet_count = gmio_uint32_bswap(total_facet_count);
|
||||
|
||||
/* Callback to notify triangle count and header data */
|
||||
if (creator != NULL && creator->binary_begin_solid_func != NULL)
|
||||
creator->binary_begin_solid_func(creator->cookie, total_facet_count, header_data);
|
||||
if (creator != NULL && creator->binary_begin_solid_func != NULL) {
|
||||
creator->binary_begin_solid_func(
|
||||
creator->cookie, total_facet_count, header_data);
|
||||
}
|
||||
|
||||
/* Read triangles */
|
||||
while (gmio_no_error(error)
|
||||
|
@ -31,15 +31,16 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
GMIO_INLINE static void write_triangle_memcpy(const gmio_stl_triangle_t* triangle,
|
||||
uint8_t* buffer)
|
||||
GMIO_INLINE static void write_triangle_memcpy(
|
||||
const gmio_stl_triangle_t* triangle, uint8_t* buffer)
|
||||
{
|
||||
memcpy(buffer, triangle, GMIO_STLB_TRIANGLE_RAWSIZE);
|
||||
}
|
||||
|
||||
static void gmio_stlb_write_facets(const gmio_stl_mesh_t* mesh,
|
||||
uint8_t* buffer,
|
||||
const gmio_stlb_readwrite_helper_t* wparams)
|
||||
static void gmio_stlb_write_facets(
|
||||
const gmio_stl_mesh_t* mesh,
|
||||
uint8_t* buffer,
|
||||
const gmio_stlb_readwrite_helper_t* wparams)
|
||||
{
|
||||
const uint32_t facet_count = wparams->facet_count;
|
||||
const uint32_t i_facet_offset = wparams->i_facet_offset;
|
||||
@ -51,7 +52,10 @@ static void gmio_stlb_write_facets(const gmio_stl_mesh_t* mesh,
|
||||
return;
|
||||
|
||||
triangle.attribute_byte_count = 0;
|
||||
for (i_facet = i_facet_offset; i_facet < (i_facet_offset + facet_count); ++i_facet) {
|
||||
for (i_facet = i_facet_offset;
|
||||
i_facet < (i_facet_offset + facet_count);
|
||||
++i_facet)
|
||||
{
|
||||
mesh->get_triangle_func(mesh->cookie, i_facet, &triangle);
|
||||
|
||||
if (wparams->fix_endian_func != NULL)
|
||||
@ -63,15 +67,22 @@ static void gmio_stlb_write_facets(const gmio_stl_mesh_t* mesh,
|
||||
} /* end for */
|
||||
}
|
||||
|
||||
int gmio_stlb_write(const gmio_stl_mesh_t* mesh,
|
||||
gmio_transfer_t* trsf,
|
||||
const gmio_stlb_write_options_t* options)
|
||||
int gmio_stlb_write(
|
||||
const gmio_stl_mesh_t* mesh,
|
||||
gmio_transfer_t* trsf,
|
||||
const gmio_stlb_write_options_t* options)
|
||||
{
|
||||
const gmio_endianness_t host_byte_order = gmio_host_endianness();
|
||||
const gmio_endianness_t byte_order = options != NULL ? options->byte_order : host_byte_order;
|
||||
const uint8_t* header_data = options != NULL ? options->header_data : NULL;
|
||||
/* Constants */
|
||||
const gmio_endianness_t host_byte_order =
|
||||
gmio_host_endianness();
|
||||
const gmio_endianness_t byte_order =
|
||||
options != NULL ? options->byte_order : host_byte_order;
|
||||
const uint8_t* header_data =
|
||||
options != NULL ? options->header_data : NULL;
|
||||
const uint32_t facet_count =
|
||||
mesh != NULL ? mesh->triangle_count : 0;
|
||||
/* Variables */
|
||||
gmio_stlb_readwrite_helper_t wparams = {0};
|
||||
const uint32_t facet_count = mesh != NULL ? mesh->triangle_count : 0;
|
||||
uint32_t i_facet = 0;
|
||||
int error = GMIO_NO_ERROR;
|
||||
|
||||
@ -84,7 +95,8 @@ int gmio_stlb_write(const gmio_stl_mesh_t* mesh,
|
||||
/* Initialize wparams */
|
||||
if (host_byte_order != byte_order)
|
||||
wparams.fix_endian_func = gmio_stl_triangle_bswap;
|
||||
wparams.facet_count = gmio_size_to_uint32(trsf->buffer_size / GMIO_STLB_TRIANGLE_RAWSIZE);
|
||||
wparams.facet_count = gmio_size_to_uint32(
|
||||
trsf->buffer_size / GMIO_STLB_TRIANGLE_RAWSIZE);
|
||||
|
||||
/* Write header */
|
||||
if (header_data == NULL) {
|
||||
@ -92,8 +104,11 @@ int gmio_stlb_write(const gmio_stl_mesh_t* mesh,
|
||||
memset(trsf->buffer, 0, GMIO_STLB_HEADER_SIZE);
|
||||
header_data = (const uint8_t*)trsf->buffer;
|
||||
}
|
||||
if (gmio_stream_write(&trsf->stream, header_data, GMIO_STLB_HEADER_SIZE, 1) != 1)
|
||||
if (gmio_stream_write(&trsf->stream, header_data, GMIO_STLB_HEADER_SIZE, 1)
|
||||
!= 1)
|
||||
{
|
||||
return GMIO_STREAM_ERROR;
|
||||
}
|
||||
|
||||
/* Write facet count */
|
||||
if (byte_order == GMIO_LITTLE_ENDIAN)
|
||||
|
@ -27,68 +27,69 @@ namespace internal {
|
||||
|
||||
static StlMesh_Mesh* occMeshPtr(const Handle_StlMesh_Mesh& mesh)
|
||||
{
|
||||
return mesh.operator->();
|
||||
return mesh.operator->();
|
||||
}
|
||||
|
||||
static void occmesh_add_triangle(void* cookie,
|
||||
uint32_t tri_id,
|
||||
const gmio_stl_triangle_t* tri)
|
||||
{
|
||||
StlMesh_Mesh* mesh = static_cast<StlMesh_Mesh*>(cookie);
|
||||
if (tri_id == 0)
|
||||
mesh->AddDomain();
|
||||
mesh->AddTriangle(mesh->AddOnlyNewVertex(tri->v1.x, tri->v1.y, tri->v1.z),
|
||||
mesh->AddOnlyNewVertex(tri->v2.x, tri->v2.y, tri->v2.z),
|
||||
mesh->AddOnlyNewVertex(tri->v3.x, tri->v3.y, tri->v3.z),
|
||||
tri->normal.x, tri->normal.y, tri->normal.z);
|
||||
StlMesh_Mesh* mesh = static_cast<StlMesh_Mesh*>(cookie);
|
||||
if (tri_id == 0)
|
||||
mesh->AddDomain();
|
||||
mesh->AddTriangle(mesh->AddOnlyNewVertex(tri->v1.x, tri->v1.y, tri->v1.z),
|
||||
mesh->AddOnlyNewVertex(tri->v2.x, tri->v2.y, tri->v2.z),
|
||||
mesh->AddOnlyNewVertex(tri->v3.x, tri->v3.y, tri->v3.z),
|
||||
tri->normal.x, tri->normal.y, tri->normal.z);
|
||||
}
|
||||
|
||||
static void occmesh_get_triangle(const void* cookie,
|
||||
uint32_t tri_id,
|
||||
gmio_stl_triangle_t* triangle)
|
||||
static void occmesh_get_triangle(
|
||||
const void* cookie, uint32_t tri_id, gmio_stl_triangle_t* triangle)
|
||||
{
|
||||
const gmio_OccStlMeshDomain* meshCookie =
|
||||
static_cast<const gmio_OccStlMeshDomain*>(cookie);
|
||||
const StlMesh_SequenceOfMeshTriangle& occTriangles =
|
||||
meshCookie->mesh()->Triangles(meshCookie->domainId());
|
||||
const Handle_StlMesh_MeshTriangle& occTri =
|
||||
occTriangles.Value(tri_id + 1);
|
||||
Standard_Integer v1;
|
||||
Standard_Integer v2;
|
||||
Standard_Integer v3;
|
||||
Standard_Real xN;
|
||||
Standard_Real yN;
|
||||
Standard_Real zN;
|
||||
occTri->GetVertexAndOrientation(v1, v2, v3, xN, yN, zN);
|
||||
triangle->normal.x = float(xN);
|
||||
triangle->normal.y = float(yN);
|
||||
triangle->normal.z = float(zN);
|
||||
const gmio_OccStlMeshDomain* meshCookie =
|
||||
static_cast<const gmio_OccStlMeshDomain*>(cookie);
|
||||
const StlMesh_SequenceOfMeshTriangle& occTriangles =
|
||||
meshCookie->mesh()->Triangles(meshCookie->domainId());
|
||||
const Handle_StlMesh_MeshTriangle& occTri =
|
||||
occTriangles.Value(tri_id + 1);
|
||||
Standard_Integer v1;
|
||||
Standard_Integer v2;
|
||||
Standard_Integer v3;
|
||||
Standard_Real xN;
|
||||
Standard_Real yN;
|
||||
Standard_Real zN;
|
||||
occTri->GetVertexAndOrientation(v1, v2, v3, xN, yN, zN);
|
||||
triangle->normal.x = float(xN);
|
||||
triangle->normal.y = float(yN);
|
||||
triangle->normal.z = float(zN);
|
||||
|
||||
const TColgp_SequenceOfXYZ& vertices = meshCookie->mesh()->Vertices(meshCookie->domainId());
|
||||
const gp_XYZ& coordsV1 = vertices.Value(v1);
|
||||
const gp_XYZ& coordsV2 = vertices.Value(v2);
|
||||
const gp_XYZ& coordsV3 = vertices.Value(v3);
|
||||
triangle->v1.x = float(coordsV1.X());
|
||||
triangle->v2.x = float(coordsV2.X());
|
||||
triangle->v3.x = float(coordsV3.X());
|
||||
const TColgp_SequenceOfXYZ& vertices =
|
||||
meshCookie->mesh()->Vertices(meshCookie->domainId());
|
||||
const gp_XYZ& coordsV1 = vertices.Value(v1);
|
||||
const gp_XYZ& coordsV2 = vertices.Value(v2);
|
||||
const gp_XYZ& coordsV3 = vertices.Value(v3);
|
||||
triangle->v1.x = float(coordsV1.X());
|
||||
triangle->v2.x = float(coordsV2.X());
|
||||
triangle->v3.x = float(coordsV3.X());
|
||||
|
||||
triangle->v1.y = float(coordsV1.Y());
|
||||
triangle->v2.y = float(coordsV2.Y());
|
||||
triangle->v3.y = float(coordsV3.Y());
|
||||
triangle->v1.y = float(coordsV1.Y());
|
||||
triangle->v2.y = float(coordsV2.Y());
|
||||
triangle->v3.y = float(coordsV3.Y());
|
||||
|
||||
triangle->v1.z = float(coordsV1.Z());
|
||||
triangle->v2.z = float(coordsV2.Z());
|
||||
triangle->v3.z = float(coordsV3.Z());
|
||||
triangle->v1.z = float(coordsV1.Z());
|
||||
triangle->v2.z = float(coordsV2.Z());
|
||||
triangle->v3.z = float(coordsV3.Z());
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
void gmio_stl_set_occmesh(gmio_stl_mesh_t *mesh, const gmio_OccStlMeshDomain &meshCookie)
|
||||
void gmio_stl_set_occmesh(
|
||||
gmio_stl_mesh_t *mesh, const gmio_OccStlMeshDomain &meshCookie)
|
||||
{
|
||||
std::memset(mesh, 0, sizeof(gmio_stl_mesh_t));
|
||||
mesh->cookie = &meshCookie;
|
||||
mesh->triangle_count = meshCookie.mesh()->NbTriangles(meshCookie.domainId());
|
||||
mesh->get_triangle_func = internal::occmesh_get_triangle;
|
||||
std::memset(mesh, 0, sizeof(gmio_stl_mesh_t));
|
||||
mesh->cookie = &meshCookie;
|
||||
mesh->triangle_count = meshCookie.mesh()->NbTriangles(meshCookie.domainId());
|
||||
mesh->get_triangle_func = internal::occmesh_get_triangle;
|
||||
}
|
||||
|
||||
gmio_stl_mesh gmio_stl_occmesh(const gmio_OccStlMeshDomain &meshCookie)
|
||||
@ -98,11 +99,12 @@ gmio_stl_mesh gmio_stl_occmesh(const gmio_OccStlMeshDomain &meshCookie)
|
||||
return occmesh;
|
||||
}
|
||||
|
||||
void gmio_stl_set_occmesh_creator(gmio_stl_mesh_creator_t *creator, const Handle_StlMesh_Mesh &mesh)
|
||||
void gmio_stl_set_occmesh_creator(
|
||||
gmio_stl_mesh_creator_t *creator, const Handle_StlMesh_Mesh &mesh)
|
||||
{
|
||||
std::memset(creator, 0, sizeof(gmio_stl_mesh_creator_t));
|
||||
creator->cookie = internal::occMeshPtr(mesh);
|
||||
creator->add_triangle_func = internal::occmesh_add_triangle;
|
||||
std::memset(creator, 0, sizeof(gmio_stl_mesh_creator_t));
|
||||
creator->cookie = internal::occMeshPtr(mesh);
|
||||
creator->add_triangle_func = internal::occmesh_add_triangle;
|
||||
}
|
||||
|
||||
gmio_stl_mesh_creator gmio_stl_occmesh_creator(const Handle_StlMesh_Mesh &mesh)
|
||||
@ -112,28 +114,29 @@ gmio_stl_mesh_creator gmio_stl_occmesh_creator(const Handle_StlMesh_Mesh &mesh)
|
||||
return occ_creator;
|
||||
}
|
||||
|
||||
gmio_OccStlMeshDomain::gmio_OccStlMeshDomain(const Handle_StlMesh_Mesh &stlMesh, int domId)
|
||||
: m_mesh(stlMesh),
|
||||
m_domainId(domId)
|
||||
gmio_OccStlMeshDomain::gmio_OccStlMeshDomain(
|
||||
const Handle_StlMesh_Mesh &stlMesh, int domId)
|
||||
: m_mesh(stlMesh),
|
||||
m_domainId(domId)
|
||||
{
|
||||
}
|
||||
|
||||
const Handle_StlMesh_Mesh &gmio_OccStlMeshDomain::mesh() const
|
||||
{
|
||||
return m_mesh;
|
||||
return m_mesh;
|
||||
}
|
||||
|
||||
void gmio_OccStlMeshDomain::setMesh(const Handle_StlMesh_Mesh &stlMesh)
|
||||
{
|
||||
m_mesh = stlMesh;
|
||||
m_mesh = stlMesh;
|
||||
}
|
||||
|
||||
int gmio_OccStlMeshDomain::domainId() const
|
||||
{
|
||||
return m_domainId;
|
||||
return m_domainId;
|
||||
}
|
||||
|
||||
void gmio_OccStlMeshDomain::setDomainId(int domId)
|
||||
{
|
||||
m_domainId = domId;
|
||||
m_domainId = domId;
|
||||
}
|
||||
|
@ -35,17 +35,17 @@ struct gmio_stl_mesh_creator;
|
||||
class GMIO_LIBSUPPORT_EXPORT gmio_OccStlMeshDomain
|
||||
{
|
||||
public:
|
||||
gmio_OccStlMeshDomain(const Handle_StlMesh_Mesh& stlMesh, int domId = 1);
|
||||
gmio_OccStlMeshDomain(const Handle_StlMesh_Mesh& stlMesh, int domId = 1);
|
||||
|
||||
const Handle_StlMesh_Mesh& mesh() const;
|
||||
void setMesh(const Handle_StlMesh_Mesh& stlMesh);
|
||||
const Handle_StlMesh_Mesh& mesh() const;
|
||||
void setMesh(const Handle_StlMesh_Mesh& stlMesh);
|
||||
|
||||
int domainId() const;
|
||||
void setDomainId(int domId);
|
||||
int domainId() const;
|
||||
void setDomainId(int domId);
|
||||
|
||||
private:
|
||||
Handle_StlMesh_Mesh m_mesh;
|
||||
int m_domainId;
|
||||
Handle_StlMesh_Mesh m_mesh;
|
||||
int m_domainId;
|
||||
};
|
||||
|
||||
/*! Initializes \p mesh so it maps to a domain in StlMesh_Mesh
|
||||
|
@ -22,50 +22,47 @@ QT_USE_NAMESPACE
|
||||
|
||||
static gmio_bool_t gmio_stream_qiodevice_at_end(void* cookie)
|
||||
{
|
||||
return static_cast<QIODevice*>(cookie)->atEnd();
|
||||
return static_cast<QIODevice*>(cookie)->atEnd();
|
||||
}
|
||||
|
||||
static int gmio_stream_qiodevice_error(void* cookie)
|
||||
{
|
||||
const QIODevice* device = static_cast<QIODevice*>(cookie);
|
||||
const QFile* file = dynamic_cast<const QFile*>(device);
|
||||
if (file != NULL) {
|
||||
return file->error();
|
||||
}
|
||||
else {
|
||||
const QString err_str = static_cast<QIODevice*>(cookie)->errorString();
|
||||
return !err_str.isEmpty() ? 1 : 0;
|
||||
}
|
||||
return 0;
|
||||
const QIODevice* device = static_cast<QIODevice*>(cookie);
|
||||
const QFile* file = dynamic_cast<const QFile*>(device);
|
||||
if (file != NULL) {
|
||||
return file->error();
|
||||
}
|
||||
else {
|
||||
const QString err_str = static_cast<QIODevice*>(cookie)->errorString();
|
||||
return !err_str.isEmpty() ? 1 : 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static size_t gmio_stream_qiodevice_read(void* cookie,
|
||||
void* ptr,
|
||||
size_t item_size,
|
||||
size_t item_count)
|
||||
static size_t gmio_stream_qiodevice_read(
|
||||
void* cookie, void* ptr, size_t item_size, size_t item_count)
|
||||
{
|
||||
QIODevice* device = static_cast<QIODevice*>(cookie);
|
||||
const qint64 c = device->read(static_cast<char*>(ptr), item_size * item_count);
|
||||
return c / item_size;
|
||||
QIODevice* device = static_cast<QIODevice*>(cookie);
|
||||
const qint64 c = device->read(static_cast<char*>(ptr), item_size * item_count);
|
||||
return c / item_size;
|
||||
}
|
||||
|
||||
static size_t gmio_stream_qiodevice_write(void* cookie,
|
||||
const void* ptr,
|
||||
size_t item_size,
|
||||
size_t item_count)
|
||||
static size_t gmio_stream_qiodevice_write(
|
||||
void* cookie, const void* ptr, size_t item_size, size_t item_count)
|
||||
{
|
||||
QIODevice* device = static_cast<QIODevice*>(cookie);
|
||||
const qint64 c = device->write(static_cast<const char*>(ptr), item_size * item_count);
|
||||
return c / item_size;
|
||||
QIODevice* device = static_cast<QIODevice*>(cookie);
|
||||
const qint64 c = device->write(
|
||||
static_cast<const char*>(ptr), item_size * item_count);
|
||||
return c / item_size;
|
||||
}
|
||||
|
||||
void gmio_stream_set_qiodevice(gmio_stream_t* stream, QIODevice* device)
|
||||
{
|
||||
stream->cookie = device;
|
||||
stream->at_end_func = gmio_stream_qiodevice_at_end;
|
||||
stream->error_func = gmio_stream_qiodevice_error;
|
||||
stream->read_func = gmio_stream_qiodevice_read;
|
||||
stream->write_func = gmio_stream_qiodevice_write;
|
||||
stream->cookie = device;
|
||||
stream->at_end_func = gmio_stream_qiodevice_at_end;
|
||||
stream->error_func = gmio_stream_qiodevice_error;
|
||||
stream->read_func = gmio_stream_qiodevice_read;
|
||||
stream->write_func = gmio_stream_qiodevice_write;
|
||||
}
|
||||
|
||||
gmio_stream_t gmio_stream_qiodevice(QIODevice* device)
|
||||
|
@ -19,13 +19,13 @@
|
||||
#include "../gmio_core/global.h"
|
||||
|
||||
#ifdef GMIO_LIBSUPPORT_DLL
|
||||
# ifdef GMIO_LIBSUPPORT_MAKE_DLL
|
||||
# define GMIO_LIBSUPPORT_EXPORT GMIO_DECL_EXPORT
|
||||
# else
|
||||
# define GMIO_LIBSUPPORT_EXPORT GMIO_DECL_IMPORT
|
||||
# endif /* GMIO_LIBSUPPORT_MAKE_DLL */
|
||||
# ifdef GMIO_LIBSUPPORT_MAKE_DLL
|
||||
# define GMIO_LIBSUPPORT_EXPORT GMIO_DECL_EXPORT
|
||||
# else
|
||||
# define GMIO_LIBSUPPORT_EXPORT GMIO_DECL_IMPORT
|
||||
# endif /* GMIO_LIBSUPPORT_MAKE_DLL */
|
||||
#else
|
||||
# define GMIO_LIBSUPPORT_EXPORT
|
||||
# define GMIO_LIBSUPPORT_EXPORT
|
||||
#endif /* GMIO_LIBSUPPORT_DLL */
|
||||
|
||||
#endif /* GMIO_C_SUPPORT_GLOBAL_H */
|
||||
|
Loading…
Reference in New Issue
Block a user