Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

Types.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Oliver Kohlbacher $
00032 // $Authors: Marc Sturm, Clemens Groepl $
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> // for size_t
00042 #include <ctime>
00043 #include <cmath>
00044 #include <string>
00045 #include <iostream>
00046 #include <iomanip>
00047 
00048 // If possible use the ISO C99-compliant header stdint.h
00049 // to define the portable integer types.
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   //typedef size_t UInt;
00092   typedef unsigned int UInt;
00093 
00099   //typedef OPENMS_SIZE_T_SIGNED Int;
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 & /* unused */ = 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   META-COMMENT:  DO NOT INTRODUCE ANY LINEBREAKS BELOW IN
00276   "<code>std::numeric_limits<long double>::digits10 == 18</code>".
00277   The doxygen parser (version 1.5.5) will get confused!  (Clemens)
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 & /* unused */)
00305   {
00306     // Self-explanatory compile time error!
00307     return FloatingPointType::Sorry_but_writtenDigits_is_designed_to_work_for_floating_point_types_only;
00308   }
00309 
00310   // Note: I once tried to move PrecisionWrapper to namespace Internal, but oops! operator <<  won't be found (through ADL?) anymore.
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();     // intentionally not implemented
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     // Same test as used by isnan(), spelled out here to avoid issues during overload resolution.
00368     if (rhs.ref_ != rhs.ref_)
00369     {
00370       // That's what Linux GCC uses, and gnuplot understands.
00371       // Windows would print stuff like 1.#QNAN which makes testing hard.
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 & /* unused */ = 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;                      // oops!
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 } // namespace OpenMS
00460 
00461 #endif // OPENMS_CONCEPT_TYPES_H

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:46 using doxygen 1.7.1