CppADCodeGen 2.4.3
A C++ Algorithmic Differentiation Package with Source Code Generation
Loading...
Searching...
No Matches
linux_dynamiclib_model.hpp
1#ifndef CPPAD_CG_LINUX_DYNAMICLIB_MODEL_INCLUDED
2#define CPPAD_CG_LINUX_DYNAMICLIB_MODEL_INCLUDED
3/* --------------------------------------------------------------------------
4 * CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
5 * Copyright (C) 2012 Ciengis
6 * Copyright (C) 2018 Joao Leal
7 *
8 * CppADCodeGen is distributed under multiple licenses:
9 *
10 * - Eclipse Public License Version 1.0 (EPL1), and
11 * - GNU General Public License Version 3 (GPL3).
12 *
13 * EPL1 terms and conditions can be found in the file "epl-v10.txt", while
14 * terms and conditions for the GPL3 can be found in the file "gpl3.txt".
15 * ----------------------------------------------------------------------------
16 * Author: Joao Leal
17 */
18#if CPPAD_CG_SYSTEM_LINUX
19
20#include <typeinfo>
21#include <dlfcn.h>
22
23namespace CppAD {
24namespace cg {
25
32template<class Base>
33class LinuxDynamicLibModel : public FunctorGenericModel<Base> {
34protected:
36 LinuxDynamicLib<Base>* _dynLib;
37
38public:
39
40 virtual ~LinuxDynamicLibModel() {
41 if (_dynLib != nullptr) {
42 _dynLib->destroyed(this);
43 }
44 }
45
46protected:
47
53 LinuxDynamicLibModel(LinuxDynamicLib<Base>* dynLib, const std::string& name) :
54 FunctorGenericModel<Base>(name),
55 _dynLib(dynLib) {
56
57 CPPADCG_ASSERT_UNKNOWN(_dynLib != nullptr);
58
59 this->init();
60 }
61
62 LinuxDynamicLibModel(const LinuxDynamicLibModel&) = delete;
63 LinuxDynamicLibModel& operator=(const LinuxDynamicLibModel&) = delete;
64
65 void* loadFunction(const std::string& functionName, bool required = true) override {
66 return _dynLib->loadFunction(functionName, required);
67 }
68
69 void modelLibraryClosed() override {
70 _dynLib = nullptr;
71 FunctorGenericModel<Base>::modelLibraryClosed();
72 }
73
74 friend class LinuxDynamicLib<Base>;
75};
76
77} // END cg namespace
78} // END CppAD namespace
79
80#endif
81#endif