Mercurial > hg > octave-lojdl
diff liboctave/util/data-conv.h @ 17439:6690dba6078a
improve efficiency of fwrite
* oct-stream.h, oct-stream.cc (write_int, do_write): Delete.
(convert_ints, convert_data, octave_stream::write_bytes
octave_stream::skip_bytes): New functions.
(octave_stream::write): Improve efficiency by writing data in larger
chunks.
* oct-stream.cc: Delete unnecessary template instantiations.
* data-conv.h, data-conv.cc (is_equivalent_type): New template.
Provide specializations for core Octave data types.
(oct_data_conv::data_type_size): New function.
(oct_data_conv::data_type_to_string): Correct spelling of unsigned.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 13 Sep 2013 23:31:11 -0400 |
parents | 648dabbb4c6b |
children |
line wrap: on
line diff
--- a/liboctave/util/data-conv.h +++ b/liboctave/util/data-conv.h @@ -26,6 +26,7 @@ #include <limits> #include "mach-info.h" +#include "oct-inttypes.h" class OCTAVE_API @@ -61,6 +62,8 @@ dt_unknown = 23 // Must be last, have largest value! }; + static size_t data_type_size (data_type dt); + static data_type string_to_data_type (const std::string& s); static void string_to_data_type (const std::string& s, int& block_size, @@ -125,4 +128,137 @@ write_floats (std::ostream& os, const float *data, save_type type, octave_idx_type len); +template <typename T> +inline bool +is_equivalent_type (oct_data_conv::data_type) +{ + return false; +} + +template <> +inline bool +is_equivalent_type<int8_t> (oct_data_conv::data_type t) +{ + return t == oct_data_conv::dt_int8; +} + +template <> +inline bool +is_equivalent_type<int16_t> (oct_data_conv::data_type t) +{ + return t == oct_data_conv::dt_int16; +} + +template <> +inline bool +is_equivalent_type<int32_t> (oct_data_conv::data_type t) +{ + return t == oct_data_conv::dt_int32; +} + +template <> +inline bool +is_equivalent_type<int64_t> (oct_data_conv::data_type t) +{ + return t == oct_data_conv::dt_int64; +} + +template <> +inline bool +is_equivalent_type<uint8_t> (oct_data_conv::data_type t) +{ + return t == oct_data_conv::dt_uint8; +} + +template <> +inline bool +is_equivalent_type<uint16_t> (oct_data_conv::data_type t) +{ + return t == oct_data_conv::dt_uint16; +} + +template <> +inline bool +is_equivalent_type<uint32_t> (oct_data_conv::data_type t) +{ + return t == oct_data_conv::dt_uint32; +} + +template <> +inline bool +is_equivalent_type<uint64_t> (oct_data_conv::data_type t) +{ + return t == oct_data_conv::dt_uint64; +} + +template <> +inline bool +is_equivalent_type<octave_int8> (oct_data_conv::data_type t) +{ + return t == oct_data_conv::dt_int8; +} + +template <> +inline bool +is_equivalent_type<octave_int16> (oct_data_conv::data_type t) +{ + return t == oct_data_conv::dt_int16; +} + +template <> +inline bool +is_equivalent_type<octave_int32> (oct_data_conv::data_type t) +{ + return t == oct_data_conv::dt_int32; +} + +template <> +inline bool +is_equivalent_type<octave_int64> (oct_data_conv::data_type t) +{ + return t == oct_data_conv::dt_int64; +} + +template <> +inline bool +is_equivalent_type<octave_uint8> (oct_data_conv::data_type t) +{ + return t == oct_data_conv::dt_uint8; +} + +template <> +inline bool +is_equivalent_type<octave_uint16> (oct_data_conv::data_type t) +{ + return t == oct_data_conv::dt_uint16; +} + +template <> +inline bool +is_equivalent_type<octave_uint32> (oct_data_conv::data_type t) +{ + return t == oct_data_conv::dt_uint32; +} + +template <> +inline bool +is_equivalent_type<octave_uint64> (oct_data_conv::data_type t) +{ + return t == oct_data_conv::dt_uint64; +} + +template <> +inline bool +is_equivalent_type<double> (oct_data_conv::data_type t) +{ + return t == oct_data_conv::dt_double; +} + +template <> +inline bool +is_equivalent_type<float> (oct_data_conv::data_type t) +{ + return t == oct_data_conv::dt_single || t == oct_data_conv::dt_float; +} + #endif