comparison liboctave/util/data-conv.cc @ 22197:e43d83253e28

refill multi-line macro definitions Use the Emacs C++ mode style for line continuation markers in multi-line macro definitions. * make_int.cc, __dsearchn__.cc, __magick_read__.cc, besselj.cc, bitfcns.cc, bsxfun.cc, cellfun.cc, data.cc, defun-dld.h, defun-int.h, defun.h, det.cc, error.h, find.cc, gcd.cc, graphics.cc, interpreter.h, jit-ir.h, jit-typeinfo.h, lookup.cc, ls-mat5.cc, max.cc, mexproto.h, mxarray.in.h, oct-stream.cc, ordschur.cc, pr-output.cc, profiler.h, psi.cc, regexp.cc, sparse-xdiv.cc, sparse-xpow.cc, tril.cc, txt-eng.h, utils.cc, variables.cc, variables.h, xdiv.cc, xpow.cc, __glpk__.cc, ov-base.cc, ov-base.h, ov-cell.cc, ov-ch-mat.cc, ov-classdef.cc, ov-complex.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-float.cc, ov-float.h, ov-flt-complex.cc, ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-int-traits.h, ov-lazy-idx.h, ov-perm.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, ov-scalar.h, ov-str-mat.cc, ov-type-conv.h, ov.cc, ov.h, op-class.cc, op-int-conv.cc, op-int.h, op-str-str.cc, ops.h, lex.ll, Array.cc, CMatrix.cc, CSparse.cc, MArray.cc, MArray.h, MDiagArray2.cc, MDiagArray2.h, MSparse.h, Sparse.cc, dMatrix.cc, dSparse.cc, fCMatrix.cc, fMatrix.cc, idx-vector.cc, f77-fcn.h, quit.h, bsxfun-decl.h, bsxfun-defs.cc, lo-specfun.cc, oct-convn.cc, oct-convn.h, oct-norm.cc, oct-norm.h, oct-rand.cc, Sparse-op-decls.h, Sparse-op-defs.h, mx-inlines.cc, mx-op-decl.h, mx-op-defs.h, mach-info.cc, oct-group.cc, oct-passwd.cc, oct-syscalls.cc, oct-time.cc, data-conv.cc, kpse.cc, lo-ieee.h, lo-macros.h, oct-cmplx.h, oct-glob.cc, oct-inttypes.cc, oct-inttypes.h, oct-locbuf.h, oct-sparse.h, url-transfer.cc, oct-conf-post.in.h, shared-fcns.h: Refill macro definitions.
author John W. Eaton <jwe@octave.org>
date Mon, 01 Aug 2016 12:40:18 -0400
parents c4ab2e54f100
children bac0d6f07a3e
comparison
equal deleted inserted replaced
22196:dd992fd74fce 22197:e43d83253e28
36 #include "lo-error.h" 36 #include "lo-error.h"
37 #include "lo-ieee.h" 37 #include "lo-ieee.h"
38 #include "oct-locbuf.h" 38 #include "oct-locbuf.h"
39 39
40 #if defined (OCTAVE_HAVE_LONG_LONG_INT) 40 #if defined (OCTAVE_HAVE_LONG_LONG_INT)
41 # define FIND_SIZED_INT_TYPE(VAL, BITS, TQ, Q) \ 41 # define FIND_SIZED_INT_TYPE(VAL, BITS, TQ, Q) \
42 do \ 42 do \
43 { \ 43 { \
44 int sz = BITS / std::numeric_limits<unsigned char>::digits; \ 44 int sz = BITS / std::numeric_limits<unsigned char>::digits; \
45 if (sizeof (TQ char) == sz) \ 45 if (sizeof (TQ char) == sz) \
46 VAL = oct_data_conv::dt_ ## Q ## char; \ 46 VAL = oct_data_conv::dt_ ## Q ## char; \
47 else if (sizeof (TQ short) == sz) \ 47 else if (sizeof (TQ short) == sz) \
48 VAL = oct_data_conv::dt_ ## Q ## short; \ 48 VAL = oct_data_conv::dt_ ## Q ## short; \
49 else if (sizeof (TQ int) == sz) \ 49 else if (sizeof (TQ int) == sz) \
50 VAL = oct_data_conv::dt_ ## Q ## int; \ 50 VAL = oct_data_conv::dt_ ## Q ## int; \
51 else if (sizeof (TQ long) == sz) \ 51 else if (sizeof (TQ long) == sz) \
52 VAL = oct_data_conv::dt_ ## Q ## long; \ 52 VAL = oct_data_conv::dt_ ## Q ## long; \
53 else if (sizeof (TQ long long) == sz) \ 53 else if (sizeof (TQ long long) == sz) \
54 VAL = oct_data_conv::dt_ ## Q ## longlong; \ 54 VAL = oct_data_conv::dt_ ## Q ## longlong; \
55 else \ 55 else \
56 VAL = oct_data_conv::dt_unknown; \ 56 VAL = oct_data_conv::dt_unknown; \
57 } \ 57 } \
58 while (0) 58 while (0)
59 #else 59 #else
60 # define FIND_SIZED_INT_TYPE(VAL, BITS, TQ, Q) \ 60 # define FIND_SIZED_INT_TYPE(VAL, BITS, TQ, Q) \
61 do \ 61 do \
62 { \ 62 { \
63 int sz = BITS / std::numeric_limits<unsigned char>::digits; \ 63 int sz = BITS / std::numeric_limits<unsigned char>::digits; \
64 if (sizeof (TQ char) == sz) \ 64 if (sizeof (TQ char) == sz) \
65 VAL = oct_data_conv::dt_ ## Q ## char; \ 65 VAL = oct_data_conv::dt_ ## Q ## char; \
66 else if (sizeof (TQ short) == sz) \ 66 else if (sizeof (TQ short) == sz) \
67 VAL = oct_data_conv::dt_ ## Q ## short; \ 67 VAL = oct_data_conv::dt_ ## Q ## short; \
68 else if (sizeof (TQ int) == sz) \ 68 else if (sizeof (TQ int) == sz) \
69 VAL = oct_data_conv::dt_ ## Q ## int; \ 69 VAL = oct_data_conv::dt_ ## Q ## int; \
70 else if (sizeof (TQ long) == sz) \ 70 else if (sizeof (TQ long) == sz) \
71 VAL = oct_data_conv::dt_ ## Q ## long; \ 71 VAL = oct_data_conv::dt_ ## Q ## long; \
72 else \ 72 else \
73 VAL = oct_data_conv::dt_unknown; \ 73 VAL = oct_data_conv::dt_unknown; \
74 } \ 74 } \
75 while (0) 75 while (0)
76 #endif 76 #endif
77 77
78 #define FIND_SIZED_FLOAT_TYPE(VAL, BITS) \ 78 #define FIND_SIZED_FLOAT_TYPE(VAL, BITS) \
79 do \ 79 do \
80 { \ 80 { \
81 int sz = BITS / std::numeric_limits<unsigned char>::digits; \ 81 int sz = BITS / std::numeric_limits<unsigned char>::digits; \
82 if (sizeof (float) == sz) \ 82 if (sizeof (float) == sz) \
83 VAL = oct_data_conv::dt_float; \ 83 VAL = oct_data_conv::dt_float; \
84 else if (sizeof (double) == sz) \ 84 else if (sizeof (double) == sz) \
85 VAL = oct_data_conv::dt_double; \ 85 VAL = oct_data_conv::dt_double; \
86 else \ 86 else \
87 VAL = oct_data_conv::dt_unknown; \ 87 VAL = oct_data_conv::dt_unknown; \
88 } \ 88 } \
89 while (0) 89 while (0)
90 90
91 // I'm not sure it is worth the trouble, but let's use a lookup table 91 // I'm not sure it is worth the trouble, but let's use a lookup table
92 // for the types that are supposed to be a specific number of bits 92 // for the types that are supposed to be a specific number of bits
93 // wide. Given the macros above, this should work as long as 93 // wide. Given the macros above, this should work as long as
144 s.resize (k); 144 s.resize (k);
145 145
146 return s; 146 return s;
147 } 147 }
148 148
149 #define GET_SIZED_INT_TYPE(T, U) \ 149 #define GET_SIZED_INT_TYPE(T, U) \
150 do \ 150 do \
151 { \ 151 { \
152 switch (sizeof (T)) \ 152 switch (sizeof (T)) \
153 { \ 153 { \
154 case 1: \ 154 case 1: \
155 retval = dt_ ## U ## int8; \ 155 retval = dt_ ## U ## int8; \
156 break; \ 156 break; \
157 \ 157 \
158 case 2: \ 158 case 2: \
159 retval = dt_ ## U ## int16; \ 159 retval = dt_ ## U ## int16; \
160 break; \ 160 break; \
161 \ 161 \
162 case 4: \ 162 case 4: \
163 retval = dt_ ## U ## int32; \ 163 retval = dt_ ## U ## int32; \
164 break; \ 164 break; \
165 \ 165 \
166 case 8: \ 166 case 8: \
167 retval = dt_ ## U ## int64; \ 167 retval = dt_ ## U ## int64; \
168 break; \ 168 break; \
169 \ 169 \
170 default: \ 170 default: \
171 retval = dt_unknown; \ 171 retval = dt_unknown; \
172 break; \ 172 break; \
173 } \ 173 } \
174 } \ 174 } \
175 while (0) 175 while (0)
176 176
177 size_t 177 size_t
178 oct_data_conv::data_type_size (data_type dt) 178 oct_data_conv::data_type_size (data_type dt)
179 { 179 {
570 } 570 }
571 571
572 return retval; 572 return retval;
573 } 573 }
574 574
575 #define LS_DO_READ(TYPE, swap, data, size, len, stream) \ 575 #define LS_DO_READ(TYPE, swap, data, size, len, stream) \
576 do \ 576 do \
577 { \ 577 { \
578 if (len > 0) \ 578 if (len > 0) \
579 { \ 579 { \
580 OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \ 580 OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \
581 std::streamsize n_bytes = size * static_cast<std::streamsize> (len); \ 581 std::streamsize n_bytes = size * static_cast<std::streamsize> (len); \
582 stream.read (reinterpret_cast<char *> (ptr), n_bytes); \ 582 stream.read (reinterpret_cast<char *> (ptr), n_bytes); \
583 if (swap) \ 583 if (swap) \
584 swap_bytes< size > (ptr, len); \ 584 swap_bytes< size > (ptr, len); \
585 for (octave_idx_type i = 0; i < len; i++) \ 585 for (octave_idx_type i = 0; i < len; i++) \
586 data[i] = ptr[i]; \ 586 data[i] = ptr[i]; \
587 } \ 587 } \
588 } \ 588 } \
589 while (0) 589 while (0)
590 590
591 // Have to use copy here to avoid writing over data accessed via 591 // Have to use copy here to avoid writing over data accessed via
592 // Matrix::data (). 592 // Matrix::data ().
593 593
594 #define LS_DO_WRITE(TYPE, data, size, len, stream) \ 594 #define LS_DO_WRITE(TYPE, data, size, len, stream) \
595 do \ 595 do \
596 { \ 596 { \
597 if (len > 0) \ 597 if (len > 0) \
598 { \ 598 { \
599 char tmp_type = type; \ 599 char tmp_type = type; \
600 stream.write (&tmp_type, 1); \ 600 stream.write (&tmp_type, 1); \
601 OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \ 601 OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \
602 for (octave_idx_type i = 0; i < len; i++) \ 602 for (octave_idx_type i = 0; i < len; i++) \
603 ptr[i] = static_cast<TYPE> (data[i]); \ 603 ptr[i] = static_cast<TYPE> (data[i]); \
604 std::streamsize n_bytes = size * static_cast<std::streamsize> (len); \ 604 std::streamsize n_bytes = size * static_cast<std::streamsize> (len); \
605 stream.write (reinterpret_cast<char *> (ptr), n_bytes); \ 605 stream.write (reinterpret_cast<char *> (ptr), n_bytes); \
606 } \ 606 } \
607 } \ 607 } \
608 while (0) 608 while (0)
609 609
610 // Loading variables from files. 610 // Loading variables from files.
611 611
612 OCTAVE_NORETURN static 612 OCTAVE_NORETURN static