Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
Types.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2013.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Oliver Kohlbacher $
32 // $Authors: Marc Sturm, Clemens Groepl $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_CONCEPT_TYPES_H
36 #define OPENMS_CONCEPT_TYPES_H
37 
38 #include <OpenMS/config.h>
39 
40 #include <limits>
41 #include <cstddef> // for size_t
42 #include <ctime>
43 #include <cmath>
44 #include <string>
45 #include <iostream>
46 #include <iomanip>
47 
48 // If possible use the ISO C99-compliant header stdint.h
49 // to define the portable integer types.
50 #ifdef OPENMS_HAS_STDINT_H
51 #include <stdint.h>
52 #endif
53 
54 namespace OpenMS
55 {
61  typedef OPENMS_INT32_TYPE Int32;
62 
68  typedef OPENMS_INT64_TYPE Int64;
69 
75  typedef OPENMS_UINT64_TYPE UInt64;
76 
84  typedef time_t Time;
85 
91  //typedef size_t UInt;
92  typedef unsigned int UInt;
93 
99  //typedef OPENMS_SIZE_T_SIGNED Int;
100  typedef int Int;
101 
109  typedef float Real;
110 
118  typedef double DoubleReal;
119 
120 
128  typedef OPENMS_BYTE_TYPE Byte;
129 
137  typedef OPENMS_UINT64_TYPE UID;
138 
144  typedef size_t Size;
145 
151  typedef ptrdiff_t SignedSize;
152 
153  enum ASCII
154  {
156  ASCII__BELL = '\a',
164 
171  };
172 
215 
216 
221  template <typename FloatingPointType>
222  inline Int writtenDigits(const FloatingPointType & /* unused */ = FloatingPointType());
223 
225  template <>
226  inline Int writtenDigits<float>(const float &)
227  {
228  return std::numeric_limits<float>::digits10;
229  }
230 
232  template <>
233  inline Int writtenDigits<double>(const double &)
234  {
235  return std::numeric_limits<double>::digits10;
236  }
237 
239  template <>
240  inline Int writtenDigits<int>(const int &)
241  {
242  return std::numeric_limits<int>::digits10;
243  }
244 
246  template <>
247  inline Int writtenDigits<unsigned int>(const unsigned int &)
248  {
249  return std::numeric_limits<unsigned int>::digits10;
250  }
251 
253  template <>
254  inline Int writtenDigits<long int>(const long int &)
255  {
256  return std::numeric_limits<int>::digits10;
257  }
258 
260  template <>
261  inline Int writtenDigits<unsigned long int>(const unsigned long int &)
262  {
263  return std::numeric_limits<unsigned int>::digits10;
264  }
265 
266  class DataValue;
268  template <>
270  {
271  return std::numeric_limits<double>::digits10;
272  }
273 
274  /*
275  META-COMMENT: DO NOT INTRODUCE ANY LINEBREAKS BELOW IN
276  "<code>std::numeric_limits<long double>::digits10 == 18</code>".
277  The doxygen parser (version 1.5.5) will get confused! (Clemens)
278  */
279 
290  template <>
291  inline Int writtenDigits<long double>(const long double &)
292  {
293 #ifndef OPENMS_WINDOWSPLATFORM
294  return std::numeric_limits<long double>::digits10;
295 
296 #else
297  return std::numeric_limits<double>::digits10;
298 
299 #endif
300  }
301 
303  template <typename FloatingPointType>
304  inline Int writtenDigits(const FloatingPointType & /* unused */)
305  {
306  // Self-explanatory compile time error!
307  return FloatingPointType::Sorry_but_writtenDigits_is_designed_to_work_for_floating_point_types_only;
308  }
309 
310  // Note: I once tried to move PrecisionWrapper to namespace Internal, but oops! operator << won't be found (through ADL?) anymore.
312  template <typename FloatingPointType>
314  {
316  PrecisionWrapper(const FloatingPointType rhs) :
317  ref_(rhs) {}
319  ref_(rhs.ref_) {}
320  FloatingPointType const ref_;
321 private:
322  PrecisionWrapper(); // intentionally not implemented
323  };
324 
357  template <typename FloatingPointType>
358  inline const PrecisionWrapper<FloatingPointType> precisionWrapper(const FloatingPointType rhs)
359  {
361  }
362 
364  template <typename FloatingPointType>
365  inline std::ostream & operator<<(std::ostream & os, const PrecisionWrapper<FloatingPointType> & rhs)
366  {
367  // Same test as used by isnan(), spelled out here to avoid issues during overload resolution.
368  if (rhs.ref_ != rhs.ref_)
369  {
370  // That's what Linux GCC uses, and gnuplot understands.
371  // Windows would print stuff like 1.#QNAN which makes testing hard.
372  return os << "nan";
373  }
374  else
375  {
376  const std::streamsize prec_save = os.precision();
377  return os << std::setprecision(writtenDigits(FloatingPointType()))
378  << rhs.ref_ << std::setprecision(prec_save);
379  }
380  }
381 
383 
428  template <typename Type>
429  std::string typeAsString(const Type & /* unused */ = Type())
430  {
431 #ifndef OPENMS_COMPILER_GXX
432  return "[ Sorry, OpenMS::typeAsString() relies upon GNU extension __PRETTY_FUNCTION__ ]";
433 
434 #else
435  std::string pretty(__PRETTY_FUNCTION__);
436  static char const context_left[] = "with Type =";
437  static char const context_right[] = "]";
438  size_t left = pretty.find(context_left);
439  left += sizeof(context_left);
440  size_t right = pretty.rfind(context_right);
441  if (right <= left)
442  return pretty; // oops!
443 
444  return pretty.substr(left, right - left);
445 
446 #endif
447  }
448 
449  namespace Internal
450  {
456  extern OPENMS_DLLAPI const char * OpenMS_locale;
457  }
458 
459 } // namespace OpenMS
460 
461 #endif // OPENMS_CONCEPT_TYPES_H
Definition: Types.h:155
float Real
Real type.
Definition: Types.h:109
Int writtenDigits< DataValue >(const DataValue &)
DataValue will be printed like double.
Definition: Types.h:269
Definition: Types.h:168
unsigned int UInt
Unsigned integer type.
Definition: Types.h:92
Definition: Types.h:167
Definition: Types.h:161
Int writtenDigits(const FloatingPointType &=FloatingPointType())
Number of digits commonly used for writing a floating point type (a.k.a. precision). Specializations are defined for float, double, long double.
Definition: Types.h:304
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:151
const char * OpenMS_locale
Definition: Types.h:170
Definition: Types.h:159
Definition: Types.h:156
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:57
Int writtenDigits< float >(const float &)
Number of digits commonly used for writing a float (a.k.a. precision).
Definition: Types.h:226
Definition: Types.h:157
std::string typeAsString(const Type &=Type())
Returns the Type as as std::string.
Definition: Types.h:429
Definition: Types.h:163
Int writtenDigits< int >(const int &)
We do not want to bother people who unintentionally provide an int argument to this.
Definition: Types.h:240
Definition: Types.h:158
Int writtenDigits< long int >(const long int &)
We do not want to bother people who unintentionally provide a long int argument to this...
Definition: Types.h:254
const PrecisionWrapper< FloatingPointType > precisionWrapper(const FloatingPointType rhs)
Wrapper function that sets the appropriate precision for output temporarily. The original precision i...
Definition: Types.h:358
OPENMS_INT32_TYPE Int32
Signed integer type (32bit)
Definition: Types.h:61
ASCII
Definition: Types.h:153
OPENMS_UINT64_TYPE UInt64
Unsigned integer type (64bit)
Definition: Types.h:75
Definition: Types.h:165
Definition: Types.h:166
Definition: Types.h:160
Int writtenDigits< unsigned long int >(const unsigned long int &)
We do not want to bother people who unintentionally provide an unsigned long int argument to this...
Definition: Types.h:261
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:144
Int writtenDigits< unsigned int >(const unsigned int &)
We do not want to bother people who unintentionally provide an unsigned int argument to this...
Definition: Types.h:247
OPENMS_INT64_TYPE Int64
Signed integer type (64bit)
Definition: Types.h:68
OPENMS_BYTE_TYPE Byte
Byte type.
Definition: Types.h:128
PrecisionWrapper(const FloatingPointType rhs)
Constructor. Note: Normally you will prefer to use the &quot;make&quot;-function precisionWrapper(), which see.
Definition: Types.h:316
Definition: Types.h:169
Int writtenDigits< double >(const double &)
Number of digits commonly used for writing a double (a.k.a. precision).
Definition: Types.h:233
Wrapper class to implement output with appropriate precision. See precisionWrapper().
Definition: Types.h:313
int Int
Signed integer type.
Definition: Types.h:100
Int writtenDigits< long double >(const long double &)
Number of digits commonly used for writing a long double (a.k.a. precision). ...
Definition: Types.h:291
time_t Time
Time type.
Definition: Types.h:84
OPENMS_UINT64_TYPE UID
A unique object ID (as unsigned 64bit type).
Definition: Types.h:137
FloatingPointType const ref_
Definition: Types.h:320
Definition: Types.h:162
PrecisionWrapper(const PrecisionWrapper &rhs)
Definition: Types.h:318
double DoubleReal
Double-precision real type.
Definition: Types.h:118

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:23 using doxygen 1.8.5