YARP
Yet Another Robot Platform
SharedLibraryClassFactory.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef YARP_OS_SHAREDLIBRARYCLASSFACTORY_H
7 #define YARP_OS_SHAREDLIBRARYCLASSFACTORY_H
8 
10 
11 namespace yarp {
12 namespace os {
13 
20 template <class T>
22 {
23 public:
25 
26  SharedLibraryClassFactory(const char* dll_name, const char* fn_name = nullptr) :
27  SharedLibraryFactory(dll_name, fn_name)
28  {
29  }
30 
31  T* create()
32  {
33  if (!isValid()) {
34  return nullptr;
35  }
36  return (T*)getApi().create();
37  }
38 
39  void destroy(T* obj) const
40  {
41  if (!isValid()) {
42  return;
43  }
44  getApi().destroy(obj);
45  }
46 };
47 
48 } // namespace os
49 } // namespace yarp
50 
51 #endif // YARP_OS_SHAREDLIBRARYCLASSFACTORY_H
A type-safe wrapper for SharedLibraryFactory, committing to creation/destruction of instances of a pa...
SharedLibraryClassFactory(const char *dll_name, const char *fn_name=nullptr)
A wrapper for a named factory method in a named shared library.
bool isValid() const
Check if factory is configured and present.
const SharedLibraryClassApi & getApi() const
Get the factory API, which has creation/deletion methods.
The main, catch-all namespace for YARP.
Definition: dirs.h:16