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
mc_control::fsm::StateFactory::StateConfiguration::config
mc_rtc::Configuration config
Definition: StateFactory.h:126
mc_rtc::Configuration
Simplify access to values hold within a JSON file.
Definition: Configuration.h:165
mc_control::fsm::StateFactory::configuration
const StateConfiguration & configuration(const std::string &state) const
Definition: StateFactory.h:130
MC_CONTROL_FSM_DLLAPI
#define MC_CONTROL_FSM_DLLAPI
Definition: api.h:50
mc_rtc::ObjectLoader
ltdl wrapper for factory-like classes
Definition: loader.h:37
mc_control::fsm::StateFactory::StateConfiguration::arg
std::string arg
Definition: StateFactory.h:124
mc_control::fsm::StateFactory
Definition: StateFactory.h:32
mc_control::fsm::Controller
struct MC_CONTROL_FSM_DLLAPI Controller
Definition: State.h:23
mc_control::fsm::StateFactory::StateConfiguration::base
std::string base
Definition: StateFactory.h:122
mc_control::fsm::StateFactory::StateConfiguration
Definition: StateFactory.h:119
loader.h
ltdl wrapper for mc_rtc purpose
mc_rtc::Configuration
struct MC_RTC_UTILS_DLLAPI Configuration
Definition: Configuration.h:46
mc_control
Definition: CompletionCriteria.h:10
State.h
mc_rtc::ObjectLoader::register_object
void register_object(const std::string &name, std::function< RetT *(const Args &...)> callback)
mc_control::fsm::StatePtr
std::shared_ptr< State > StatePtr
Definition: State.h:172
mc_control::fsm::Controller
Definition: Controller.h:49
mc_rtc
Definition: Contact.h:87
mc_control::fsm::StateFactory::register_object
void register_object(const std::string &name, std::function< RetT *(const Args &...)> callback)
Definition: StateFactory.h:112