importer.cpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010-2023 Joel Andersson, Joris Gillis, Moritz Diehl,
6  * KU Leuven. All rights reserved.
7  * Copyright (C) 2011-2014 Greg Horn
8  *
9  * CasADi is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * CasADi is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with CasADi; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 
26 #include "importer.hpp"
27 #include "importer_internal.hpp"
28 
29 namespace casadi {
30 
32  }
33 
34  Importer::Importer(const std::string& name,
35  const std::string& compiler,
36  const Dict& opts) {
37  if (compiler=="none") {
38  own(new ImporterInternal(name));
39  } else if (compiler=="dll") {
40  own(new DllLibrary(name));
41  } else {
42  own(ImporterInternal::getPlugin(compiler).creator(name));
43  }
44  (*this)->construct(opts);
45  }
46 
48  return static_cast<ImporterInternal*>(SharedObject::operator->());
49  }
50 
52  return static_cast<const ImporterInternal*>(SharedObject::operator->());
53  }
54 
56  return dynamic_cast<const ImporterInternal*>(ptr)!=nullptr;
57  }
58 
59  bool Importer::has_plugin(const std::string& name) {
60  return ImporterInternal::has_plugin(name);
61  }
62 
63  void Importer::load_plugin(const std::string& name) {
65  }
66 
67  std::string Importer::doc(const std::string& name) {
68  return ImporterInternal::getPlugin(name).doc;
69  }
70 
71  std::string Importer::plugin_name() const {
72  return (*this)->plugin_name();
73  }
74 
75  bool Importer::has_function(const std::string& symname) const {
76  return (*this)->has_function(symname);
77  }
78 
79  signal_t Importer::get_function(const std::string& symname) {
80  return (*this)->get_function(symname);
81  }
82 
83  bool Importer::has_meta(const std::string& cmd, casadi_int ind) const {
84  return (*this)->has_meta(cmd, ind);
85  }
86 
87  std::string Importer::get_meta(const std::string& cmd, casadi_int ind) const {
88  return (*this)->get_meta(cmd, ind);
89  }
90 
91  bool Importer::inlined(const std::string& symname) const {
92  return (*this)->inlined(symname);
93  }
94 
95  std::string Importer::body(const std::string& symname) const {
96  return (*this)->body(symname);
97  }
98 
99  std::string Importer::library() const {
100  return (*this)->library();
101  }
102 
104  return (*this)->serialize(s);
105  }
106 
109  }
110 
112  Importer ret;
113  ret.own(node);
114  return ret;
115  }
116 
118  Importer ret = create(node);
119  ret->construct(opts);
120  return ret;
121  }
122 
123 } // namespace casadi
Helper class for Serialization.
Dynamically linked library.
SharedObjectInternal * operator->() const
Access a member function or object.
Importer internal class.
void construct(const Dict &opts)
Construct.
static ImporterInternal * deserialize(DeserializingStream &s)
Importer.
Definition: importer.hpp:86
std::string library() const
Get library name.
Definition: importer.cpp:99
static bool test_cast(const SharedObjectInternal *ptr)
Check if a particular cast is allowed.
Definition: importer.cpp:55
std::string body(const std::string &symname) const
Get the function body, if inlined.
Definition: importer.cpp:95
static bool has_plugin(const std::string &name)
Check if a plugin is available.
Definition: importer.cpp:59
void serialize(SerializingStream &s) const
Serialize an object.
Definition: importer.cpp:103
static Importer deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
Definition: importer.cpp:107
Importer()
Default constructor.
Definition: importer.cpp:31
static void load_plugin(const std::string &name)
Explicitly load a plugin dynamically.
Definition: importer.cpp:63
bool has_meta(const std::string &cmd, casadi_int ind=-1) const
Does a meta entry exist?
Definition: importer.cpp:83
static std::string doc(const std::string &name)
Get solver specific documentation.
Definition: importer.cpp:67
std::string get_meta(const std::string &cmd, casadi_int ind=-1) const
Get entry as a text.
Definition: importer.cpp:87
ImporterInternal * operator->()
Access functions of the node.
Definition: importer.cpp:47
bool has_function(const std::string &symname) const
Definition: importer.cpp:75
static Importer create(ImporterInternal *node)
Create from node.
Definition: importer.cpp:111
std::string plugin_name() const
Query plugin name.
Definition: importer.cpp:71
bool inlined(const std::string &symname) const
Check if a function is inlined.
Definition: importer.cpp:91
signal_t get_function(const std::string &symname)
Get a function pointer for numerical evaluation.
Definition: importer.cpp:79
static bool has_plugin(const std::string &pname, bool verbose=false)
Check if a plugin is available or can be loaded.
static Plugin & getPlugin(const std::string &pname)
Load and get the creator function.
static Plugin load_plugin(const std::string &pname, bool register_plugin=true, bool needs_lock=true)
Load a plugin dynamically.
Helper class for Serialization.
The casadi namespace.
Definition: archiver.cpp:28
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
void(* signal_t)(void)
Function pointer types for the C API.