OpenMS
ListUtilsIO.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, 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: Stephan Aiche $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
12 
13 #include <iterator>
14 #include <ostream>
15 #include <vector>
16 
17 // This header collects io relevant parts of ListUtils. Separating the from the
18 // rest avoids inclusion of ostream headers in a lot of classes.
19 
20 namespace OpenMS
21 {
28  template <typename T>
29  inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& v)
30  {
31  os << "[";
32 
33  if (!v.empty())
34  {
35  for (auto it = v.begin(); it < v.end() - 1; ++it)
36  { // convert to String manually, since this is much faster than ostream build-in conversion;
37  // If T is a String, the compiler will (hopefully) elide the copy
38  os << String(*it) << ", ";
39  }
40  os << String(v.back());
41  }
42 
43  os << "]";
44  return os;
45  }
46 
47  template<typename T>
49  {
50  const std::vector<T>& value;
51  VecLowPrecision(const std::vector<T>& v) : value(v) {}
52  };
55  template <typename T>
56  inline std::ostream& operator<<(std::ostream& os, const VecLowPrecision<T>& val)
57  {
58  os << "[";
59  const auto& v = val.value;
60  if (!v.empty())
61  {
62  for (auto it = v.begin(); it < v.end() - 1; ++it)
63  { // convert to String manually, since this is much faster than ostreams build-in conversion;
64  os << String(*it, false) << ", ";
65  }
66  os << String(v.back(), false);
67  }
68 
69  os << "]";
70  return os;
71  }
72 
74  template <typename TString>
75  inline std::vector<String>& operator<<(std::vector<String>& sl, const TString& string)
76  {
77  sl.push_back(string);
78  return sl;
79  }
80 
81 }
82 
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)
Definition: ListUtilsIO.h:49
const std::vector< T > & value
Definition: ListUtilsIO.h:50
VecLowPrecision(const std::vector< T > &v)
Definition: ListUtilsIO.h:51