data-conv.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #if !defined (octave_data_conv_h)
00024 #define octave_data_conv_h 1
00025 
00026 #include <climits>
00027 
00028 #include "mach-info.h"
00029 
00030 class
00031 OCTAVE_API
00032 oct_data_conv
00033 {
00034 public:
00035 
00036   enum data_type
00037     {
00038       dt_int8      =  0,
00039       dt_uint8     =  1,
00040       dt_int16     =  2,
00041       dt_uint16    =  3,
00042       dt_int32     =  4,
00043       dt_uint32    =  5,
00044       dt_int64     =  6,
00045       dt_uint64    =  7,
00046       dt_single    =  8,
00047       dt_double    =  9,
00048       dt_char      = 10,
00049       dt_schar     = 11,
00050       dt_uchar     = 12,
00051       dt_logical   = 13,
00052       dt_short     = 14,
00053       dt_ushort    = 15,
00054       dt_int       = 16,
00055       dt_uint      = 17,
00056       dt_long      = 18,
00057       dt_ulong     = 19,
00058       dt_longlong  = 20,
00059       dt_ulonglong = 21,
00060       dt_float     = 22,
00061       dt_unknown   = 23 // Must be last, have largest value!
00062     };
00063 
00064   static data_type string_to_data_type (const std::string& s);
00065 
00066   static void string_to_data_type (const std::string& s, int& block_size,
00067                                    data_type& input_type,
00068                                    data_type& output_type);
00069 
00070   static void string_to_data_type (const std::string& s, int& block_size,
00071                                    data_type& output_type);
00072 
00073   static std::string data_type_as_string (data_type dt);
00074 };
00075 
00076 // Add new entries to the end of this enum, otherwise Octave will not
00077 // be able to read binary data files stored in Octave's binary data
00078 // format that were created with previous versions of Octave.
00079 
00080 enum save_type
00081   {
00082     LS_U_CHAR  = 0,
00083     LS_U_SHORT = 1,
00084     LS_U_INT   = 2,
00085     LS_CHAR    = 3,
00086     LS_SHORT   = 4,
00087     LS_INT     = 5,
00088     LS_FLOAT   = 6,
00089     LS_DOUBLE  = 7,
00090     LS_U_LONG  = 8,
00091     LS_LONG    = 9
00092   };
00093 
00094 extern OCTAVE_API void
00095 do_double_format_conversion (void *data, octave_idx_type len,
00096                              oct_mach_info::float_format from_fmt,
00097                              oct_mach_info::float_format to_fmt
00098                                = oct_mach_info::native_float_format ());
00099 
00100 extern OCTAVE_API void
00101 do_float_format_conversion (void *data, octave_idx_type len,
00102                             oct_mach_info::float_format from_fmt,
00103                             oct_mach_info::float_format to_fmt
00104                               = oct_mach_info::native_float_format ());
00105 
00106 extern OCTAVE_API void
00107 do_float_format_conversion (void *data, size_t sz, octave_idx_type len,
00108                             oct_mach_info::float_format from_fmt,
00109                             oct_mach_info::float_format to_fmt
00110                               = oct_mach_info::native_float_format ());
00111 
00112 extern OCTAVE_API void
00113 read_doubles (std::istream& is, double *data, save_type type,
00114               octave_idx_type len, bool swap, oct_mach_info::float_format fmt);
00115 
00116 extern OCTAVE_API void
00117 write_doubles (std::ostream& os, const double *data, save_type type,
00118                octave_idx_type len);
00119 
00120 extern OCTAVE_API void
00121 read_floats (std::istream& is, float *data, save_type type,
00122              octave_idx_type len, bool swap, oct_mach_info::float_format fmt);
00123 
00124 extern OCTAVE_API void
00125 write_floats (std::ostream& os, const float *data, save_type type,
00126               octave_idx_type len);
00127 
00128 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines