YARP
Yet Another Robot Platform
SharedLibraryClassFactory.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_OS_SHAREDLIBRARYCLASSFACTORY_H
10 #define YARP_OS_SHAREDLIBRARYCLASSFACTORY_H
11 
13 
14 namespace yarp {
15 namespace os {
16 
23 template <class T>
25 {
26 public:
28 
29  SharedLibraryClassFactory(const char* dll_name, const char* fn_name = nullptr) :
30  SharedLibraryFactory(dll_name, fn_name)
31  {
32  }
33 
34  T* create()
35  {
36  if (!isValid()) {
37  return nullptr;
38  }
39  return (T*)getApi().create();
40  }
41 
42  void destroy(T* obj) const
43  {
44  if (!isValid()) {
45  return;
46  }
47  getApi().destroy(obj);
48  }
49 };
50 
51 } // namespace os
52 } // namespace yarp
53 
54 #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: environment.h:18