ros2_control - rolling
Loading...
Searching...
No Matches
handle.hpp
1// Copyright 2020 ros2_control development team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef TRANSMISSION_INTERFACE__HANDLE_HPP_
16#define TRANSMISSION_INTERFACE__HANDLE_HPP_
17
18#include <string>
19#include "hardware_interface/macros.hpp"
20
22{
23class Handle
24{
25public:
26 Handle(
27 const std::string & prefix_name, const std::string & interface_name,
28 double * value_ptr = nullptr)
29 : prefix_name_(prefix_name), interface_name_(interface_name), value_ptr_(value_ptr)
30 {
31 }
32
33 Handle(const Handle & other) = default;
34
35 Handle(Handle && other) = default;
36
37 Handle & operator=(const Handle & other) = default;
38
39 Handle & operator=(Handle && other) = default;
40
41 virtual ~Handle() = default;
42
44 inline operator bool() const { return value_ptr_ != nullptr; }
45
46 const std::string get_name() const { return prefix_name_ + "/" + interface_name_; }
47
48 const std::string & get_interface_name() const { return interface_name_; }
49
50 const std::string & get_prefix_name() const { return prefix_name_; }
51
52 double get_value() const
53 {
54 THROW_ON_NULLPTR(value_ptr_);
55 return *value_ptr_;
56 }
57
58 void set_value(double value)
59 {
60 THROW_ON_NULLPTR(this->value_ptr_);
61 *this->value_ptr_ = value;
62 }
63
64protected:
65 std::string prefix_name_;
66 std::string interface_name_;
67 double * value_ptr_ = nullptr;
68};
69
72{
73public:
74 using transmission_interface::Handle::Handle;
75};
76
79{
80public:
81 using transmission_interface::Handle::Handle;
82};
83
84} // namespace transmission_interface
85
86#endif // TRANSMISSION_INTERFACE__HANDLE_HPP_
Definition handle.hpp:24
Definition handle.hpp:79
Definition accessor.hpp:25