Gazebo Common

API Reference

4.7.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 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 
76  public: TemplatePluginPtr(TemplatePluginPtr &&_other);
77 
86  public: template <typename OtherPluginType>
89 
95  public: TemplatePluginPtr &operator =(const TemplatePluginPtr &_other);
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
bool operator>=(const TemplatePluginPtr &_other) const
Comparison operator.
friend class TemplatePluginPtr
Definition: gz/common/PluginPtr.hh:217
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:41
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:40
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:54