Gazebo Utils

API Reference

1.5.1
gz/utils/ImplPtr.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #ifndef GZ_UTILS__IMPLPTR_HH_
19 #define GZ_UTILS__IMPLPTR_HH_
20 
21 #include <memory>
22 #include <utility>
23 
24 #include <gz/utils/config.hh>
25 #include <gz/utils/detail/DefaultOps.hh>
27 #include <gz/utils/Export.hh>
28 
29 namespace ignition
30 {
31  namespace utils
32  {
72  template <class T,
73  class Deleter = void (*)(T*),
74  class Operations = detail::CopyMoveDeleteOperations<T> >
75  class ImplPtr
76  {
85  public: template <class U, class D, class Ops>
86  ImplPtr(U *_ptr, D &&_deleter, Ops &&_ops);
87 
90  public: ImplPtr(const ImplPtr &_other);
91 
95  public: ImplPtr &operator=(const ImplPtr &_other);
96 
97  // We explicitly declare the move constructor to make it clear that it is
98  // available.
99  public: ImplPtr(ImplPtr &&) = default;
100 
101  // We explicitly declare the move assignment operator to make it clear
102  // that it is available.
103  public: ImplPtr &operator=(ImplPtr &&) = default;
104 
106  public: ~ImplPtr() = default;
107 
112  public: T &operator*();
113 
118  public: const T &operator*() const;
119 
124  public: T *operator->();
125 
130  public: const T *operator->() const;
131 
136  public: T *Get();
137 
142  public: const T *Get() const;
143 
152  private: ImplPtr Clone() const;
153 
155  private: std::unique_ptr<T, Deleter> ptr;
156 
158  private: Operations ops;
159  };
160 
184  template <class T, typename... Args>
185  ImplPtr<T> MakeImpl(Args &&..._args);
186 
201  template <class T, class Deleter = void (*)(T*)>
203 
227  template <class T, typename... Args>
228  UniqueImplPtr<T> MakeUniqueImpl(Args &&..._args);
229  } // namespace utils
230 } // namespace ignition
231 
234 #define IGN_UTILS_IMPL_PTR_FWD(ImplementationClass, memberName) \
235  IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING \
236  private: ::ignition::utils::ImplPtr<ImplementationClass> memberName; \
237  IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
238 
241 #define IGN_UTILS_UNIQUE_IMPL_PTR_FWD(ImplementationClass, memberName) \
242  IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING \
243  private: ::ignition::utils::UniqueImplPtr<ImplementationClass> memberName; \
244  IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
245 
248 #define IGN_UTILS_IMPL_PTR(memberName) \
249  public: class Implementation; \
250  IGN_UTILS_IMPL_PTR_FWD(Implementation, memberName)
251 
254 #define IGN_UTILS_UNIQUE_IMPL_PTR(memberName) \
255  public: class Implementation; \
256  IGN_UTILS_UNIQUE_IMPL_PTR_FWD(Implementation, memberName)
257 
258 
259 #include <gz/utils/detail/ImplPtr.hh>
260 
261 #endif // GZ_UTILS__IMPLPTR_HH_
Definition: gz/utils/Environment.hh:26
UniqueImplPtr< T > MakeUniqueImpl(Args &&..._args)
Pass this to the constructor of a UniqueImplPtr object to easily initialize it. All the arguments pas...
The ImplPtr class provides a convenient away to achieve the Rule of Zero while keeping all the benefi...
Definition: gz/utils/ImplPtr.hh:75
ImplPtr< T > MakeImpl(Args &&..._args)
Pass this to the constructor of an ImplPtr object to easily initialize it. All the arguments passed i...
STL class.