OpenMS
Loading...
Searching...
No Matches
PrecisionWrapper.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg $
6// $Authors: Marc Sturm, Clemens Groepl $
7// --------------------------------------------------------------------------
8
9#pragma once
10
11#include <OpenMS/config.h>
14#include <iostream>
15
16namespace OpenMS
17{
18
22 template <typename FloatingPointType>
24 {
26 explicit PrecisionWrapper(const FloatingPointType rhs) :
27 ref_(rhs) {}
29 ref_(rhs.ref_) {}
30 FloatingPointType const ref_;
31private:
32 PrecisionWrapper(); // intentionally not implemented
33 };
34
68 template <typename FloatingPointType>
69 inline const PrecisionWrapper<FloatingPointType> precisionWrapper(const FloatingPointType rhs)
70 {
72 }
73
75 template <typename FloatingPointType>
76 inline std::ostream & operator<<(std::ostream & os, const PrecisionWrapper<FloatingPointType> & rhs)
77 {
78 // manual conversion to String is much faster than ostreams internal conversion
79 // (this calls the correct overload for extra precision)
80 String s(rhs.ref_, true);
81 os << s;
82 return os;
83 }
84} // namespace OpenMS
85
A more convenient string class.
Definition String.h:34
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
const PrecisionWrapper< FloatingPointType > precisionWrapper(const FloatingPointType rhs)
Wrapper function that sets the appropriate precision for output temporarily. The original precision i...
Definition PrecisionWrapper.h:69
Wrapper class to implement output with appropriate precision. See precisionWrapper().
Definition PrecisionWrapper.h:24
FloatingPointType const ref_
Definition PrecisionWrapper.h:30
PrecisionWrapper(const FloatingPointType rhs)
Constructor. Note: Normally you will prefer to use the "make"-function precisionWrapper(),...
Definition PrecisionWrapper.h:26
PrecisionWrapper(const PrecisionWrapper &rhs)
Definition PrecisionWrapper.h:28