ORCA: Optimization-based framework for Robotic Control Applications
ParameterBase.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <orca/utils/Utils.h>
4 
5 namespace orca
6 {
7 namespace common
8 {
13 enum class ParamPolicy
14 {
15  Required = 0
16  , Optional
17 };
22 {
23 public:
24  using Ptr = std::shared_ptr<ParameterBase>;
25 
26  virtual ~ParameterBase() {}
27 
32  bool loadFromString(const std::string& s)
33  {
34  try
35  {
36  if(onLoadFromString(s))
37  {
38  if(on_success_)
39  on_success_();
40  return true;
41  }
42  } catch(std::exception& e) {
43  utils::orca_throw(e.what());
44  }
45 
46  return false;
47  }
48  virtual void print() const = 0;
49  virtual bool isSet() const = 0;
50  const std::string& getName() const { return name_; }
51  void setName(const std::string& name) { name_ = name; }
52  void setRequired(bool is_required) { is_required_ = is_required; }
53  bool isRequired() const { return is_required_; }
57  void onSuccess(std::function<void(void)> f)
58  {
59  on_success_ = f;
60  }
61 protected:
62  virtual bool onLoadFromString(const std::string& s) = 0;
63 private:
64  std::string name_;
65  bool is_required_ = false;
66  std::function<void(void)> on_success_;
67 };
68 
69 } // namespace common
70 } // namespace orca
void onSuccess(std::function< void(void)> f)
The callback called if loadFromString is successful.
Definition: ParameterBase.h:57
const std::string & getName() const
Definition: ParameterBase.h:50
void orca_throw(const std::string &arg)
Definition: Utils.h:153
void setName(const std::string &name)
Definition: ParameterBase.h:51
bool loadFromString(const std::string &s)
Load the parameter from a YAML string It calls a callback on success.
Definition: ParameterBase.h:32
void setRequired(bool is_required)
Definition: ParameterBase.h:52
Definition: CartesianAccelerationPID.h:44
std::shared_ptr< ParameterBase > Ptr
Definition: ParameterBase.h:24
bool isRequired() const
Definition: ParameterBase.h:53
ParameterBase is the public interface to any parameter.
Definition: ParameterBase.h:21
ParamPolicy
The ParamPolicy defines if an error should be thrown when trying to do anything with the task before ...
Definition: ParameterBase.h:13
virtual ~ParameterBase()
Definition: ParameterBase.h:26