StateFactory.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_control/fsm/State.h>
8 #include <mc_rtc/loader.h>
9 
10 #include <unordered_map>
11 
12 namespace mc_rtc
13 {
14 struct Configuration;
15 }
16 
17 namespace mc_control
18 {
19 
20 namespace fsm
21 {
22 
24 
33 {
42  StateFactory(const std::vector<std::string> & paths, const std::vector<std::string> & files, bool verbose);
43 
45  void load_libraries(const std::vector<std::string> & paths);
46 
48  void load_files(const std::vector<std::string> & files);
49 
51  void load(const std::map<std::string, mc_rtc::Configuration> & states);
52 
64  void load(const std::string & name, const std::string & base, const mc_rtc::Configuration & config);
65 
73  StatePtr create(const std::string & state, Controller & ctl, const mc_rtc::Configuration & config);
74 
76  StatePtr create(const std::string & state, Controller & ctl);
77 
83  StatePtr create(const std::string & state, const mc_rtc::Configuration & config);
84 
90  StatePtr create(const std::string & state);
91 
93  bool hasState(const std::string & state) const;
94 
96  const std::vector<std::string> & states() const;
97 
99  bool load_with_loader(const std::string & state);
100 
111  template<typename RetT, typename... Args>
112  void register_object(const std::string & name, std::function<RetT *(const Args &...)> callback)
113  {
115  states_.push_back(name);
116  }
117 
120  {
122  std::string base;
124  std::string arg;
127  };
128 
130  inline const StateConfiguration & configuration(const std::string & state) const
131  {
132  return states_configurations_.at(state);
133  }
134 
135 private:
137  StatePtr create(const std::string & state, const std::string & final_name);
138 
140  StatePtr create(const std::string & state,
141  Controller & ctl,
142  bool configure,
143  const mc_rtc::Configuration & config = {});
145  void update(const std::string & cn);
146 
147 private:
148  std::vector<std::string> states_;
149  std::unordered_map<std::string, StateConfiguration> states_configurations_;
150 };
151 
152 } // namespace fsm
153 
154 } // namespace mc_control
#define MC_CONTROL_FSM_DLLAPI
Definition: api.h:50
ltdl wrapper for mc_rtc purpose
struct MC_CONTROL_FSM_DLLAPI Controller
Definition: State.h:23
std::shared_ptr< State > StatePtr
Definition: State.h:172
Definition: CompletionCriteria.h:11
Definition: Contact.h:88
struct MC_RTC_UTILS_DLLAPI Configuration
Definition: Configuration.h:46
Definition: Controller.h:50
mc_rtc::Configuration config
Definition: StateFactory.h:126
std::string base
Definition: StateFactory.h:122
std::string arg
Definition: StateFactory.h:124
Definition: StateFactory.h:33
void load_libraries(const std::vector< std::string > &paths)
bool hasState(const std::string &state) const
bool load_with_loader(const std::string &state)
StatePtr create(const std::string &state)
StatePtr create(const std::string &state, Controller &ctl, const mc_rtc::Configuration &config)
void register_object(const std::string &name, std::function< RetT *(const Args &...)> callback)
Definition: StateFactory.h:112
const std::vector< std::string > & states() const
void load_files(const std::vector< std::string > &files)
StateFactory(const std::vector< std::string > &paths, const std::vector< std::string > &files, bool verbose)
const StateConfiguration & configuration(const std::string &state) const
Definition: StateFactory.h:130
StatePtr create(const std::string &state, Controller &ctl)
void load(const std::string &name, const std::string &base, const mc_rtc::Configuration &config)
StatePtr create(const std::string &state, const mc_rtc::Configuration &config)
void load(const std::map< std::string, mc_rtc::Configuration > &states)
Simplify access to values hold within a JSON file.
Definition: Configuration.h:166
ltdl wrapper for factory-like classes
Definition: loader.h:187
void register_object(const std::string &name, std::function< RetT *(const Args &...)> callback)