List of all members | Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes
casadi::Archiver Class Referenceabstract

Archiver interface. More...

#include <archiver_impl.hpp>

Detailed Description

Zip and unzip archives without a core dependency

Author
Joris Gillis
Date
2025

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

Definition at line 47 of file archiver_impl.hpp.

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

Classes

struct  Exposed
 

Public Types

typedef bool(* Unpack) (const std::string &src, const std::string &target_dir)
 
typedef bool(* UnpackFromStringStream) (std::stringstream &src, const std::string &target_dir)
 
typedef bool(* Pack) (const std::string &src_dir, const std::string &path)
 
typedef bool(* PackToStream) (const std::string &src_dir, std::ostream &src)
 
typedef bool(* PackEntries) (const std::vector< std::pair< std::string, std::string > > &entries, const std::string &path)
 
typedef Archiver *(* Creator) ()
 
typedef int(* RegFcn) (Plugin *plugin)
 

Public Member Functions

virtual const char * plugin_name () const=0
 
virtual void deps_version_check (const std::string &stage) const
 
void serialize_type (SerializingStream &s) const
 Serialize type information. More...
 

Static Public Member Functions

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 Archiverinstantiate (const std::string &fname, const std::string &pname, Problem problem)
 
static ProtoFunctiondeserialize (DeserializingStream &s)
 Deserialize with type disambiguation. More...
 

Static Public Attributes

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

Member Typedef Documentation

◆ Creator

typedef Archiver*(* casadi::Archiver::Creator) ()

Definition at line 64 of file archiver_impl.hpp.

◆ Pack

typedef bool(* casadi::Archiver::Pack) (const std::string &src_dir, const std::string &path)

Definition at line 54 of file archiver_impl.hpp.

◆ PackEntries

typedef bool(* casadi::Archiver::PackEntries) (const std::vector< std::pair< std::string, std::string > > &entries, const std::string &path)

Definition at line 59 of file archiver_impl.hpp.

◆ PackToStream

typedef bool(* casadi::Archiver::PackToStream) (const std::string &src_dir, std::ostream &src)

Definition at line 56 of file archiver_impl.hpp.

◆ RegFcn

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

Definition at line 73 of file plugin_interface.hpp.

◆ Unpack

typedef bool(* casadi::Archiver::Unpack) (const std::string &src, const std::string &target_dir)

Definition at line 50 of file archiver_impl.hpp.

◆ UnpackFromStringStream

typedef bool(* casadi::Archiver::UnpackFromStringStream) (std::stringstream &src, const std::string &target_dir)

Definition at line 52 of file archiver_impl.hpp.

Member Function Documentation

◆ deps_version_check()

virtual void casadi::PluginInterface< Archiver >::deps_version_check ( const std::string &  stage) const
inlinevirtualinherited

Definition at line 112 of file plugin_interface.hpp.

112 {}

◆ deserialize()

static ProtoFunction* casadi::PluginInterface< Archiver >::deserialize ( DeserializingStream s)
inlinestaticinherited

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

Definition at line 124 of file plugin_interface.hpp.

124  {
125  std::string class_name, plugin_name;
126  s.unpack("PluginInterface::plugin_name", plugin_name);
128  return deserialize(s);
129  }
static Deserialize plugin_deserialize(const std::string &pname)
Get the plugin deserialize_map.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
virtual const char * plugin_name() const=0
ProtoFunction *(* Deserialize)(DeserializingStream &)

◆ getPlugin()

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

Definition at line 102 of file plugin_interface.hpp.

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

◆ has_plugin()

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

Definition at line 76 of file plugin_interface.hpp.

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

◆ instantiate()

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

Definition at line 106 of file plugin_interface.hpp.

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

◆ load_library()

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

Definition at line 92 of file plugin_interface.hpp.

187  {
188 
189 #ifndef WITH_DL
190  casadi_error("WITH_DL option needed for dynamic loading");
191 #else // WITH_DL
192 
193  // Get the name of the shared library
194  std::string lib = std::string(CasadiMeta::shared_library_prefix()) + libname +
195  CasadiMeta::shared_library_suffix();
196 
197  // Build up search paths;
198  std::vector<std::string> search_paths = get_search_paths();
199  return open_shared_library(lib, search_paths, resultpath,
200  "PluginInterface::load_plugin", global);
201 
202 #endif // WITH_DL
203  }
std::vector< std::string > get_search_paths()
Definition: casadi_os.cpp:79

◆ load_plugin()

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

Definition at line 88 of file plugin_interface.hpp.

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

◆ plugin_deserialize()

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

Definition at line 82 of file plugin_interface.hpp.

165  {
166  Deserialize m = getPlugin(pname).deserialize;
167  casadi_assert(m, "Plugin \"" + pname + "\" does not support deserialize");
168  return m;
169  }

◆ plugin_name()

virtual const char* casadi::PluginInterface< Archiver >::plugin_name ( ) const
pure virtualinherited

◆ plugin_options()

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

Definition at line 79 of file plugin_interface.hpp.

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

◆ pluginFromRegFcn()

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

Definition at line 85 of file plugin_interface.hpp.

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

◆ registerPlugin() [1/2]

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

Definition at line 96 of file plugin_interface.hpp.

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

◆ registerPlugin() [2/2]

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

Definition at line 99 of file plugin_interface.hpp.

273  {
274  registerPlugin(pluginFromRegFcn(regfcn), needs_lock);
275  }

◆ serialize_type()

void casadi::PluginInterface< Archiver >::serialize_type ( SerializingStream s) const
inlineinherited

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

Definition at line 117 of file plugin_interface.hpp.

117  {
118  s.pack("PluginInterface::plugin_name", std::string(plugin_name()));
119  }

Member Data Documentation

◆ infix_

const std::string casadi::Archiver::infix_ = "archiver"
static

Definition at line 85 of file archiver_impl.hpp.

◆ meta_doc

const std::string casadi::Archiver::meta_doc
static

Definition at line 66 of file archiver_impl.hpp.

◆ solvers_

std::map< std::string, Archiver::Plugin > casadi::Archiver::solvers_
static

Definition at line 78 of file archiver_impl.hpp.


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