Mercurial > hg > octave-nkf
annotate liboctave/byte-swap.h @ 9300:fddb9f9f724b
Correct documentation for keyboard function
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Wed, 03 Jun 2009 13:21:37 -0700 |
parents | eb63fbe60fab |
children | 4c0cdbe0acca |
rev | line source |
---|---|
1960 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1996, 1997, 1998, 2004, 2005, 2006, 2007, 2008 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 | |
5775 | 26 // FIXME -- not sure these volatile qualifiers are really |
3215 | 27 // needed or appropriate here. |
28 | |
1960 | 29 static inline void |
3215 | 30 swap_bytes (volatile void *ptr, unsigned int i, unsigned int j) |
1960 | 31 { |
3215 | 32 volatile char *t = static_cast<volatile char *> (ptr); |
3145 | 33 |
1960 | 34 char tmp = t[i]; |
35 t[i] = t[j]; | |
36 t[j] = tmp; | |
37 } | |
38 | |
4944 | 39 template <int n> |
40 void | |
41 swap_bytes (volatile void *ptr) | |
1960 | 42 { |
8381
ad896677a2e2
implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
43 for (int i = 0; i < n/2; i++) |
4944 | 44 swap_bytes (ptr, i, n-1-i); |
45 } | |
3145 | 46 |
4944 | 47 template <> |
48 inline void | |
49 swap_bytes <1> (volatile void *) | |
50 { | |
51 } | |
52 | |
53 template <> | |
54 inline void | |
55 swap_bytes <2> (volatile void *ptr) | |
56 { | |
57 swap_bytes (ptr, 0, 1); | |
1960 | 58 } |
59 | |
4944 | 60 template <> |
61 inline void | |
62 swap_bytes <4> (volatile void *ptr) | |
1960 | 63 { |
4944 | 64 swap_bytes (ptr, 0, 3); |
65 swap_bytes (ptr, 1, 2); | |
1960 | 66 } |
67 | |
4944 | 68 template <> |
69 inline void | |
70 swap_bytes <8> (volatile void *ptr) | |
1960 | 71 { |
4944 | 72 swap_bytes (ptr, 0, 7); |
73 swap_bytes (ptr, 1, 6); | |
74 swap_bytes (ptr, 2, 5); | |
75 swap_bytes (ptr, 3, 4); | |
1960 | 76 } |
77 | |
4944 | 78 template <int n> |
79 void | |
80 swap_bytes (volatile void *ptr, int len) | |
1960 | 81 { |
3215 | 82 volatile char *t = static_cast<volatile char *> (ptr); |
3145 | 83 |
1960 | 84 for (int i = 0; i < len; i++) |
85 { | |
4944 | 86 swap_bytes<n> (t); |
87 t += n; | |
1960 | 88 } |
89 } | |
90 | |
4944 | 91 template <> |
92 inline void | |
93 swap_bytes<1> (volatile void *, int) | |
1960 | 94 { |
95 } | |
96 | |
97 #endif | |
98 | |
99 /* | |
100 ;;; Local Variables: *** | |
101 ;;; mode: C++ *** | |
102 ;;; End: *** | |
103 */ |