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

#include <xml_file_internal.hpp>

Detailed Description

Definition at line 35 of file xml_file_internal.hpp.

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

Classes

struct  Exposed
 

Public Types

typedef XmlFileInternal *(* Creator) ()
 
using weak_ref_type = WeakRefInternal
 
typedef int(* RegFcn) (Plugin *plugin)
 

Public Member Functions

 XmlFileInternal ()
 
 ~XmlFileInternal () override
 
void disp (std::ostream &stream, bool more=false) const override
 Print a description. More...
 
virtual XmlNode parse (const std::string &filename)
 
virtual void dump (const std::string &filename, const XmlNode &node)
 
virtual std::string class_name () const =0
 Readable name of the internal class. More...
 
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...
 
virtual const char * plugin_name () const=0
 
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 XmlFileInternalinstantiate (const std::string &fname, const std::string &pname, Problem problem)
 
static ProtoFunctiondeserialize (DeserializingStream &s)
 Deserialize with type disambiguation. More...
 

Static Public Attributes

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

Protected Member Functions

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...
 

Member Typedef Documentation

◆ Creator

typedef XmlFileInternal*(* casadi::XmlFileInternal::Creator) ()

Definition at line 57 of file xml_file_internal.hpp.

◆ RegFcn

typedef int(* casadi::PluginInterface< XmlFileInternal >::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

◆ XmlFileInternal()

casadi::XmlFileInternal::XmlFileInternal ( )

Definition at line 30 of file xml_file_internal.cpp.

30  {
31 }

◆ ~XmlFileInternal()

casadi::XmlFileInternal::~XmlFileInternal ( )
override

Definition at line 33 of file xml_file_internal.cpp.

33  {
34 }

Member Function Documentation

◆ class_name()

virtual std::string casadi::SharedObjectInternal::class_name ( ) const
pure virtualinherited

Implemented in casadi::SymbolicQr, casadi::Sqpmethod, casadi::ShellCompiler, casadi::Scpgen, casadi::RungeKutta, casadi::Qrsqp, casadi::Qrqp, casadi::QpToNlp, casadi::Newton, casadi::Lsqr, casadi::LinsolTridiag, casadi::LinsolQr, casadi::LinsolLdl, casadi::LinearInterpolantJac, casadi::LinearInterpolant, casadi::Ipqp, casadi::ImplicitToNlp, casadi::Feasiblesqpmethod, casadi::FastNewton, casadi::Collocation, casadi::BSplineInterpolant, casadi::WorhpInterface, casadi::TinyXmlInterface, casadi::SuperscsInterface, casadi::KinsolInterface, casadi::IdasInterface, casadi::CvodesInterface, casadi::SqicInterface, casadi::SnoptInterface, casadi::SlicotExpm, casadi::SlicotDple, casadi::SLEQPInterface, casadi::QpoasesInterface, casadi::ProxqpInterface, casadi::OsqpInterface, casadi::OoqpInterface, casadi::MumpsInterface, casadi::MadnlpInterface, casadi::LapackQr, casadi::LapackLu, casadi::KnitroInterface, casadi::IpoptInterface, casadi::Ma27Interface, casadi::HpmpcInterface, casadi::HpipmInterface, casadi::HighsInterface, casadi::GurobiInterface, casadi::FatropInterface, casadi::FatropConicInterface, casadi::DaqpInterface, casadi::CsparseInterface, casadi::CSparseCholeskyInterface, casadi::CplexInterface, casadi::ClpInterface, casadi::ClarabelInterface, casadi::ClangCompiler, casadi::CbcInterface, casadi::BonminInterface, casadi::Blocksqp, casadi::AmplInterface, casadi::AlpaqaInterface, casadi::SXFunction, casadi::Switch, casadi::SparsityInternal, casadi::WeakRefInternal, casadi::ZipMemResource, casadi::ZipResource, casadi::DirResource, casadi::OptiNode, casadi::Nlpsol, casadi::MXNode, casadi::MXFunction, casadi::MapSum, casadi::ThreadMap, casadi::OmpMap, casadi::Map, casadi::JitFunction, casadi::Interpolant, casadi::DllLibrary, casadi::ImporterInternal, casadi::GenericTypeInternal< ID, T >, casadi::FmuFunction, casadi::Fmu3, casadi::Fmu2, casadi::Smoothing, casadi::CentralDiff, casadi::BackwardDiff, casadi::ForwardDiff, casadi::External, casadi::DaeBuilderInternal, casadi::CallbackInternal, and casadi::BlazingSplineFunction.

Referenced by casadi::FunctionInternal::call_forward(), casadi::FunctionInternal::call_reverse(), casadi::FunctionInternal::codegen_body(), casadi::ProtoFunction::construct(), casadi::FmuInternal::deserialize(), casadi::ResourceInternal::deserialize(), casadi::FmuInternal::disp(), casadi::FunctionInternal::disp(), casadi::LinsolInternal::disp(), dump(), casadi::FunctionInternal::eval(), casadi::FunctionInternal::eval_dm(), casadi::FunctionInternal::eval_sx(), casadi::FunctionInternal::export_code(), casadi::LinsolInternal::generate(), casadi::FunctionInternal::generate_dependencies(), casadi::Conic::generateNativeCode(), casadi::FmuInternal::get_adjoint_derivative(), casadi::FunctionInternal::get_forward(), casadi::FunctionInternal::get_function(), casadi::FunctionInternal::get_jacobian(), casadi::FunctionInternal::get_reverse(), casadi::FiniteDiff::init(), casadi::FunctionInternal::instruction_constant(), casadi::FunctionInternal::instruction_id(), casadi::FunctionInternal::instruction_input(), casadi::FunctionInternal::instruction_MX(), casadi::FunctionInternal::instruction_output(), casadi::FunctionInternal::instructions_sx(), casadi::LinsolInternal::linsol_eval_sx(), casadi::FunctionInternal::n_instructions(), casadi::FunctionInternal::n_nodes(), casadi::LinsolInternal::neig(), casadi::LinsolInternal::nfact(), casadi::FunctionInternal::oracle(), parse(), casadi::LinsolInternal::rank(), casadi::FmuInternal::serialize_type(), casadi::ResourceInternal::serialize_type(), and casadi::LinsolInternal::solve().

◆ 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()

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

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

Definition at line 121 of file plugin_interface.hpp.

121  {
122  std::string class_name, plugin_name;
123  s.unpack("PluginInterface::plugin_name", plugin_name);
125  return deserialize(s);
126  }
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 &)

◆ 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::XmlFileInternal::disp ( std::ostream &  stream,
bool  more = false 
) const
overridevirtual

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

Implements casadi::SharedObjectInternal.

Definition at line 44 of file xml_file_internal.cpp.

44  {
45 }

◆ dump()

void casadi::XmlFileInternal::dump ( const std::string &  filename,
const XmlNode node 
)
virtual

Reimplemented in casadi::TinyXmlInterface.

Definition at line 52 of file xml_file_internal.cpp.

52  {
53  casadi_error("dump not defined for " + class_name());
54 }
virtual std::string class_name() const =0
Readable name of the internal class.

References casadi::SharedObjectInternal::class_name().

◆ getCount()

Definition at line 60 of file generic_shared_internal.hpp.

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

◆ getPlugin()

PluginInterface< XmlFileInternal >::Plugin & casadi::PluginInterface< XmlFileInternal >::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_plugin()

bool casadi::PluginInterface< XmlFileInternal >::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

◆ 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  }

◆ instantiate()

XmlFileInternal * casadi::PluginInterface< XmlFileInternal >::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.

◆ load_library()

handle_t casadi::PluginInterface< XmlFileInternal >::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  }
std::vector< std::string > get_search_paths()
Definition: casadi_os.cpp:49

◆ load_plugin()

PluginInterface< XmlFileInternal >::Plugin casadi::PluginInterface< XmlFileInternal >::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()

◆ parse()

XmlNode casadi::XmlFileInternal::parse ( const std::string &  filename)
virtual

Reimplemented in casadi::TinyXmlInterface.

Definition at line 47 of file xml_file_internal.cpp.

47  {
48  casadi_error("parse not defined for " + class_name());
49  return XmlNode();
50 }

References casadi::SharedObjectInternal::class_name().

◆ plugin_deserialize()

Deserialize casadi::PluginInterface< XmlFileInternal >::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  }

◆ plugin_name()

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

Implemented in casadi::TinyXmlInterface.

◆ plugin_options()

const Options & casadi::PluginInterface< XmlFileInternal >::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< XmlFileInternal >::Plugin casadi::PluginInterface< XmlFileInternal >::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  }

◆ registerPlugin() [1/2]

void casadi::PluginInterface< XmlFileInternal >::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< XmlFileInternal >::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_type()

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

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

Definition at line 114 of file plugin_interface.hpp.

114  {
115  s.pack("PluginInterface::plugin_name", std::string(plugin_name()));
116  }

◆ 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  }

◆ 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

◆ infix_

const std::string casadi::XmlFileInternal::infix_ = "xmlfile"
static

Definition at line 70 of file xml_file_internal.hpp.

◆ solvers_

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

Definition at line 63 of file xml_file_internal.hpp.


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