Ignition Common

API Reference

3.6.1
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 
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>
104  TemplatePluginPtr &operator =(
105  const TemplatePluginPtr<OtherPluginType> &_other);
106 
113  public: TemplatePluginPtr &operator =(TemplatePluginPtr &&_other);
114 
118  public: TemplatePluginPtr &operator =(std::nullptr_t);
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 "ignition/common/detail/PluginPtr.hh"
230 
231 #endif
This class manages the lifecycle of a plugin instance. It can receive a plugin instance from the Plug...
Definition: PluginPtr.hh:53
Class for loading plugins.
Definition: PluginLoader.hh:40
Holds info required to construct a plugin.
Definition: PluginInfo.hh:38
Forward declarations for the common classes.