mc_solver::GenericLoader< Derived, T > Struct Template Reference

#include <mc_solver/GenericLoader.h>

Classes

struct  Handle
 

Public Types

using T_ptr = std::shared_ptr< T >
 
using load_fun = std::function< T_ptr(mc_solver::QPSolver &, const mc_rtc::Configuration &)>
 
using storage_t = std::map< std::string, load_fun >
 

Static Public Member Functions

static Handle register_load_function (const std::string &type, load_fun fn)
 
static void unregister_load_function (const std::string &type)
 
static T_ptr load (mc_solver::QPSolver &solver, const std::string &file)
 
static T_ptr load (mc_solver::QPSolver &solver, const char *file)
 
static T_ptr load (mc_solver::QPSolver &solver, const mc_rtc::Configuration &config)
 
template<typename U , typename std::enable_if<(!std::is_same< U, T >::value) &&std::is_base_of< T, U >::value, int >::type = 0>
static std::shared_ptr< U > load (mc_solver::QPSolver &solver, const std::string &file)
 
template<typename U , typename std::enable_if<(!std::is_same< U, T >::value) &&std::is_base_of< T, U >::value, int >::type = 0>
static std::shared_ptr< U > load (mc_solver::QPSolver &solver, const char *file)
 
template<typename U , typename std::enable_if<(!std::is_same< U, T >::value) &&std::is_base_of< T, U >::value, int >::type = 0>
static std::shared_ptr< U > load (mc_solver::QPSolver &solver, const mc_rtc::Configuration &config)
 

Detailed Description

template<typename Derived, typename T>
struct mc_solver::GenericLoader< Derived, T >

Retrieve an object using a JSON configuration object and a solver instance

Other objects can register new types that can be loaded through such an interface. If you are writing a new mc_tasks::MetaTask or mc_solver::ConstraintSet you will probably register through mc_tasks::MetaTaskLoader and mc_solver::ConstraintSetLoader respectively.

The CRTP is used to provide an ODR-resilient storage here.

Member Typedef Documentation

◆ load_fun

template<typename Derived , typename T >
using mc_solver::GenericLoader< Derived, T >::load_fun = std::function<T_ptr(mc_solver::QPSolver &, const mc_rtc::Configuration &)>

A function that is able to load a T object through a solver instance and JSON configuration

◆ storage_t

template<typename Derived , typename T >
using mc_solver::GenericLoader< Derived, T >::storage_t = std::map<std::string, load_fun>

Storage type, actual storage location is returned by Derived::storage()

◆ T_ptr

template<typename Derived , typename T >
using mc_solver::GenericLoader< Derived, T >::T_ptr = std::shared_ptr<T>

shared_ptr to T

Member Function Documentation

◆ load() [1/6]

template<typename Derived , typename T >
static T_ptr mc_solver::GenericLoader< Derived, T >::load ( mc_solver::QPSolver solver,
const char *  file 
)
static

Load an object from a file (C-style string)

Parameters
solverSolver to create the object for
fileFile to load the object from
Exceptions
Ifthe file does not exist or the loaded JSON object does not represent a known object

◆ load() [2/6]

template<typename Derived , typename T >
template<typename U , typename std::enable_if<(!std::is_same< U, T >::value) &&std::is_base_of< T, U >::value, int >::type = 0>
static std::shared_ptr<U> mc_solver::GenericLoader< Derived, T >::load ( mc_solver::QPSolver solver,
const char *  file 
)
static

Retrieve a more precise object's type from a file (C-style string)

◆ load() [3/6]

template<typename Derived , typename T >
static T_ptr mc_solver::GenericLoader< Derived, T >::load ( mc_solver::QPSolver solver,
const mc_rtc::Configuration config 
)
static

Load an object from an mc_rtc::Configuration object

Parameters
solverSolver to create the object for
configConfiguration to load the object from
Exceptions
Ifthe loaded JSON object does not represent a known object

◆ load() [4/6]

template<typename Derived , typename T >
template<typename U , typename std::enable_if<(!std::is_same< U, T >::value) &&std::is_base_of< T, U >::value, int >::type = 0>
static std::shared_ptr<U> mc_solver::GenericLoader< Derived, T >::load ( mc_solver::QPSolver solver,
const mc_rtc::Configuration config 
)
static

Retrieve a more precise object's type from a Configuration entry

◆ load() [5/6]

template<typename Derived , typename T >
static T_ptr mc_solver::GenericLoader< Derived, T >::load ( mc_solver::QPSolver solver,
const std::string &  file 
)
static

Load an object from a file

Parameters
solverSolver to create the object for
fileFile to load the object from
Exceptions
Ifthe file does not exist or the loaded JSON object does not represent a known object

◆ load() [6/6]

template<typename Derived , typename T >
template<typename U , typename std::enable_if<(!std::is_same< U, T >::value) &&std::is_base_of< T, U >::value, int >::type = 0>
static std::shared_ptr<U> mc_solver::GenericLoader< Derived, T >::load ( mc_solver::QPSolver solver,
const std::string &  file 
)
static

Retrieve a more precise object's type from a file

◆ register_load_function()

template<typename Derived , typename T >
static Handle mc_solver::GenericLoader< Derived, T >::register_load_function ( const std::string &  type,
load_fun  fn 
)
static

Register a new loading function

Parameters
typeType of the object this function handles. It should match the "type" entry of the expected JSON objects
fnFunction that will be registered

◆ unregister_load_function()

template<typename Derived , typename T >
static void mc_solver::GenericLoader< Derived, T >::unregister_load_function ( const std::string &  type)
static

Remove a registered loading function

This is mostly called automatically by the handle returned by register_load_function

Parameters
typeType of the object to un-register

The documentation for this struct was generated from the following file: