OpenMS
TypeAsString.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- 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>
12 
13 #include <string>
14 
15 namespace OpenMS
16 {
62  template <typename Type>
63  std::string typeAsString(const Type & /* unused */ = Type())
64  {
65 #if ! defined(OPENMS_PRETTY_FUNCTION)
66  return "[ Sorry, OpenMS::typeAsString() relies upon extension OPENMS_PRETTY_FUNCTION ]";
67 #else
68  std::string pretty(OPENMS_PRETTY_FUNCTION);
69  static char const context_left[] = "with Type =";
70  static char const context_right[] = "]";
71  size_t left = pretty.find(context_left);
72  left += sizeof(context_left);
73  size_t right = pretty.rfind(context_right);
74  if (right <= left || right == std::string::npos || left == std::string::npos)
75  return pretty; // different format as expected
76 
77  return pretty.substr(left, right - left);
78 
79 #endif
80  }
81 
82 } // namespace OpenMS
83 
84 
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
std::string typeAsString(const Type &=Type())
Returns the Type as as std::string.
Definition: TypeAsString.h:63