1-Wire® library for mbed. Complete 1-Wire library that supports our silicon masters along with a bit-bang master on the MAX32600MBED platform with one common interface for mbed. Slave support has also been included and more slaves will be added as time permits.
Dependents: MAXREFDES131_Qt_Demo MAX32630FTHR_iButton_uSD_Logger MAX32630FTHR_DS18B20_uSD_Logger MAXREFDES130_131_Demo ... more
array.h
00001 /******************************************************************//** 00002 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00020 * OTHER DEALINGS IN THE SOFTWARE. 00021 * 00022 * Except as contained in this notice, the name of Maxim Integrated 00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00024 * Products, Inc. Branding Policy. 00025 * 00026 * The mere transfer of this software does not imply any licenses 00027 * of trade secrets, proprietary technology, copyrights, patents, 00028 * trademarks, maskwork rights, or any other form of intellectual 00029 * property whatsoever. Maxim Integrated Products, Inc. retains all 00030 * ownership rights. 00031 **********************************************************************/ 00032 00033 #ifndef OneWire_array 00034 #define OneWire_array 00035 00036 #include <stdint.h> 00037 #include <stddef.h> 00038 #include <iterator> 00039 #include <algorithm> 00040 #include <cstring> 00041 00042 namespace OneWire 00043 { 00044 /// Generic array class similar to std::array. 00045 template <typename T, size_t N> 00046 class array 00047 { 00048 public: 00049 typedef T value_type; 00050 typedef size_t size_type; 00051 typedef ptrdiff_t difference_type; 00052 typedef value_type & reference; 00053 typedef const value_type & const_reference; 00054 typedef value_type * pointer; 00055 typedef const value_type * const_pointer; 00056 typedef pointer iterator; 00057 typedef const_pointer const_iterator; 00058 typedef std::reverse_iterator<iterator> reverse_iterator; 00059 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 00060 00061 // Element access 00062 reference operator[](size_t pos) { return _buffer[pos]; } 00063 const_reference operator[](size_t pos) const { return _buffer[pos]; } 00064 reference front() { return const_cast<reference>(static_cast<const array<T, N> &>(*this).front()); } 00065 const_reference front() const { return _buffer[0]; } 00066 reference back() { return const_cast<reference>(static_cast<const array<T, N> &>(*this).back()); } 00067 const_reference back() const { return _buffer[N - 1]; } 00068 T * data() { return const_cast<T *>(static_cast<const array<T, N> &>(*this).data()); } 00069 const T * data() const { return _buffer; } 00070 00071 // Iterators 00072 iterator begin() { return const_cast<iterator>(static_cast<const array<T, N> &>(*this).begin()); } 00073 const_iterator begin() const { return cbegin(); } 00074 const_iterator cbegin() const { return &front(); } 00075 iterator end() { return const_cast<iterator>(static_cast<const array<T, N> &>(*this).end()); } 00076 const_iterator end() const { return cend(); } 00077 const_iterator cend() const { return &_buffer[N]; } 00078 reverse_iterator rbegin() { return reverse_iterator(&back()); } 00079 const_reverse_iterator rbegin() const { return crbegin(); } 00080 const_reverse_iterator crbegin() const { return const_reverse_iterator(&back()); } 00081 reverse_iterator rend() { return reverse_iterator(--begin()); } 00082 const_reverse_iterator rend() const { return crend(); } 00083 const_reverse_iterator crend() const { return const_reverse_iterator(--begin()); } 00084 00085 // Capacity 00086 static bool empty() { return size() == 0; } 00087 static size_type size() { return N; } 00088 static size_type max_size() { return size(); } 00089 static const size_type csize = N; ///< Alternative to size() when a constant expression is required. 00090 00091 // Operations 00092 void fill(const T & value) { std::fill(begin(), end(), value); } 00093 00094 bool operator==(const array<T, N> & rhs) const { return (std::memcmp(this->_buffer, rhs._buffer, N * sizeof(T)) == 0); } 00095 bool operator!=(const array<T, N> & rhs) const { return !operator==(rhs); } 00096 00097 T _buffer[N]; 00098 }; 00099 } 00100 00101 #endif
Generated on Tue Jul 12 2022 15:46:20 by 1.7.2