STIR  6.2.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 
43 START_NAMESPACE_STIR
44 
55 {
56 public:
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 
120 template <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
126 template <>
127 struct TypeForNumericType<NumericType::SCHAR>
128 {
129  typedef signed char type;
130 };
131 template <>
132 struct TypeForNumericType<NumericType::UCHAR>
133 {
134  typedef unsigned char type;
135 };
136 template <>
137 struct TypeForNumericType<NumericType::SHORT>
138 {
139  typedef signed short type;
140 };
141 template <>
142 struct TypeForNumericType<NumericType::USHORT>
143 {
144  typedef unsigned short type;
145 };
146 template <>
147 struct TypeForNumericType<NumericType::INT>
148 {
149  typedef signed int type;
150 };
151 template <>
152 struct TypeForNumericType<NumericType::UINT>
153 {
154  typedef unsigned int type;
155 };
156 template <>
157 struct TypeForNumericType<NumericType::LONG>
158 {
159  typedef signed long type;
160 };
161 template <>
162 struct TypeForNumericType<NumericType::ULONG>
163 {
164  typedef unsigned long type;
165 };
166 template <>
167 struct TypeForNumericType<NumericType::FLOAT>
168 {
169  typedef float type;
170 };
171 template <>
172 struct TypeForNumericType<NumericType::DOUBLE>
173 {
174  typedef double type;
175 };
176 #endif
177 
178 END_NAMESPACE_STIR
179 
180 #include "stir/NumericType.inl"
181 
182 #endif
Type
An enum for the supported types.
Definition: NumericType.h:61
Type id
stores the current type
Definition: NumericType.h:78
Implementation of inline methods of class stir::NumericType.
A helper class that specifies the C++ type for a particular NumericType.
Definition: NumericType.h:121
provides names for some numeric types and methods for finding their properties.
Definition: NumericType.h:54
basic configuration include file