Mercurial > hg > octave-nkf
annotate liboctave/util/byte-swap.h @ 20330:2db2db2df55b
Automatically convert arrays of java primitives into Octave types (bug #44882)
* libinterp/octave-value/ov-java.cc (box): when the result of a java method is
a java primitive type, these are converted to octave types automatically. We
seem to be handling this correctly for scalars but not for arrays yet. This
fixes it on the java -> octave direction.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Mon, 20 Apr 2015 15:01:27 +0100 |
parents | 4197fc428c7d |
children |
rev | line source |
---|---|
1960 | 1 /* |
2 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
1960 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1960 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1960 | 20 |
21 */ | |
22 | |
23 #if !defined (octave_byte_swap_h) | |
24 #define octave_byte_swap_h 1 | |
25 | |
26 static inline void | |
17413
e89e86e1a551
eliminate unnecessary volatile declarations
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
27 swap_bytes (void *ptr, unsigned int i, unsigned int j) |
1960 | 28 { |
17413
e89e86e1a551
eliminate unnecessary volatile declarations
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
29 char *t = static_cast<char *> (ptr); |
3145 | 30 |
1960 | 31 char tmp = t[i]; |
32 t[i] = t[j]; | |
33 t[j] = tmp; | |
34 } | |
35 | |
4944 | 36 template <int n> |
37 void | |
17413
e89e86e1a551
eliminate unnecessary volatile declarations
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
38 swap_bytes (void *ptr) |
1960 | 39 { |
8381
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
40 for (int i = 0; i < n/2; i++) |
4944 | 41 swap_bytes (ptr, i, n-1-i); |
42 } | |
3145 | 43 |
4944 | 44 template <> |
45 inline void | |
17413
e89e86e1a551
eliminate unnecessary volatile declarations
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
46 swap_bytes<1> (void *) |
4944 | 47 { |
48 } | |
49 | |
50 template <> | |
51 inline void | |
17413
e89e86e1a551
eliminate unnecessary volatile declarations
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
52 swap_bytes<2> (void *ptr) |
4944 | 53 { |
54 swap_bytes (ptr, 0, 1); | |
1960 | 55 } |
56 | |
4944 | 57 template <> |
58 inline void | |
17413
e89e86e1a551
eliminate unnecessary volatile declarations
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
59 swap_bytes<4> (void *ptr) |
1960 | 60 { |
4944 | 61 swap_bytes (ptr, 0, 3); |
62 swap_bytes (ptr, 1, 2); | |
1960 | 63 } |
64 | |
4944 | 65 template <> |
66 inline void | |
17413
e89e86e1a551
eliminate unnecessary volatile declarations
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
67 swap_bytes<8> (void *ptr) |
1960 | 68 { |
4944 | 69 swap_bytes (ptr, 0, 7); |
70 swap_bytes (ptr, 1, 6); | |
71 swap_bytes (ptr, 2, 5); | |
72 swap_bytes (ptr, 3, 4); | |
1960 | 73 } |
74 | |
4944 | 75 template <int n> |
76 void | |
17413
e89e86e1a551
eliminate unnecessary volatile declarations
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
77 swap_bytes (void *ptr, int len) |
1960 | 78 { |
17413
e89e86e1a551
eliminate unnecessary volatile declarations
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
79 char *t = static_cast<char *> (ptr); |
3145 | 80 |
1960 | 81 for (int i = 0; i < len; i++) |
82 { | |
4944 | 83 swap_bytes<n> (t); |
84 t += n; | |
1960 | 85 } |
86 } | |
87 | |
4944 | 88 template <> |
89 inline void | |
17413
e89e86e1a551
eliminate unnecessary volatile declarations
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
90 swap_bytes<1> (void *, int) |
1960 | 91 { |
92 } | |
93 | |
94 #endif |