Gazebo Common

API Reference

4.8.1
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 IGNITION_COMMON_PLUGINPTR_HH_
20 #define IGNITION_COMMON_PLUGINPTR_HH_
21 
22 #include <map>
23 #include <string>
24 #include <memory>
25 
26 #include <gz/common/config.hh>
28 
29 namespace ignition
30 {
31  namespace common
32  {
33  // Forward declarations
34  struct PluginInfo;
35  namespace detail { template<class, class> class ComposePlugin; }
36 
53  template <typename PluginType>
54  class TemplatePluginPtr final
55  {
59  public: ~TemplatePluginPtr() = default;
60 
64  public: TemplatePluginPtr();
65 
69  public: TemplatePluginPtr(const TemplatePluginPtr &_other);
70 
77 
86  public: template <typename OtherPluginType>
89 
96 
104  public: template <typename OtherPluginType>
106  const TemplatePluginPtr<OtherPluginType> &_other);
107 
115 
120 
125  public: PluginType *operator ->() const;
126 
130  public: PluginType &operator *() const;
131 
136  public: bool operator ==(const TemplatePluginPtr &_other) const;
137 
145  public: bool operator <(const TemplatePluginPtr &_other) const;
146 
154  public: bool operator >(const TemplatePluginPtr &_other) const;
155 
162  public: bool operator !=(const TemplatePluginPtr &_other) const;
163 
171  public: bool operator <=(const TemplatePluginPtr &_other) const;
172 
180  public: bool operator >=(const TemplatePluginPtr &_other) const;
181 
188  public: std::size_t Hash() const;
189 
193  public: bool IsEmpty() const;
194 
197  public: operator bool() const;
198 
202  public: void Clear();
203 
210  private: explicit TemplatePluginPtr(const PluginInfo *_info);
211 
213  private: std::unique_ptr<PluginType> dataPtr;
214 
215  // Declare friendship
216  friend class PluginLoader;
217  template <class> friend class TemplatePluginPtr;
218  };
219 
223 
227  }
228 }
229 
230 #include "gz/common/detail/PluginPtr.hh"
231 
232 #endif
Class for loading plugins.
Definition: gz/common/PluginLoader.hh:42
This class manages the lifecycle of a plugin instance. It can receive a plugin instance from the igni...
Definition: gz/common/PluginPtr.hh:55
bool operator>(const TemplatePluginPtr &_other) const
Comparison operator.
TemplatePluginPtr(const TemplatePluginPtr &_other)
Copy constructor. This PluginPtr will now point at the same plugin instance as _other,...
TemplatePluginPtr(const TemplatePluginPtr< OtherPluginType > &_other)
Casting constructor. This PluginPtr will now point at the same plugin instance as _other,...
bool operator!=(const TemplatePluginPtr &_other) const
Comparison operator.
bool operator<(const TemplatePluginPtr &_other) const
Comparison operator.
TemplatePluginPtr(TemplatePluginPtr &&_other)
Move constructor. This PluginPtr will take ownership of the plugin instance held by _other....
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...
TemplatePluginPtr & operator=(const TemplatePluginPtr &_other)
Copy assignment operator. This PluginPtr will now point at the same plugin instance as _other,...
bool IsEmpty() const
Check if this PluginPtr is holding a plugin instance.
friend class TemplatePluginPtr
Definition: gz/common/PluginPtr.hh:217
void Clear()
Clears the Plugin instance from this PluginPtr. IsEmpty() will return true after this is used,...
PluginType & operator*() const
Get a reference to the wrapper for the plugin instance that is being managed by this PluginPtr.
bool operator==(const TemplatePluginPtr &_other) const
Comparison operator. Returns true if this Plugin is holding the same plugin instance as _other,...
bool operator<=(const TemplatePluginPtr &_other) const
Comparison operator.
TemplatePluginPtr()
Default constructor. Creates a PluginPtr object that does not point to any plugin instance....
bool operator>=(const TemplatePluginPtr &_other) const
Comparison operator.
PluginType * operator->() const
Access the wrapper for the plugin instance and call one of its member functions.
Forward declarations for the common classes.
Holds info required to construct a plugin.
Definition: gz/common/PluginInfo.hh:41