Add some utility variant API functions

This commit is contained in:
Hugues Delorme 2015-03-19 16:34:53 +01:00
parent a0fa9bb206
commit e7757fcbda
6 changed files with 73 additions and 12 deletions

View File

@ -24,6 +24,12 @@ void gmio_stream_set_null(gmio_stream_t* stream)
memset(stream, 0, sizeof(gmio_stream_t)); memset(stream, 0, sizeof(gmio_stream_t));
} }
gmio_stream_t gmio_stream_null()
{
gmio_stream_t null_stream = { 0 };
return null_stream;
}
static gmio_bool_t gmio_stream_stdio_at_end(void* cookie) static gmio_bool_t gmio_stream_stdio_at_end(void* cookie)
{ {
return feof((FILE*) cookie); return feof((FILE*) cookie);
@ -54,3 +60,10 @@ void gmio_stream_set_stdio(gmio_stream_t* stream, FILE* file)
stream->read_func = gmio_stream_stdio_read; stream->read_func = gmio_stream_stdio_read;
stream->write_func = gmio_stream_stdio_write; stream->write_func = gmio_stream_stdio_write;
} }
gmio_stream_t gmio_stream_stdio(FILE* file)
{
gmio_stream_t stdio_stream = { 0 };
gmio_stream_set_stdio(&stdio_stream, file);
return stdio_stream;
}

View File

@ -98,9 +98,15 @@ GMIO_C_LINKAGE_BEGIN
/*! Installs a null stream */ /*! Installs a null stream */
GMIO_LIB_EXPORT void gmio_stream_set_null(gmio_stream_t* stream); GMIO_LIB_EXPORT void gmio_stream_set_null(gmio_stream_t* stream);
/*! Returns a null stream */
GMIO_LIB_EXPORT gmio_stream_t gmio_stream_null();
/*! Configures \p stream for standard FILE* (cookie will hold \p file) */ /*! Configures \p stream for standard FILE* (cookie will hold \p file) */
GMIO_LIB_EXPORT void gmio_stream_set_stdio(gmio_stream_t* stream, FILE* file); GMIO_LIB_EXPORT void gmio_stream_set_stdio(gmio_stream_t* stream, FILE* file);
/*! Returns a stream for standard FILE* (cookie will hold \p file) */
GMIO_LIB_EXPORT gmio_stream_t gmio_stream_stdio(FILE* file);
GMIO_C_LINKAGE_END GMIO_C_LINKAGE_END
#endif /* GMIO_STREAM_H */ #endif /* GMIO_STREAM_H */

View File

@ -15,9 +15,6 @@
#include <gmio_support/occ_libstl.h> #include <gmio_support/occ_libstl.h>
#include <gmio_stl/stl_mesh.h>
#include <gmio_stl/stl_mesh_creator.h>
#include <cstring> #include <cstring>
#include <StlMesh_Mesh.hxx> #include <StlMesh_Mesh.hxx>
#include <StlMesh_MeshTriangle.hxx> #include <StlMesh_MeshTriangle.hxx>
@ -86,7 +83,7 @@ static void occmesh_get_triangle(const void* cookie,
} // namespace internal } // namespace internal
void gmio_stl_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)); std::memset(mesh, 0, sizeof(gmio_stl_mesh_t));
mesh->cookie = &meshCookie; mesh->cookie = &meshCookie;
@ -94,13 +91,27 @@ void gmio_stl_occmesh(gmio_stl_mesh_t *mesh, const gmio_OccStlMeshDomain &meshCo
mesh->get_triangle_func = internal::occmesh_get_triangle; mesh->get_triangle_func = internal::occmesh_get_triangle;
} }
void gmio_stl_occmesh_creator(gmio_stl_mesh_creator_t *creator, const Handle_StlMesh_Mesh &mesh) gmio_stl_mesh gmio_stl_occmesh(const gmio_OccStlMeshDomain &meshCookie)
{
gmio_stl_mesh occmesh = { 0 };
gmio_stl_set_occmesh(&occmesh, meshCookie);
return occmesh;
}
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)); std::memset(creator, 0, sizeof(gmio_stl_mesh_creator_t));
creator->cookie = internal::occMeshPtr(mesh); creator->cookie = internal::occMeshPtr(mesh);
creator->add_triangle_func = internal::occmesh_add_triangle; creator->add_triangle_func = internal::occmesh_add_triangle;
} }
gmio_stl_mesh_creator gmio_stl_occmesh_creator(const Handle_StlMesh_Mesh &mesh)
{
gmio_stl_mesh_creator occ_creator = { 0 };
gmio_stl_set_occmesh_creator(&occ_creator, mesh);
return occ_creator;
}
gmio_OccStlMeshDomain::gmio_OccStlMeshDomain(const Handle_StlMesh_Mesh &stlMesh, int domId) gmio_OccStlMeshDomain::gmio_OccStlMeshDomain(const Handle_StlMesh_Mesh &stlMesh, int domId)
: m_mesh(stlMesh), : m_mesh(stlMesh),
m_domainId(domId) m_domainId(domId)

View File

@ -21,6 +21,9 @@
#define GMIO_SUPPORT_OCC_LIBSTL_H #define GMIO_SUPPORT_OCC_LIBSTL_H
#include "support_global.h" #include "support_global.h"
#include "../gmio_stl/stl_mesh.h"
#include "../gmio_stl/stl_mesh_creator.h"
#include <Handle_StlMesh_Mesh.hxx> #include <Handle_StlMesh_Mesh.hxx>
struct gmio_stl_mesh; struct gmio_stl_mesh;
struct gmio_stl_mesh_creator; struct gmio_stl_mesh_creator;
@ -50,13 +53,32 @@ private:
* \c mesh->cookie will point to \p meshCookie * \c mesh->cookie will point to \p meshCookie
*/ */
GMIO_LIBSUPPORT_EXPORT GMIO_LIBSUPPORT_EXPORT
void gmio_stl_occmesh(gmio_stl_mesh* mesh, const gmio_OccStlMeshDomain& meshCookie); void gmio_stl_set_occmesh(
gmio_stl_mesh* mesh, const gmio_OccStlMeshDomain& meshCookie);
/*! Returns a gmio_stl_mesh mapped to domain in StlMesh_Mesh
*
* The mesh's cookie will point to \p meshCookie
*/
GMIO_LIBSUPPORT_EXPORT
gmio_stl_mesh gmio_stl_occmesh(const gmio_OccStlMeshDomain& meshCookie);
/*! Initializes \p creator to build a new domain in a StlMesh_Mesh object /*! Initializes \p creator to build a new domain in a StlMesh_Mesh object
* *
* \c creator->cookie will point to the internal data(ie. StlMesh_Mesh*) of handle \p mesh * \c creator->cookie will point to the internal data(ie StlMesh_Mesh*) of
* handle \p mesh
*/ */
GMIO_LIBSUPPORT_EXPORT GMIO_LIBSUPPORT_EXPORT
void gmio_stl_occmesh_creator(gmio_stl_mesh_creator* creator, const Handle_StlMesh_Mesh& mesh); void gmio_stl_set_occmesh_creator(
gmio_stl_mesh_creator* creator, const Handle_StlMesh_Mesh& mesh);
/*! Returns a gmio_stl_mesh_creator that will build a new domain in a
* StlMesh_Mesh object
*
* The creator's cookie will point to the internal data(ie StlMesh_Mesh*) of
* handle \p mesh
*/
GMIO_LIBSUPPORT_EXPORT
gmio_stl_mesh_creator gmio_stl_occmesh_creator(const Handle_StlMesh_Mesh& mesh);
#endif /* GMIO_SUPPORT_OCC_LIBSTL_H */ #endif /* GMIO_SUPPORT_OCC_LIBSTL_H */

View File

@ -15,8 +15,6 @@
#include <gmio_support/qt_stream.h> #include <gmio_support/qt_stream.h>
#include <gmio_core/stream.h>
#include <QtCore/QFile> #include <QtCore/QFile>
#include <QtCore/QIODevice> #include <QtCore/QIODevice>
@ -69,3 +67,10 @@ void gmio_stream_set_qiodevice(gmio_stream_t* stream, QIODevice* device)
stream->read_func = gmio_stream_qiodevice_read; stream->read_func = gmio_stream_qiodevice_read;
stream->write_func = gmio_stream_qiodevice_write; stream->write_func = gmio_stream_qiodevice_write;
} }
gmio_stream_t gmio_stream_qiodevice(QIODevice* device)
{
gmio_stream_t qtstream = { 0 };
gmio_stream_set_qiodevice(&qtstream, device);
return qtstream;
}

View File

@ -21,9 +21,9 @@
#define GMIO_SUPPORT_QT_STREAM_H #define GMIO_SUPPORT_QT_STREAM_H
#include "support_global.h" #include "support_global.h"
#include "../gmio_core/stream.h"
#include <QtCore/QtGlobal> #include <QtCore/QtGlobal>
struct gmio_stream;
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QIODevice; class QIODevice;
QT_END_NAMESPACE QT_END_NAMESPACE
@ -31,6 +31,10 @@ QT_END_NAMESPACE
/*! Configures \p stream for \c QIODevice* (cookie will hold \p device) */ /*! Configures \p stream for \c QIODevice* (cookie will hold \p device) */
GMIO_LIBSUPPORT_EXPORT GMIO_LIBSUPPORT_EXPORT
void gmio_stream_set_qiodevice( void gmio_stream_set_qiodevice(
struct gmio_stream* stream, QT_PREPEND_NAMESPACE(QIODevice)* device); gmio_stream_t* stream, QT_PREPEND_NAMESPACE(QIODevice)* device);
/*! Returns a gmio_stream for \c QIODevice* (cookie will hold \p device) */
GMIO_LIBSUPPORT_EXPORT
gmio_stream_t gmio_stream_qiodevice(QT_PREPEND_NAMESPACE(QIODevice)* device);
#endif /* GMIO_SUPPORT_QT_STREAM_H */ #endif /* GMIO_SUPPORT_QT_STREAM_H */