SkillWithContextBlueprint.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package RobotAPI
17  * @author Christoph Pohl ( christoph dot pohl at kit dot edu )
18  * @date 05.12.23
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
26 
27 namespace armarx
28 {
29  namespace skills
30  {
31 // template <typename T>
32 // concept takesContext = requires(typename T::Context cntxt) {
33 // { T::connectTo(cntxt) } -> void;
34 // };
35 
36 
37  template <typename SkillT>
39  {
40  public:
41  using ContextT = typename SkillT::Context;
42 
43  template <typename... Args>
44  SkillWithContextBlueprint(Args&&... args) :
45  SkillBlueprint(*SkillBlueprint::ForSkill<SkillT>(std::forward<Args>(args)...))
46  {
47  }
48 
49  virtual std::unique_ptr<Skill>
50  createSkill(const ProviderID& pid) const override
51  {
52  if (not isConnected_)
53  {
54  return nullptr;
55  }
56  auto s = _createSkill();
57  s->setProviderId(pid);
58  static_cast<SkillT*>(s.get())->connectTo(context_);
59  return s;
60  }
61 
62  virtual SkillDescription
64  {
65  auto s = _createSkill();
66  s->setProviderId(pid);
67  return s->getSkillDescription();
68  }
69 
70  void
71  connectTo(const ContextT& context)
72  {
73  context_ = context;
74  isConnected_ = true;
75  }
76 
77  private:
78  std::atomic_bool isConnected_ = false;
79  ContextT context_;
80  };
81  } // namespace skills
82 } // namespace armarx
armarx::skills::SkillWithContextBlueprint::createSkill
virtual std::unique_ptr< Skill > createSkill(const ProviderID &pid) const override
Definition: SkillWithContextBlueprint.h:50
skills
This file is part of ArmarX.
armarx::skills::SkillDescription
Definition: SkillDescription.h:18
SkillFactory.h
armarx::skills::SkillWithContextBlueprint
Definition: SkillWithContextBlueprint.h:38
armarx::skills::ProviderID
Definition: ProviderID.h:15
armarx::skills::SkillWithContextBlueprint::connectTo
void connectTo(const ContextT &context)
Definition: SkillWithContextBlueprint.h:71
armarx::skills::SkillBlueprint::ForSkill
requires static isSkill< _Skill > std::unique_ptr< SkillBlueprint > ForSkill(Args &&... args)
Definition: SkillFactory.h:32
armarx::skills::SkillBlueprint::_createSkill
FunctionTypeToCreateSkill _createSkill
Definition: SkillFactory.h:61
armarx::skills::SkillBlueprint
Definition: SkillFactory.h:11
armarx::skills::SkillWithContextBlueprint::SkillWithContextBlueprint
SkillWithContextBlueprint(Args &&... args)
Definition: SkillWithContextBlueprint.h:44
std
Definition: Application.h:66
armarx::skills::SkillWithContextBlueprint::ContextT
typename SkillT::Context ContextT
Definition: SkillWithContextBlueprint.h:41
armarx::skills::SkillWithContextBlueprint::createSkillDescription
virtual SkillDescription createSkillDescription(const skills::ProviderID &pid) const
Definition: SkillWithContextBlueprint.h:63
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28