Ardour  9.0-pre0-582-g084a23a80d
comparable_shared_ptr.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Sakari Bergen <sakari.bergen@beatwaves.net>
3  * Copyright (C) 2013 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2014 John Emmas <john@creativepost.co.uk>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #pragma once
22 
24 
25 #include <boost/operators.hpp>
26 
27 #include <memory>
28 
29 namespace ARDOUR {
30 
31 template<typename T>
32 class /*LIBARDOUR_API*/ ComparableSharedPtr : public std::shared_ptr<T>
33  , public boost::less_than_comparable<ComparableSharedPtr<T> >
34 {
35  public:
37  template<class Y>
38  explicit ComparableSharedPtr (Y * p) : std::shared_ptr<T> (p) {}
39 
40  template<class Y, class D>
41  ComparableSharedPtr (Y * p, D d) : std::shared_ptr<T> (p, d) {}
42 
43  template<class Y, class D, class A>
44  ComparableSharedPtr (Y * p, D d, A a) : std::shared_ptr<T> (p, d, a) {}
45 
46  ComparableSharedPtr (ComparableSharedPtr const & r) : std::shared_ptr<T> (r) {}
47 
49  std::shared_ptr<T>(r).swap(*this);
50  return *this;
51  }
52 
53  template<class Y>
54  ComparableSharedPtr(ComparableSharedPtr<Y> const & r) : std::shared_ptr<T> (r) {}
55 
56  template<class Y>
57  ComparableSharedPtr(ComparableSharedPtr<Y> const & r, T * p) : std::shared_ptr<T> (r, p) {}
58 
59  template<class Y>
60  bool operator< (ComparableSharedPtr<Y> const & other) const { return **this < *other; }
61 };
62 
63 
64 } // namespace ARDOUR
65 
ComparableSharedPtr(ComparableSharedPtr< Y > const &r)
ComparableSharedPtr(ComparableSharedPtr const &r)
ComparableSharedPtr(ComparableSharedPtr< Y > const &r, T *p)
bool operator<(ComparableSharedPtr< Y > const &other) const
ComparableSharedPtr & operator=(ComparableSharedPtr const &r)