STIR 6.4.0
NumericType.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2000 PARAPET partners
3 Copyright (C) 2000-2009 Hammersmith Imanet Ltd
4 This file is part of STIR.
5
6 SPDX-License-Identifier: Apache-2.0 AND License-ref-PARAPET-license
7
8 See STIR/LICENSE.txt for details
9*/
10
11#ifndef __stir_NumericType_H__
12#define __stir_NumericType_H__
13
22/*
23 Modification History:
24
25 - first version by Kris Thielemans
26
27 - KT 28/07/98
28 added two methods to NumericType:
29 inline bool signed_type() const;
30 inline bool integer_type() const;
31
32 - KT 15/12/99
33 removed inlining. Gave troubles with gcc on NT.
34 added method that returns Interfile info
35
36 - KT 15/07/04
37 added TypeForNumericType
38*/
39
40#include "stir/common.h"
41#include <string>
42
43START_NAMESPACE_STIR
44
53
55{
56public:
58 // BIT has to be the first type, and UNKNOWN_TYPE has to be
59 // the last name for the implementation of the 2nd NumericType constructor
60 // to work
61 enum Type
62 {
63 BIT,
64 SCHAR,
65 UCHAR,
66 SHORT,
67 USHORT,
68 INT,
69 UINT,
70 LONG,
71 ULONG,
72 FLOAT,
73 DOUBLE,
74 UNKNOWN_TYPE
75 };
76
79
81 inline NumericType(Type t = UNKNOWN_TYPE);
82
84
89 NumericType(const std::string& number_format, const std::size_t size_in_bytes);
90
92 inline bool operator==(NumericType type) const;
93 inline bool operator!=(NumericType type) const;
94
96 std::size_t size_in_bytes() const;
97
98 std::size_t size_in_bits() const;
99
101 bool signed_type() const;
102
104 bool integer_type() const;
105
107 void get_Interfile_info(std::string& number_format, std::size_t& size_in_bytes) const;
108};
109
120template <int numeric_type_enum>
122{
123};
124
125#ifndef DOXYGEN_SKIP // disable definitions when running doxygen to avoid having all of this in the doc
126template <>
127struct TypeForNumericType<NumericType::SCHAR>
128{
129 typedef signed char type;
130};
131template <>
132struct TypeForNumericType<NumericType::UCHAR>
133{
134 typedef unsigned char type;
135};
136template <>
137struct TypeForNumericType<NumericType::SHORT>
138{
139 typedef signed short type;
140};
141template <>
142struct TypeForNumericType<NumericType::USHORT>
143{
144 typedef unsigned short type;
145};
146template <>
147struct TypeForNumericType<NumericType::INT>
148{
149 typedef signed int type;
150};
151template <>
152struct TypeForNumericType<NumericType::UINT>
153{
154 typedef unsigned int type;
155};
156template <>
157struct TypeForNumericType<NumericType::LONG>
158{
159 typedef signed long type;
160};
161template <>
162struct TypeForNumericType<NumericType::ULONG>
163{
164 typedef unsigned long type;
165};
166template <>
167struct TypeForNumericType<NumericType::FLOAT>
168{
169 typedef float type;
170};
171template <>
172struct TypeForNumericType<NumericType::DOUBLE>
173{
174 typedef double type;
175};
176#endif
177
178END_NAMESPACE_STIR
179
180#include "stir/NumericType.inl"
181
182#endif
Implementation of inline methods of class stir::NumericType.
provides names for some numeric types and methods for finding their properties.
Definition NumericType.h:55
std::size_t size_in_bytes() const
as reported by sizeof(), so it is really size_in_sizeof_char
Definition NumericType.cxx:113
bool operator==(NumericType type) const
comparison operator
Definition NumericType.inl:30
Type
An enum for the supported types.
Definition NumericType.h:62
bool integer_type() const
returns true for all built-in types, except float and double
Definition NumericType.cxx:181
NumericType(Type t=UNKNOWN_TYPE)
constructor, defaulting to unknown type
Definition NumericType.inl:25
bool signed_type() const
returns true for all built-in types, except unsigned types
Definition NumericType.cxx:151
void get_Interfile_info(std::string &number_format, std::size_t &size_in_bytes) const
returns the names and size a la Interfile. see NumericType(const string&,const std::size_t)
Definition NumericType.cxx:81
NumericType(const std::string &number_format, const std::size_t size_in_bytes)
A constructor to work from named types a la Interfile.
Type id
stores the current type
Definition NumericType.h:78
basic configuration include file
A helper class that specifies the C++ type for a particular NumericType.
Definition NumericType.h:122