DART  6.10.1
LockableReference.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2021, The DART development contributors
3  * All rights reserved.
4  *
5  * The list of contributors can be found at:
6  * https://github.com/dartsim/dart/blob/master/LICENSE
7  *
8  * This file is provided under the following "BSD-style" License:
9  * Redistribution and use in source and binary forms, with or
10  * without modification, are permitted provided that the following
11  * conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef DART_COMMON_LOCKABLEREFERENCE_HPP_
34 #define DART_COMMON_LOCKABLEREFERENCE_HPP_
35 
36 #include <memory>
37 #include <vector>
38 
39 namespace dart {
40 namespace common {
41 
50 {
51 public:
53  constexpr LockableReference() noexcept = default;
54 
56  virtual ~LockableReference() = default;
57 
61  virtual void lock() = 0;
62 
65  virtual bool try_lock() noexcept = 0;
66 
68  virtual void unlock() noexcept = 0;
69 
70 protected:
73 };
74 
78 template <typename LockableT>
80 {
81 public:
82  using Lockable = LockableT;
83 
91  std::weak_ptr<const void> lockableHolder, Lockable& lockable) noexcept;
92 
93  // Documentation inherited
94  void lock() override;
95 
96  // Documentation inherited
97  bool try_lock() noexcept override;
98 
99  // Documentation inherited
100  void unlock() noexcept override;
101 
102 private:
104  std::weak_ptr<const void> mLockableHolder;
105 
107  Lockable& mLockable;
108 };
109 
117 template <typename LockableT>
119 {
120 public:
121  using Lockable = LockableT;
122 
130  template <typename InputIterator>
132  std::weak_ptr<const void> lockableHolder,
133  InputIterator first,
134  InputIterator last);
135 
136  // Documentation inherited
137  void lock() override;
138 
139  // Documentation inherited
140  bool try_lock() noexcept override;
141 
142  // Documentation inherited
143  void unlock() noexcept override;
144 
145 private:
147  template <typename T>
148  T* ptr(T& obj);
149 
151  template <typename T>
152  T* ptr(T* obj);
153 
155  std::weak_ptr<const void> mLockableHolder;
156 
158  std::vector<Lockable*> mLockables;
159 };
160 
161 } // namespace common
162 } // namespace dart
163 
164 #include "dart/common/detail/LockableReference-impl.hpp"
165 
166 #endif // DART_COMMON_LOCKABLEREFERENCE_HPP_
LockableReference is a wrapper class of single or multiple Lockable object(s) to provide unified inte...
Definition: LockableReference.hpp:50
virtual void lock()=0
Locks lockable that this class references; blocks if one of the lockables are not avaliable.
constexpr LockableReference() noexcept=default
Default construtor.
virtual void unlock() noexcept=0
Unlocks the lockables.
virtual bool try_lock() noexcept=0
Tries to lock the lockables that this class references; returns false if one of the lockables is not ...
MultiLockableReference references multiple lockables.
Definition: LockableReference.hpp:119
LockableT Lockable
Definition: LockableReference.hpp:121
This class references a single lockable.
Definition: LockableReference.hpp:80
LockableT Lockable
Definition: LockableReference.hpp:82
Definition: BulletCollisionDetector.cpp:65
Definition: SharedLibraryManager.hpp:46