13 # include <vcl_msvc_warnings.h> 30 block.
ptr =
new char[block.
size];
32 catch (
const std::bad_alloc& )
50 std::cerr <<
"I/O ERROR: vsl_block_binary_read()\n";
52 std::cerr <<
" Data was saved using unspecialised slow form and is being loaded\n" 53 <<
" using specialised fast form.\n\n";
55 std::cerr <<
" Data was saved using specialised fast form and is being loaded\n" 56 <<
" using unspecialised slow form.\n\n";
58 is.
is().clear(std::ios::badbit);
71 const std::size_t wanted =
sizeof(T) * nelems;
75 const std::size_t items_per_block = block.
size /
sizeof(T);
80 std::size_t items = std::min(items_per_block, nelems);
81 std::size_t bytes =
sizeof(T) * items;
83 os.
os().write( block.
ptr, bytes);
98 is.
is().read((
char*) begin, nelems*
sizeof(T));
113 if (block.
size == wanted)
117 (
unsigned char *)block.
ptr, nelems);
119 os.
os().write( block.
ptr, nbytes);
125 std::size_t n=nelems;
127 assert (n > items_per_block);
129 std::size_t n_bytes=0;
132 std::size_t items = std::min(items_per_block, n);
134 (
unsigned char *)block.
ptr, items);
146 std::size_t items = std::min(items_per_block, n);
148 (
unsigned char *)block.
ptr, items );
149 os.
os().write( block.
ptr, bytes);
167 if (nbytes==0)
return;
172 std::size_t n_bytes_converted = 0;
173 if (block.
size == nbytes)
182 std::size_t offset=0;
183 std::size_t bytes_left = nbytes;
184 std::size_t bytes_read = 0;
187 assert (offset < block.
size);
190 std::size_t bytes = std::min((std::size_t)nbytes-bytes_read, block.
size-offset);
191 is.
is().read(block.
ptr+offset, bytes);
198 for (
unsigned char *p = (
unsigned char *)block.
ptr, *p_end=p+bytes+offset; p!=p_end; ++p)
203 std::cerr <<
"\nI/O ERROR: vsl_block_binary_read(.., int*,..)" 204 <<
" Corrupted data stream\n";
205 is.
is().clear(std::ios::badbit);
210 std::size_t bytes_converted =
215 offset = (bytes + offset) - bytes_converted;
216 n_bytes_converted += bytes_converted;
217 bytes_left -= bytes_converted;
220 std::memcpy(block.
ptr, block.
ptr + bytes_converted, offset);
222 if (bytes_left != 0 || nelems != 0 || bytes_read != nbytes)
224 std::cerr <<
"\nI/O ERROR: vsl_block_binary_read(.., int*,..)" 225 <<
" Corrupted data stream\n";
226 is.
is().clear(std::ios::badbit);
229 if (n_bytes_converted != nbytes)
231 std::cerr <<
"\nI/O ERROR: vsl_block_binary_read(.., int*,..)" 232 <<
" Corrupted data stream\n";
233 is.
is().clear(std::ios::badbit);
245 os.
os().write((
char*) begin, nelems);
256 is.
is().read((
char*) begin, nelems);
288 #if VXL_HAS_INT_64 && !VXL_INT_64_IS_LONG 293 #endif //VXL_HAS_INT_64 && !VXL_INT_64_IS_LONG void vsl_block_binary_write_byte_impl(vsl_b_ostream &os, const T *begin, std::size_t nelems)
Write a block of bytes to a vsl_b_ostream.
A binary output adaptor for any std::ostream.
Set of functions to do binary IO on a block of values.
void vsl_b_write(vsl_b_ostream &os, char n)
Write char to vsl_b_ostream.
void vsl_swap_bytes(char *ptr, unsigned nbyte, std::size_t nelem=1)
Perform byte swapping in situ.
void vsl_block_binary_write_float_impl(vsl_b_ostream &os, const T *begin, std::size_t nelems)
Write a block of floats to a vsl_b_ostream.
void vsl_block_binary_read_byte_impl(vsl_b_istream &is, T *begin, std::size_t nelems)
Read a block of bytes from a vsl_b_ostream.
std::istream & is() const
A reference to the adaptor's stream.
vsl_block_t allocate_up_to(std::size_t nbytes)
std::size_t vsl_convert_from_arbitrary_length(const unsigned char *buffer, unsigned long *ints, std::size_t count=1)
Decode a buffer of arbitrary length integers.
void vsl_block_binary_read_confirm_specialisation(vsl_b_istream &is, bool specialised)
Error checking.
#define VSL_MAX_ARBITRARY_INT_BUFFER_LENGTH(size_of_type)
The maximum length of buffer to use with arbitrary length integers.
void vsl_block_binary_write_int_impl(vsl_b_ostream &os, const T *begin, std::size_t nelems)
Write a block of signed ints to a vsl_b_ostream.
void vsl_b_read(vsl_b_istream &is, char &n)
Read char from vsl_b_istream.
An adaptor for any std::istream to make it suitable for binary input.
std::size_t vsl_convert_to_arbitrary_length(const unsigned long *ints, unsigned char *buffer, std::size_t count=1)
Encode an array of ints into an arbitrary length format.
void vsl_block_binary_read_int_impl(vsl_b_istream &is, T *begin, std::size_t nelems)
Read a block of signed ints from a vsl_b_istream.
void vsl_block_binary_read_float_impl(vsl_b_istream &is, T *begin, std::size_t nelems)
Read a block of floats from a vsl_b_ostream.
std::ostream & os() const
A reference to the adaptor's stream.
void vsl_swap_bytes_to_buffer(const char *source, char *dest, unsigned nbyte, std::size_t nelem=1)
Perform byte swapping to a buffer.