List of all members | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions
casadi::DllLibrary Class Reference

Dynamically linked library. More...

#include <importer_internal.hpp>

Detailed Description

Author
Joel Andersson
Date
2016

Extra doc: https://github.com/casadi/casadi/wiki/L_21i

Definition at line 187 of file importer_internal.hpp.

Inheritance diagram for casadi::DllLibrary:
Inheritance graph
[legend]
Collaboration diagram for casadi::DllLibrary:
Collaboration graph
[legend]

Public Types

typedef ImporterInternal *(* Creator) (const std::string &name)
 
using weak_ref_type = WeakRefInternal
 
typedef int(* RegFcn) (Plugin *plugin)
 

Public Member Functions

 DllLibrary (const std::string &bin_name)
 
void finalize () override
 
void init_handle ()
 
 ~DllLibrary () override
 
std::string class_name () const override
 Get type name. More...
 
signal_t get_function (const std::string &symname) override
 Get a function pointer for numerical evaluation. More...
 
std::string library () const override
 Get library name. More...
 
bool can_have_meta () const override
 Can meta information be read? More...
 
void disp (std::ostream &stream, bool more) const override
 Print. More...
 
void construct (const Dict &opts)
 Construct. More...
 
virtual void init (const Dict &opts)
 Initialize. More...
 
const char * plugin_name () const override
 Queery plugin name. More...
 
bool has_function (const std::string &symname) const
 Get a function pointer for numerical evaluation. More...
 
bool has_meta (const std::string &cmd, casadi_int ind=-1) const
 Does an entry exist? More...
 
std::string get_meta (const std::string &cmd, casadi_int ind=-1) const
 Get entry as a text. More...
 
void read_meta (std::istream &file, casadi_int &offset)
 Get meta information. More...
 
void read_external (const std::string &sym, bool inlined, std::istream &file, casadi_int &offset)
 Get an external function declaration. More...
 
bool inlined (const std::string &symname) const
 
std::string body (const std::string &symname) const
 Get the function body, if inlined. More...
 
std::string to_text (const std::string &cmd, casadi_int ind=-1) const
 Get entry as a text. More...
 
void serialize (SerializingStream &s) const
 
virtual void serialize_type (SerializingStream &s) const
 
virtual void serialize_body (SerializingStream &s) const
 
casadi_int getCount () const
 Get the reference count. More...
 
std::string debug_repr (const SharedObjectInternal *) const
 
GenericWeakRef< SharedObject, SharedObjectInternal > * weak ()
 Get a weak reference to the object. More...
 

Static Public Member Functions

static ImporterInternaldeserialize (DeserializingStream &s)
 
static std::string shortname ()
 Short name. More...
 
static std::string indexed (const std::string &cmd, casadi_int ind)
 
static bool has_plugin (const std::string &pname, bool verbose=false)
 Check if a plugin is available or can be loaded. More...
 
static const Optionsplugin_options (const std::string &pname)
 Get the plugin options. More...
 
static Deserialize plugin_deserialize (const std::string &pname)
 Get the plugin deserialize_map. More...
 
static Plugin pluginFromRegFcn (RegFcn regfcn)
 Instantiate a Plugin struct from a factory function. More...
 
static Plugin load_plugin (const std::string &pname, bool register_plugin=true, bool needs_lock=true)
 Load a plugin dynamically. More...
 
static handle_t load_library (const std::string &libname, std::string &resultpath, bool global)
 Load a library dynamically. More...
 
static void registerPlugin (const Plugin &plugin, bool needs_lock=true)
 Register an integrator in the factory. More...
 
static void registerPlugin (RegFcn regfcn, bool needs_lock=true)
 Register an integrator in the factory. More...
 
static Plugin & getPlugin (const std::string &pname)
 Load and get the creator function. More...
 
static ImporterInternalinstantiate (const std::string &fname, const std::string &pname, Problem problem)
 

Public Attributes

std::string name_
 C filename. More...
 
std::map< std::string, std::pair< casadi_int, std::string > > meta_
 Meta data. More...
 
std::map< std::string, std::pair< bool, std::string > > external_
 External functions. More...
 
bool verbose_
 Verbose – for debugging purposes. More...
 

Static Public Attributes

static std::map< std::string, Plugin > solvers_
 Collection of solvers. More...
 
static const std::string infix_ = "importer"
 Infix. More...
 

Protected Member Functions

 DllLibrary (DeserializingStream &s)
 
void initSingleton ()
 
void destroySingleton ()
 
shared_from_this ()
 Get a shared object from the current internal object. More...
 
const B shared_from_this () const
 Get a shared object from the current internal object. More...
 
virtual const Optionsget_options () const
 Options. More...
 
static const Options options_
 Options. More...
 

Member Typedef Documentation

◆ Creator

typedef ImporterInternal*(* casadi::ImporterInternal::Creator) (const std::string &name)
inherited

Definition at line 66 of file importer_internal.hpp.

◆ RegFcn

typedef int(* casadi::PluginInterface< ImporterInternal >::RegFcn) (Plugin *plugin)
inherited

Definition at line 73 of file plugin_interface.hpp.

◆ weak_ref_type

Definition at line 152 of file shared_object.hpp.

Constructor & Destructor Documentation

◆ DllLibrary() [1/2]

casadi::DllLibrary::DllLibrary ( const std::string &  bin_name)
explicit

Definition at line 224 of file importer_internal.cpp.

225  : ImporterInternal(bin_name), handle_(nullptr) {
226 
227  }
ImporterInternal(const std::string &name)
Constructor.

Referenced by deserialize().

◆ ~DllLibrary()

casadi::DllLibrary::~DllLibrary ( )
override

Definition at line 257 of file importer_internal.cpp.

257  {
258 #ifdef WITH_DL
259  if (handle_) close_shared_library(handle_);
260 #endif // WITH_DL
261  }

◆ DllLibrary() [2/2]

casadi::DllLibrary::DllLibrary ( DeserializingStream s)
inlineexplicitprotected

Definition at line 225 of file importer_internal.hpp.

225 : ImporterInternal(s) {}

Member Function Documentation

◆ body()

std::string casadi::ImporterInternal::body ( const std::string &  symname) const
inherited

Definition at line 301 of file importer_internal.cpp.

301  {
302  auto it = external_.find(symname);
303  casadi_assert_dev(it!=external_.end() && it->second.first);
304  return it->second.second;
305  }
std::map< std::string, std::pair< bool, std::string > > external_
External functions.

References casadi::ImporterInternal::external_.

◆ can_have_meta()

bool casadi::DllLibrary::can_have_meta ( ) const
inlineoverridevirtual

Reimplemented from casadi::ImporterInternal.

Definition at line 220 of file importer_internal.hpp.

220 { return false;}

◆ class_name()

std::string casadi::DllLibrary::class_name ( ) const
inlineoverridevirtual

Extra doc: https://github.com/casadi/casadi/wiki/L_21j

Reimplemented from casadi::ImporterInternal.

Definition at line 211 of file importer_internal.hpp.

211 { return "DllLibrary";}

◆ construct()

void casadi::ImporterInternal::construct ( const Dict opts)
inherited

Prepares the function for evaluation

Extra doc: https://github.com/casadi/casadi/wiki/L_21b

Definition at line 57 of file importer_internal.cpp.

57  {
58  // Sanitize dictionary is needed
59  if (!Options::is_sane(opts)) {
60  // Call recursively
61  return construct(Options::sanitize(opts));
62  }
63 
64  // Make sure all options exist
65  get_options().check(opts);
66 
67  // Initialize object
68  init(opts);
69 
70  // Revisit class hierarchy in reverse order
71  finalize();
72  }
virtual void init(const Dict &opts)
Initialize.
void construct(const Dict &opts)
Construct.
virtual const Options & get_options() const
Options.
static bool is_sane(const Dict &opts)
Is the dictionary sane.
Definition: options.cpp:169
static Dict sanitize(const Dict &opts, bool top_level=true)
Sanitize a options dictionary.
Definition: options.cpp:173
void check(const Dict &opts) const
Check if options exist.
Definition: options.cpp:240

References casadi::Options::check(), casadi::ImporterInternal::finalize(), casadi::ImporterInternal::get_options(), casadi::ImporterInternal::init(), casadi::Options::is_sane(), and casadi::Options::sanitize().

Referenced by casadi::Importer::create().

◆ debug_repr()

std::string casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::debug_repr ( const Internal *  i) const
inherited

Definition at line 62 of file generic_shared_internal.hpp.

162  {
163  // Note: i != this because of something something multiple inheritance
164  return str( (casadi_int)(i)) + "/" + static_cast<const Internal*>(this)->class_name();
165  }
std::string str(const T &v)
String representation, any type.

◆ deserialize()

ImporterInternal * casadi::DllLibrary::deserialize ( DeserializingStream s)
static

Definition at line 344 of file importer_internal.cpp.

344  {
345  DllLibrary* ret = new DllLibrary(s);
346  ret->finalize();
347  return ret;
348  }
DllLibrary(const std::string &bin_name)

References DllLibrary(), and finalize().

Referenced by casadi::ImporterInternal::deserialize().

◆ destroySingleton()

void casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::destroySingleton ( )
inlineprotectedinherited

Called in the destructor of singletons

Definition at line 77 of file generic_shared_internal.hpp.

77  {
78  static_cast<Internal*>(this)->count--;
79  }

◆ disp()

void casadi::ImporterInternal::disp ( std::ostream &  stream,
bool  more 
) const
overridevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_21a

Implements casadi::SharedObjectInternal.

Definition at line 38 of file importer_internal.cpp.

38  {
39  }

◆ finalize()

void casadi::DllLibrary::finalize ( )
overridevirtual

Reimplemented from casadi::ImporterInternal.

Definition at line 253 of file importer_internal.cpp.

253  {
254  init_handle();
255  }

References init_handle().

Referenced by deserialize().

◆ get_function()

signal_t casadi::DllLibrary::get_function ( const std::string &  symname)
overridevirtual

Reimplemented from casadi::ImporterInternal.

Definition at line 263 of file importer_internal.cpp.

263  {
264 #ifdef WITH_DL
265 #ifdef _WIN32
266 #if __GNUC__
267 #pragma GCC diagnostic push
268 #pragma GCC diagnostic ignored "-Wcast-function-type"
269 #endif
270  return reinterpret_cast<signal_t>(GetProcAddress(handle_, TEXT(sym.c_str())));
271 #if __GNUC__
272 #pragma GCC diagnostic pop
273 #endif
274 #else // _WIN32
275  signal_t fcnPtr = reinterpret_cast<signal_t>(dlsym(handle_, sym.c_str()));
276  if (dlerror()) {
277  fcnPtr=nullptr;
278  dlerror(); // Reset error flags
279  }
280  return fcnPtr;
281 #endif // _WIN32
282 #endif // WITH_DL
283  }
void(* signal_t)(void)
Function pointer types for the C API.

◆ get_meta()

std::string casadi::ImporterInternal::get_meta ( const std::string &  cmd,
casadi_int  ind = -1 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_21f

Definition at line 285 of file importer_internal.cpp.

285  {
286  if (ind>=0) return get_meta(indexed(cmd, ind));
287  casadi_assert(has_meta(cmd), "No such command: " + cmd);
288  return meta_.at(cmd).second;
289  }
std::map< std::string, std::pair< casadi_int, std::string > > meta_
Meta data.
std::string get_meta(const std::string &cmd, casadi_int ind=-1) const
Get entry as a text.
bool has_meta(const std::string &cmd, casadi_int ind=-1) const
Does an entry exist?
static std::string indexed(const std::string &cmd, casadi_int ind)

References casadi::ImporterInternal::has_meta(), casadi::ImporterInternal::indexed(), and casadi::ImporterInternal::meta_.

◆ get_options()

virtual const Options& casadi::ImporterInternal::get_options ( ) const
inlinevirtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_21c

Reimplemented in casadi::ShellCompiler, and casadi::ClangCompiler.

Definition at line 80 of file importer_internal.hpp.

80 { return options_;}
static const Options options_
Options.

Referenced by casadi::ImporterInternal::construct().

◆ getCount()

Definition at line 60 of file generic_shared_internal.hpp.

186  {
187  return static_cast<const Internal*>(this)->count;
188  }

◆ getPlugin()

PluginInterface< ImporterInternal >::Plugin & casadi::PluginInterface< ImporterInternal >::getPlugin ( const std::string &  pname)
staticinherited

Definition at line 102 of file plugin_interface.hpp.

291  {
292 
293 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
294  std::lock_guard<std::mutex> lock(Derived::mutex_solvers_);
295 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
296 
297  // Check if the solver has been loaded
298  auto it=Derived::solvers_.find(pname);
299 
300  // Load the solver if needed
301  if (it==Derived::solvers_.end()) {
302  load_plugin(pname, true, false);
303  it=Derived::solvers_.find(pname);
304  }
305  casadi_assert_dev(it!=Derived::solvers_.end());
306  return it->second;
307  }
static Plugin load_plugin(const std::string &pname, bool register_plugin=true, bool needs_lock=true)
Load a plugin dynamically.

◆ has_function()

bool casadi::ImporterInternal::has_function ( const std::string &  symname) const
inherited

Definition at line 216 of file importer_internal.cpp.

216  {
217  // Check if in meta information
218  if (external_.find(symname)!=external_.end()) return true;
219 
220  // Convert to a dummy function pointer
221  return const_cast<ImporterInternal*>(this)->get_function(symname)!=nullptr;
222  }
virtual signal_t get_function(const std::string &symname)
Get a function pointer for numerical evaluation.

References casadi::ImporterInternal::external_, and casadi::ImporterInternal::get_function().

◆ has_meta()

bool casadi::ImporterInternal::has_meta ( const std::string &  cmd,
casadi_int  ind = -1 
) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_21e

Definition at line 291 of file importer_internal.cpp.

291  {
292  if (ind>=0) return has_meta(indexed(cmd, ind));
293  return meta_.find(cmd) != meta_.end();
294  }

References casadi::ImporterInternal::indexed(), and casadi::ImporterInternal::meta_.

Referenced by casadi::ImporterInternal::get_meta().

◆ has_plugin()

bool casadi::PluginInterface< ImporterInternal >::has_plugin ( const std::string &  pname,
bool  verbose = false 
)
staticinherited

Definition at line 76 of file plugin_interface.hpp.

131  {
132 
133 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
134  std::lock_guard<std::mutex> lock(Derived::mutex_solvers_);
135 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
136 
137  // Quick return if available
138  if (Derived::solvers_.find(pname) != Derived::solvers_.end()) {
139  return true;
140  }
141 
142  // Try loading the plugin
143  try {
144  (void)load_plugin(pname, false, false);
145  return true;
146  } catch (CasadiException& ex) {
147  if (verbose) {
148  casadi_warning(ex.what());
149  }
150  return false;
151  }
152  }
std::vector< casadi_int > find(const std::vector< T > &v)
find nonzeros

◆ indexed()

static std::string casadi::ImporterInternal::indexed ( const std::string &  cmd,
casadi_int  ind 
)
inlinestaticinherited

Convert indexed command

Definition at line 150 of file importer_internal.hpp.

150  {
151  std::stringstream ss;
152  ss << cmd << "[" << ind << "]";
153  return ss.str();
154  }

Referenced by casadi::ImporterInternal::get_meta(), and casadi::ImporterInternal::has_meta().

◆ init()

void casadi::ImporterInternal::init ( const Dict opts)
virtualinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_21d

Reimplemented in casadi::ShellCompiler, and casadi::ClangCompiler.

Definition at line 74 of file importer_internal.cpp.

74  {
75  // Read meta information from file
76  if (can_have_meta()) {
77  casadi_int offset = 0;
78  auto file_ptr = Filesystem::ifstream_ptr(name_);
79  std::istream& file = *file_ptr;
80 
81  std::string line;
82  while (getline(file, line)) {
83  // Update offset
84  offset++;
85 
86  // Try to find a /*CASADIMETA delimiter
87  std::string cmd = "/*CASADIMETA";
88  size_t pos = line.find(cmd);
89  if (pos != std::string::npos) {
90  read_meta(file, offset);
91  continue;
92  }
93 
94  // Try to find a /*CASADIEXTERNAL delimiter
95  cmd = "/*CASADIEXTERNAL";
96  pos = line.find(cmd);
97  if (pos != std::string::npos) {
98  std::istringstream ss(line.substr(pos+cmd.size()));
99  // Read name
100  std::string sym;
101  ss >> sym;
102  casadi_assert_dev(ss.good());
103  // Default attributes
104  bool inlined = false;
105 
106  // Read attributes: FIXME(@jaeandersson): Hacky
107  size_t eqpos = line.find('=', pos+cmd.size());
108  if (eqpos != std::string::npos) {
109  std::string attr = "inline";
110  if (line.compare(eqpos-attr.size(), attr.size(), attr)==0) {
111  casadi_assert_dev(line.size()>eqpos+1);
112  if (line.at(eqpos+1)=='1') {
113  inlined=true;
114  } else {
115  casadi_assert_dev(line.at(eqpos+1)=='0');
116  }
117  }
118  }
119 
120  read_external(sym, inlined, file, offset);
121  continue;
122  }
123  }
124  }
125 
126  // Read options
127  for (auto&& op : opts) {
128  if (op.first=="verbose") {
129  verbose_ = op.second;
130  }
131  }
132  }
static std::unique_ptr< std::istream > ifstream_ptr(const std::string &path, std::ios_base::openmode mode=std::ios_base::in, bool fail=true)
Definition: filesystem.cpp:135
void read_meta(std::istream &file, casadi_int &offset)
Get meta information.
bool verbose_
Verbose – for debugging purposes.
bool inlined(const std::string &symname) const
virtual bool can_have_meta() const
Can meta information be read?
void read_external(const std::string &sym, bool inlined, std::istream &file, casadi_int &offset)
Get an external function declaration.
std::string name_
C filename.

References casadi::ImporterInternal::can_have_meta(), casadi::Filesystem::ifstream_ptr(), casadi::ImporterInternal::inlined(), casadi::ImporterInternal::name_, casadi::ImporterInternal::read_external(), casadi::ImporterInternal::read_meta(), and casadi::ImporterInternal::verbose_.

Referenced by casadi::ImporterInternal::construct(), casadi::ClangCompiler::init(), and casadi::ShellCompiler::init().

◆ init_handle()

void casadi::DllLibrary::init_handle ( )

Definition at line 229 of file importer_internal.cpp.

229  {
230 
231  std::vector<std::string> search_paths = get_search_paths();
232 
234  std::string dir = Filesystem::parent_path(name_);
235  // Does search path already contain the directory?
236  for (const std::string& path : search_paths) {
237  if (path==dir) {
238  dir = "";
239  break;
240  }
241  }
242  // Add directory to search path
243  if (!dir.empty()) search_paths.push_back(dir);
244  }
245 
246 #ifdef WITH_DL
247  handle_ = open_shared_library(name_, search_paths, "DllLibrary::init_handle");
248 #else // WITH_DL
249  casadi_error("CommonExternal: WITH_DL not activated");
250 #endif // WITH_DL
251  }
static bool has_parent_path(const std::string &path)
Definition: filesystem.cpp:53
static std::string parent_path(const std::string &path)
Definition: filesystem.cpp:58
static bool is_enabled()
Definition: filesystem.cpp:83
std::vector< std::string > get_search_paths()
Definition: casadi_os.cpp:67
std::vector< casadi_int > path(const std::vector< casadi_int > &map, casadi_int i_start)

References casadi::get_search_paths(), casadi::Filesystem::has_parent_path(), casadi::Filesystem::is_enabled(), casadi::ImporterInternal::name_, casadi::Filesystem::parent_path(), and casadi::path().

Referenced by finalize().

◆ initSingleton()

void casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::initSingleton ( )
inlineprotectedinherited

Called in the constructor of singletons to avoid that the counter reaches zero

Definition at line 71 of file generic_shared_internal.hpp.

71  {
72  casadi_assert_dev(static_cast<Internal*>(this)->count==0);
73  static_cast<Internal*>(this)->count++;
74  }

◆ inlined()

bool casadi::ImporterInternal::inlined ( const std::string &  symname) const
inherited

Definition at line 296 of file importer_internal.cpp.

296  {
297  auto it = external_.find(symname);
298  return it!=external_.end() && it->second.first;
299  }

References casadi::ImporterInternal::external_.

Referenced by casadi::ImporterInternal::init(), and casadi::ImporterInternal::read_external().

◆ instantiate()

ImporterInternal * casadi::PluginInterface< ImporterInternal >::instantiate ( const std::string &  fname,
const std::string &  pname,
Problem  problem 
)
staticinherited

Definition at line 106 of file plugin_interface.hpp.

313  {
314 
315  // Assert the plugin exists (needed for adaptors)
316  if (!has_plugin(pname, true)) {
317  casadi_error("Plugin '" + pname + "' is not found.");
318  }
319  return getPlugin(pname).creator(fname, problem);
320  }
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.

◆ library()

std::string casadi::DllLibrary::library ( ) const
overridevirtual

Reimplemented from casadi::ImporterInternal.

Definition at line 350 of file importer_internal.cpp.

350  {
351  return name_;
352  }

References casadi::ImporterInternal::name_.

◆ load_library()

handle_t casadi::PluginInterface< ImporterInternal >::load_library ( const std::string &  libname,
std::string &  resultpath,
bool  global 
)
staticinherited

Definition at line 92 of file plugin_interface.hpp.

184  {
185 
186 #ifndef WITH_DL
187  casadi_error("WITH_DL option needed for dynamic loading");
188 #else // WITH_DL
189 
190  // Get the name of the shared library
191  std::string lib = SHARED_LIBRARY_PREFIX + libname + SHARED_LIBRARY_SUFFIX;
192 
193  // Build up search paths;
194  std::vector<std::string> search_paths = get_search_paths();
195  return open_shared_library(lib, search_paths, resultpath,
196  "PluginInterface::load_plugin", global);
197 
198 #endif // WITH_DL
199  }

◆ load_plugin()

PluginInterface< ImporterInternal >::Plugin casadi::PluginInterface< ImporterInternal >::load_plugin ( const std::string &  pname,
bool  register_plugin = true,
bool  needs_lock = true 
)
staticinherited

Definition at line 88 of file plugin_interface.hpp.

204  {
205 
206 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
207  casadi::conditional_lock_guard<std::mutex> lock(Derived::mutex_solvers_, needs_lock);
208 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
209 
210  // Issue warning and quick return if already loaded
211  if (Derived::solvers_.find(pname) != Derived::solvers_.end()) {
212  casadi_warning("PluginInterface: Solver " + pname + " is already in use. Ignored.");
213  return Plugin();
214  }
215 
216  // Logger singletons are lazily instantiated on first uout()/uerr() calls
217  // This instantation may lead to a data race with potential instatiations in plugin
218  // To be safe, trigger instantatin before any plugin loading
219  uout();
220  uerr();
221 
222 #ifndef WITH_DL
223  casadi_error("WITH_DL option needed for dynamic loading");
224 #else // WITH_DL
225  // Retrieve the registration function
226  RegFcn reg;
227 
228  // Load the dll
229  std::string regName = "casadi_register_" + Derived::infix_ + "_" + pname;
230 
231  std::string searchpath;
232  handle_t handle = load_library("casadi_" + Derived::infix_ + "_" + pname, searchpath,
233  false);
234 
235 #ifdef _WIN32
236 
237 #if __GNUC__
238 #pragma GCC diagnostic push
239 #pragma GCC diagnostic ignored "-Wcast-function-type"
240 #endif
241  reg = reinterpret_cast<RegFcn>(GetProcAddress(handle, TEXT(regName.c_str())));
242 #if __GNUC__
243 #pragma GCC diagnostic pop
244 #endif
245 
246 #else // _WIN32
247  // Reset error
248  dlerror();
249 
250  // Load creator
251  reg = reinterpret_cast<RegFcn>(dlsym(handle, regName.c_str()));
252 #endif // _WIN32
253  casadi_assert(reg!=nullptr,
254  "PluginInterface::load_plugin: no \"" + regName + "\" found in " + searchpath + ".");
255 
256  // Create a temporary struct
257  Plugin plugin = pluginFromRegFcn(reg);
258  // Register the plugin
259  if (register_plugin) {
260  registerPlugin(plugin, false);
261  }
262 
263  return plugin;
264 
265 #endif // WITH_DL
266  }
static handle_t load_library(const std::string &libname, std::string &resultpath, bool global)
Load a library dynamically.
static Plugin pluginFromRegFcn(RegFcn regfcn)
Instantiate a Plugin struct from a factory function.
static void registerPlugin(const Plugin &plugin, bool needs_lock=true)
Register an integrator in the factory.
std::ostream & uerr()
std::ostream & uout()

◆ plugin_deserialize()

Deserialize casadi::PluginInterface< ImporterInternal >::plugin_deserialize ( const std::string &  pname)
staticinherited

Definition at line 82 of file plugin_interface.hpp.

162  {
163  Deserialize m = getPlugin(pname).deserialize;
164  casadi_assert(m, "Plugin \"" + pname + "\" does not support deserialize");
165  return m;
166  }
ProtoFunction *(* Deserialize)(DeserializingStream &)

◆ plugin_name()

const char* casadi::ImporterInternal::plugin_name ( ) const
inlineoverridevirtualinherited

Implements casadi::PluginInterface< ImporterInternal >.

Reimplemented in casadi::ShellCompiler, and casadi::ClangCompiler.

Definition at line 107 of file importer_internal.hpp.

107 { return "none";}

◆ plugin_options()

const Options & casadi::PluginInterface< ImporterInternal >::plugin_options ( const std::string &  pname)
staticinherited

Definition at line 79 of file plugin_interface.hpp.

155  {
156  const Options *op = getPlugin(pname).options;
157  casadi_assert(op!=nullptr, "Plugin \"" + pname + "\" does not support options");
158  return *op;
159  }

◆ pluginFromRegFcn()

PluginInterface< ImporterInternal >::Plugin casadi::PluginInterface< ImporterInternal >::pluginFromRegFcn ( RegFcn  regfcn)
staticinherited

Definition at line 85 of file plugin_interface.hpp.

170  {
171  // Create a temporary struct
172  Plugin plugin;
173 
174  // Set the fields
175  int flag = regfcn(&plugin);
176  casadi_assert(flag==0, "Registration of plugin failed.");
177 
178  return plugin;
179  }

◆ read_external()

void casadi::ImporterInternal::read_external ( const std::string &  sym,
bool  inlined,
std::istream &  file,
casadi_int &  offset 
)
inherited

Definition at line 181 of file importer_internal.cpp.

182  {
183  // New entry
184  std::stringstream ss;
185 
186  // Are we still in the function declaration
187  bool in_declaration = true;
188 
189  // Loop over the lines
190  std::string line;
191  while (getline(file, line)) {
192  offset++;
193 
194  // Skip line if still in declaration
195  if (in_declaration) {
196  size_t stop = line.find('{');
197  if (stop != std::string::npos) in_declaration = false;
198  continue;
199  }
200 
201  // End of declaration found?
202  if (line.find("/*CASADIEXTERNAL") != std::string::npos) {
203  auto new_el = external_.insert(std::make_pair(sym, std::make_pair(inlined, ss.str())));
204  casadi_assert(new_el.second, "Duplicate symbol: \"" + sym + "\"");
205  return;
206  }
207 
208  // Add to entry
209  if (inlined) {
210  ss << line << std::endl;
211  }
212  }
213  casadi_error("End-of-file reached while searching for \"/*CASADIEXTERNAL\"");
214  }

References casadi::ImporterInternal::external_, and casadi::ImporterInternal::inlined().

Referenced by casadi::ImporterInternal::init().

◆ read_meta()

void casadi::ImporterInternal::read_meta ( std::istream &  file,
casadi_int &  offset 
)
inherited

Definition at line 134 of file importer_internal.cpp.

134  {
135  // Loop over the lines
136  std::string line;
137  while (getline(file, line)) {
138  offset++;
139 
140  // End of meta found?
141  if (line.find("*/") != std::string::npos) return;
142 
143  // If comment or empty line, skip
144  if (line.empty() || line.at(0)=='#') continue;
145 
146  // Get command string
147  casadi_assert(line.at(0)==':',
148  "Syntax error: " + line + " is not a command string");
149  std::string cmd = line.substr(1, line.find(' ')-1);
150 
151  // New entry
152  std::stringstream ss;
153 
154  // Collect the meta data
155  line = line.substr(cmd.size()+2);
156  while (true) {
157  // Find the backslash, if any
158  size_t stop = line.find('\\');
159 
160  // Add to entry
161  ss << line.substr(0, stop);
162 
163  // Break if not multiline
164  if (stop == std::string::npos) break;
165 
166  // Read another line
167  ss << std::endl;
168  if (!getline(file, line)) {
169  casadi_error("Failed to read \"" + cmd + "\"");
170  }
171  offset++;
172  }
173 
174  // Insert new element in map
175  auto new_el = meta_.insert(std::make_pair(cmd, std::make_pair(offset, ss.str())));
176  casadi_assert(new_el.second, "Duplicate entry: \"" + cmd + "\"");
177  }
178  casadi_error("End-of-file reached while searching for \"*/\"");
179  }

References casadi::ImporterInternal::meta_.

Referenced by casadi::ImporterInternal::init().

◆ registerPlugin() [1/2]

void casadi::PluginInterface< ImporterInternal >::registerPlugin ( const Plugin &  plugin,
bool  needs_lock = true 
)
staticinherited

Definition at line 96 of file plugin_interface.hpp.

274  {
275 
276 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
277  casadi::conditional_lock_guard<std::mutex> lock(Derived::mutex_solvers_, needs_lock);
278 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
279 
280  // Check if the solver name is in use
281  typename std::map<std::string, Plugin>::iterator it=Derived::solvers_.find(plugin.name);
282  casadi_assert(it==Derived::solvers_.end(),
283  "Solver " + str(plugin.name) + " is already in use");
284 
285  // Add to list of solvers
286  Derived::solvers_[plugin.name] = plugin;
287  }

◆ registerPlugin() [2/2]

void casadi::PluginInterface< ImporterInternal >::registerPlugin ( RegFcn  regfcn,
bool  needs_lock = true 
)
staticinherited

Definition at line 99 of file plugin_interface.hpp.

269  {
270  registerPlugin(pluginFromRegFcn(regfcn), needs_lock);
271  }

◆ serialize()

void casadi::ImporterInternal::serialize ( SerializingStream s) const
inherited

Definition at line 311 of file importer_internal.cpp.

311  {
312  serialize_type(s);
313  serialize_body(s);
314  }
virtual void serialize_body(SerializingStream &s) const
virtual void serialize_type(SerializingStream &s) const

References casadi::ImporterInternal::serialize_body(), and casadi::ImporterInternal::serialize_type().

◆ serialize_body()

void casadi::ImporterInternal::serialize_body ( SerializingStream s) const
virtualinherited

Definition at line 320 of file importer_internal.cpp.

320  {
321  s.version("ImporterInternal", 1);
322  s.pack("ImporterInternal::name", name_);
323  s.pack("ImporterInternal::meta", meta_);
324  s.pack("ImporterInternal::external", external_);
325  }

References casadi::ImporterInternal::external_, casadi::ImporterInternal::meta_, casadi::ImporterInternal::name_, casadi::SerializingStream::pack(), and casadi::SerializingStream::version().

Referenced by casadi::ImporterInternal::serialize().

◆ serialize_type()

void casadi::ImporterInternal::serialize_type ( SerializingStream s) const
virtualinherited

Definition at line 316 of file importer_internal.cpp.

316  {
317  s.pack("ImporterInternal::type", class_name());
318  }
std::string class_name() const override
Get type name.

References casadi::ImporterInternal::class_name(), and casadi::SerializingStream::pack().

Referenced by casadi::ImporterInternal::serialize().

◆ shared_from_this() [1/2]

B casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::shared_from_this ( )
inlineprotectedinherited

Definition at line 83 of file generic_shared_internal.hpp.

83  {
84  casadi_assert_dev(B::test_cast(static_cast<Internal*>(this)));
85  B ret;
86  ret.own(static_cast<Internal*>(this));
87  return ret;
88  }

◆ shared_from_this() [2/2]

const B casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::shared_from_this ( ) const
inlineprotectedinherited

Definition at line 92 of file generic_shared_internal.hpp.

92  {
93  casadi_assert_dev(B::test_cast(static_cast<const Internal*>(this)));
94  B ret;
95  ret.own(const_cast<Internal*>(static_cast<const Internal*>(this)));
96  return ret;
97  }

◆ shortname()

static std::string casadi::ImporterInternal::shortname ( )
inlinestaticinherited

Definition at line 104 of file importer_internal.hpp.

104 { return "importer";}

◆ to_text()

std::string casadi::ImporterInternal::to_text ( const std::string &  cmd,
casadi_int  ind = -1 
) const
inherited

◆ weak()

Extra doc: https://github.com/casadi/casadi/wiki/L_1ai

Definition at line 67 of file generic_shared_internal.hpp.

191  {
192  if (weak_ref_==nullptr) {
193  weak_ref_ = new GenericWeakRef<Shared, Internal>(static_cast<Internal*>(this));
194  }
195  return weak_ref_;
196  }

Member Data Documentation

◆ external_

std::map<std::string, std::pair<bool, std::string> > casadi::ImporterInternal::external_
inherited

◆ infix_

const std::string casadi::ImporterInternal::infix_ = "importer"
staticinherited

Definition at line 101 of file importer_internal.hpp.

◆ meta_

std::map<std::string, std::pair<casadi_int, std::string> > casadi::ImporterInternal::meta_
inherited

◆ name_

std::string casadi::ImporterInternal::name_
inherited

◆ options_

const Options casadi::ImporterInternal::options_
staticinherited
Initial value:
= {{},
{{"verbose",
"Verbose evaluation -- for debugging"}}
}
}

Extra doc: https://github.com/casadi/casadi/wiki/L_21c

Definition at line 79 of file importer_internal.hpp.

◆ solvers_

std::map< std::string, ImporterInternal::Plugin > casadi::ImporterInternal::solvers_
staticinherited

Definition at line 94 of file importer_internal.hpp.

◆ verbose_

bool casadi::ImporterInternal::verbose_
inherited

The documentation for this class was generated from the following files: