Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef OPENMS_CONCEPT_TYPES_H
00036 #define OPENMS_CONCEPT_TYPES_H
00037
00038 #include <OpenMS/config.h>
00039
00040 #include <limits>
00041 #include <cstddef>
00042 #include <ctime>
00043 #include <cmath>
00044 #include <string>
00045 #include <iostream>
00046 #include <iomanip>
00047
00048
00049
00050 #ifdef OPENMS_HAS_STDINT_H
00051 #include <stdint.h>
00052 #endif
00053
00054 namespace OpenMS
00055 {
00061 typedef OPENMS_INT32_TYPE Int32;
00062
00068 typedef OPENMS_INT64_TYPE Int64;
00069
00075 typedef OPENMS_UINT64_TYPE UInt64;
00076
00084 typedef time_t Time;
00085
00091
00092 typedef unsigned int UInt;
00093
00099
00100 typedef int Int;
00101
00109 typedef float Real;
00110
00118 typedef double DoubleReal;
00119
00120
00128 typedef OPENMS_BYTE_TYPE Byte;
00129
00137 typedef OPENMS_UINT64_TYPE UID;
00138
00144 typedef size_t Size;
00145
00151 typedef ptrdiff_t SignedSize;
00152
00153 enum ASCII
00154 {
00155 ASCII__BACKSPACE = '\b',
00156 ASCII__BELL = '\a',
00157 ASCII__CARRIAGE_RETURN = '\r',
00158 ASCII__HORIZONTAL_TAB = '\t',
00159 ASCII__NEWLINE = '\n',
00160 ASCII__RETURN = ASCII__NEWLINE,
00161 ASCII__SPACE = ' ',
00162 ASCII__TAB = ASCII__HORIZONTAL_TAB,
00163 ASCII__VERTICAL_TAB = '\v',
00164
00165 ASCII__COLON = ':',
00166 ASCII__COMMA = ',',
00167 ASCII__EXCLAMATION_MARK = '!',
00168 ASCII__POINT = '.',
00169 ASCII__QUESTION_MARK = '?',
00170 ASCII__SEMICOLON = ';'
00171 };
00172
00215
00216
00221 template <typename FloatingPointType>
00222 inline Int writtenDigits(const FloatingPointType & = FloatingPointType());
00223
00225 template <>
00226 inline Int writtenDigits<float>(const float &)
00227 {
00228 return std::numeric_limits<float>::digits10;
00229 }
00230
00232 template <>
00233 inline Int writtenDigits<double>(const double &)
00234 {
00235 return std::numeric_limits<double>::digits10;
00236 }
00237
00239 template <>
00240 inline Int writtenDigits<int>(const int &)
00241 {
00242 return std::numeric_limits<int>::digits10;
00243 }
00244
00246 template <>
00247 inline Int writtenDigits<unsigned int>(const unsigned int &)
00248 {
00249 return std::numeric_limits<unsigned int>::digits10;
00250 }
00251
00253 template <>
00254 inline Int writtenDigits<long int>(const long int &)
00255 {
00256 return std::numeric_limits<int>::digits10;
00257 }
00258
00260 template <>
00261 inline Int writtenDigits<unsigned long int>(const unsigned long int &)
00262 {
00263 return std::numeric_limits<unsigned int>::digits10;
00264 }
00265
00266 class DataValue;
00268 template <>
00269 inline Int writtenDigits<DataValue>(const DataValue &)
00270 {
00271 return std::numeric_limits<double>::digits10;
00272 }
00273
00274
00275
00276
00277
00278
00279
00290 template <>
00291 inline Int writtenDigits<long double>(const long double &)
00292 {
00293 #ifndef OPENMS_WINDOWSPLATFORM
00294 return std::numeric_limits<long double>::digits10;
00295
00296 #else
00297 return std::numeric_limits<double>::digits10;
00298
00299 #endif
00300 }
00301
00303 template <typename FloatingPointType>
00304 inline Int writtenDigits(const FloatingPointType & )
00305 {
00306
00307 return FloatingPointType::Sorry_but_writtenDigits_is_designed_to_work_for_floating_point_types_only;
00308 }
00309
00310
00312 template <typename FloatingPointType>
00313 struct PrecisionWrapper
00314 {
00316 PrecisionWrapper(const FloatingPointType rhs) :
00317 ref_(rhs) {}
00318 PrecisionWrapper(const PrecisionWrapper & rhs) :
00319 ref_(rhs.ref_) {}
00320 FloatingPointType const ref_;
00321 private:
00322 PrecisionWrapper();
00323 };
00324
00357 template <typename FloatingPointType>
00358 inline const PrecisionWrapper<FloatingPointType> precisionWrapper(const FloatingPointType rhs)
00359 {
00360 return PrecisionWrapper<FloatingPointType>(rhs);
00361 }
00362
00364 template <typename FloatingPointType>
00365 inline std::ostream & operator<<(std::ostream & os, const PrecisionWrapper<FloatingPointType> & rhs)
00366 {
00367
00368 if (rhs.ref_ != rhs.ref_)
00369 {
00370
00371
00372 return os << "nan";
00373 }
00374 else
00375 {
00376 const std::streamsize prec_save = os.precision();
00377 return os << std::setprecision(writtenDigits(FloatingPointType()))
00378 << rhs.ref_ << std::setprecision(prec_save);
00379 }
00380 }
00381
00383
00428 template <typename Type>
00429 std::string typeAsString(const Type & = Type())
00430 {
00431 #ifndef OPENMS_COMPILER_GXX
00432 return "[ Sorry, OpenMS::typeAsString() relies upon GNU extension __PRETTY_FUNCTION__ ]";
00433
00434 #else
00435 std::string pretty(__PRETTY_FUNCTION__);
00436 static char const context_left[] = "with Type =";
00437 static char const context_right[] = "]";
00438 size_t left = pretty.find(context_left);
00439 left += sizeof(context_left);
00440 size_t right = pretty.rfind(context_right);
00441 if (right <= left)
00442 return pretty;
00443
00444 return pretty.substr(left, right - left);
00445
00446 #endif
00447 }
00448
00449 namespace Internal
00450 {
00456 extern OPENMS_DLLAPI const char * OpenMS_locale;
00457 }
00458
00459 }
00460
00461 #endif // OPENMS_CONCEPT_TYPES_H