OneWire Library for Arduino  version: 1.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
array.h
Go to the documentation of this file.
1 /******************************************************************/
33 #ifndef OneWire_array
34 #define OneWire_array
35 
36 #include <stdint.h>
37 #include <stddef.h>
38 
39 namespace OneWire
40 {
42  template <typename T, size_t N>
43  class array
44  {
45  public:
47  static const size_t length = N;
48 
50  typedef T Buffer[N];
51 
52  private:
53  Buffer m_buffer;
54 
55  public:
56  const array<T, N> & operator=(const array<T, N> & rhs)
57  {
58  if (this != &rhs)
59  {
60  memcpy(this->m_buffer, rhs.m_buffer, N * sizeof(T));
61  }
62  return rhs;
63  }
64 
65  bool operator==(const array<T, N> & rhs) const
66  {
67  return (memcmp(this->m_buffer, rhs.m_buffer, N * sizeof(T)) == 0);
68  }
69 
70  bool operator!=(const array<T, N> & rhs) const
71  {
72  return !operator==(rhs);
73  }
74 
76  operator Buffer &()
77  {
78  return m_buffer;
79  }
80 
82  operator const Buffer &() const
83  {
84  return m_buffer;
85  }
86 
88 
89  array<T, N>(const array<T, N> & copy)
90  {
91  operator=(copy);
92  }
93 
94  array<T, N>(const Buffer & buffer)
95  {
96  memcpy(m_buffer, buffer, N * sizeof(T));
97  }
98  };
99 }
100 
101 #endif
static const size_t length
Number of elements contained in the array.
Definition: array.h:47
T Buffer[N]
Built-in array representation.
Definition: array.h:50
Definition: DS2484.h:41
const array< T, N > & operator=(const array< T, N > &rhs)
Definition: array.h:56
bool operator==(const array< T, N > &rhs) const
Definition: array.h:65
Generic array class similar to std::array.
Definition: array.h:43
bool operator!=(const array< T, N > &rhs) const
Definition: array.h:70