38 # error C++ compiler required
44 #include "../gmio_core/stream.h"
49 template<
typename CHAR,
typename TRAITS>
53 template<
typename CHAR,
typename TRAITS>
67 template<
typename STREAM>
68 bool stream_cpp_at_end(
void* cookie)
70 STREAM* s =
static_cast<STREAM*
>(cookie);
74 template<
typename STREAM>
75 int stream_cpp_error(
void* cookie)
77 STREAM* s =
static_cast<STREAM*
>(cookie);
81 template<
typename STREAM>
82 size_t istream_cpp_read(
83 void* cookie,
void* ptr,
size_t item_size,
size_t item_count)
85 STREAM* s =
static_cast<STREAM*
>(cookie);
86 s->read(static_cast<char*>(ptr), item_size * item_count);
87 return static_cast<size_t>(s->gcount() / item_size);
90 template<
typename STREAM>
91 size_t ostream_cpp_write(
92 void* cookie,
const void* ptr,
size_t item_size,
size_t item_count)
94 STREAM* s =
static_cast<STREAM*
>(cookie);
95 s->write(static_cast<const char*>(ptr), item_size * item_count);
97 return item_size * item_count;
100 template<
typename STREAM>
103 STREAM* s =
static_cast<STREAM*
>(cookie);
104 std::streampos pos = s->tellg();
105 s->seekg(0, std::ios_base::beg);
106 std::streampos begin_pos = s->tellg();
107 s->seekg(0, std::ios_base::end);
108 std::streampos end_pos = s->tellg();
109 s->seekg(pos, std::ios_base::beg);
110 return end_pos - begin_pos;
113 template<
typename STREAM>
116 STREAM* s =
static_cast<STREAM*
>(cookie);
117 std::streampos pos = s->tellp();
118 s->seekp(0, std::ios_base::beg);
119 std::streampos begin_pos = s->tellp();
120 s->seekp(0, std::ios_base::end);
121 std::streampos end_pos = s->tellp();
122 s->seekp(pos, std::ios_base::beg);
123 return end_pos - begin_pos;
128 std::memcpy(&pos->
cookie[0], &spos,
sizeof(std::streampos));
134 std::memcpy(&spos, &pos->
cookie[0],
sizeof(std::streampos));
138 template<
typename STREAM>
141 copy_cpp_streampos(pos, static_cast<STREAM*>(cookie)->tellg());
145 template<
typename STREAM>
148 static_cast<STREAM*
>(cookie)->seekg(to_cpp_streampos(pos));
152 template<
typename STREAM>
155 copy_cpp_streampos(pos, static_cast<STREAM*>(cookie)->tellp());
159 template<
typename STREAM>
160 static int ostream_cpp_set_pos(
void* cookie,
const gmio_streampos* pos)
162 static_cast<STREAM*
>(cookie)->seekp(to_cpp_streampos(pos));
166 template<
typename STREAM>
167 void stream_cpp_init_common(STREAM* s,
gmio_stream* stream)
171 stream->
func_at_end = gmio::internal::stream_cpp_at_end<STREAM>;
172 stream->
func_error = gmio::internal::stream_cpp_error<STREAM>;
178 template<
typename CHAR,
typename TRAITS>
181 typedef std::basic_istream<CHAR, TRAITS> CppStream;
183 gmio::internal::stream_cpp_init_common(s, &stream);
184 stream.
func_size = gmio::internal::istream_cpp_size<CppStream>;
185 stream.
func_read = gmio::internal::istream_cpp_read<CppStream>;
186 stream.
func_get_pos = gmio::internal::istream_cpp_get_pos<CppStream>;
187 stream.
func_set_pos = gmio::internal::istream_cpp_set_pos<CppStream>;
191 template<
typename CHAR,
typename TRAITS>
194 typedef std::basic_ostream<CHAR, TRAITS> CppStream;
196 gmio::internal::stream_cpp_init_common(s, &stream);
197 stream.
func_size = gmio::internal::ostream_cpp_size<CppStream>;
198 stream.
func_write = gmio::internal::ostream_cpp_write<CppStream>;
199 stream.
func_get_pos = gmio::internal::ostream_cpp_get_pos<CppStream>;
200 stream.
func_set_pos = gmio::internal::ostream_cpp_set_pos<CppStream>;
gmio_stream gmio_istream_cpp(std::basic_istream< CHAR, TRAITS > *s)
Returns a gmio_stream for C++ input stream (cookie will hold s )
#define GMIO_INLINE
Expands to the C compiler specific inline keyword (if any)
Definition: global.h:178
int(* func_get_pos)(void *cookie, struct gmio_streampos *pos)
Function that retrieves the current position in the stream.
Definition: stream.h:138
bool(* func_at_end)(void *cookie)
Function that checks end-of-stream indicator.
Definition: stream.h:92
size_t(* func_write)(void *cookie, const void *ptr, size_t size, size_t count)
Function that writes block of data to stream.
Definition: stream.h:128
gmio_stream gmio_ostream_cpp(std::basic_ostream< CHAR, TRAITS > *s)
Returns a gmio_stream for C++ output stream (cookie will hold s )
int(* func_set_pos)(void *cookie, const struct gmio_streampos *pos)
Function that restores the current position in the stream to pos.
Definition: stream.h:146
size_t(* func_read)(void *cookie, void *ptr, size_t size, size_t count)
Function that reads block of data from stream.
Definition: stream.h:115
Specifies a position within a stream.
Definition: streampos.h:54
int64_or_long gmio_streamsize_t
Type able to represent the size(in bytes) of a stream.
Definition: stream.h:57
uint8_t cookie[GMIO_STREAMPOS_COOKIE_SIZE]
Stores the actual(concrete) stream position object.
Definition: streampos.h:57
Stream that can get input from an arbitrary data source or can write output to an arbitrary data sink...
Definition: stream.h:78
Global declarations for the support module.
void * cookie
Opaque pointer on the user stream, passed as first argument to hook functions.
Definition: stream.h:82
int(* func_error)(void *cookie)
Function that checks error indicator.
Definition: stream.h:102
gmio_streamsize_t(* func_size)(void *cookie)
Function that returns the size(in bytes) of the stream.
Definition: stream.h:131
struct gmio_stream gmio_stream_null()
Returns a null stream.