Gazebo Common

API Reference

3.17.0
gz/common/PluginPtr.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 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 
19 #ifndef GZ_COMMON_PLUGINPTR_HH_
20 #define GZ_COMMON_PLUGINPTR_HH_
21 
22 #include <map>
23 #include <string>
24 #include <memory>
25 
26 #include "gz/common/Plugin.hh"
27 
28 namespace ignition
29 {
30  namespace common
31  {
32  // Forward declarations
33  struct PluginInfo;
34  namespace detail { template<class, class> class ComposePlugin; }
35 
52  template <typename PluginType>
53  class TemplatePluginPtr final
54  {
58  public: ~TemplatePluginPtr() = default;
59 
63  public: TemplatePluginPtr();
64 
68  public: TemplatePluginPtr(const TemplatePluginPtr &_other);
69 
75  public: TemplatePluginPtr(TemplatePluginPtr &&_other);
76 
85  public: template <typename OtherPluginType>
88 
94  public: TemplatePluginPtr &operator =(const TemplatePluginPtr &_other);
95 
103  public: template <typename OtherPluginType>
105  const TemplatePluginPtr<OtherPluginType> &_other);
106 
114 
119 
124  public: PluginType *operator ->() const;
125 
129  public: PluginType &operator *() const;
130 
135  public: bool operator ==(const TemplatePluginPtr &_other) const;
136 
144  public: bool operator <(const TemplatePluginPtr &_other) const;
145 
153  public: bool operator >(const TemplatePluginPtr &_other) const;
154 
161  public: bool operator !=(const TemplatePluginPtr &_other) const;
162 
170  public: bool operator <=(const TemplatePluginPtr &_other) const;
171 
179  public: bool operator >=(const TemplatePluginPtr &_other) const;
180 
187  public: std::size_t Hash() const;
188 
192  public: bool IsEmpty() const;
193 
196  public: operator bool() const;
197 
201  public: void Clear();
202 
209  private: explicit TemplatePluginPtr(const PluginInfo *_info);
210 
212  private: std::unique_ptr<PluginType> dataPtr;
213 
214  // Declare friendship
215  friend class PluginLoader;
216  template <class> friend class TemplatePluginPtr;
217  };
218 
222 
226  }
227 }
228 
229 #include "gz/common/detail/PluginPtr.hh"
230 
231 #endif
bool operator>=(const TemplatePluginPtr &_other) const
Comparison operator.
friend class TemplatePluginPtr
Definition: gz/common/PluginPtr.hh:216
bool operator<=(const TemplatePluginPtr &_other) const
Comparison operator.
Forward declarations for the common classes.
bool operator!=(const TemplatePluginPtr &_other) const
Comparison operator.
bool operator==(const TemplatePluginPtr &_other) const
Comparison operator. Returns true if this Plugin is holding the same plugin instance as _other,...
Class for loading plugins.
Definition: gz/common/PluginLoader.hh:40
bool operator>(const TemplatePluginPtr &_other) const
Comparison operator.
std::size_t Hash() const
Produces a hash for the plugin instance that this PluginPtr is holding. This function allows PluginPt...
~TemplatePluginPtr()=default
Destructor. Deletes this PluginPtr's reference to the plugin instance. Once all PluginPtrs that refer...
void Clear()
Clears the Plugin instance from this PluginPtr. IsEmpty() will return true after this is used,...
Holds info required to construct a plugin.
Definition: gz/common/PluginInfo.hh:38
PluginType & operator*() const
Get a reference to the wrapper for the plugin instance that is being managed by this PluginPtr.
TemplatePluginPtr & operator=(const TemplatePluginPtr &_other)
Copy assignment operator. This PluginPtr will now point at the same plugin instance as _other,...
bool operator<(const TemplatePluginPtr &_other) const
Comparison operator.
bool IsEmpty() const
Check if this PluginPtr is holding a plugin instance.
PluginType * operator->() const
Access the wrapper for the plugin instance and call one of its member functions.
This class manages the lifecycle of a plugin instance. It can receive a plugin instance from the igni...
Definition: gz/common/PluginPtr.hh:53