ros2_canopen  master
C++ ROS CANopen Library
word_accessor.hpp
Go to the documentation of this file.
1 #ifndef WORD_ACCESSOR_HPP
2 #define WORD_ACCESSOR_HPP
3 
4 #include <cstdint>
5 
6 namespace ros2_canopen
7 {
8 template <uint16_t MASK>
10 {
11  uint16_t & word_;
12 
13 public:
14  WordAccessor(uint16_t & word) : word_(word) {}
15  bool set(uint8_t bit)
16  {
17  uint16_t val = MASK & (1 << bit);
18  word_ |= val;
19  return val;
20  }
21  bool reset(uint8_t bit)
22  {
23  uint16_t val = MASK & (1 << bit);
24  word_ &= ~val;
25  return val;
26  }
27  bool get(uint8_t bit) const { return word_ & (1 << bit); }
28  uint16_t get() const { return word_ & MASK; }
29  WordAccessor & operator=(const uint16_t & val)
30  {
31  word_ = (word_ & ~MASK) | (val & MASK);
32  return *this;
33  }
34 };
35 } // namespace ros2_canopen
36 
37 #endif // WORD_ACCESSOR_HPP
Definition: word_accessor.hpp:10
bool reset(uint8_t bit)
Definition: word_accessor.hpp:21
WordAccessor(uint16_t &word)
Definition: word_accessor.hpp:14
bool set(uint8_t bit)
Definition: word_accessor.hpp:15
bool get(uint8_t bit) const
Definition: word_accessor.hpp:27
WordAccessor & operator=(const uint16_t &val)
Definition: word_accessor.hpp:29
uint16_t get() const
Definition: word_accessor.hpp:28
Definition: configuration_manager.hpp:28