DART  6.7.3
LockableReference.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2019, 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 
90  std::weak_ptr<const void> lockableHolder, Lockable& lockable) noexcept;
91 
92  // Documentation inherited
93  void lock() override;
94 
95  // Documentation inherited
96  bool try_lock() noexcept override;
97 
98  // Documentation inherited
99  void unlock() noexcept override;
100 
101 private:
103  std::weak_ptr<const void> mLockableHolder;
104 
106  Lockable& mLockable;
107 };
108 
116 template <typename LockableT>
118 {
119 public:
120  using Lockable = LockableT;
121 
129  template <typename InputIterator>
131  std::weak_ptr<const void> lockableHolder,
132  InputIterator first,
133  InputIterator last);
134 
135  // Documentation inherited
136  void lock() override;
137 
138  // Documentation inherited
139  bool try_lock() noexcept override;
140 
141  // Documentation inherited
142  void unlock() noexcept override;
143 
144 private:
146  template <typename T>
147  T* ptr(T& obj);
148 
150  template <typename T>
151  T* ptr(T* obj);
152 
154  std::weak_ptr<const void> mLockableHolder;
155 
157  std::vector<Lockable*> mLockables;
158 };
159 
160 } // namespace common
161 } // namespace dart
162 
163 #include "dart/common/detail/LockableReference-impl.hpp"
164 
165 #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:118
LockableT Lockable
Definition: LockableReference.hpp:120
This class references a single lockable.
Definition: LockableReference.hpp:80
LockableT Lockable
Definition: LockableReference.hpp:82
Definition: BulletCollisionDetector.cpp:63
Definition: SharedLibraryManager.hpp:43