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