1960
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_byte_swap_h) |
|
24 #define octave_byte_swap_h 1 |
|
25 |
|
26 static inline void |
3145
|
27 swap_bytes (void *ptr, unsigned int i, unsigned int j) |
1960
|
28 { |
3145
|
29 char *t = static_cast<char *> (ptr); |
|
30 |
1960
|
31 char tmp = t[i]; |
|
32 t[i] = t[j]; |
|
33 t[j] = tmp; |
|
34 } |
|
35 |
|
36 static inline void |
3145
|
37 swap_2_bytes (void *ptr) |
1960
|
38 { |
3145
|
39 char *t = static_cast<char *> (ptr); |
|
40 |
1960
|
41 swap_bytes (t, 0, 1); |
|
42 } |
|
43 |
|
44 static inline void |
3145
|
45 swap_4_bytes (void *ptr) |
1960
|
46 { |
3145
|
47 char *t = static_cast<char *> (ptr); |
|
48 |
1960
|
49 swap_bytes (t, 0, 3); |
|
50 swap_bytes (t, 1, 2); |
|
51 } |
|
52 |
|
53 static inline void |
3145
|
54 swap_8_bytes (void *ptr) |
1960
|
55 { |
3145
|
56 char *t = static_cast<char *> (ptr); |
|
57 |
1960
|
58 swap_bytes (t, 0, 7); |
|
59 swap_bytes (t, 1, 6); |
|
60 swap_bytes (t, 2, 5); |
|
61 swap_bytes (t, 3, 4); |
|
62 } |
|
63 |
|
64 static inline void |
3145
|
65 swap_2_bytes (void *ptr, int len) |
1960
|
66 { |
3145
|
67 char *t = static_cast<char *> (ptr); |
|
68 |
1960
|
69 for (int i = 0; i < len; i++) |
|
70 { |
3145
|
71 swap_2_bytes (t); |
|
72 t += 2; |
1960
|
73 } |
|
74 } |
|
75 |
|
76 static inline void |
3145
|
77 swap_4_bytes (void *ptr, int len) |
1960
|
78 { |
3145
|
79 char *t = static_cast<char *> (ptr); |
|
80 |
1960
|
81 for (int i = 0; i < len; i++) |
|
82 { |
3145
|
83 swap_4_bytes (t); |
|
84 t += 4; |
1960
|
85 } |
|
86 } |
|
87 |
|
88 static inline void |
3145
|
89 swap_8_bytes (void *ptr, int len) |
1960
|
90 { |
3145
|
91 char *t = static_cast<char *> (ptr); |
|
92 |
1960
|
93 for (int i = 0; i < len; i++) |
|
94 { |
3145
|
95 swap_8_bytes (t); |
|
96 t += 8; |
1960
|
97 } |
|
98 } |
|
99 |
|
100 #endif |
|
101 |
|
102 /* |
|
103 ;;; Local Variables: *** |
|
104 ;;; mode: C++ *** |
|
105 ;;; End: *** |
|
106 */ |