Device interface library for multiple platforms including Mbed.
Dependents: DeepCover Embedded Security in IoT MaximInterface MAXREFDES155#
Maxim Interface is a library framework focused on providing flexible and expressive hardware interfaces. Both communication interfaces such as I2C and 1-Wire and device interfaces such as DS18B20 are supported. Modern C++ concepts are used extensively while keeping compatibility with C++98/C++03 and requiring no external dependencies. The embedded-friendly design does not depend on exceptions or RTTI.
The full version of the project is hosted on GitLab: https://gitlab.com/iabenz/MaximInterface
Diff: Utilities/array.hpp
- Revision:
- 5:a8c83a2e6fa4
- Parent:
- 0:f77ad7f72d04
- Child:
- 6:471901a04573
--- a/Utilities/array.hpp Fri Jan 19 10:25:02 2018 -0600 +++ b/Utilities/array.hpp Wed Jan 23 13:11:04 2019 -0600 @@ -55,58 +55,90 @@ typedef std::reverse_iterator<iterator> reverse_iterator; typedef std::reverse_iterator<const_iterator> const_reverse_iterator; - // Element access + /// @name Element access + /// @{ reference operator[](size_type pos) { return const_cast<reference>( static_cast<const array &>(*this).operator[](pos)); } - const_reference operator[](size_type pos) const { return _buffer[pos]; } + + const_reference operator[](size_type pos) const { return data()[pos]; } + reference front() { return const_cast<reference>(static_cast<const array &>(*this).front()); } - const_reference front() const { return _buffer[0]; } + + const_reference front() const { return operator[](0); } + reference back() { return const_cast<reference>(static_cast<const array &>(*this).back()); } - const_reference back() const { return _buffer[size() - 1]; } + + const_reference back() const { return operator[](size() - 1); } + pointer data() { return const_cast<pointer>(static_cast<const array &>(*this).data()); } + const_pointer data() const { return _buffer; } + /// @} - // Iterators + /// @name Iterators + /// @{ iterator begin() { return const_cast<iterator>(static_cast<const array &>(*this).cbegin()); } + const_iterator begin() const { return cbegin(); } - const_iterator cbegin() const { return _buffer; } + + const_iterator cbegin() const { return data(); } + iterator end() { return const_cast<iterator>(static_cast<const array &>(*this).cend()); } + const_iterator end() const { return cend(); } - const_iterator cend() const { return _buffer + size(); } + + const_iterator cend() const { return cbegin() + size(); } + reverse_iterator rbegin() { return reverse_iterator(end()); } + const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } + const_reverse_iterator crbegin() const { return rbegin(); } + reverse_iterator rend() { return reverse_iterator(begin()); } + const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } + const_reverse_iterator crend() const { return rend(); } + /// @} - // Capacity + /// @name Capacity + /// @{ static bool empty() { return size() == 0; } + static size_type size() { return N; } + static size_type max_size() { return size(); } - static const size_type csize = - N; ///< Alternative to size() when a constant expression is required. + + /// Alternative to size() when a constant expression is required. + static const size_type csize = N; + /// @} - // Operations + /// @name Operations + /// @{ void fill(const_reference value) { std::fill(begin(), end(), value); } + void swap(array & other) { std::swap_ranges(begin(), end(), other.begin()); } + /// @} + /// @private + /// Implementation detail set public to allow aggregate initialization. T _buffer[N]; };