GenericLoader.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2019 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
7 #include <mc_rtc/Configuration.h>
8 #include <mc_rtc/logging.h>
9 #include <mc_solver/QPSolver.h>
10 
11 namespace mc_solver
12 {
13 
25 template<typename Derived, typename T>
27 {
29  using T_ptr = std::shared_ptr<T>;
30 
33  using load_fun = std::function<T_ptr(mc_solver::QPSolver &, const mc_rtc::Configuration &)>;
34 
36  using storage_t = std::map<std::string, load_fun>;
37 
43  struct Handle
44  {
45  Handle() = default;
46  Handle(const std::string & type);
47  ~Handle();
48  Handle(const Handle &) = delete;
49  Handle & operator=(const Handle &) = delete;
50  Handle(Handle && h);
51  Handle & operator=(Handle && h);
52 
53  private:
54  std::string type_ = "";
55  };
56 
64  static Handle register_load_function(const std::string & type, load_fun fn);
65 
74  static void unregister_load_function(const std::string & type);
75 
85  static T_ptr load(mc_solver::QPSolver & solver, const std::string & file);
86 
96  static T_ptr load(mc_solver::QPSolver & solver, const char * file);
97 
106  static T_ptr load(mc_solver::QPSolver & solver, const mc_rtc::Configuration & config);
107 
109  template<typename U,
110  typename std::enable_if<(!std::is_same<U, T>::value) && std::is_base_of<T, U>::value, int>::type = 0>
111  static std::shared_ptr<U> load(mc_solver::QPSolver & solver, const std::string & file);
112 
114  template<typename U,
115  typename std::enable_if<(!std::is_same<U, T>::value) && std::is_base_of<T, U>::value, int>::type = 0>
116  static std::shared_ptr<U> load(mc_solver::QPSolver & solver, const char * file);
117 
119  template<typename U,
120  typename std::enable_if<(!std::is_same<U, T>::value) && std::is_base_of<T, U>::value, int>::type = 0>
121  static std::shared_ptr<U> load(mc_solver::QPSolver & solver, const mc_rtc::Configuration & config);
122 
123 private:
124  template<typename U>
125  static std::shared_ptr<U> cast(const T_ptr & p);
126 
127  static storage_t & get_fns();
128 };
129 
130 } // namespace mc_solver
131 
132 #include "GenericLoader.hpp"
mc_rtc::Configuration
Simplify access to values hold within a JSON file.
Definition: Configuration.h:165
mc_solver::GenericLoader< ConstraintSetLoader, ConstraintSet >::T_ptr
std::shared_ptr< ConstraintSet > T_ptr
Definition: GenericLoader.h:29
mc_solver::GenericLoader::Handle
Definition: GenericLoader.h:43
mc_solver::QPSolver
Definition: QPSolver.h:85
mc_solver::GenericLoader
Definition: GenericLoader.h:26
mc_solver::GenericLoader< ConstraintSetLoader, ConstraintSet >::load_fun
std::function< T_ptr(mc_solver::QPSolver &, const mc_rtc::Configuration &)> load_fun
Definition: GenericLoader.h:33
mc_solver::GenericLoader::Handle::operator=
Handle & operator=(const Handle &)=delete
mc_solver::GenericLoader< ConstraintSetLoader, ConstraintSet >::storage_t
std::map< std::string, load_fun > storage_t
Definition: GenericLoader.h:36
mc_solver::GenericLoader::load
static T_ptr load(mc_solver::QPSolver &solver, const std::string &file)
Configuration.h
logging.h
mc_solver
Definition: Contact.h:17
mc_solver::GenericLoader::Handle::Handle
Handle()=default
mc_solver::GenericLoader::Handle::~Handle
~Handle()
mc_solver::GenericLoader::unregister_load_function
static void unregister_load_function(const std::string &type)
mc_solver::GenericLoader::register_load_function
static Handle register_load_function(const std::string &type, load_fun fn)
QPSolver.h