annotate liboctave/byte-swap.h @ 5103:e2ed74b9bfa0 after-gnuplot-split

[project @ 2004-12-28 02:43:01 by jwe]
author jwe
date Tue, 28 Dec 2004 02:43:01 +0000
parents 44046bbaa52c
children 4c8a2e4e0717
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
1 /*
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
2
2847
8b262e771614 [project @ 1997-03-27 16:18:26 by jwe]
jwe
parents: 1993
diff changeset
3 Copyright (C) 1996, 1997 John W. Eaton
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
4
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
6
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
10 later version.
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
11
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
15 for more details.
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
16
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, write to the Free
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
20
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
21 */
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
22
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
23 #if !defined (octave_byte_swap_h)
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
24 #define octave_byte_swap_h 1
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
25
3215
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3145
diff changeset
26 // XXX FIXME XXX -- not sure these volatile qualifiers are really
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3145
diff changeset
27 // needed or appropriate here.
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3145
diff changeset
28
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
29 static inline void
3215
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3145
diff changeset
30 swap_bytes (volatile void *ptr, unsigned int i, unsigned int j)
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
31 {
3215
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3145
diff changeset
32 volatile char *t = static_cast<volatile char *> (ptr);
3145
0d640dc625c7 [project @ 1998-02-05 08:44:59 by jwe]
jwe
parents: 2847
diff changeset
33
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
34 char tmp = t[i];
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
35 t[i] = t[j];
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
36 t[j] = tmp;
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
37 }
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
38
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
39 template <int n>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
40 void
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
41 swap_bytes (volatile void *ptr)
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
42 {
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
43 for (size_t i = 0; i < n/2; i++)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
44 swap_bytes (ptr, i, n-1-i);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
45 }
3145
0d640dc625c7 [project @ 1998-02-05 08:44:59 by jwe]
jwe
parents: 2847
diff changeset
46
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
47 template <>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
48 inline void
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
49 swap_bytes <1> (volatile void *)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
50 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
51 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
52
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
53 template <>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
54 inline void
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
55 swap_bytes <2> (volatile void *ptr)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
56 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
57 swap_bytes (ptr, 0, 1);
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
58 }
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
59
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
60 template <>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
61 inline void
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
62 swap_bytes <4> (volatile void *ptr)
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
63 {
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
64 swap_bytes (ptr, 0, 3);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
65 swap_bytes (ptr, 1, 2);
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
66 }
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
67
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
68 template <>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
69 inline void
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
70 swap_bytes <8> (volatile void *ptr)
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
71 {
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
72 swap_bytes (ptr, 0, 7);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
73 swap_bytes (ptr, 1, 6);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
74 swap_bytes (ptr, 2, 5);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
75 swap_bytes (ptr, 3, 4);
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
76 }
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
77
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
78 template <int n>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
79 void
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
80 swap_bytes (volatile void *ptr, int len)
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
81 {
3215
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3145
diff changeset
82 volatile char *t = static_cast<volatile char *> (ptr);
3145
0d640dc625c7 [project @ 1998-02-05 08:44:59 by jwe]
jwe
parents: 2847
diff changeset
83
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
84 for (int i = 0; i < len; i++)
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
85 {
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
86 swap_bytes<n> (t);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
87 t += n;
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
88 }
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
89 }
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
90
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
91 template <>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
92 inline void
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
93 swap_bytes<1> (volatile void *, int)
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
94 {
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
95 }
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
96
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
97 #endif
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
98
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
99 /*
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
100 ;;; Local Variables: ***
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
101 ;;; mode: C++ ***
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
102 ;;; End: ***
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
103 */