2015-11-03 02:34:27 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2015 F4EXB //
|
|
|
|
// written by Edouard Griffiths //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
2019-04-11 08:32:15 -04:00
|
|
|
// (at your option) any later version. //
|
2015-11-03 02:34:27 -05:00
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _UTIL_BITFIELDINDEX_H_
|
|
|
|
#define _UTIL_BITFIELDINDEX_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
template <unsigned int size>
|
2017-05-05 04:40:45 -04:00
|
|
|
struct BitfieldIndex
|
2015-11-03 02:34:27 -05:00
|
|
|
{
|
|
|
|
uint32_t v : size;
|
2017-05-05 04:40:45 -04:00
|
|
|
|
|
|
|
BitfieldIndex() : v(0) {}
|
2015-11-03 02:34:27 -05:00
|
|
|
BitfieldIndex(int i) { v = i; }
|
2017-05-05 04:40:45 -04:00
|
|
|
|
2015-11-03 02:34:27 -05:00
|
|
|
BitfieldIndex& operator=(const BitfieldIndex& rhs) { v = rhs.v; return *this; }
|
|
|
|
BitfieldIndex& operator=(const int& rhi) { v = rhi; return *this; }
|
|
|
|
BitfieldIndex& operator++() { v++; return *this; }
|
|
|
|
BitfieldIndex operator++(int) { BitfieldIndex x(*this); ++(*this); return x; }
|
2017-05-05 04:40:45 -04:00
|
|
|
BitfieldIndex& operator+=(const BitfieldIndex& b) { v += b.v; return *this; }
|
2015-11-03 02:34:27 -05:00
|
|
|
BitfieldIndex& operator-=(const BitfieldIndex& b) { v -= b.v; return *this; }
|
2017-05-05 04:40:45 -04:00
|
|
|
BitfieldIndex& operator+=(int i) { v += i; return *this; }
|
2015-11-03 02:34:27 -05:00
|
|
|
BitfieldIndex& operator-=(int i) { v -= i; return *this; }
|
2017-05-05 04:40:45 -04:00
|
|
|
BitfieldIndex operator+(const BitfieldIndex& b) const { BitfieldIndex x(*this); x.v += b.v; return x; }
|
|
|
|
BitfieldIndex operator-(const BitfieldIndex& b) const { BitfieldIndex x(*this); x.v -= b.v; return x; }
|
|
|
|
BitfieldIndex operator+(int i) const { BitfieldIndex x(*this); x.v += i; return x; }
|
|
|
|
BitfieldIndex operator-(int i) const { BitfieldIndex x(*this); x.v -= i; return x; }
|
2015-11-03 02:34:27 -05:00
|
|
|
|
|
|
|
operator int() const { return v; }
|
|
|
|
};
|
|
|
|
|
|
|
|
template <unsigned int size>
|
2018-03-03 19:47:51 -05:00
|
|
|
BitfieldIndex<size> operator+(const BitfieldIndex<size> &a, const BitfieldIndex<size> &b)
|
|
|
|
{
|
|
|
|
BitfieldIndex<size> x;
|
|
|
|
x.v = a.v + b.v;
|
|
|
|
return x;
|
|
|
|
}
|
2017-05-05 04:40:45 -04:00
|
|
|
|
2015-11-03 02:34:27 -05:00
|
|
|
template <unsigned int size>
|
2018-03-03 19:47:51 -05:00
|
|
|
BitfieldIndex<size> operator-(const BitfieldIndex<size> &a, const BitfieldIndex<size> &b)
|
|
|
|
{
|
|
|
|
BitfieldIndex<size> x;
|
|
|
|
x.v = a.v - b.v;
|
|
|
|
return x;
|
|
|
|
}
|
2015-11-03 02:34:27 -05:00
|
|
|
|
|
|
|
#endif // _UTIL_BITFIELDINDEX_H_
|