OpenMS
Helpers.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: Hannes Roest $
6 // $Authors: Hannes Roest $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 #include <vector>
12 #include <boost/shared_ptr.hpp>
13 
14 namespace OpenMS
15 {
16  namespace Helpers
17  {
18 
22  template <class T>
23  const std::vector<boost::shared_ptr<const T> >&
24  constifyPointerVector(const std::vector<boost::shared_ptr<T> >& vec)
25  {
26  return reinterpret_cast<const std::vector<boost::shared_ptr<const T> >&>(vec);
27  }
28 
29 
33  template <class PtrType>
34  inline bool cmpPtrSafe(const PtrType& a, const PtrType& b)
35  {
36  // We are not interested whether the pointers are equal but whether the
37  // contents are equal
38  if (a == nullptr && b == nullptr)
39  {
40  return true;
41  }
42  else if (a == nullptr || b == nullptr)
43  {
44  return false; // one is null the other is not
45  }
46  else
47  {
48  // compare the internal object
49  return (*a == *b);
50  }
51  }
52 
56  template <class ContainerType>
57  inline bool cmpPtrContainer(const ContainerType& a, const ContainerType& b)
58  {
59  if (a.size() != b.size()) return false;
60 
61  // check that all elements of a and b are equal using safe comparison
62  // (taking NULL into account)
63  for (typename ContainerType::size_type i = 0; i < a.size(); i++)
64  {
65  if (!cmpPtrSafe(a[i], b[i]))
66  {
67  return false;
68  }
69  }
70  return true;
71  }
72 
73  }
74 }
75 
76 
bool cmpPtrSafe(const PtrType &a, const PtrType &b)
Helper comparing two pointers for equality (taking NULL into account)
Definition: Helpers.h:34
const std::vector< boost::shared_ptr< const T > > & constifyPointerVector(const std::vector< boost::shared_ptr< T > > &vec)
Helper function to add constness to a vector of shared pointers.
Definition: Helpers.h:24
bool cmpPtrContainer(const ContainerType &a, const ContainerType &b)
Helper function to compare two pointer-containers for equality of all elements.
Definition: Helpers.h:57
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19