Mercurial > octave
annotate liboctave/system/mach-info.h @ 23820:1a08d0ac510f
move union field type punning code to C (bug #51638)
* cmach-info.h, cmach-info.c: New files, extracted and adapted from
mach-info.h and mach-info.cc.
* liboctave/system/module.mk: Update.
* mach-info.cc: Include cmach-info.h.
* mach-info.h (enum float_format): Set explicit values and note that
other code must change if the values change.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 01 Aug 2017 15:38:34 -0400 |
parents | 26e19cf8e0d9 |
children | 194eb4bd202b |
rev | line source |
---|---|
1960 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 1996-2017 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 | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
9 the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
10 (at your option) any later version. |
1960 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
15 GNU General Public License for more details. |
1960 | 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 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
23 #if ! defined (octave_mach_info_h) |
2317 | 24 #define octave_mach_info_h 1 |
25 | |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
26 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
27 |
2317 | 28 #include <string> |
29 | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
30 namespace octave |
2317 | 31 { |
23745
a732be902061
don't use singleton pattern for mach_info
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
32 namespace mach_info |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
33 { |
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
34 enum float_format |
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
35 { |
23820
1a08d0ac510f
move union field type punning code to C (bug #51638)
John W. Eaton <jwe@octave.org>
parents:
23756
diff
changeset
|
36 // If these values change, you must also change the values |
1a08d0ac510f
move union field type punning code to C (bug #51638)
John W. Eaton <jwe@octave.org>
parents:
23756
diff
changeset
|
37 // returned by octave_get_float_format. |
1a08d0ac510f
move union field type punning code to C (bug #51638)
John W. Eaton <jwe@octave.org>
parents:
23756
diff
changeset
|
38 |
1a08d0ac510f
move union field type punning code to C (bug #51638)
John W. Eaton <jwe@octave.org>
parents:
23756
diff
changeset
|
39 flt_fmt_unknown = 0, |
1a08d0ac510f
move union field type punning code to C (bug #51638)
John W. Eaton <jwe@octave.org>
parents:
23756
diff
changeset
|
40 flt_fmt_ieee_little_endian = 1, |
1a08d0ac510f
move union field type punning code to C (bug #51638)
John W. Eaton <jwe@octave.org>
parents:
23756
diff
changeset
|
41 flt_fmt_ieee_big_endian = 2, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
42 }; |
2317 | 43 |
23745
a732be902061
don't use singleton pattern for mach_info
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
44 float_format native_float_format (void); |
2317 | 45 |
23745
a732be902061
don't use singleton pattern for mach_info
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
46 bool words_big_endian (void); |
2317 | 47 |
23745
a732be902061
don't use singleton pattern for mach_info
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
48 bool words_little_endian (void); |
2317 | 49 |
23745
a732be902061
don't use singleton pattern for mach_info
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
50 float_format string_to_float_format (const std::string&); |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
51 |
23745
a732be902061
don't use singleton pattern for mach_info
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
52 std::string float_format_as_string (float_format); |
a732be902061
don't use singleton pattern for mach_info
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
53 } |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
54 } |
2317 | 55 |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
56 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS) |
2317 | 57 |
23756
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
58 class oct_mach_info |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
59 { |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
60 public: |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
61 |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
62 typedef octave::mach_info::float_format float_format; |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
63 |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
64 OCTAVE_DEPRECATED (4.4, "use 'octave::mach_info::native_float_format' instead") |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
65 static float_format native_float_format (void) |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
66 { |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
67 return octave::mach_info::native_float_format (); |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
68 } |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
69 |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
70 OCTAVE_DEPRECATED (4.4, "use 'octave::mach_info::words_big_endian' instead") |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
71 static bool words_big_endian (void) |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
72 { |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
73 return octave::mach_info::words_big_endian (); |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
74 } |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
75 |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
76 OCTAVE_DEPRECATED (4.4, "use 'octave::mach_info::words_little_endian' instead") |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
77 static bool words_little_endian (void) |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
78 { |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
79 return octave::mach_info::words_little_endian (); |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
80 } |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
81 |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
82 OCTAVE_DEPRECATED (4.4, "use 'octave::mach_info::string_to_float_format' instead") |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
83 static float_format string_to_float_format (const std::string& str) |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
84 { |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
85 return octave::mach_info::string_to_float_format (str); |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
86 } |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
87 |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
88 OCTAVE_DEPRECATED (4.4, "use 'octave::mach_info::float_format_as_string' instead") |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
89 static std::string float_format_as_string (float_format ff) |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
90 { |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
91 return octave::mach_info::float_format_as_string (ff); |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
92 } |
26e19cf8e0d9
use class instead of typedef to preserve deprecated function names
John W. Eaton <jwe@octave.org>
parents:
23745
diff
changeset
|
93 }; |
1960 | 94 |
95 #endif | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
96 |
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
97 #endif |