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
yarp::os::SharedLibraryClassFactory::create
T * create()
Definition: SharedLibraryClassFactory.h:34
yarp::os::SharedLibraryClassFactory::destroy
void destroy(T *obj) const
Definition: SharedLibraryClassFactory.h:42
yarp::os::SharedLibraryClassFactory::SharedLibraryClassFactory
SharedLibraryClassFactory(const char *dll_name, const char *fn_name=nullptr)
Definition: SharedLibraryClassFactory.h:29
yarp::os::SharedLibraryClassApi::destroy
void(* destroy)(void *obj)
Definition: SharedLibraryClassApi.h:46
yarp::os::SharedLibraryClassFactory::SharedLibraryClassFactory
SharedLibraryClassFactory()=default
yarp::os::SharedLibraryClassFactory
A type-safe wrapper for SharedLibraryFactory, committing to creation/destruction of instances of a pa...
Definition: SharedLibraryClassFactory.h:25
yarp::os::SharedLibraryFactory
A wrapper for a named factory method in a named shared library.
Definition: SharedLibraryFactory.h:31
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
SharedLibraryFactory.h
yarp::os::SharedLibraryClassApi::create
void *(* create)()
Definition: SharedLibraryClassApi.h:45
yarp::os::SharedLibraryFactory::isValid
bool isValid() const
Check if factory is configured and present.
Definition: SharedLibraryFactory.cpp:76
yarp::os::SharedLibraryFactory::getApi
const SharedLibraryClassApi & getApi() const
Get the factory API, which has creation/deletion methods.
Definition: SharedLibraryFactory.cpp:106