uTL
micro Template library
_1wire_id.h
Go to the documentation of this file.
1 
21 #ifndef __utl_com_1wire_id_h__
22 #define __utl_com_1wire_id_h__
23 
24 #include <utl/core/impl.h>
25 #include <utl/container/id.h>
26 
27 namespace utl {
28 
32  class _1wire_id_t : public id_t<uint8_t, 8> {
33 
37  public:
39  _1wire_id_t () noexcept
40  : id_t<uint8_t, 8> {0, 0, 0, 0, 0, 0, 0, 0} { }
41  _1wire_id_t (const _1wire_id_t& id) noexcept {
42  std::copy(id.begin(), id.end(), this->begin());
43  }
45 
48  static constexpr const _1wire_id_t& nullDev () { return nullDev_; }
51 
54  uint8_t& family() noexcept { return front(); }
55  const uint8_t& family() const noexcept { return front(); }
57 
60  uint8_t& crc8() noexcept { return back(); }
61  const uint8_t& crc8() const noexcept { return back(); }
63 
72  static int compare (const _1wire_id_t& lhs, const _1wire_id_t& rhs) noexcept {
73  auto p = std::mismatch (lhs.rbegin(), lhs.rend(), rhs.rbegin());
74  if (p.first == lhs.rend()) return 0;
75  else if (*p.first < *p.second) return -1;
76  else return 1;
77  }
79 
82  private:
83  static const _1wire_id_t nullDev_;
85  };
86 
87  // Init static member
89 
90 } // namespace tbx
91 
92 #endif /* __utl_com_1wire_id_h__ */
reference back() noexcept
Definition: id.h:184
iterator end() noexcept
Definition: id.h:109
_1wire_id_t(const _1wire_id_t &id) noexcept
Definition: _1wire_id.h:41
static int compare(const _1wire_id_t &lhs, const _1wire_id_t &rhs) noexcept
Full compare two dev_ids.
Definition: _1wire_id.h:72
reference front() noexcept
Definition: id.h:176
uint8_t & crc8() noexcept
Definition: _1wire_id.h:60
A container for device IDs.
uint8_t & family() noexcept
Definition: _1wire_id.h:54
const uint8_t & family() const noexcept
Definition: _1wire_id.h:55
const uint8_t & crc8() const noexcept
Definition: _1wire_id.h:61
STL&#39;s core language concepts.
Definition: _1wire.h:30
static const _1wire_id_t nullDev_
Definition: _1wire_id.h:83
A standard container for storing IDs as a fixed size sequence of bytes. This type is based on etl::ar...
Definition: id.h:78
static constexpr const _1wire_id_t & nullDev()
Return nullDev reference.
Definition: _1wire_id.h:50
_1wire_id_t() noexcept
Definition: _1wire_id.h:39
iterator begin() noexcept
Definition: id.h:107
Implementation detail main forward header.